Theoretical Computer Science 346 (2005) 183 www.elsevier.com/locate/tcs
Preface With the publication of this special issue the community of Theoretical Computer Science aims at commemorating the sudden and unexpected death of Prof. Alberto Del Lungo, on 1st June, 2003. This volume contains a biographical contribution, written by the Guest Editors, and a collection of 15 invited papers, referred at the usual high level journal standard. The scientific contributions range, mainly, but not exclusively in the areas of Alberto’s research interests: enumeration of combinatorial objects, random and exhaustive generation of combinatorial objects, algebraic and bijective combinatorics, discrete tomography, discrete geometry and topology, computational complexity, tilings and patterns, combinatorial mathematical biology. As Guest Editors we would like to thank the authors who contributed to the issue, and the referees for their careful and invaluable work. Special thanks are due Andrea Frosini, in preparing the final version of this issue, and to the Editor in Chief of Theoretical Computer Science—A, Prof. Giorgio Ausiello for the help and advice he gave us through all the steps necessary to the preparation of this volume. Elisa Pergola Dipartimento di Sistemi e Informatica Universita di Firenze, Viale Mrgagni, 65 50134 Firenze, Italy E-mail address:
[email protected]fi.it Simone Rinaldi Dipartimento di Scienze Matematiche ed Informatiche ‘‘R.Magari’’ Universita di Siena, Pian dei Mantellini 44 53100 Siena, Italy E-mail address:
[email protected]
0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.022
Theoretical Computer Science 346 (2005) 184 – 188 www.elsevier.com/locate/tcs
Editorial
In memoriam: Alberto Del Lungo (1965–2003) Monimentis, quae consecravit sapientia, vetustas nocere non potest, nulla abolebit aetas nulla deminuet (Seneca, De brev. vit., 15,4) Caro Alberto, ............ How often we have written these two words at the beginning of our conversations dealing with the most varied subjects: from our own daily routines to organization problems and above all scientific matters. These are the very words we have decided to start this book with, as this volume is dedicated to you. Alberto del Lungo was born in Pelago (Florence) on July 8th, 1965. He grew up in the tranquillity of the surrounding countryside, living his happy childhood in the serene atmosphere provided by his loving family which supported him throughout his school years. In 1984 he took a secondary-school diploma in Engineering at the Istituto Tecnico Industriale (technical school) “Leonardo da Vinci” in Florence and in 1992 he graduated at the University of Florence with a degree in Mathematics. Alberto’s degree thesis brought him closer to Professor Renzo Pinzani, with whom he immediately established a strong relationship based on mutual respect and esteem. In 1993 Alberto began studying for his research doctorate in Automation and Information Technology at the Department of Systems Analysis and Computer Science (DSI) of the University of Florence together with the research team headed by Professor Pinzani, finally getting his PhD in 1995. In the month of February of the following year, Alberto starts working as a researcher at the Faculty of Natural, Physical and Mathematical Sciences, where he tirelessly keeps on doing research and cooperating with an increasing number of scientists and colleagues no matter the additional teaching and bureaucratic activities deriving from his new position. In 1999 Alberto married Marina Giordano in a small church, in the countryside near his hometown. Marina had become his ever-present companion since the very first time they met, as she was always ready to support and encourage him at any time in their life as a married couple. On the other hand Alberto himself “could not even think of his life without Marina”. In 1998 Alberto left DSI to join the Department of Mathematics and Computer Science of the University of Siena where he was appointed associate professor at the Faculty of Natural, Physical and Mathematical Science. Although the new environment initially worried him, Alberto soon recovered his self-confidence, thus perfectly integrating with the new
0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.021
Editorial / Theoretical Computer Science 346 (2005) 184 – 188
185
department where he became a central point of reference both for his own colleagues and for the other workers of the faculty and of the entire university, who turned to him for advice not only in scientific matters but also in case of organization problems. Alberto divided his energies between his research activity, publishing activity for TCS (Series A) (indeed he had become part of the Editorial Board in 2000), the development of the university course in Computer Science in Siena, and the setting up of a master in bioinformatics, which still carries his name. In December 2002 Alberto was appointed tenured professor at the Faculty of Natural, Physical and Mathematical Science of the University of Siena. Alberto had now realized his dream, and it was a remarkable achievement which rewarded him for his hard and brilliant work and for all the energies he had devoted to his career. Alberto’s renewed enthusiasm led to intense and fruitful research activities and to the cooperation with an increasing number of scientists both at national and international level. Alberto died on June 1st, 2003 of a heart attack. The book on bioinformatics he had been reading the night before was still on his bed-side table, together with a plane ticket for Paris, where he should have flown on a mission the following day. The incredulity of Alberto’s relatives, friends and colleagues following his untimely death was soon replaced by the bitter awareness of the gap he had left in their hearts, which nobody could ever fill again. At Alberto’s funeral in the main church in his hometown, Professor Maurice Nivat suggested publishing a special issue of TCS-A dedicated to Alberto Del Lungo. Professor Giorgio Ausiello, editor in chief of TCS-A, reacted enthusiastically to this suggestion and supported the publication of this volume, as during his short period of cooperation with Alberto, Professor Ausiello had already begun to appreciate his great qualities. Alberto’s brilliant career is characterized by a remarkable scientific activity. Alberto’s interest in combinatorial analysis started in 1991, when he started working on his degree thesis on “Algorithms for the Generation of Directed Animals”, which laid the foundations of the ECO method. ECO is a constructive method to produce all the objects of a given class, according to the growth of a certain parameter (the size) of the objects. Basically, the idea is to perform local expansions on each object of size n, thus constructing a set of objects of the successive size. This construction should induce a partition of all the objects of any given size (that is, all the objects of a given size are produced exactly once from the objects of immediately lower size, thorough the ECO construction). If an ECO construction is sufficiently regular, then it is often possible to describe it using a succession rule, and to define those functional equations which comply with the multi-varied generating function of the class of these same objects, taking into consideration different enumeration parameters. Alberto’s doctorate gave excellent results, resulting from his fruitful cooperation with the research team he worked with at DSI as well as with a great number of international scientific connections. Professor Pinzani enthusiastically encouraged Alberto to carry out research in new sectors with tireless energy while, the reflexive attitude of Professor Elena Barcucci helped him express his original results with a rigorous and thorough method. While working at DSI, Alberto also dealt with enumerating combinatorial analysis and random generation of combinatorial structures. The ECO method was formalized and applied to a great number of combinatorial structures [5]. In order to meet the demands voiced by the scientific community, he also studied permutations with forbidden patterns, enumerating, through different parameters, classes of parameterized excluded-pattern permutations, thus developing a general method to study some permutations characterized by excluded patterns
186
Editorial / Theoretical Computer Science 346 (2005) 184 – 188
of increasing length [7,8]. The potential of the ECO method is also analyzed bijectively as studied in [6] and used as a general instrument to obtain the random generation of objects [1]. “He was my best student. . .” These few words uttered by Professor Renzo Pinzani simply account for such remarkable and diversified achievements and make it clear how difficult it is to meet such an exceptional person as Alberto, endowed with a rare mixture of good qualities, including intelligence, obstinacy, strength, understanding, fancy, and concreteness. . . On his turn Alberto himself used to say the following sentence: “Renzo?!. . . how could you ever quarrel with him. . .” Indeed Alberto and Renzo often argued about political matters concerning the university as well as about other scientific issues. Every discussion helped Alberto grow in different ways and this fact, together with the great affection, esteem and trust that bounded Alberto to Renzo contributed to the ensuing steady and strong relationship which linked them, untouched by time or distance, even when Alberto was in Siena and could not simply knock on Renzo’s door every morning to discuss about the latest news. During one of his frequent trips to France, Professor Jean-Guy Penaud of LaBRI (Laboratoire Bordelais de Recherche Informatique) presented to Alberto the problem of giving a bijective proof of the enumerative formula regarding non-separable rooted planar maps, which had been determined analytically by Tutte. After a few days of drawing and writing formulas on the blackboard, Alberto solves the problems, coming up with a bijection between non-separable rooted planar maps and left ternary trees, that is to say ternary trees that are designed so as to grow exclusively on their left side, as determined by straight vertical line passing through its root [11]. Such work greatly influenced the following studies on planar maps as far as both their random generation and their enumeration are concerned. At a seminar held at the Dipartimento di Sistemi e Informatica di Firenze, on September 1992, Alberto met Professor Maurice Nivat, who illustrated him the problem of establishing the existence of a polyomino with a given number of cells in every column and every row. Alberto was always ready to take up new challenges, his enthusiasm and thirst for knowledge as well as his firmness and the awareness of his own capabilities (he used to say: “I have a slow, sequential brain”) helped him work out a solution for Professor Nivat’s problem for several classes of polyominoes [9]. This event marked the beginning of a long-term friendship and a profitable cooperation. Professor Nivat acquainted Alberto with Discrete Tomography and Alberto did not take long to make his own contributions to this sector. Alberto knew that the reconstruction of convex polynomials in lines or columns through their orthogonal projections was an NP-complete problem, but he was not at all discouraged and in [3] is developed a polynomial algorithm for reconstructing convex polyominoes from their horizontal and vertical projections. In [4] the execution time of the previous algorithm is lowered thanks to some properties of convex polyominoes. The problem of reconstructing a sum of k permutation matrices from its diagonal sums is known to be NP-complete. In [10], Alberto proves that a simple variant of this problem in which the permutation matrices lie on a cylinder instead of on a plane can be solved in polynomial time, and he furnishes the corresponding algorithm. He obtains these results by means of a generalization of a classical theorem of Hall on the finite abelian groups. The above-mentioned episodes are just a few examples of the great results obtained by Alberto in the field of Discrete Tomography. The great importance of Alberto’s remarkable achievements in this sector is further stressed by the authoritative position he had gained
Editorial / Theoretical Computer Science 346 (2005) 184 – 188
187
in this field in Italy and by the request of his contribution in [14], while his doctoral thesis “Discrete Tomography: reconstructing digital pictures from their projections” testifies to his passion for this subject. “It’s difficult to keep pace with Maurice, but if you are able to do so, you will be spellbound. . .” These were the words he used to describe Professor Nivat, when we first met him at DSI. They were uttered with a sweet smile of affection and an intense, deep look. It took us a while to understand that Alberto was not only talking about Maurice as a scientist, but as a man too. In Siena Alberto further demonstrated that he was not only an excellent researcher but also a good teacher. A good small team of well integrated researchers soon gathers around him, the young students are eager to learn from him and the first scientific results of this cooperation are soon visible. Just to give a few examples, we could mention [2], and [12]. The first article was born as an answer to Propp’s question appeared on the “domino” forum: “Is there a technology for reverse-engineering a combinatorial problem from a rational generating function?” Making use of some results from the theory of N-rational series the authors obtained an automatic interpretation of recurrence relations with constant coefficients in terms of regular languages and a characterization of the set of generating functions of regular languages. It is thus possible, through an algorithm, to pass from a rational function in this set to a regular expression whose generating function is this same function. In the second paper [12] Alberto and his collaborators developed a general methodology for the generation and enumeration of some classes of convex polyominoes. In practice, they first determine ECO constructions which apply to all these classes, and the associated succession rules. The enumeration is then derived in novel fashion, starting from a method proposed by Fédou and Garcia, for some algebraic succession rules, and extending it to the present case on noting that a convex polyomino with semi-perimeter n + 2 has a representation as a word of length n of a non-commutative formal power series over an infinite alphabet; this non-commutative power series admits a decomposition in terms of some auxiliary power series which yields an algebraic system of equations on taking commutative images; and the solution of this system is then the desired generating function. The Editors would like to thank all the people who have made the publication of this volume possible, starting with the authors who have provided high-quality works and have followed with precision the referees’ suggestions; the referees who have improved the quality of the original manuscripts and have promptly satisfied our requests; the Editor in Chief, Professor Giorgio Ausiello, who has constantly encouraged us, downplaying difficulties and misunderstandings and following every step of our work. We owe a special thank-you also to Andrea Frosini, whose material and moral support has played an essential role right from the start. This issue does not only illustrate the results achieved by Professor Alberto del Lungo in his specific field of research but also shows his efforts in other sectors of Combinatorial analysis and of Discrete Geometry so as to demonstrate how highly esteemed he was by the entire international scientific community. This homage will not certainly fill the gap left by Alberto but it can help us revive his smile forever, and remember his readiness to help, his enthusiasm and his capabilities. His works and the memory of Alberto as a man will certainly represent a guiding presence for the future, as he will be walking by our side along the difficult paths of scientific research and of our personal lives. We cannot deny the difficulties we have gone through while writing this volume: it has been hard to relive,
188
Editorial / Theoretical Computer Science 346 (2005) 184 – 188
in a very short time, long years of common interests, little shared secrets, and past daily routines. . . . It has been difficult not to give way to despair when we had the illusion of writing to Alberto to ask for his advice, as we used to do in the past, when at the end of all our conversations we would ask him: “. . .what do you think about it?” Ciao Alberto, Elisa and Simone References [1] E. Barcucci, A. Del Lungo (Eds.), Random generation of combinatorial objects and bijective combinatorics, Theoretical Computer Science, Vol. 307(2), Elsevier, Amsterdam, The Netherlands, 2003, pp. i–iv, 219–453. [2] E. Barcucci, A. Del Lungo, A. Frosini, S. Rinaldi, A technology for reverse-engineering a combinatorial problem from a rational generating function, Adv. Appl. Math. 26 (2001) 129–153. [3] E. Barcucci, A. Del Lungo, M. Nivat, R. Pinzani, Reconstructing convex polyominoes from horizontal and vertical projections, Theoret. Comput. Sci. 155 (1996) 321–347. [4] E. Barcucci, A. Del Lungo, M. Nivat, R. Pinzani, Reconstructing convex polyominoes from horizontal and vertical projections II, in: Discrete Geometry for Computer Imagery, Lyon, 1996, Lecture Notes in Computer Science, Vol. 1176, Springer, Berlin, 1996, pp. 295–306. [5] E. Barcucci, A. Del Lungo, E. Pergola, R. Pinzani, ECO: a general methodology for the enumeration of combinatorial objects, J. Differential Equations Appl. 5 (1999) 435–490. [6] E. Barcucci, A. Del Lungo, E. Pergola, R. Pinzani, Directed animals forests of trees and permutations, Discrete Math. 204 (1999) 41–71. [7] E. Barcucci, A. Del Lungo, E. Pergola, R. Pinzani, From motzkin to catalan permutations, Discrete Math. 217 (2000) 33–49. [8] E. Barcucci, A. Del Lungo, E. Pergola, R. Pinzani, Permutations avoiding an increasing number of lengthincreasing forbidden subsequences, Discrete Math. Theoret. Comput. Sci. 4 (2000) 31–44. [9] A. Del Lungo, Polyominoes defined by two vectors, Theoret. Comput. Sci. 127 (1994) 187–198. [10] A. Del Lungo, Reconstructing permutation matrices from diagonal sums, Theoret. Comput. Sci. 281 (2002) 235–249. [11] A. Del Lungo, F. Del Ristoro, J.G. Penaud, Left ternary trees and non-separable rooted planar maps, Theoret. Comput. Sci. 233 (2000) 201–215. [12] A. Del Lungo, E. Duchi, A. Frosini, S. Rinaldi, On the generation and enumeration of some classes of convex polyominoes, Electronic J. Combinatorics 11 (2004) #R60. [14] A. Del Lungo, M. Nivat, Reconstruction of connected sets from two projections, in: G.T. Herman, A. Kuba (Eds.), Discrete Tomography: Foundations, Algorithms, and Applications, Birkhäuser, Boston, Cambridge, MA, 1999 (Chapter 7).
E. Pergola Università di Firenze, Dipartimento di Sistemi e Informatica, Viale Morgagni, 65, 50134, Firenze, Italy E-mail address:
[email protected]fi.it S. Rinaldi Università di Siena, Dipartimento di Scienze Matematiche e Informatiche, Pian dei Mantellini, 44, 53100, Siena, Italy E-mail address:
[email protected]
Theoretical Computer Science 346 (2005) 189 – 199 www.elsevier.com/locate/tcs
Minimal change list for Lucas strings and some graph theoretic consequences Jean-Luc Baril, Vincent Vajnovszki∗ LE2I– CNRS UMR 5158, Université de Bourgogne B.P. 47 870, 21078 Dijon-Cedex, France
Abstract We give a minimal change list for the set of order p length-n Lucas strings, i.e., the set of length-n binary strings with no p consecutive 1’s nor a 1 prefix and a 1m suffix with +m p. The construction of this list proves also that the order p n-dimensional Lucas cube has a Hamiltonian path if and only if n is not a multiple of p + 1, and its second power always has a Hamiltonian path. © 2005 Elsevier B.V. All rights reserved. Keywords: Minimal change list; Gray code; Fibonacci and Lucas string; Lucas cube; Hamiltonian path
1. Introduction The Hamming distance between two strings in {0, 1}n is the number of positions in which they differ. A k-Gray code for a set of binary strings B ⊂ {0, 1}n is an ordered list B for B, such that the Hamming distance d between any two consecutive strings in B is at most k. In addition, if the list B minimizes both k = max d(x, x ) and d(x, x ), where (x, x ) ranges over all pairs of successive strings in B, then it is called minimal change list or minimal Gray code. Obviously, a 1-Gray code is a minimal change list. We call Hamiltonian a graph having a Hamiltonian path and a k-Gray code is a Hamiltonian path in Qkn |B, the restriction of the kth power of the hypercube Qn to the set B. The set Fn,p , of order p length-n Fibonacci strings, is the set of length-n binary strings such that there are no p consecutive 1’s. The set Ln,p , of order p length-n Lucas strings, is the set of all strings in Fn,p which do not begin by 1 and end by 1m with + m p. ∗ Corresponding author.
E-mail addresses:
[email protected] (J.-L. Baril),
[email protected] (V. Vajnovszki). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.020
190
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
In other words, Ln,p is the set of length-n binary strings such that there are no 1p factors if strings are regarded circularly, i.e., the last entry of a string is followed by the first one. A number of papers concerning the Fibonacci and Lucas strings have been published [3,6–9,13,15]. In the present one we introduce an order relation on {0, 1}n which induces a minimal change list on Ln,p . Note that this order relation yields a 1-Gray code on the set Fn,p , of order p length-n Fibonacci strings [13]. This paper is the extended version of [2] and the remaining is organized as follows. In the next section we prove that a 1-Gray code for Ln,p is possible only if (p + 1) does not divide n. In Section 3 we give such a Gray code and a 2-Gray code when (p + 1) divides n; both of them are minimal change lists. Few graph theoretic consequences are presented in Section 4 and in the final part some algorithmic considerations are given. 2. Parity difference relation For a binary string set B we denote by B (resp. B ) the subset of B of strings with an odd (resp. even) number of 1’s. Let Q(Ln,p ) be the order p n-dimensional Lucas cube, i.e., the restriction of the hypercube Qn to the set Ln,p . The graph Q(Ln,p ) is bipartite, and with the notations above {Ln,p , Ln,p } is a bipartition. No Hamiltonian path is possible in Q(Ln,p ) (or equivalently, 1-Gray code for Ln,p ) if |card(Ln,p ) − card(Ln,p )| > 1, i.e., the number of vertices in the two bipartitions differs by more than one. The main result of this section is Theorem 5. In the following we suppose p > 1 fixed and more often in this section we will omit the subscript p for the sets Fn,p , Ln,p and other related things. Let {n }n 0 and {n }n 0 be the parity difference integer sequences corresponding to Fibonacci and Lucas strings defined by • n = card(F n ) − card(Fn ), and • n = card(Ln ) − card(Ln ). Lemma 1. (1) n satisfies n = n−1 − n−2 + · · · + (−1)p+1 n−p
for n p + 1.
(1)
(2) n is related to n by n = n−2 − 2 · n−3 + · · · + (−1)p+1 p · n−p−1
for n p + 2.
Proof. 1. The recursive definition in [13] Fn = 0 · Fn−1 ∪ 10 · Fn−2 ∪ 110 · Fn−3 ∪ · · · ∪ 1p−1 0 · Fn−p can be expanded as Fn = 0 · Fn−1 ∪ 10 · F n−2 ∪ 110 · Fn−3 ∪ ···,
and F n = 0 · F n−1 ∪ 10 · Fn−2 ∪ 110 · F n−3 ∪ · · · ,
and (1) holds.
for n p + 1
(2)
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
191
2. When np + 2 the set Ln is the union of the sets in the table below, where the strings with prefix 1i−1 0 are in the ith line and those with the suffix 01j −1 are in the jth column, 1i, j p. 0 · Fn−2 · 0, 10 · Fn−3 · 0, .. . 1p−2 0 · Fn−p · 0, 1p−1 0 · Fn−p−1 · 0
0 · Fn−3 · 01, 10 · Fn−p−4 · 01, .. . 1p−2 0 · Fn−p−1 · 01
· · · 0 · Fn−p · 01p−2 , · · · 10 · Fn−p−1 · 01p−2 .. .
0 · Fn−p−1 · 01p−1
In this decomposition, each Fn−k−1 occurs exactly k times, and reading this table diagonally one has card(Ln ) =
p j =1
j · card(Fn−j −1 ),
and Fn−k−1 appears as 1s 0 · Fn−k−1 · 01t , with s + t = k − 1, thus card(Ln ) = card(Fn−2 ) + 2 · card(F n−3 ) + 3 · card(Fn−4 )...,
and card(Ln ) = card(F n−2 ) + 2 · card(Fn−3 ) + 3 · card(F n−4 ) . . . ,
so (2) holds.
The next proposition gives the generating function for the sequences {n }n 0 (except its first term) and {n }n 0 (except its p + 2 first terms). Proposition 2. If (z) and (z) denote the generating functions for the sequences {n }n 0 and {n }n 0 , respectively, then (1) (z) = 0 + z · (−z)p−1 ·
1+z , 1 − (−z)p+1
(3)
(2) (z) =
p+1 j =0
j zj + zp+2 · (−1)p+1 ·
1 − (p + 1)(−z)p + p(−z)p+1 . (1 − (−z)p+1 ) · (1 + z)
(4)
Proof. 1. For i = 1, 2, . . . , p − 1 all strings in {0, 1}i are in Fi , and half of them are in Fi and other half are in F i , so 1 = 2 = · · · = p−1 = 0. If i = p, then a single string in {0, 1}p does not belong to Fp , namely 1p , so p = (−1)p+1 . By relation (1) we have (z) = 0 + z ·
f (z) , (1 − (−z)p+1 )/(1 + z)
where f (z) = (−z)p−1 is given by the values of 1 , 2 , . . . , p . See for instance Flajolet and Sedgewick’s seminal book [4, p. 79].
192
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
2. If ∗ (z) = (z) −
p+1 j =0
j zj , then relation (2) gives (see again [4])
∗ (z) = ((z) − 0 ) · (z2 − 2z3 + · · · + (−1)p+1 pzp+1 ) and finally ∗ (z) = zp+2 · (−1)p+1 ·
1 − (p + 1)(−z)p + p(−z)p+1 . (1 − (−z)p+1 ) · (1 + z)
(5)
For np + 2, n is given by the coefficient of zn in (4). The next corollary shows that the sequence {n }n 0 is periodic from n p + 1 and gives its generating function if it is extended by periodicity to 0 , 1 , . . . , p+1 . Corollary 3. The sequence {n }n p+2 has the period 2(p + 1). In addition, if one defines n = n+2(p+1) for all n = 0, 1, . . . , p + 1 then its generating function becomes (z) =
(−z)p+1 + (p + 1)z + p . (1 − (−z)p+1 ) · (1 + z)
(6)
Proof. For ∗ (z) given by relation (5) it is easy to show that (∗ (z)/zp+2 )(1 − z2(p+1) ) is a polynomial of degree less than 2p + 2. Thus ∗ (z)/zp+2 is the generating function for a periodic integer sequence with the period 2(p + 1), and so is (z) assuming it is extended by periodicity. For (6) it is enough to find a polynomial g(z) of degree less than p+2 such that ∗ (z)−g(z) is divisible by z2(p+1) , and in this case (z) = (∗ (z) − g(z))/z2(p+1) . It is not hard to check that g(z) = (−z)p+2 ((−z)p − 1)/(z + 1) satisfies this and we obtain (6). Corollary 4. The parity difference integer sequence corresponding to Lucas strings satisfies n,p =
(−1)n+1 if (p + 1) |n, (−1)n · p if (p + 1)|n.
(7)
Proof. (z) in relation (6) can be expressed as p+1 1 − 1 − (−z)p+1 1+z = (p + 1) · (−z)k(p+1) − (−z)n
(z) =
k 0
and n,p is the coefficient of zn in (z).
n0
Observe that the choice of i,p , i = 1, 2, . . . , p + 1, in Corollary 3 seems arbitrary since extended by periodicity. In fact, for i = 1, 2, . . . , p all the 2i strings in {0, 1}i
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
193
are in Li,p , except 1i which contains p consecutive 1’s if strings are regarded circularly. In this case i,p = (−1)i+1 , and similarly, p+1,p = (−1)p+1 p, which are in accord with (7). Theorem 5. If Q(Ln,p ) is Hamiltonian then (p + 1) |n. Proof. If Q(Ln,p ) is Hamiltonian then |n,p | 1, so (p + 1) |n. The Hamiltonism of Q(Ln,p ), when (p + 1) |n, is shown constructively in the next section. 3. The Gray codes We adopt the convention that lower case bold letters represent length-n binary strings, e.g., x = x1 x2 . . . xn ; and we use the same group of letters to denote a set A and an ordered list A for a set A. A list A for the set A ⊂ {0, 1}n is equivalent to an order relation on A: x < y iff x precedes y in A. For example, if x = y ∈ {0, 1}n and i is the leftmost position with xi = yi then: • the lexicographic order is given by: x < y iff xi is even (= 0), and yi is odd (= 1); i • the reflected Gray code order due to Frank Gray in 1953 [5] is given by: x < y iff j =1 xj i is even (and j =1 yj is odd). We say that an order relation < on a set of strings induces a k-Gray code if the set listed in < order yields a k-Gray code, i.e., successive strings differ in at most k positions. So, the reflected Gray code order above induces a 1-Gray code on {0, 1}n ; and its restriction to the strings with fixed density (i.e., strings in {0, 1}n with a constant number of 1’s) induces a 2-Gray code, called revolving door code by Nijenhuis and Wilf [10]. According to [13] we recall the following definition which gives another order relation on binary strings and all of those presented here are particular cases of genlex order [14], that is, any set of strings listed in such an order has the property that strings with a common prefix are contiguous. Definition 6. We say that xis less than y in local reflected order, denoted by x ≺ y, if i i j =1 (1 − xj ) is odd and j =1 (1 − yj ) is even, where i is the leftmost position with xi = yi . Remark 7. (1) x ≺ y iff the prefix x1 x2 . . . xi contains an odd number of 0’s. (2) x ≺ y iff x > y in reflected Gray code order, with x and y the bitwise complement of x and y. (3) As the reflected Gray code order, the local reflected order ≺ induces a 1-Gray code on {0, 1}n and a 2-Gray code on length-n binary strings with fixed density. (4) In [13] it is shown that, unlike the reflected Gray code order, the local reflected order ≺ induces a 1-Gray code on the set Fn,p . The main result of this section is Corollary 12 and Theorem 13 which say that ≺ induces also a minimal Gray on the set Ln,p , of order p length-n Lucas strings.
194
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
If z is a length-k string, we denote by zn/k the length-n prefix of the infinite string zzz . . ., or equivalently, zn/k = zz . . . z zr , n/k
where r = n mod k, and zr is the length-r prefix of z. In the following, the length-(p + 1) binary string = 1 . . . 1 00 p−1
plays a central role for our purposes. Let Fn,p and Ln,p be the lists obtained by ordering the sets Fn,p and Ln,p , respectively, by the relation ≺. In [13] it is proved that the first and the last strings of Fn,p are first(Fn,p ) = 0(n−1)/(p+1) and last(Fn,p ) = n/(p+1) . The next lemma gives similar results for Ln,p . Lemma 8. (1) first(Ln,p ) = 0(n−1)/(p+1) . (2) last(Ln,p ) = (n−1)/(p+1) 0. j Proof. 1. Let f1 f2 . . . fn = 0(n−1)/(p+1) and 1 j n such that i=1 (1 − fi ) is even, then: (1) j > 0 and fj = 0, and (2) fj −1 is the rightmost 1 bit in a contiguous 1’s sequence of length p − 1 and, by Definition 6, 0(n−1)/(p+1) has no predecessor in Ln,p in ≺ order. The proof of 2 is similar, the string (n−1)/(p+1) 0 has no successor in Ln,p . Now we describe how we compute the successor of a string in the lists Fn,p and Ln,p . Since in the lists Fn,p and Ln,p strings with a common prefix are contiguous, the successor of x ∈ Fn,p (resp. of x ∈ Ln,p ) is given by changing the rightmost bit in x such that the obtained string remains in Fn,p (resp. in Ln,p ), and it is greater than x in ≺ order. More formally we have: Lemma 9. Let x = last(Fn,p ) and s(x) its successor in Fn,p , then either 1, 2 or 3 below holds. (1) x contains an odd number of 0’s and it has not a suffix of the form 1p−1 0. In this case s(x) = x1 . . . xn−1 (1 − xn ). (2) x contains an even number of 0’s and ends by 1p−1 0. Then s(x) = x1 . . . xn−2 0xn . (3) x contains an even number of 0’s and does not end by 1p−1 0, or it contains an odd number of 0’s and ends by 1p−1 0. Let x1 x2 . . . xk−1 xk be the length minimal prefix of x with an odd number of 0’s and such that x = x1 x2 . . . xk−1 xk 0(n−k−1)/(p+1) (with (n−k−1)/(p+1) possibly empty). In this case s(x) = x1 x2 . . . xk−1 (1 − xk )0 (n−k−1)/(p+1) . Note that if x is like described in point 3 of Lemma 9 then the required prefix x1 x2 . . . xk−1 xk always exists. For example, in F6,3 we have: by point 1, s(010011) = 010010; by point 2, s(000110) = 000100; and by point 3, s(100100) = 100110 and s(100110) = 110110. In
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
195
[13] a similar idea is used to compute, in constant time, the successor s(x) of a Fibonacci string x. Obviously, if x is a Lucas string then s(x) is a Fibonacci string but not necessarily a Lucas string too. The next proposition states that if we denote by succ(x) the successor of x ∈ Ln,p in the list Ln,p then succ(x) is either s(x), s 2 (x) = s(s(x)) or s 3 (x) = s(s(s(x))). Proposition 10. Let x ∈ Ln,p , x = last(Ln,p ) and s(x) ∈ Ln,p ; then either 1 or 2 below holds. (1) (p + 1)|n and x = 1k 00(n−k−2)/(p+1) with 0 k < p − 1. In this case succ(x) = 1k+1 0(n−k−3)/(p+1) 0 = s 2 (x). (2) x = 1k z1 0 with 0 < k, < p − 1 and k + p − 1. In this case succ(x) = 1k s(z)1 0 = s 3 (x). Proof. When s(x) is not a Lucas string then it is obtained from x by changing the 0 bit which either follows a 1’s prefix or is in the last position. Remark 11. (1) If (p + 1)|n then there exist exactly p − 1 Lucas strings as in point 1 of Proposition 10, one for each k, 0 k < p − 1. In addition, if x is such a string and d denotes the Hamming distance then (a) d(x, succ(x)) = d(x, s 2 (x)) = 2, (b) the string v = 1k 00(n−k−3)/(p+1) 0 ∈ Ln,p is the predecessor of x in ≺ order (i.e., succ(v) = x) and d(v, succ(x)) = 1. (In fact v = x · succ(x), the bitwise product of x and succ(x).) (2) If x is a Lucas string as in point 2 of Proposition 10 then d(x, succ(x)) = d(1k z1 0, 1k z 1 0) = d(z, z ) = 1. This remark proves the following: Corollary 12. (1) If (p + 1) |n then Ln,p is a 1-Gray code for Ln,p . (2) If (p + 1)|n then Ln,p is a 2-Gray code for Ln,p and there are exactly p − 1 strings with d(x, succ(x)) = 2.
196
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
Table 1 The lists L4,2 and L4,3 L4,2
L4,3
0100 0101 0001 0000 0010 1010 1000
0110 0100 0101 0001 0000 0010 0011 1010 1000 1001 1100
Changed bits are in bold-face.
0110
0110 0101
1100
1101
0100
0011
0010 0000
0001
1010
1000
1011
1001
(a)
0000
0110 1100
0101
0100
1010
0011
0010
0001
1000
0011
0010
1001
(b)
0000
1100
0101
0100
0001
1010
1000
1001
(c)
Fig. 1. (a) The Hamiltonian path F4,3 in Q(F4,3 ). (b) The ‘path’ L4,3 in Q(L4,3 ), dashed arcs connect distance-2 vertices. (c) An H(1, 2)-path in Q(L4,3 ).
Theorem 13. Ln,p is a minimal change list for the set Ln,p . Proof. By Corollary 4, there are no more restrictive Gray code as Ln,p .
See Table 1 and Fig. 1(b) for the list L4,2 and L4,3 .
4. Graph theoretic issues Here we present some graph theoretic consequences of the previous results. 4.1. Hamiltonicity For a graph G let Gk be its kth power, where edges connect vertices which are linked by a path in G of length at most k. A k-Gray code for B ⊂ {0, 1}n is a Hamiltonian path for Qkn |B, the restriction of the kth power of the hypercube to the set B. Generally, (Qn |B)k is a subgraph of Qkn |B and equality holds if Hamming distance and the shortest path length coincide on Qn |B; this is the case for B = Fn,p or Ln,p , but not for Dyck words for instance, since the restriction of Qn to length-n Dyck words is not a connected graph.
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
197
As in Section 2, let Q(Ln,p ) = Qn |Ln,p denote the Lucas cube. Corollary 12 says that Ln,p is a Hamiltonian path in: • the Lucas cube iff (p + 1) |n; • the second power of the Lucas cube elsewhere. (In general, Q(Ln,p ) is not 2-connected as it may be checked for L3,2 , and so, the Hamiltonicity of its second power cannot be obtained trivially from a well-known result in graph theory). Corollary 14. If (p + 1)|n then (1) the minimal number of paths covering Q(Ln,p ) is p; (2) the length of the maximal path in Q(Ln,p ) is card(Ln,p ) − p + 1. Proof. Point 1 follows from Corollary 12. For point 2, from Remark 11, it results that by bypassing in Ln,p the p − 1 strings y = succ(x), with d(x, y) = 2, we obtain a maximal length path in Q(Ln,p ). When a graph does not have a Hamiltonian path it may be desirable to visit each vertex but not necessarily once, such that the Hamming distance between two successive vertices is one. Following [12], a graph is in the class H(s, t) if it has a path that visits every vertex at least s times and at most t times, and such a path is called H(s, t)-path. Thus a graph is in H(1, 1) exactly if it is Hamiltonian. In this context, we have: Corollary 15. If (p + 1)|n then Q(Ln,p ) is in H(1, 2). Proof. When (p+1)|n, by point 1(a) of Remark 11, in the list Ln,p there are strings x which differ from succ(x) in two positions. For each such string, we insert v—the predecessor of x, see point 1(b) of Remark 11—between x and succ(x) and one obtains an H(1, 2) path in Q(Ln,p ). Notice that in the H(1, 2) paths above exactly p − 1 strings are visited twice, and this is optimal. See Fig. 1(c) for an H(1, 2) path in Q(L4,3 ). 4.2. Some structural properties Let us now recall some definitions concerning a connected graph G with vertices set V : • the eccentricity of a vertex v is e(v) = maxu∈V d(u, v), • the diameter of G is diam(G) = maxu,v∈V d(u, v) = maxv∈V e(v), • the radius of G is rad(G) = minv∈V e(v), and • the center of G is Z(G) = {u ∈ G | e(u) = rad(G)}. The next proposition generalizes similar results presented in [9] for Ln,2 . Proposition 16. Let n1, p 2. n − 1 if p = 2 and n odd, (1) diam(Q(Ln,p )) = n otherwise, (2) e(0n ) = n − pn , (3) rad(Q(Ln,p )) = n − pn and Z(Q(Ln,p )) = {0n }.
198
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
Proof. 1. Let x = 1010 . . . (xi = 1 iff i is odd) and y = 0101 . . . (yi = 1 iff i is even). If p = 2 and n is even or if p > 2 then x, y ∈ Ln,p and they are at maximal distance equal to n. If p = 2 and n is odd there does not exist a pair of strings in Ln,p at distance n and it is easy to find two strings at distance n − 1. 2. Let v = 1p−1 0 . . . 1p−1 01k 0 with 0 k p−1. Clearly, v ∈ Ln,p and it has a minimum number of 0’s, namely n/p, or equivalently, a maximal number of 1’s, equal to n− n/p, So, e(0n ) = d(0n , v) = n − n/p. The same result can be obtained by replacing v by any of its circular shifts. 3. For any Lucas string u = 0n we construct another Lucas string at distance greater than n − n/p to u. The bitwise product v · x of a Lucas string v by a binary (not necessarily Lucas) string x is a Lucas string and d(x, v · x) equals the number of positions i where vi = 0 and xi = 1. Let u ∈ Ln,p , u = 0n , u its bitwise complement and v a circular permutation of the string 1p−1 0 . . . 1p−1 01k 0 given in point 2, such that u and v have at least one 0 in the same position. v · u ∈ Ln,p and since v has exactly n/p 0’s and at least one of them corresponds to a 0 in u one has d(u, v · u) < n/p. By the triangle inequality d(u, v · u) + d(v · u, u) d(u, u) = n and so d(u, v · u) n − d(u, v · u) > n −
n . p
A stable set of a graph is a subset of vertices such that there are not two adjacent vertices and the stability number, denoted by (G), is the number of vertices in a stable set of maximum cardinality. Proposition 17. (Q(Ln,p )) = max(card(Ln,p ), card(Ln,p )) where {Ln,p , Ln,p } is the bipartition of Ln,p . Proof. Let A be the set of maximum cardinality between Ln,p and Ln,p , and B the other set. Clearly, A is stable and we will prove that any stable set has at most the same cardinality as A. By Corollaries 4 and 12, the successor succ(x) of x in the list Ln,p induces an injective function succ : B → A; in addition, x ∈ B and succ(x) ∈ A are connected in Q(Ln,p ). Thus, if a stable set contains x ∈ B then it must not contain succ(x) ∈ A, and so the cardinality of a stable set does not exceed that of A. 5. Algorithmic considerations In [13] is given an exhaustive generating algorithm for the list Fn,p which runs with constant delay between any two successive strings. Now we show how one can modify this algorithm in order to produce efficiently the list Ln,p . Proposition 10 guarantees that at most two Fibonacci strings exist between any two consecutive Lucas string in Ln,p ; and by point 2 of Lemma 8 the last string in Ln,p is followed by at most one Fibonacci string. So, the algorithm in [13] can be modified to
J.-L. Baril, V. Vajnovszki / Theoretical Computer Science 346 (2005) 189 – 199
199
generate the list Ln,p by simply bypassing the Fibonacci strings which are not Lucas strings. The obtained algorithm inherits the constant delay property if one can decide, in constant time, if the current generated Fibonacci string is also a Lucas string. Additional variables, as (1) the length of the contiguous prefix of 1’s and (2) the length and the first position of the rightmost contiguous sequence of 1’s, can be used to distinguish in constant time Fibonacci from Lucas strings. Acknowledgements We thank Olivier Togni who presented us the problem we deal with in this paper and for some technical suggestions. References [2] J.-L. Baril, V. Vajnovszki, Gray codes for order p Lucas strings, in: T. Harju, J. Karhumäki (Eds.), Proc. 4th Internat. Conf. on Combinatorics on Words, September 2003, Turku, Finland, TUCS General Publication, No. 27, August 2003, pp. 149–158. [3] E. Dedó, D. Torri, N. Zagaglia Salvi, The observability of the Fibonacci and the Lucas cubes, Combinatorics ’98 (Palermo), Discrete Math. 255 (1–3) (2002) 55–63. [4] P. Flajolet, R. Sedgewick, Introduction à l’analyse des algorithmes, Thomson Publishing, 1996. [5] F. Gray, Pulse code communication, US Patent 2632058, 1953. [6] W.-J. Hsu, Fibonacci cubes—a new interconnection topology, IEEE Trans. Parallel Distrib. Systems 4 (1) (1993) 3–12. [7] J.C. Lagarias, D.P. Weisser, Fibonacci and Lucas cubes, Fibonacci Quart. 19 (1) (1981) 39–43. [8] J. Liu, W.-J. Hsu, M.J. Chung, Generalized Fibonacci cubes are mostly Hamiltonian, J. Graph Theory 18 (8) (1994) 817–829. [9] E. Munarini, C. Perelli Cippo, N. Zagaglia Salvi, On the Lucas cubes, Fibonacci Quart. 39 (1) (2001) 12–21. [10] A. Nijenhuis, H.S. Wilf, Combinatorial Algorithms for Computers and Calculators, Academic Press, New York, 1978. [12] G. Pruesse, F. Ruskey, Generating linear extensions fast, SIAM J. Comput. 23 (1994) 373–386. [13] V. Vajnovszki, A loopless generation of bitstrings without p consecutive ones, Discrete Mathematics and Theoretical Computer Science, Springer, Berlin, 2001, pp. 227–240. [14] T.R. Walsh, Generating Gray codes in O(1) worst-case time per word, DMTCS03, Lecture Notes in Computer Science, Vol. 2731, Springer, Berlin, 2003, pp. 72–88. [15] J. Wu, Extended Fibonacci cubes, IEEE Trans. Parallel Distrib. Systems 8 (12) (1997) 1203–1210.
Theoretical Computer Science 346 (2005) 200 – 225 www.elsevier.com/locate/tcs
The discrete Green Theorem and some applications in discrete geometry夡 S. Brlek, G. Labelle, A. Lacasse∗ LaCIM, Université du Québec à Montréal, C. P. 8888 Succursale “Centre-Ville”, Montréal (QC), Canada H3C 3P8
Dedicated to the memory of Alberto Del Lungo
Abstract The discrete version of Green’s Theorem and bivariate difference calculus provide a general and unifying framework for the description and generation of incremental algorithms. It may be used to compute various statistics about regions bounded by a finite and closed polygonal path. More specifically, we illustrate its use for designing algorithms computing many statistics about polyominoes, regions whose boundary is encoded by four letter words: area, coordinates of the center of gravity, moment of inertia, set characteristic function, the intersection with a given set of pixels, hook-lengths, higher order moments and also q-statistics for projections. © 2005 Published by Elsevier B.V. Keywords: Discrete Green Theorem; Discrete geometry; Polyominoes
1. Introduction The classical Green’s Theorem may be seen as a generalization of the Fundamental Theorem of Calculus and links surface integrals to contour integrals. More precisely, for
夡 The
work was supported by NSERC (Canada).
∗ Corresponding author.
E-mail addresses:
[email protected] (S. Brlek),
[email protected] (G. Labelle),
[email protected] (A. Lacasse). 0304-3975/$ - see front matter © 2005 Published by Elsevier B.V. doi:10.1016/j.tcs.2005.08.019
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
201
s=(0,0) (a)
(b)
Fig. 1. (a) A typical polyomino; (b) a closed curve but not a polyomino.
any convenient closed region of the plane with boundary () we have jQ jP − dx dy = P (x, y) dx + Q(x, y) dy. jy jx () This is particularly true for regions defined on regular lattices such as square, hexagonal or triangular lattices of the plane. On the other hand, many basic parameters associated with closed regions are represented by surface integrals. For instance, the area A(), center of gravity CG(), moment of inertia I(), of a closed region are defined by the double integrals x dx dy y dx dy dx dy, CG() = (x, ¯ y) ¯ = A() = , , A() A() ((x − x) ¯ 2 +(y − y) ¯ 2 ) dx dy= (x 2 +y 2 ) dx dy − (x¯ 2 + y¯ 2 )A(). I()=
In this paper we restrict the study to regions that are commonly used in discrete geometry, namely the polyominos, but one should keep in mind that a more general formulation could be presented. A polyomino P is a finite union of closed cells in the unit lattice square (pixels) of the plane whose boundary (P) consists of a simple closed polygonal path (see Fig. 1(a)). In particular, our polyominoes are simply connected (contain no holes), and have no multiple points (see Fig. 1(b)). The polygonal path (contour) of a polyomino is encoded by an ordered pair (s, w) where s is a lattice point belonging to and w is a word over the 4-letter alphabet A = {r, u, l, d} = {r :→
u :↑
l :←
d :↓}
also known as the Freeman chain code [9,10], where the letters correspond to the unit translations in the lattice directions: right, up, left and down. The word w represents the perimeter of the polyomino read in a counterclockwise way starting from the point s. The use of s may be avoided in the encodings by assuming that s is always the lowest left most point of the polyomino and that s = (0, 0) by using a suitable translation. In this way, the polyomino of Fig. 1(a) is encoded by the single word w = rrddrurruurdruururullldluululldddldldd.
202
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
Area= 26 Center of gravity = (3.65, 1.54) Moment of inertia = 152.68 Horizontal projections = (1,2,3,4,5,5,3,2,1) Vertical projections = (1,2,4,9,6,3,1)
Fig. 2. Some parameters for polyominoes.
Since polyominoes are given by words describing their contours, it is natural to use Green’s Theorem for the construction of our first general algorithms in order to compute not only some basic statistics such as the area, center of gravity, moment of inertia, projections (see Fig. 2) but the boolean operations on the underlying sets as well. In Section 2, we introduce the notion of incremental algorithm for polyominoes given by their contour and show how Green’s Theorem can be used to generate families of such algorithms. In Section 3, we drop the continuity conditions of Green’s Theorem and deal with general additive incremental algorithms for which the output associated with the sum of two polyominoes is the sum of the outputs associated to each polyomino. More general algorithms are then obtained by the use of weight functions W : Z × Z − → A. In particular, if W is the boolean valued characteristic function of a point, then the output of the algorithm is boolean valued and decides if a given pixel belongs to a given polyomino. This result extends to sets of pixels, providing the computation of the set characteristic function and some particular instances such as the size of hook-lengths. Higher order moments are also obtained in this way when the weight function involves Stirling numbers of the second kind. When A is a ring of formal Laurent power series, the use of q-analogues yields the simultaneous computation of both the horizontal and vertical projections. The power and effectiveness of Green’s Theorem already appeared in the literature. More precisely, it is useful for region filling (see for example [15]) and also for the efficient computation of the moments of closed regions [14,17,18]. Our present approach is similar to the one given in [14,17,18], but differs by the choice of the Stirling numbers instead of the Bernouilli numbers. For a general presentation of polyominoes and their properties see [11]. A survey of enumerative results concerning polyominoes can be found in [16] (see also [2,4,7]). The core of the third author’s Master thesis [12] contains in full detail—but is not limited to—the results presented here with numerous examples. 2. Green’s Theorem and incremental algorithms The following version of Green’s Theorem [13] is sufficient to start our analysis. Theorem 1. Let P (x, y), Q(x, y) be two continuously differentiable functions on an open set containing a simply connected region bounded by a simple piecewise continuously
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
203
differentiable positively oriented curve . Then jQ jP P (x, y) dx + Q(x, y) dy. − dx dy = jy jx Since the above parameters involve integrals of the form f (x, y) dx dy,
where will be a polyomino, our next step is to choose P (x, y) and Q(x, y), in Green’s Theorem, such that (jQ/jx − jP /jy) = f . There are many ways to achieve this and three solutions are provided in the following useful lemma. Lemma 2. Let P be a polyomino with contour , and let f (x, y) be a R-valued continuous function. Then, f (x, y) dx dy = f1 (x, y) dy (1) P = − f2 (x, y) dx (2) = F (x, y)(x dy − y dx), (3)
where
x
f1 (x, y)= F (x, y) =
1
f (u, y) du,
f2 (x, y) =
y
f (x, v) dv,
f (sx, sy)s ds.
0
t dt means indefinite integration. The notation denotes a line integral along while Proof. For (1), take P = 0, Q = f1 in Green’s Theorem. For (2), take P = −f2 , Q = 0. Formula (3) is more delicate and can be established as follows. Take, in Green’s Theorem, P (x, y) = −yF (x, y) and Q(x, y) = xF (x, y). We must show that (jQ/jx − jP /jy) = f . In order to do this, note first that jQ jP jF jF − = 2F + x +y . jx jy jx jy Next, consider an extra variable u such that 0 < u1. Then, 1 2 2 u F (ux, uy) = u f (sux, suy)s ds u0 = f (x, y) d (via = su). 0
Differentiating with respect to u gives 2uF (ux, uy) + u2
jF jF (ux, uy)x + u2 (ux, uy)y = uf (ux, uy). jx jy
204
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
vi+1
vi
vi
vi+1 0
0
Fig. 3. A positive and a negative triangle.
Finally, taking u = 1, one obtains the desired equality jF jF 2F + x +y = f. jx jy Remark 3. The above proof of (3) uses Green’s Theorem but it is more algebraic than geometric. An alternate geometric proof of (3), not using Green’s Theorem, is provided now. Its advantage relies on the fact that it may be adapted to any piecewise continuously differentiable curve . Alternate geometric proof of (3): Let v0 , v1 , . . . , vn be the successive vertices of the contour of P. For any two successive vertices vi and vi+1 on , consider the triangle Ti whose vertices are 0, vi and vi+1 taken in this order. The triangle Ti is considered to be positive if the angle defined by the vectors vi and vi+1 is positive and Ti is negative otherwise (see Fig. 3). We obviously have, n−1 f (x, y) dx dy = f (x, y) dx dy. P
i=0
Ti
Now let vi = (xi , yi ) and vi+1 = (xi+1 , yi+1 ) = (xi +xi , yi +yi ) and take the following parametrization for the triangle Ti : x = x(s, t) = s(xi + txi ),
y = y(s, t) = s(yi + tyi ),
where 0 s 1 and 0 t 1. The Jacobian of this transformation is j(x, y) = s(xi yi − yi xi ). j(s, t) By the change of variables for double integrals, we have, for i = 0, 1, . . . , n − 1 : 1 1 j(x, y) f (x, y) dx dy = f (x(s, t), y(s, t)) ds dt j(s, t) Ti 0 0 1 1 f (s(xi + txi ), s(yi + tyi ))s(xi yi − yi xi ) ds dt = 0 0 1 F (xi + txi , yi + tyi )(xi yi − yi xi ) dt = 0 = F (x, y)(x dy − y dx). [vi ,vi+1 ]
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
205
2.1. Incremental algorithms The evaluation of each line integral (1)–(3) of Lemma 2 can be broken into simpler integrals over successive unit (horizontal or vertical) line segments forming : n−1 = ,
i=0
[vi ,vi+1 ]
where vi = (xi , yi ), i = 0, . . . , n − 1, denote the successive vertices of the contour of P, and satisfy vn = v0 , vi+1 = vi + vi = (xi + xi , yi + yi ). Since polyominoes are coded by (s, w) where s ∈ Z × Z is the starting point and w is a word over the alphabet A = {r, u, l, d}, the translation into incremental algorithms follows easily: start from the source point s and traverse the contour (P ) = by reading w letter by letter. At each step, the performed action depends only on the current position on (P ) and on the letter read. More precisely, consider four vectors identified with the letters of A r = (1, 0),
u = (0, 1),
l = (−1, 0),
d = (0, −1)
and take four functions indexed by A, r (x, y),
u (x, y),
l (x, y),
d (x, y).
Now read the word w = w1 w2 . . . wn sequentially from the left, cumulating the partial sums as follows, where wi is the vector corresponding to the letter wi : v := (x0 , y0 ); S := 0; for i := 1 to n do S := S + wi (v); v := v + wi end for return S. Hereafter an incremental algorithm is denoted by • = d , h , g , b and the following suggestive notation represents its output: Output(•, P) = r (xi , yi ) + u (xi , yi ) + l (xi , yi ) + d (xi , yi ). →
←
↑
↓
The formulas (1), (2) and (3) of Lemma 2 yield the corresponding incremental algorithms called, respectively, V-algorithm, H-algorithm and VH-algorithm, where the letters V and H stand for the vertical and horizontal directions: in a V-algorithm (resp. H-algorithm) only vertical (resp. horizontal) sides of the polyomino are used, while in a VH-algorithm both vertical and horizontal sides are used. Proposition 4 (Green’s type algorithms). Let P = (s, w) and f (x, y) be continuous. Then, f (x, y) dx dy = r (xi , yi ) + u (xi , yi ) + l (xi , yi ) + d (xi , yi ), P
→
↑
←
↓
206
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
where the functions r , u , l , d are taken from any of the following three sets of possibilities: 1 1 V-algo. r = 0, u = 0 f1 (x, y + t) dt, l = 0, d = − 0 f1 (x, y − t) dt. 1 1 H-algo. r = − 0 f2 (x + t, y) dt, u = 0, l = 0 f2 (x − t, y) dt, d = 0. 1 1 VH-algo. r = −y 0 F (x + t, y) dt, u = x 0 F (x, y + t) dt, 1 1 d = −x 0 F (x, y − t) dt, l = y 0 F (x − t, y) dt, where f1 (x, y), f2 (x, y) and F (x, y) are defined by Lemma 2. Proof. Let be any one of the three differential forms f1 (x, y)dy,
−f2 (x, y) dx,
F (x, y)(x dy − y dx)
appearing in the line integrals (1), (2), (3) of Lemma 2. Then,
f (x, y) dx dy = P
=
n−1 i=0
[vi ,vi+1 ]
,
where v0 , v1 , . . . , vn−1 , vn (= v0 ) are the vertices of the contour of P. Now if (s, w) encodes P, with the starting point (x0 , y0 ) and the 4-letter word w = w1 w2 . . . wn , then the side [vi , vi+1 ] of the contour is parametrized by (x, y) = (x(t), y(t)), 0 t 1, where x = x(t) = xi + t,
y = y(t) = yi
(dx = dtdy = 0)
if wi+1 = r,
x = x(t) = xi ,
y = y(t) = yi + t
(dx = 0dy = dt)
if wi+1 = u,
x = x(t) = xi − t,
y = y(t) = yi
(dx = −dt, dy = 0)
if wi+1 = l,
x = x(t) = xi ,
y = y(t) = yi − t
(dx = 0, dy = −dt) if wi+1 = d.
We conclude by evaluating the line integrals (1), (2), (3) of Lemma 2 using the corresponding parametrizations. 2.2. Elementary applications and examples The tables below contain elementary instances of these algorithms for the computation of P f (x, y) dx dy and some computations are carried out on the simple polyomino w = rrdrrululululddd and s = (0, 0):
Below are listed the algorithms for the area (Table 1), where f (x, y) = 1; for the center of gravity (Table 2), where f (x, y) = x and f (x, y) = y; and for the moment of inertia
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
207
Table 1 Area Algorithm
r
u
l
d
V H VH
0 −y −y/2
x 0 x/2
0 y y/2
−x 0 −x/2
2 2 (Table 3), where f (x, y) = x +y . • V-algo for the area: → 0 + ↑ xi + ← 0 + ↓ − xi , 1 dx dy = 0 + 0 − x3 + 0 + 0 + x5 + 0 + x7 + 0 + x9 + 0 + x11 P
+ 0 − x13 − x14 − x15 = −2 + 4 + 3 + 2 + 1 − 0 − 0 − 0 = 8. • VH-algo for the area: → − yi /2 + ↑ xi /2 + ← yi /2 + ↓ − xi /2, 1 dx dy = −y0 /2−y1 /2−x2 /2 − y3 /2 − y4 /2 + x5 /2 + y6 /2 − y7 /2 + y8 /2 P
−x9 /2 + y10 /2 + x11 /2 + y12 /2 − x13 /2 − x14 /2 − x15 /2 = −1 + 1/2 + 1/2 + 2 + 3/2 + 1/2 + 1 + 1 + 1/2 + 3/2 = 8. • V-algo for x¯ of the center of gravity: → 0 + ↑ xi2 /2 + ← 0 + ↓ − xi2 /2, P
x dx dy = 0 + 0 − x22 /2 + 0 + 0 + x52 /2 + 0 + x72 /2 + 0 + x92 /2 + 0 2 2 2 2 + x11 /2 + 0 − x13 /2 − x14 /2 − x15 /2
= (−22 + 42 + 32 + 22 + 12 )/2 = 26/2 = 13. • V-algo for the integral involved in the moment of inertia: (x 2 + y 2 ) dx dy = xi3 /3 + xi yi2 + xi yi + xi /3 P
↑
+
↓
− xi3 /3 − xi yi2 + xi yi − xi /3 = 425/24.
• We compute now the probability that a random point (x, y) ∈ R × R, under a normal bivariate probability distribution, f (x, y) = (1/) exp(−x 2 − y 2 ), falls in a given polyomino P. In this case the VH-algorithm is complicated and only the V and H-algorithms are given (Table 4). Discrete probability distributions (such as uniform distributions over rectangles) will be considered in the next section. Due to its formulation, the VH-algorithm is in general more complicated than the corresponding V and H-algorithms. There is, however, an important class of functions for which the VH-algorithm is generally preferable: the class of homogeneous functions, i.e. functions f (x, y), satisfying a functional equation of the form f (sx, sy) = s k f (x, y) for a constant k, called the degree of homogeneity. The VH-algorithm is given now.
208
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
Table 2 Center of gravity Algorithm
r
u
l
d
V (num x) ¯ (num y) ¯
0 0
x 2 /2 x/2 + xy
0 0
−x 2 /2 x/2 − xy
H (num x) ¯ (num y) ¯
−y/2 − xy −y 2 /2
0 0
−y/2 + xy y 2 /2
0 0
VH (num x) ¯ (num y) ¯
−xy/3 − y/6 −y 2 /3
x 2 /3 xy/3 + x/6
xy/3 − y/6 y 2 /3
−x 2 /3 −xy/3 + x/6
Table 3 Moment of inertia V
r = 0 l = 0
u = x/3 + xy + x 3 /3 + xy 2 d = −x/3 + xy − x 3 /3 − xy 2
H
r = −y/3 − xy − x 2 y − y 3 /3 l = y/3 − xy + x 2 y + y 3 /3 r = −y/12 − xy/4 − x 2 y/4 − y 3 /4 l = y/12 − xy/4 + x 2 y/4 + y 3 /4
u d u d
VH
=0 =0 = x/12 + xy/4 + x 3 /4 + xy 2 /4 = −x/12 + xy/4 − x 3 /4 − xy 2 /4
Table 4 √ f (x, y) = (1/) exp(−x 2 − y 2 ), erf(x) = (2/ ) 0x exp(−t 2 ) dt V
H
r = 0
u = 41 erf(x)(erf(y + 1) − erf(y))
l = 0
d = 41 erf(x)(erf(y − 1) − erf(y))
r = − 41 erf(y)(erf(x + 1) − erf(x))
u = 0
l = − 41 erf(y)(erf(x − 1) − erf(x))
d = 0
Corollary 5. Let f (x, y) be continuous and homogeneous of degree k > −2. Assume that r = −
y (f1 (x + 1, y) − f1 (x, y)), k+2
u =
x (f2 (x, y + 1) − f2 (x, y)), k+2
l = −
y (f1 (x − 1, y) − f1 (x, y)), k+2
d =
x (f2 (x, y − 1) − f2 (x, y)), k+2
where f1 (x, y) and f2 (x,y) are defined in Lemma 2. Then the corresponding incremental VH-algorithm computes P f (x, y) dx dy, for any polyomino P. Proof. Let f (x, y) be homogeneous of degree k. Then the function F (x, y) of Proposition 4 takes the very simple form F (x, y) = 0
1
f (sx, sy)s ds = 0
1
s k+1 f (x, y) ds =
1 f (x, y). k+2
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
209
Hence, for the corresponding VH-algorithm, we have, 1 1 y r (x, y) = − F (x + t, y)y dt = − f (x + t, y) dt k+2 0 0 x+1 y y f (x, y) dx = − (f1 (x + 1, y) − f1 (x, y)), =− k+2 x k+2 by definition of f1 (x, y). The verification of the formulas for u , l and d is left to the reader. A typical illustration of Corollary 5, for which the VH-algorithm is simpler than the corresponding V or H-algorithms, is provided by the computation of the average euclidean distance from a given point (a, b) ∈ Z × Z to a random point in a polyomino P is given by the formula 2 2 P (x − a) + (y − b) dx dy , A(P) where A(P) is computed by some of our previous algorithms. We only need to compute the integral P f (x, y) dx dy. This is achieved easily by replacing the starting point s = (x0 , y0 ) by s − (a, b) = (x0 − a, y0 − b). It corresponds to the choice f (x, y) = x 2 + y 2 and k = 1 in Corollary 5. In this case, the functions f1 (x, y) and f2 (x, y) are given by the formulas 1 if y = 0, 2 x|x| f1 (x, y) = 1 1 2 2 2 2 2 otherwise, 2 x x + y + 2 y ln(x + x + y ) 1 if x = 0, 2 y|y| f2 (x, y) = 1 1 2 2 2 2 2 otherwise. 2 y x + y + 2 x ln(y + x + y ) Note that f1 (0, 0) = f2 (0, 0) = 0 by taking limits. 3. Additive incremental algorithms and applications In the foreseen examples, the function f (x, y) was assumed to be continuous. Nevertheless this much restrictive condition may be dropped by assuming, for example, that f is piecewise continuous in each variable, and we still may use Proposition 4 as a guideline for producing corresponding algorithms. Indeed, algorithms for the computation of horizontal and vertical projections of a polyomino can be found in this way: fix an integer and define f by f (x, y) = ( x < + 1),
where denotes the characteristic function. Then, P f (x, y) dx dy is clearly the -vertical projection of the polyomino P: f (x, y) dx dy = #{ ∈ Z|Pix, ⊆ P} = v (P), P
210
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
where Pix, denotes the unit pixel of the plane having the point (, ) ∈ Z × Z as its lowest left corner, that is:
Pix, = {(x, y) ∈ R × R|x < + 1, y < + 1}, and its closure (with condition x +1, y +1) is denoted Pix, . In this case, following Proposition 4, we find that x if x < , 0 (x < + 1) dx = x − if x < + 1, f1 (x, y) = 1 if + 1 x. This gives the following algorithm as the reader can easily check: V-algorithm for the vertical projection v (P): r = 0,
u = (x + 1),
l = 0,
d = − (x + 1).
Similarly, taking f (x, y) = ( y < + 1), the -horizontal projection of P #{ ∈ Z | Pix, ⊆ P} = h (P), is computed by the following algorithm: H-Algorithm for the horizontal projection h (P): r = − (y + 1),
u = 0,
l = (y + 1),
d = 0.
These algorithms for the projections are special instances of the general notion of additive incremental algorithm which we now define. Definition 6. An incremental algorithm • = r , u , l , d is additive if, whenever P = P1 ∪ P2 with disjoint interiors (see Fig. 4), we have Output(•, P) = Output(•, P1 ∪ P2 ) = Output(•, P1 ) + Output(•, P2 ). An example of a nonadditive incremental algorithm is given by the computation of a polyomino’s perimeter in which case r = u = l = d = 1. Proposition 7. An incremental algorithm • = r , u , l , d , where the ’s are Rvalued (or more generally A-valued where A is a ring) is additive if and only if l (x, y) = −r (x − 1, y) and
d (x, y) = −u (x, y − 1).
(4)
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
211
Fig. 4. P = P1 ∪ P2 with disjoint interiors.
( x,y)
P1 (x-1,y)
(x,y)
P1
( x,y +1)
( x +1,y +1)
P2
P2
( x,y)
( x+1,y)
(x,y-1) (a)
(b)
(c)
Fig. 5. (a) Vertical domino, (b) horizontal domino, (c) a pixel Pixx,y .
Moreover, the output of an additive incremental algorithm •, on a polyomino P is given by Output(•, P) = x u (, ) − y r (, ), (5) Pix, ⊆P
where x (x, y) = (x + 1, y) − (x, y) and y (x, y) = (x, y + 1) − (x, y). Proof. Since any polyomino P can be written as a finite union of the closure Pix, of its pixels P= Pix, , Pix, ⊆P
the output of an additive incremental algorithm satisfies Output(•, Pix, ). Output(•, P) = Pix, ⊆P
In particular, if P1 , P2 are both single pixels and P is a vertical domino as in Fig. 5(a), then, Output(•, P) = Output(•, P1 ∪ P2 ) = Output(•, P1 ) + Output(•, P2 ). Hence l (x, y) = −r (x − 1, y) in order to cancel the contribution of the common horizontal edge of the domino P. A similar argument (see Fig. 5(b)) shows that using an horizontal domino d (x, y) = −u (x, y − 1). This shows that the stated conditions are necessary for additivity. Their sufficiency follows from the automatic cancellation of the common boundaries of P1 and P2 (see Fig. 5)
212
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
for general polyominoes with disjoint interiors such that P = P1 ∪ P2 . The formula for Output(•, P) also follows from these conditions since for any closed pixel Pix, , we must have (see Fig. 5(c)), for any additive incremental algorithm, Output(•, Pix, ) = r (, ) + u ( + 1, ) + l ( + 1, + 1) + d (, + 1) = r (, ) + u ( + 1, ) − r (, + 1) − u (, ) = x u (, ) − y r (, ).
Proposition 7 may be used for proving, for instance, that a given additive incremental algorithm is actually correct. Indeed, one can check by using it, that the above algorithms for the projection v (P) and h (P) are valid. The validity of the boolean valued additive incremental algorithms in the next sections can also be checked with it. Another use of this proposition is to produce new algorithms starting first from an arbitrary choice of functions r (x, y), u (x, y); secondly, by defining the associated functions l (x, y), d (x, y) from (4); and, finally, by computing the corresponding output using (5). See Section 3.4 for such an example. The next corollary may be considered as an inverse of Proposition 7. It shows how to find r (x, y), u (x, y), l (x, y), d (x, y) starting from the desired output. It also describes a close connection between general additive incremental algorithms and the bivariate calculus of finite differences. Corollary 8. Let A be a ring and W : Z × Z → A be a weight function associated with each pixel Pixx,y in the plane. Then, the most general additive incremental algorithm, • = r , u , l , d having the output W (x, y) ∈ A, Pixx,y ⊆P
for each polyomino P, is of the form r (x, y) = V 0 (x, y) + (x, y − 1) − (x − 1, y − 1), u (x, y) = U 0 (x, y) + (x − 1, y) − (x − 1, y − 1), l (x, y) = −r (x − 1, y), d (x, y) = −u (x, y − 1), where (U 0 (x, y), V 0 (x, y)) is a particular solution of the difference equation x U (x, y) − y V (x, y) = W (x, y) and : Z × Z → A is arbitrary. Proof. Since the difference equation is linear, it is sufficient to show (see Proposition 7) that the general solution of the associated homogeneous equation x U (x, y) − y V (x, y) = 0
(6)
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
213
is given by U (x, y) = (x − 1, y) − (x − 1, y − 1), V (x, y) = (x, y − 1) − (x − 1, y − 1),
(7) (8)
where (x, y) is arbitrary. Indeed, substituting (7) in (6) gives x U − y V = [((x, y) − (x, y − 1)) − ((x − 1, y) − (x − 1, y − 1))] −[((x, y) − (x − 1, y)) − ((x, y − 1) − (x − 1, y − 1))] = 0. Conversely, in order to show that for any solution (U, V ) of the homogeneous equation there corresponds a function , we introduce two auxiliary summation operators, x1 and y 1 , defined on functions g : Z × Z → A, by x g(k, y) if x > 0, k=1 x if x = 0, 1 g(x, y) = 0 − −x−1 k=0 g(−k, y) if x < 0, y
and similarly for 1 g(x, y). The reader can check that, for any function (x, y), we have, ∇ x (x, y) = (x, y)− (x − 1, y) = g(x, y) ⇐⇒ (x, y) = (0, y)+ x1 g(x, y), y ∇ y (x, y) = (x, y)− (x, y − 1) = g(x, y) ⇐⇒ (x, y) = (x, 0)+ 1 g(x, y), and that the required function (x, y) can be taken as y
(x, y) = c + 1 U (1, y) + x1 V (x, y + 1), where c is an arbitrary constant (c = (0, 0), in fact).
There exist many ways to find a particular solution (U 0 , V 0 ) of the equation x U − y V = W . One way is to force V 0 (resp. U 0 ) to be 0 and take U 0 (resp. V 0 ) to be a particular solution of the simpler difference equation x U (x, y) = W (x, y)
(resp. − y V (x, y) = W (x, y)),
with particular solution U 0 = x1 W (x − 1, y),
V0 = 0
y
(resp. U 0 = 0, V 0 = − 1 W (x, y − 1)).
This method provides a particular V-algorithm (resp. H-algorithm). Formal power series may also be used: let z1 and z2 be formal variables and consider the formal Laurent series
(z1 , z2 ) = U (x, y)zx zy , U 1 2 x,y
(z1 , z2 ) = V
(z1 , z2 ) = W
x,y
y
V (x, y)z1x z2 ,
x,y
y
W (x, y)z1x z2 .
214
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
Then the difference equation x U (x, y) − y V (x, y) = W (x, y) rewrites as
(z1 , z2 ) − (1 − z2 )z1 V
(z1 , z2 ) = z1 z2 W
(z1 , z2 ), (1 − z1 )z2 U
(z1 , z2 ) and V
(z1 , z2 ) by using algebraic manipulations. In fact, which is solved for U we used this method to find the general solution of the homogeneous equation appearing in the proof of Corollary 8. Another way to find solutions to the difference equation of Corollary 8 is to express, if possible, W (x, y) in the basis x (i) y (j ) , i, j 0, where t (k) = t (t − 1) . . . (t − k + 1) is the kth falling factorial power of t. Since t t (k) = kt (k−1) , this basis is well adapted to difference equations. This method is illustrated in Section 3.4 below for the computation of higher moments of a polyomino. 3.1. Deciding if a polyomino contains a given pixel Let (, ) ∈ Z × Z and consider the following boolean-valued function W, (x, y) = (x = ) (y = ). Since Pixx,y ⊆P
W, (x, y) = (Pix, ⊆ P) =
1 if Pix, ⊆ P, 0 otherwise,
then, the following additive incremental algorithms can be used to decide whether the pixel determined by (, ) belongs or not to a polyomino P. V-algorithm: r = 0, u = (x + 1) (y = ), l = 0, d = − (x + 1) (y = + 1). H-algorithm: r = − (x = ) (y + 1), u = 0, l = (x = + 1) (y + 1), d = 0. For example, the V-algorithm applied to Fig. 6(a) with (, ) = (3, 2) gives (only nonzero terms are listed): (Pix3,2 ⊆ P) = (x14 4) (y14 = 2) − (x16 4) (y16 = 3) + (x26 4) (y26 = 2) = 1 − 1 + 1 = 1 (since, Pix3,2 ⊆ P) and to Fig. 6(b) with (, ) = (6, 0) (Pix6,0 ⊆ P) = − (x18 7) (y18 = 1) + (x24 7) (y24 = 0) = −1 + 1 = 0 (since, Pix6,0 ⊆ P). ,
,
Of course, from Corollary 8, there is an uncountable family of algorithms r , u , ,
,
l , d from which one can compute (Pix, ⊆ P).
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
(a)
215
(b)
Fig. 6. (a) Pixel Pix3,2 in the polyomino (b) pixel Pix6,0 not in the polyomino.
vi′
vi′ (a)
vj′′
vj′′
vj′′
vi′
vj′′
vi′ (b)
(c)
(d)
Fig. 7. Matching pairs.
3.2. Boolean operations From the characteristic function , it is now straightforward to define formulas for the boolean operators on polyominoes. However, better results may be achieved with a bit of care. Let P1 and P2 be two polyominoes whose contours are given respectively by vi = (xi , yi ), for i = 0, 1, . . . , n1 − 1, and vj = (xj , yj ) for j = 0, 1, . . . , n2 − 1. Proposition 9. The number of pixels in P1 ∩ P2 is given by min(xi , xj )yi yj , #(P1 ∩ P2 ) = A(P1 ∩ P2 ) = 0 i
where the sum is extended to all the ordered pairs (i, j ) of indices that match in the following sense: y = yj and yi = yj (= ±1) (Fig. 7(a), (b)), i or (i, j ) match ⇐⇒ yi = yj − 1 and yi = 1, yj = −1 (Fig. 7(c)), or y = y + 1 and y = −1, y = 1 (Fig. (d)). i i j j Proof. The number of pixels in common between P1 and P2 is given by #(P1 ∩ P2 ) = (Pixp,q ⊆ P1 ) (Pixp,q ⊆ P2 ). (p,q)∈Z×Z
216
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
Using now the V-algorithm described in Section 3.1, we can write (Pixp,q ⊆ P) = p,q (vi , vi ), i
where p,q (v, v) = (x p + 1) (y = q + (1 − y)/2)y, since y ∈ {−1, 0, 1}. Let M (resp. N) be a lower bound for all the xi and xj (resp. yi and yj ). Then, p,q #(P1 ∩ P2 ) = (vi , vi )p,q (vj , vj ) p M,q N i,j
=
(vi , vi , vj , vj ), i,j
where
(vi , vi , vj , vj ) =
p M,q N (xi p pM
=
×
p,q (vi , vi )p,q (vj , vj ) + 1) (xj p + 1
q N
(yj = q + (1 − yj )/2) (yj = q + (1 − yj )/2)
= (min(xi , xj ) − M)(yi , yi , yj , yj ) and where, 1 −1 (yi , yi , yj , yj ) = −1 0
if yi = yj and yi = yj (= ±1), if yi , yi = yj − 1, yi = 1, yj = −1, if yj , yi = yj + 1, yi = −1, yj = 1, otherwise.
Hence, #(P1 ∩ P2 ) =
0 i
(min(xi , xj ) − M)yi yj ,
and since the left-hand side is independent of M, the result follows by replacing M by M − 1. Using the de Morgan set formulas, the number of pixels in the union and difference of two polyominoes is computed by #(P1 ∪ P2 ) = #(P1 ) + #(P2 ) − #(P1 ∩ P2 ), #(P1 \ P2 ) = #(P1 ) − #(P1 ∩ P2 ). Intersection between a polyomino and a given set: Let S be a finite or infinite union of p,q p,q p,q p,q pixels and let r , u , l , d be algorithms for the computation of (Pixp,q ⊆ P)
(p, q) ∈ Z × Z.
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
217
Fig. 8. There are 21 pixels in P to the north-east of (, ).
The number #(S ∩ P) of pixels in common between S and P can be computed by taking Sr , Su , Sl , Sd , where p,q p,q Sr (x, y) = r (x, y), Su (x, y) = u (x, y), Pixp,q ⊆S
Sl (x, y)
=
Pixp,q ⊆S
Pixp,q ⊆S
p,q l (x, y),
Sd (x, y)
=
Pixp,q ⊆S
p,q
d (x, y).
In particular, to decide if a polyomino P intersects interior of S, one simply checks if the output of this algorithm is > 0. Computation of hook-lengths: Consider the north-east corner in the R×R plane associated with a given lattice point (, ) ∈ Z × Z NE, = {(x, y) ∈ R × R| x, y} = [, ∞) × [ , ∞). Then the reader can check that the following algorithms can be used to compute, for a polyomino P, the number of pixels in P ∩ NE, . That is, the number of pixels of P which are to the north-east of (, )(see Fig. 8): V-algorithm: r = 0, u = (x − ) (x + 1) (y ), l = 0, d = −(x − ) (x + 1) (y + 1). H-algorithm: r = −(y − ) (x ) (y + 1), u = 0, l = (y − ) (x + 1) (y + 1), d = 0. Definition 10. Let (, ) ∈ Z × Z and P be a polyomino. The hook-length hook , (P) is the number of pixels in the set P ∩ Hook , where Hook , = NE, \NE+1, +1 . In other words it is simply the number of pixels of P which are in the L-shaped hook Hook , determined by (, ) (see Fig. 9). Replacing (, ) by ( + 1, + 1) in the above algorithms and subtracting gives corresponding algorithms for the computation of hook-lengths. V-algorithm: (for the number of pixels in P ∩ Hook , ) r = 0, l = 0, u = (x − ) (x + 1) (y ) − (x − − 1) (x + 2) (y + 1), d = −(x − ) (x + 1) (y + 1) + (x − − 1) (x + 2) (y + 2).
218
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
Fig. 9. There are 11 pixels of P in the Hook , .
H-algorithm: (for the number of pixels in P ∩ Hook , ) u = 0, d = 0, r = −(y − ) (x ) (y + 1) + (y − − 1) (x + 1) (y + 2), l = (y − ) (x + 1) (y + 1) − (y − + 1) (x + 2) (y + 2). 3.3. Computation of higher order moments Our approach for the computation of higher order moments uses Stirling numbers. It is essentially equivalent to the one given byYang and Albregsten in [17,18] who uses Bernoulli numbers. It runs as follows. Consider two integers m, n 0 and a point (a, b) ∈ Z × Z. By definition, the (m, n)moment of a polyomino P relative to the point (a, b) is given by the integral (x − a)m (y − b)n dx dy. P
By a simple translation, the computation of such higher order moments can be reduced to central ones: x m y n dx dy. P
In this case,
(x + 1)m+1 − (x)m+1 (y + 1)n+1 − (y)n+1 m+1 n+1 P 1 = x x m+1 y y n+1 . (m + 1)(n + 1) Now, it is well-known (see [5]) that t k = kv=0 Svk t (v) , where Svk denotes the Stirling numbers of the second kind and t (v) = t (t − 1) . . . (t − v + 1). Since t t (v) = vt (v−1) , it follows that, W (x, y) =
W (x, y) =
x m y n dx dy =
0 i m,0 j n
wi,j x (i) y (j ) ,
wi,j =
(i + 1)(j + 1) m+1 n+1 S . S (m + 1)(n + 1) i+1 j +1
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
219
To find solutions (U, V ) of the difference equation of Corollary 8, let U (x, y) = ui,j x (i) y (j ) , V (x, y) = vi,j x (i) y (j ) . Then, we have x U − x V =
((i + 1)ui+1,j − (j + 1)vi,j +1 )x (i) y (j ) ,
and the problem is reduced to solve the linear system (i + 1)ui+1,j − (j + 1)vi,j +1 = wi,j ,
i, j 0.
Of course, many choices are possible for the ui,j ’s, vi,j ’s and the same kind of approach can be used for other wi,j ’s. Example. Let m = 3, n = 2. Then, (x + 1)4 − x 4 (y + 1)3 − y 3 4 3 3 2 4x + 6x + 4x + 1 3y 2 + 3y + 1 = . 4 3 On the other hand, we have, W (x, y) =
x 3 = x (3) + 3x (2) +x (1) ,
x 2 = x (2) +x (1) ,
x = x (1) ,
y 2 = y (2) + y (1) ,
y = y (1) .
Multiplying, we find, 4x (3) + 18x (2) + 14x (1) + 1 3y (2) + 6y (1) + 1 4 3 1 (3) 9 (2) (2) 3 (3) (2) (3) (1) = x y + 2x y + x + x y + 9x (2) y (1) + x (2) 3 2 2 7 7 1 1 1 + x (1) y (2) + 7x (1) y (1) + x (1) + y (2) + y (1) + 2 6 4 2 12
W (x, y) =
= + · · · + wi,j x (i) y (j ) + · · · where wi,j = (i + 1)ui+1,j − (j + 1)vi,j +1 . For example, taking vi,j = 0, for all i, j , we have wi,j = (i + 1)ui+1,j . Hence, ui+1,j = wi,j /(i + 1) with the normalizing condition u0,j = 0. In this way we can find all ui,j . Then, U 0 (x, y) = ui,j x (i) y (j ) 1 1 1 3 1 = x (4) y (2) + x (4) y (1) + x (4) + x (3) y (2) + 3x (3) y (1) + x (3) 4 4 12 2 3 7 (2) (2) 7 (2) (1) 7 (2) 1 (1) (1) 1 (1) + x y + x y + x + x y + x 2 2 12 2 12 1 (2) = x (x + 1)(2) (3y (2) + 3y + 1), 12 and V 0 = 0.
220
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
The corresponding values for d , h , g , b , are obtained by using the formulas of Corollary 8 taking, for example, (x, y) = 0. 3.4. Computation of families of projections We now give an example where the weights of pixels are taken in the ring A = R((q)) of formal Laurent power series in q. In analogy to the V-algorithm for the area given in Table 1, consider the algorithm associated to the functions r (x, y) = 0,
u (x, y) = [x]q ,
l (x, y) = 0,
d (x, y) = −[x]q ,
where [x]q =
1 − qx , 1−q
x ∈ Z,
denotes the q-analogue of x (q = 1 corresponds to area). In this case, x u = [x + 1]q − [x]q = y r = 0.
1 − qx 1 − q x+1 − = qx , 1−q 1−q
So that, in view of Proposition 7, the output of this algorithm on P is Output(•, P) =
Pix, ⊆P
x u (, ) − y r (, ) =
Pix, ⊆P
q =
∈Z
v (P)q .
This is the generating Laurent series of the family of all vertical projections v (P), ∈ Z, and also a q-analogue of area. A similar approach can be used for the family h (P), ∈ Z, of all horizontal projections. Factoring out (1 − q) (resp. (1 − t)), the reader can easily check that the following holds: Corollary 11. Let q and t be formal variables and P be a polyomino. Then, (a) for the V-algorithm • = r = 0, u = −q x , l = 0, d = q x , we have ∈Z
v (P)q =
Output(•, P) , 1−q
(b) for the H-algorithm • = r = t y , u = 0, l = −t y , d = 0, we have
∈Z
h (P)t =
Output(•, P) , 1−t
where v (P), ∈ Z, and h (P), ∈ Z, denote the families of vertical and horizontal projections of the polyomino P. We illustrate this corollary with the polyomino of Fig. 10.
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
221
2 5 5 3 3 2 1 Fig. 10. Family of vertical projections.
The computation using the V-algorithm gives Output(•, P) = 0 − q x1 + 0 − q x3 + 0 + 0 + 0 − q x7 + 0 − q x9 + 0 − q x11 + 0 + q x13 + 0 −q x15 + 0 − q x17 + 0 + q x19 + 0 + q x21 + q x22 + 0 + q x24 + q x25 + 0 + q x27 = −q 1 − q 2 − q 5 − q 4 −q 3 + q 2 − q 1 − q 0 + q −1 + q −2 + q −2 + q −1 + q −1 +q 0 = 2q −2 + 3q −1 − 2q 1 − q 3 − q 4 − q 5 and then, ∈Z
v (P)q =
(2q −2 + 3q −1 − 2q 1 − q 3 − q 4 − q 5 ) Output(•, P) = 1−q (1 − q)
= 2q −2 + 5q −1 + 5 + 3q + 3q 2 + 2q 3 + q 4 , where the coefficients of the polynomial correspond to the vertical projections of the polyomino (see Fig. 10).
4. Conclusion The Discrete Green Theorem provides a general framework allowing the discovery and development of new algorithms for the computation of many statistics on polyominoes. Let us mention, the computation of oblique projections or the computation of various probabilities related to polyominoes. The algorithms described in Corollary 11 or their variants might be of some help for the study of families of polyominoes defined by their projections (see [1,8]). Computations on integer partitions are obtained along the same lines since partitions are special cases of polyominoes which are encoded by words of the following type w = r i d j , where is a word on {u, l} containing i times the letter l and j times the letter u (see Fig. 11). It should also be possible to study salient and reentrant points on polyominoes in the sense of [6], by extending the concept of incremental algorithm to higher order (where, at
222
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
j
i Fig. 11. A partition encoded by w = rrrrrrrrrrrulululullulluullulldddddddd.
v4
v1
v5 vi+1
vi
v3
0 (a)
v2 v0
0 (b)
Fig. 12. (a) Closed polygonal path P, (b) triangle with oblique segment [vi , vi+1 ].
each step, the action made depends on the current position on the boundary and on the next k letters read). Since polyominoes are easily encoded by 4-letter words, we can classify polyominoes according to the value of various parameters by using the appropriate algorithm. For instance, given an integer n, the n-ominoes can be classified according to (weakly) increasing moments of inertia. If two n-ominoes, P and Q satisfy I(P)I(Q), we can say that P is rounder than Q. We give in the Appendix the output of a simple Maple program implementing some of the algorithms on a polyomino having perimeter 44, and also a classification according to roundness for small n-ominoes, n5 (roundest first). It turns out that the roundest n-omino is not necessarily unique. Note also that their complexity is (time and space) linear in the boundary size of a polyomino: indeed the Freeman chain code of a polyomino is its perimeter, whose size determines the number of iterations in the incremental algorithms. The careful reader has certainly noticed that the algorithms carried out can be straightforwardly adapted to more general objects: for a polyomino with holes it suffices to subtract the holes; needless to say that they can also be extended to planar objects coded by a closed polygonal paths (self-intersecting or not). The alternate proof of Lemma 2 can be adapted to create such algorithms using triangles of the form #0vi vi+1 where the segment [vi , vi+1 ] can be oblique (see Fig. 12). The resulting algorithms for closed polygonal paths P will have
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
223
the form Output(•, P) =
n−1
n−1
i=0
i=0
(vi , vi ) =
(xi , yi , xi , yi )
for suitable functions (v, v) = (x, y, x, y). In particular, when the vi are restricted to be in a finite set {1 , 2 , . . . , m }, then the corresponding algorithm takes the form Output(•, P) = where the
j (xi , yi ) =
m n−1
j (xi , yi ),
i=0 j =1
(xi , yi , xi , yi ) if vi = j , 0 otherwise.
For example, algorithms for paths on hexagonal lattices in the complex plane can be analyzed by taking the k ’s to be the complex 6th roots of unity. 5. Uncited reference [3]. Acknowledgements The authors wish to thank the anonymous referees for the very careful reading of the paper and their valuable comments. Part of the material produced here was presented at the DGCI’03 conference held in Napoli (Italia). Appendix It is easy to implement in Maple the incremental algorithms developed above. Here is the output of a program on the human-like polyomino (see Fig. 14) described by the word w = rruuurddrrrulluuuurrrulllluldllulddrrdddddld :
font=tir at 6pt
Area: 27. Center of gravity: [47/18, 239/54], [2.611111111, 4.425925926]. Moment of inertia: 11719/54, 217.0185185. Vertical projections: 2q −1 + 2 + 7q + 5q 2 + 6q 3 + 2q 4 + 2q 5 + q 6 . Horizontal projections: 2 + 4t + 2t 2 + 3t 3 + 3t 4 + 3t 5 + 8t 6 + 2t 7 .
In Fig. 13, we classify n-ominoes according to weakly increasing moment of inertia (for n = 1, 2, . . . , 5). In this figure, P Q means that I(P)I(Q) or, equivalently, that P is rounder than Q. Equality of roundness is possible for distinct n-ominoes. The roundest n-omino is not always unique (see n = 5). We leave open the problem of the explicit geometrical description of the roundest n-omino(es) as a function of n.
224
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
(a) 1-omino
(b) 2-ominoes
< (c)
<
3-ominoes
<
<
(d)
4-ominoes
=
=
<
<
<
<
=
<
=
<
<
<
5-ominoes
(e)
Fig. 13. Polyominoes of given area classified according to decreasing roundness.
(0,0) Fig. 14. Human-like polyomino.
References [1] E. Barcucci, A. Del Lungo, M. Nivat, R. Pinzani, Reconstruction convex polyominoes from horizontal and vertical projections, Theoret. Comput. Sci. 155 (1996) 321–347. [2] M. Bousquet-Mélou, New enumerative results on two-dimensional directed animals, Discrete Math. 180 (1–3) (1998) 73–106. [3] S. Brlek, G. Labelle, A. Lacasse, Incremental algorithms based on discrete Green Theorem, in: I. Nyström, G. Sanniti di Baja, S. Svensson (Eds.), Proc. DGCI’03, Naples, Italy, 2003, Lecture Notes in Computer Science, Vol. 2886, Springer, Berlin, 2003, pp. 277–287. [4] A.L. Clarke, Isometrical polyominoes, J. Recreational Math. 13 (1980) 18–25.
S. Brlek et al. / Theoretical Computer Science 346 (2005) 200 – 225
225
[5] L. Comtet, Advanced Combinatorics, Reidel, Dordrecht, 1974. [6] A. Daurat, M. Nivat, Salient and reentrant points of discrete sets, in: A. Del Lungo, V. Di Gesù, A. Kuba (Eds.), Proceedings IWCIA’03, Palermo, Italy, 2003, Electronic Notes in Discrete Mathematics, Vol. 12, Elsevier, Amsterdam, 2003. [7] M.P. Delest, D. Gouyou-Beauchamps, B. Vauquelin, Enumeration of parallelogram polyominoes with given bound and site perimeter, Graphs Combin. 3 (1987) 325–339. [8] A. Del Lungo, Polyominoes defined by two vectors, Theoret. Comput. Sci. 127 (1) (1994) 187–198. [9] H. Freeman, On the encoding of arbitrary geometric configurations, IRE Trans. Electron. Comput. 10 (1961) 260–268. [10] H. Freeman, Boundary encoding and processing, in: B.S. Lipkin, A. Rosenfeld (Eds.), Picture Processing and Psychopictorics, Academic Press, New York, 1970, pp. 241–266. [11] S.W. Golomb, Polyominoes: Puzzles, Patterns, Problems and Packings, Princeton University Press, Princeton, NJ, 1996. [12] A. Lacasse, Contribution à l’étude des polyominos, Mémoire de maıˆ trise, Université du Québec à Montréal, 2004. [13] W.G. McCallum, D. Hughes-Hallett, A.M Gleason, et al., Multivariable Calculus, Wiley, Indianapolis, 2002. [14] W. Philips, A new fast algorithm for moment computation, Pattern Recognition 26 (11) (1993) 1619–1621. [15] G.Y. Tang, B. Lien, Region filling with the use of the discrete Green theorem, Comput. Vision Graphics Image Process. 42 (1988) 297–305. [16] X.G. Viennot, A survey of polyomino enumeration, in: P. Leroux, C. Reutenauer (Eds.), Proc. FPSAC’92, Montréal, QC, 1992, Publications du LACIM, Vol. 11, 1992, pp. 399–420. [17] L. Yang, F. Albregtsen, Fast computation of invariant geometric moments: a new method giving correct results, Proc. ICPR’94, Jerusalem, Israel, 1994, Cedar Publications, Buffalo, 1994, pp. A:201–204. [18] L. Yang, F. Albregtsen, Fast and exact computation of Cartesian geometric moments using discrete Green’s theorem, Pattern Recognition 29 (7) (1996) 1061–1073.
Theoretical Computer Science 346 (2005) 226 – 253 www.elsevier.com/locate/tcs
Graph encoding of 2D-gon tilings Frédéric Chavanona,∗ , Matthieu Latapyc , Michel Morvana , Eric Rémilaa, b , Laurent Vuillond a LIP, UMR 5668 CNRS-INRIA-Univ. Lyon I, ENS Lyon, 46 allée d’Italie, 69364 Lyon, Cedex 07, France b Groupe de Recherches en Informatique et Mathématiques Appliquées, Institut Universitaire de Technologie de
Roanne (Univ. St-Etienne), 20 avenue de Paris, 42334 Roanne, Cedex, France c LIAFA, Université Paris 7, 2 place Jussieu, 75005 Paris, France d Laboratoire de Mathématiques, UMR 5127 CNRS, Université de Savoie, 73376 Le Bourget du Lac, France
Abstract 2D-gon tilings with parallelograms are a model used in physics to study quasicrystals, and they are also important in combinatorics for the study of aperiodic structures. In this paper, we study the graph induced by the adjacency relation between tiles. This relation can been used to encode simply and efficiently 2D-gon tilings for algorithmic manipulation. We show for example how it can be used to sample random 2D-gon tilings. © 2005 Elsevier B.V. All rights reserved. Keywords: Tilings; Algorithmics; Graph theory
1. Introduction A tiling can be defined as a partition of a given region of an affine space. More classically, one considers a finite set of shapes, called prototiles, and a region of an affine space. The tiling problem is then to decide whether this region can be tiled, i.e. covered by translated copies of prototiles, without gaps or overlappings between them. If this is possible, the region is tilable, and a solution is called a tiling of the region. The translated copies of the ∗ Corresponding author. Tel.: +33 4 72 72 80 00; fax: +33 4 72 72 80 80.
E-mail addresses:
[email protected] (F. Chavanon),
[email protected] (M. Latapy),
[email protected] (M. Morvan),
[email protected] (E. Rémila),
[email protected] (L. Vuillon). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.018
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
227
prototiles are the tiles of the tiling. If the region to tile is the whole plane, this problem has been shown to be undecidable by Berger [3], which was the first important incursion of tilings in computer science. In this paper, we are concerned with tilings of 2D-gons with parallelograms. A 2D-gon is an hexagon when D = 3, an octagon when D = 4, a decagon when D = 5, etc. Such a region can always be tiled with parallelograms. 2D-gon tilings by parallelograms appear in physics as a model for quasicrystals [7] and aperiodic structures [14]. They are also used to encode several combinatorial problems [9,11], and have been studied from many points of view [2,11,13]. In particular, they are strongly related to the oriented matroid theory, since the Bohne–Dress theorem proves the equivalence of 2D-gon tilings with a class of oriented matroids [4,13]. These tilings cannot be easily manipulated by a program when one uses the geometric definitions. Some efficient solutions arise from the oriented matroids side [1,5]. We propose here another solution from graph theory, which has the advantage of giving very simple algorithms and to introduce some interesting questions about graphs related to 2D-gon tilings. The aim of this paper is to study the graph induced by the adjacency relation between tiles, and to find the minimal amount of information that needs to be added to this graph in order to provide an effective notion of dual graph of a tiling. Our results prove that this information can be reduced to the knowledge of two tiles which are in successive position on the hull of the zonotope. In particular, the knowledge of vector and de Bruijn line multiplicities is not required and can be computed. We will first present the tilings more formally, and define the adjacency graph we use. Then we will obtain a one-to-one correspondence between a class of graphs and 2D-gon tilings by introducing the notion of graph with origins, and we give an algorithm which builds the 2D-gon tiling corresponding to a given graph with origins. We will finally see how the flip operation can be defined on the graph, which makes it possible to sample random tilings of 2D-gons. Let us emphasize on the fact that we have two aims in this study: give some properties of the adjacency graph of 2D-gon tilings, which is a fundamental object on which very few information is known, and provide a very simple and efficient way to algorithmically manipulate 2D-gon tilings. 2. Preliminaries Given two vectors v and v , we will say that v < v in the natural order if the angle between (1, 0) and v is smaller than the angle between (1, 0) and v . Let V = {v1 , v2 , . . . , vD } be a family of D pairwise non-collinear vectors with non-negative second component of the plane. We suppose that for all integer i, vi < vi+1 in the natural order. Let M = {m1 , m2 , . . . , mD } be a family of D positive integers. The integer mi is called the multiplicity of vi . The 2D-gon P associated with V and M is the region of the affine plane defined by D i vi , 0 i mi , mi ∈ M, vi ∈ V . i=1
There exists many equivalent definitions for these objects. For example, a 2D-gon can be viewed as the projection of a hypercube of dimension D onto the plane. See [16] for more
228
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
Fig. 1. A 2D-gon and its vectors, associated with M = {2, 3, 1, 1, 2}. This is a decagon with sides of length 2,3,1,1,2,2,3,1,1,2.
details. For D = 2, the 2D-gons are parallelograms; for D = 3, hexagons; for D = 4, octagons; for D = 5, decagons; etc. See Fig. 1 for an illustration. Given a 2D-gon P, a prototile of P = (V , M) is a 2D-gon built using only 2 vectors in V, each of them with multiplicity 1. Therefore, each prototile of P is a parallelogram defined by two vectors in V, and we will make no distinction between the prototile viewed as an area and the pair of the indices of the vectors in V which define it. A side of a tile will be called edge, and the vector defining an edge is the support of the edge. Finally, a tiling T of a 2D-gon P = (V , M) is a set of tiles (i.e. translated copies of the prototiles) which cover exactly P and such that there is no overlapping between tiles. Therefore, T is a set of couples, their first component being the pair of vectors which defines the prototile, the second one being a translation, or position. The positions used in 2D-gon tilings can always be written as a linear combination of vectors in V : t = i ti vi , t i being an integer between 0 and mi . More precisely, a point p of the tiling can be positioned according to each vector by being assigned the (algebraic) number of occurrences of this vector one has to use in a direct path from the point (0, 0) to p along the edges of the tiling. This leads to a D-dimensional vector, whose components are the positions according to each vector of V. A tile is assigned the position of its point closest to (0, 0). Therefore, the position will be described by the D-dimensional vector (t1 , . . . , tD ). Two tilings T and T of two 2D-gons P and P are said to be equivalent if T = T , where T and T are viewed as sets of couples. Consider for example the three tilings in Fig. 2. From left to right, they are described by T1 = T2 = T3 =
({1, 2}, (0, 0, 1, 1)), ({1, 3}, (0, 0, 0, 1)), ({1, 4}, (0, 0, 0, 0)), ({2, 3}, (1, 0, 0, 1)), ({2, 4}, (1, 0, 0, 0)), ({3, 4}, (1, 1, 0, 0)) ({1, 2}, (0, 0, 1, 1)), ({1, 3}, (0, 0, 0, 1)), ({1, 4}, (0, 0, 0, 0)), ({2, 3}, (1, 0, 0, 1)), ({2, 4}, (1, 0, 0, 0)), ({3, 4}, (1, 1, 0, 0)) ({1, 2}, (0, 0, 0, 0)), ({1, 3}, (0, 1, 0, 0)), ({1, 4}, (0, 1, 1, 0)), ({2, 3}, (0, 0, 0, 0)), ({2, 4}, (0, 0, 1, 0)), ({3, 4}, (0, 0, 0, 0))
, , .
Therefore, tilings T1 and T2 are equivalent, while T1 and T3 are not. Let P be a 2D-gon, and T be a tiling of P. The ith de Bruijn family of T is the set of all the tiles in T which are built with the vector vi . Moreover, each family can be
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
v4 v3
v2 v1
v4 v3
v4 v3 v2
229
v2 v1
v1
Fig. 2. Three tilings of 2D-gons, namely T1 , T2 and T3 from left to right; T1 and T2 are equivalent, whereas T3 is equivalent to none of the others.
C A
B
Fig. 3. A 2D-gon tiling and three de Bruijn lines (a line is a set of tiles crossed by a dotted line). A and B are in the same de Bruijn family. A is the third line of the fourth family, and B the second line of the same family. C is the first line of the first family. According to our notations, A is the ninth line of the tiling, B is the seventh, and C is the first. Notice that C crosses exactly once A and B, whereas A and B do not cross each other.
decomposed into de Bruijn lines: the jth de Bruijn line of the ith family is the set of tiles built with vi which have j − 1 as the ith component of their position. Continuing with our example of Fig. 2, we obtain that the first line of the second de Bruijn family is equal to {({2, 4}, (1, 0, 0, 0)), ({2, 3}, (1, 0, 0, 1)), ({2, 1}, (0, 0, 1, 1))} for T1 and T2 . For practical convenience, we will also say that the jth line of the ith family is the th line of the tiling where = i−1 k=1 mk + j , mk being the multiplicity of the kth family. We also define f () as the index of the vector associated with the th line, i.e. f () is the number of the line’s family. See Fig. 3 for example. Notice that two lines in the same family never have a tile in common, whereas two lines in two different families always have exactly one tile in common. Moreover, each line l, jth line of the ith family, divides the set of tiles which are not in l into two disjoint parts, one having tiles whose ith component is more than j, and the other having tiles whose ith component is less. We will use these classical properties (see [6]) in the following.
230
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
Before entering in the core of the paper, we need a few more notations, which we introduce now. Definition 1. Let P = (V , M) be a 2D-gon. For all k, 1 k D we define the kth side of P as the set of points: D i vi , ∀i < k : i = mi , ∀i > k : i = 0, and 0 k mi . i=1
Likewise, we define the (k + D)th side of P as D i vi , ∀i > k : i = mi , ∀i < k : i = 0, and 0 k mi . i=1
Moreover, the hull of P, denoted by H (P ), is the union of all the sides of P. We will also say that a tile t is on the ith side of P if one of the edges of t is included in the ith side of P. Finally, each side i of P can be divided into copies of the vector vi defining i, called steps, and orientating i in the sense of vi , one can order the edges of type vi . Then one can define the jth tile on the side i as being the tile having an edge on the jth step of the side i. We can now introduce the notion of adjacency graph associated with a tiling, which will be the main object of our study. Definition 2 (Adjacency graph of a tiling). Let T be a tiling of a given 2D-gon (V , M), and let n = |T | be the number of tiles of this tiling. The adjacency graph of T is the undirected graph A(T ) = (VT , ET ) where VT = {t ∈ T } and {t, t } ∈ ET if and only if t and t have one edge in common in T. See Fig. 4 for an example. Notice that the adjacency graph has all vertices with degree 4, except the vertices corresponding to the tiles on the hull of the tiling, which have degree 2 or 3. In the following, we consider tiles and their corresponding number without distinction. Definition 3 (Geodesic, distance, length of a path). Let T be a tiling, A its adjacency graph, and t, t two tiles of T. A path from t to t is a sequence of tiles t0 , . . . , tr such that ti and ti+1 are adjacent, t0 = t and tr = t . Such a path, containing r + 1 vertices, has length r. Moreover, the sequence of vertices of A corresponding to the path is the path from t to t in A. A geodesic from t to t is a shortest path from t to t . The distance between t and t , denoted by dist(t, t ) is the length of the shortest path between t and t . The adjacency graphs of 2D-gon tilings will be our main object of interest in the rest of this paper. We will see that they encode much information on the tiling. However, the fact that two tilings have the same adjacency graph does not imply that they are equivalent: for example, one can verify that the tilings T1 and T3 in Fig. 2 have the same adjacency graph. In order to obtain a one-to-one correspondence between a set of graphs and the set of tilings of a 2D-gon, we introduce now the de Bruijn graph.
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
6 5
231
1
3
4
5
6
6
1 6
1
1 4
2 5
3
2 6
4 3 3 1
5
4 5
2 3
4
2 2
Fig. 4. A tiling, its adjacency graph and its de Bruijn graph. Bold is the first side, determining the origin.
Definition 4 (de Bruijn graph of a tiling). Let A = (V , E) be the adjacency graph of a tiling T of a 2D-gon P. The de Bruijn graph A = (V , E, , ) is a graph with labeled vertices and with a distinguished vertex . The label (t) of t ∈ V is the pair of integers {, } such that the two de Bruijn lines which contain the tile t are the th and th. The vertex , called the origin of the graph, is associated with the tile with translation vector (0, . . . , 0) which is on the first side of P. See Fig. 4 for an example.
Theorem 1. Given the de Bruijn graph of a tiling T, Algorithm 1 constructs a tiling equivalent to T in time O(n), where n is the number of tiles of T, i.e. the number of vertices of the graph. Proof. The idea of the algorithm is to start with the origin of the graph, and then make a breadth-first search which makes it possible to compute the tile associated with each vertex, i.e. the couple of vectors which describes the prototile, and the translation vector. Let us consider a vertex v labeled with {, }, which means that it corresponds to a tile t = (, trans) in the th de Bruijn line and the th one. Recall that f (x) is the number of the de Bruijn family of the line x. Then the prototile is defined by f () and f (). The function f is easy to compute, since two de Bruijn lines and are in the same family if and only if they do not cross each other, i.e. if there is no vertex labeled {, } in the de Bruijn graph. Therefore, we can easily find all the lines which belong to the same family, and so we can find the de Bruijn families. Finally, we obtain the prototile . The next point is to compute the translation vectors. Each of them is deduced from the translation vector of a previously marked vertex. Since we start with a vertex with translation vector (0, . . . , 0) (the origin), and since we visit the vertices in a breadth-first order, a neighbor v of v visited after v has a translation vector componentwise greater than or equal to the one of v. Suppose that we have already computed the tile t = (, trans) which corresponds to v, and consider t = ( , trans ) which corresponds to v . As discussed above, we already have t = {, } and t = {, } and trans trans. The six cases illustrated in Fig. 5 can occur. They lead to two possibilities: • if f () > f () > f () (see Fig. 5a) or f () > f () > f () (see Fig. 5b), then trans = trans;
232
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
t'
t'
t'
t' t
t
t
t
υα
υα υ γ
t'
t
t
t' υα
υγ υ υγ
(a)
(b)
υ
υγ υα (c)
υ
υ
(d)
υ
υα
υγ
(e)
υ υγ
υα
(f)
Fig. 5. The six possible positions of the two tiles t and t during the computation of the translation vectors.
• in the other cases (see Fig. 5c–f), the th component of the translation vector has to be increased by one. These remarks lead directly to Algorithm 1, and since we visit each vertex twice (once to compute f (x) for all x, and once in the main loop), its complexity is O(n), where n is the number of vertices. Algorithm 1: Construction of a tiling from its de Bruijn graph. Input: G = (V , E, , ), the de Bruijn graph of a tiling T. Output: A tiling equivalent to T, given by a list of (prototile, translation). begin Let {, } = (); Set all the vertices as unmarked; resu ← {({f (), f ()}, (0, . . . , 0))}; current ← {(, (0, 0, . . . , 0))}; Mark ; while current = ∅ do foreach = (v, trans) in current do foreach unmarked vertex v such that (v, v ) ∈ E do Let {, } be the label of v, and {, } be the label of v ; Let trans be a copy of trans; if not (f () > f () > f () or f () > f () > f ()) then Increase the f ()th component of trans by one; resu ← resu ∪ {({f (), f ()}, trans )}; current ← current ∪ {(v , trans )}; Mark v ; current ← current \ {v}; Return (resu); end This result shows that all the information contained in a 2D-gon tiling is encoded in its de Bruijn graph. However, we will show that the de Bruijn graph contains much more
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
233
Fig. 6. Two tilings and their graphs with origins. Notice that, if one removes the origins, then the two graphs are isomorphic.
information than really needed to construct the tiling. Actually, we will show that the adjacency graph contains almost all the information we need. Indeed, it suffices to add two marks to the adjacency graph of T to be able to reconstruct the tiling T. This leads to the definition of the graph with origins of a tiling T. Definition 5 (Graph with origins of a tiling). Let T be a tiling of a 2D-gon, A = (V , E) its adjacency graph. The graph with origins associated with T is G = (V , E, v1 , v2 ), where v1 and v2 are two vertices in V called the origins of G and defined as follows. v1 is the tile of T on the first side of P with translation vector (0, . . . , 0). v2 is the tile having an edge on the hull of P, adjacent to v1 by a vertex on the hull of P and whose translation vector is either (1, 1, 0, . . . , 0) if v1 belongs also to the second side of the hull of P, or (1, 0, . . . , 0) otherwise. See Fig. 6 for an example. Notice that the addition of the two origins makes it possible to distinguish two different tilings which have isomorphic adjacency graphs, as shown for example in Fig. 6. We will show in the following that this is always true: the correspondence between the graphs with origins we defined and the 2D-gon tilings is one-to-one. 3. Duality In this section, we give an algorithm which computes the de Bruijn graph of a tiling from its graph with origins. This correspondence is one-to-one, therefore, together with Algorithm 1 and Theorem 1, it shows that the graphs we introduced can be considered as dual of the considered tilings, despite the fact that they are very close to adjacency graphs (they only have two additional marks). Our algorithm has complexity O(n · m), where n is the number of vertices of the graph, or equivalently the number of tiles of the tiling, and m is the sum of the multiplicities used to define the 2D-gon. In order to build the algorithm and prove its correctness, we will first prove some properties linking tilings of 2D-gons and their adjacency graphs. In particular, some special substructures, namely borders and fans, will play a very important role. We introduce them now, and prove some of their basic properties. Definition 6 (Border of a tiling). Let T be a tiling of a 2D-gon P. Let C ⊆ T be the set of tiles of T which have at least one point in H (P ). We define the border of T, denoted by B(T ) = (C, E), as follows: (t, t ) ∈ E if and only if t and t have one edge in common
234
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
Fig. 7. Left: a tiling. Right: its border and the border of its adjacency graph.
Fig. 8. Particular cases and their adjacency graphs. Bold is the border.
and if this common edge has at least one point in H (P ). Notice that this is a subgraph of the adjacency graph of T, but it is not the subgraph induced by C (some edges are missing). See Fig. 7. A remarkable property is that the border contains all vertices of degree less than 4 of the graph (i.e. degree 2 or 3), plus possibly some of the vertices of degree 4. In the following, we make no difference between the border of a tiling T and the associated path in the adjacency graph of T, called the border of the graph. 3.1. Properties of the border Every vertex of degree 2 or 3 is in the border. Moreover, there are vertices whose degree is 4. Particular cases can occur. The border of a tiling can thus have 3 possible shapes: • if there is a vertex whose degree for the border is 1, then M = (1, n). The tiling is just a juxtaposition of tiles of the same type, and the border is a line. See Fig. 8(left). • if there is a unique vertex of degree 4, then M = (1, 1, n), the tiling is an hexagon whose sides lengths are 1,1 and n. Then the border is the disjoint union of two cycles connected by the only vertex whose degree is 4. See Fig. 8(right). • in any other case, the border of the tiling is a cycle. The two first cases are easy to recognize: we are in the first one if and only if the adjacency graph is reduced to a path, we are in the second one if and only if the adjacency graph contains a cut node (i.e. a vertex whose deletion disconnects the graph). In those cases, the tiling is then easy to construct. In the following, we assume that we are not in one of those (pathological) cases. There is no loss of generality, from the remarks just above.
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
L1
L4
L2
L3
235
+ +
L3 L4
+
L2
+
Lp
L1 L
Fig. 9. A fan, and its corresponding half-lines.
Definition 7 (Fan). Given a tiling T of a 2D-gon P, a fan F of T is a p-tuple (f1 , f2 , . . . , fp ) of tiles in T such that: • ∀i p∈ {1, . . . , p − 1} fi and fi+1 have an edge in common, • i=1 fi is a point of H (P ), called the head of the fan, • f1 and fp have one edge on the hull of the 2D-gon. The tiles f1 and fp are called the endpoints of F , and the integer p − 1 is called the length of F . Moreover, we say that a fan F belongs to one side of P if one of its endpoints has an edge included in this side of P. Notice that two adjacent tiles on the hull having one edge in common constitute a particular fan of size 1. Informally, a fan can be seen as the neighborhood of its head. Remark. The border of a tiling is a concatenation of all the fans of the tiling. Moreover, the two origins given in the graph are the endpoints of a particular fan. For convenience, we introduce some notations about fans. Notation: Let F = (f1 , . . . , fp ) be a fan of a 2D-gon tiling T. For all i such that 1i p − 1, since fi and fi+1 have exactly one edge in common, there is a de Bruijn line, denoted by Li , which contains both fi and fi+1 . In addition, each Li can be split into two distinct parts, called half-lines, one containing fi and the other containing fi+1 . We denote − the part containing fi by L+ i , and the other one by Li . See Fig. 9. Notice that L (respectively Lp ), the Bruijn line different from L1 (respectively Lp−1 ) + + passing in f1 (respectively fp ), crosses L+ 1 , L2 , . . . , Lp−1 , in the order of increasing (respectively decreasing) indices starting from the fan. + + Finally, we remark that, starting from the fan, L− i successively crosses Li+1 , Li+2 , . . . , + + − − − Lp−1 and Lp , Li successively crosses Li−1 , Li−2 , . . . , L1 and L. Thus, two half-lines having same sign do not cross each other. Moreover, by construction, one may notice that, as a de Bruijn line, a half-line separates the set of tiles not contained in itself into two parts (formally, we first define, for each tile t of Li , the representing line segment of t as the closed line segment linking centers of edges of t whose type is {vi } (where vi is the common vector defining the family of Li ). + + For L+ i , consider the set Si formed by the union of representing segments of tiles of Li
236
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
4 t'
t'
4 t'
4 3
3 2 3/2 υ4
υ3
1 υ2 υ1
t
0 t
2
1 0 t
Fig. 10. Two paths with same endpoints, and the values associated with each vertex, B being the set of all lines not in the family defined by v1 .
and the line segment common to fi and fi+1 . By definition, two tiles t and t (not in L+ i ) are in the same part if there exists a continuous function f from [0, 1] to the 2D-gon P such that, f (0) is the center of the tile t, f (1) is the center of the tile t , and for each real number x ∈ [0, 1], f (x) is not element of the set Si+ ). 3.2. Shortest paths We first define some material broadly used in the following proofs. Definition 8 (Line index, line value). Let T be a tiling, L be a de Bruijn line of T or a halfline as above, and t1 , t2 be two tiles of T. As seen before, L induces a partition of T into three parts T + , T − and L. We define the line index indL (t1 , t2 ) as follows: • if t1 ∈ L and t2 ∈ T + ∪ T − , then ind L (t1 , t2 ) = 1/2, • if t1 ∈ T + and t2 ∈ T − , or t1 ∈ T − and t2 ∈ T + , then ind L (t1 , t2 ) = 1, • in the other cases, ind L (t1 , t2 ) = 0. Let B = {L1 , . . . , Lq } be a set of de Bruijn lines and half-lines of T. The line value q ind B (t1 , t2 ) is the sum k=1 ind Lk (t1 , t2 ). Intuitively, the line value from t1 to t2 counts the number of lines of B crossed by a path from t1 to t2 . Let (t0 , t1 , . . . , tr ) be a path of tiles (i.e. two consecutive tiles are adjacent) and consider the sequence (a0 , a1 , . . . , ar ) such that for each integer i, 0 i r, ai = ind B (t1 , ti ) (see Fig. 10). We assume that B is correctly constructed, i.e. for each half-line L+ , at most one element of {L− , L+ , L} is in B, and if L+ (or L− ) is in B, then the endpoint of this half-line in the fan is not element of another line (or half-line) of B. Remark that for each integer i such that 1 i < r, ind L (t1 , ti ) = ind L (t1 , ti+1 ), except if L is a line containing one of the tiles ti or ti+1 and not the other one. Since B is correctly constructed, in any case, there are at most two of these exceptions, for each of which the index can change of 1/2 unit. Thus, |ai − ai+1 | 1. Moreover we have a0 = 0. Thus, we have: • r ar , the line value is a lower bound for the distance between two tiles, • the equivalence: r = ar if and only if for each integer i such that 0 i r, ai+1 − ai = 1.
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
237
L+4 L+3 L+2 L+1
Lp
L
Fig. 11. A fan and the unique shortest path between its endpoints (Lemma 2).
Lemma 1. Let t and t be two tiles of the border linked by a de Bruijn line L, and let (t0 , t1 , . . . , tr ) be the path of tiles starting in t = t0 induced by L (i.e. t0 = t, tr = t and all tiles ti are in L). The path (t0 , t1 , . . . , tr ) is the unique shortest path between t and t . Proof. We take B as the set of the r de Bruijn lines which cut the line L. With the above notations, we have ar = r which proves that the path is a shortest path. Now, assuming the shortest path from t to t is not unique, let p be another path of length r from t to t . The paths p and (t0 , t1 , . . . , tr ) have a common prefix (maybe only t). Let c be the last vertex in both paths, and let d be the first vertex of p not in L. Let Lc be the line crossed by L in c. The tile d necessarily is also in Lc . Then ind {Lc } (t, c) = ind {Lc } (t, d). Thus |ind B (t, c)−ind B (t, d)| 1/2, which contradicts the hypothesis that p is of length r. Lemma 2. Let T be a tiling of a 2D-gon, t, t be two tiles of T having exactly one point in common and having one edge included in a given side of the 2D-gon. The common point is assumed to belong to the hull of the 2D-gon. The unique shortest path between t and t is the fan (t = f1 , f2 , . . . , fr = t ), from t to t . See Fig. 11. Proof. The argument is exactly the same as in Lemma 1, using the set formed by {L+ i |1 i p − 1} ∪ {Lp }, (we recall that Lp is defined by the edge of t which is on the hull). 3.3. Constructing the border The first step of algorithm to construct a tiling equivalent to a tiling T starting from the graph with origins of T will be to construct its border. The vertices having degree 2 or 3 are obviously part of the border. The point is first to find the vertices of degree 4 which also belong to the border, then to find the succession between vertices along the border. We first show some properties of the graph allowing to make both these at the same time. We then give an algorithm to compute the border of the adjacency graph (Theorem 2), which completes the first step of the construction of T from its graph with origins. Having shown the shortest path properties, we turn now to the main part of the algorithm. In the following, by “successive tiles” we mean two tiles of the border having degree 2 or
238
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253 L'
L tL L+ t12
T−
T+
L−
t1
t2
Fig. 12. The general case. Light grey: L+ ; Dark grey: L− .
3 and adjacent by a point of the hull of the tiling. This corresponds to two tiles which are endpoints of a same fan. The algorithm we want to build is a greedy one, which, starting with two successive tiles of the border, finds a tile successive to one of them. Hence, starting with the origins, this constructs locally the paths between successive tiles of the border, leading to a complete construction of the border. Let T be a tiling, and t1 , t2 , t3 be three tiles such that: • t1 and t3 are endpoints of a fan, whose head is a point v (i.e. v = t1 ∩ t3 ∩ H (T )), • t1 and t2 are endpoints of a fan, whose head is a point v = v (i.e. v = t1 ∩ t2 ∩ H (T )). We assume the fan whose head is v has already been constructed, and we want to construct the fan whose head is v. Let c0 be the edge of t1 on the hull and containing v. c0 induces a de Bruijn line L, which cuts the tiling into 3 parts: T + , T − and L. We assume, without loss of generality, that t3 ∈ T − . Let c be the side of t2 on the hull and containing v . c induces a de Bruijn line L . Let cp be the side of t3 on the hull and containing v. cp induces a de Bruijn line Lp . Let t12 be the tile at the crossing between L and L , if it exists. This tile separates in particular L into L+ and L− , L− being the part from t1 and t12 excluded, and L+ being the other part of L. t1 being one endpoint of L, we denote by tL its other endpoint. Hence L+ is the part of L from t12 to tL . See Fig. 12. Let t1 , t2 , . . . , tp be the tiles of the fan induced by v, in such a way that the path from t1 to t3 is t1 = t1 , t2 , . . . , tp = t3 . Let ci be the edge in common to ti+1 and ti . We call Li the de Bruijn line induced by ci . See Fig. 13. Notice that c0 and cp are the sides on the hull induced by v. We make the assumption that t1 and t3 are not adjacent (otherwise the search for t3 is obvious). For further convenience, we call this the fan search situation, and we introduce some notations: A1 is the set of tiles closer to t1 than to t2 , i.e. A1 = {t ∈ T , dist(t, t1 ) < dist(t, t2 )}. In the same way, A2 = {t ∈ T , dist(t, t2 ) < dist(t, t1 )}. A= will be the set of tiles whose distance to both t1 and t2 is the same.
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
239
L5=Lp
L' L L1 L2 L3 L4 t3
v
t1
v'
t2
Fig. 13. The fan search situation, and the numbering of the lines.
3.3.1. General case: t2 ∈ T + This induces two different cases. Either L, L and Lp are parallel (which means c0 , cp and c have same support), or at least two of them cross each other in the tiling. We start with the last case, which is the general case. (a) c0 , cp and c do not all have same support. We assume here that c0 , cp and c do not all have same support (at least two of the lines L, Lp and L cross each other). + Proposition 3. In the general fan search situation, let Thull = {t ∈ T + , deg(t) < 4}. We have: (1) L− ⊆ A1 , + ⊆ A2 ∪ A = , (2) L+ ∪ Thull (3) if L and L are parallel (i.e. c0 and c have same support), then L ∪ T − ⊆ A1 . − As a consequence of the second item, if we state: Thull = {t ∈ T − |deg(t) < 4} and − ∪ {tL } where tL denotes the A1,hull = {t ∈ A1 |deg(t) < 4}, then we have A1,hull ⊆ Thull − endpoint of L different from t1 . Moreover, when L and L are not parallel, A1,hull ⊆ Thull .
Proof. Let ui be the ith tile of L, starting from t1 , and Mi be the line crossing L on ui . We take Bi = {Mj |1j i}. We first prove dist(ui , t2 ) dist(ui , t1 ). Lemma 1 implies that dist(t1 , ui ) = i − 1. For 1 j < i, we have ind {Mj } (ui , t2 ) = 1/2 if t2 ∈ Mj , and ind {Mj } (ui , t2 ) = 1 otherwise (since ui ∈ / Mj for i = j ). Moreover, we have: ind {Mi } (ui , t2 ) = 0 if t2 ∈ Mi , ind {Mi } (ui , t2 ) = 1/2 otherwise. Since t2 is crossed by two de Bruijn lines, at most two of the preceding values are minimal. This induces that ind Bi (ui , t2 ) (i −1/2)−2 ×1/2, thus dist(ui , t2 ) i −1. Hence dist(ui , t2 ) dist(ui , t1 ). (1) Let ui ∈ L− . Assume dist(t2 , ui ) = i − 1, and let (ui = r0 , r1 , r2 , . . . , ri−1 , ri = t2 be a (i − 1)-long path from ui to t2 . We necessarily have: ind Bi (ui , rj ) = j . We easily prove by induction that, for 0 j i, rj = ui−j : the initialization of the induction is obvious, and assuming rj = ui−j , since ind B (ui , rj +1 ) = ind B (ui , rj ) + 1, one has to leave Mj , i.e. rj +1 ∈ L, thus rj +1 = ui−j −1 . This induces t2 = t1 , which contradicts the assumptions. Hence dist(ui , t2 ) > dist(ui , t1 ).
240
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
L Lp L4+ L3+ L2+ L1+ t2
t3 t1
Fig. 14. The lines that have to be crossed to reach the hull, in the fan search situation.
(2) Let t ∈ L+ . The unique shortest path from t to t1 is following L. Moreover, the path from t to t2 consisting in following L+ until t12 , then L until t2 , has length dist(t, t1 ), because t12 ∈ A= (since each line crosses L− if and only if it crosses L− ). Then L+ ⊆ A= ∪ A2 . + . Let now t ∈ Thull (a) either the shortest path from t to t1 contains at least one tile of L+ (in this case a suffix of this path is a part of L), and one can construct a path of same length leading from t to t2 by replacing the part from t12 to t1 by the path from t12 to t2 as above. Thus t ∈ A= ∪ A2 (there may exist a shorter path from t to t2 ). (b) in the other case, the shortest path from t to t1 necessarily crosses L on a tile tL of L− (the part of L from t2 to t12 , with t12 excluded). The argument used in 1 just above induces tL ∈ A2 . Hence t ∈ A2 . This leads to the result. (3) If L and L are parallel, L = L− , and 1 induces the result for L. For T − , the case is symmetrical to 2(b). The same argument leads to the conclusion (just exchange L and L , and T + and T − ). Lemma 4. Let A1,hull = {t ∈ A1 , deg(t) < 4}. We have: (1) ∀t ∈ A1,hull , dist(t, t1 ) dist(t3 , t1 ). (2) If dist(t, t1 ) = dist(t3 , t1 ) then t ∈ Lp . − Proof. Let t ∈ A1,hull . From the preceding lemma, either t ∈ Thull , or t = tL . − If t ∈ Thull : • ind L+ (t, t1 ) = 1/2, 1 • ind L+ (t, t1 ) = 1 for 2 i p − 1, i • ind Lp (t, t1 ) = 1/2 if t ∈ Lp , 1 otherwise. Then, if B is the union of the preceding lines, we have ind B (t, t1 ) p−3+1+1/2+1/2 = p − 1, i.e. dist(t, t1 ) dist(t3 , t1 ) (Fig. 14). Moreover, the equality can be obtained only for ind Lp (t, t1 ) = 1/2, i.e. t ∈ Lp .
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
241
t
t3
t1
Fig. 15. Proof of Lemma 5: the unitary zonotope (bold), gray is the geodesic from t1 to t. The fan from t1 to t3 enforces the tiling of the whole unitary zonotope, which gives the result.
If t = tL , L and L are parallel, otherwise t ∈ A2 ∪ A= . Then L and Lp cross each other (we are not in the case where L, L and Lp are parallel), and ind Lp (t, t1 ) 1/2. This leads directly to the same result as the previous case. Lemma 5. Let t ∈ A1,hull such that dist(t, t1 ) = dist(t3 , t1 ). Let (t3 = r0 , r1 , . . . , rk = t) be the geodesic from t3 to t. For each integer i such that 0 i k, ri ∈ A1,hull . Proof. Let t ∈ Lp such that dist(t, t1 ) = dist(t3 , t1 ), and let (t1 = s0 , s1 , . . . , sp−1 = t) be a geodesic from t1 to t. + + This geodesic meets successively L+ 1 , L2 , . . . , Lp−1 , Lp . Since dist(t, t1 ) = p − 1, no + other line is crossed by the geodesic, thus s0 is necessarily on L+ 1 , s1 is on L2 , . . . and sp−1 is on Lp . Let j denote the index of the last si of the fan. Assume that j < p − 1. From the condition − above, sj +1 is on L+ j +2 , thus sj +1 necessarily is in Lj , as sj . For the same reason (if − j + 1 < p − 1), sj +2 is also in Lj , and so on until sp−1 is reached. The set of de Bruijn lines crossing the geodesic (i.e. L− j ) from sj to t is {Lj +1 , Lj +2 , . . . , Lp }. Moreover these lines are exactly those which reach the hull on the part of T − between t and t3 (Fig. 15). Thus, starting from the fan, L− j +1 successively crosses Lj +2 , Lj +3 , . . . and Lp , and no − other line is crossed by Lj +1 . One can repeat the argument: starting from the fan, L− j +2 successively crosses Lj +3 , Lj +4 . . . and Lp , and no other line is crossed by L− . j +2 On the other side, for j j p − 1, from sj to the fan, the line L+ j +1 successively meets Lj , Lj +1 , . . . , Lj and no other line is crossed by L+ j +1 between sj and the fan (with the + convention Lp = Lp for j = p − 1). This induces the result: the line Lp follows the hull between t3 and t and, for each integer i such that 0 i k, one easily constructs a path of length p − 1 from t1 to ri . Proposition 6. Let X3 denote the subset of A1,hull formed by tiles t such that dist(t, t1 ) = dist(t3 , t1 ). The tile t3 is the unique element of X3 whose degree is lower than the degree of all the other tiles of X3 .
242
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
Proof. This is obvious, from the previous lemma once it has been seen that tLp , the other endpoint of Lp , cannot be in X3 : if Lp and L cross each other, then Lp is not in A1 , from Lemma 1; otherwise, Lp and L cross each other, which implies that dist(tLp , t1 ) > dist(t3 , t1 ), using the set formed by the lines L+ i for 1 i p − 1, and L . (b) c0 , cp and c have same support. We first prove a particular property of this case, and then show some particular situations leading to a further study. All takes place in the fan search situation, with c0 , cp and c having same support. Lemma 7. Let A1,hull = {t ∈ A1 , deg(t) < 4}. Then ∀t ∈ A1,hull , dist(t, t1 ) dist(t3 , t1 )− 1. Moreover, if there exists t such that dist(t, t1 ) = dist(t3 , t1 ) − 1, then t = tL , tL being the endpoint of L opposite to t1 . Proof. We can use the arguments of the similar lemma of the previous case, except when t = tL : in this case only, it is possible to have ind L+ (t, t1 ) = 1/2. Thus we obtain p−1 ind B (t, t1 ) p − 3 + 1/2 + 1/2, which gives dist (t, t1 ) dist (t3 , t1 ) − 1 and the equality can be obtained only for tL . Two particular cases may occur, which we study now, keeping the same notations as for the preceding lemma: (1) dist(tL , t1 ) = dist(t3 , t1 ) − 1. This case corresponds to the situation described in Fig. 16: since L is crossed by each half-line L+ i on a tile ui , the geodesic from t1 to tL is necessarily (u1 , u2 , . . . , up−1 ), (t1 = u1 and tL = up−1 ). Since L and Lp are parallel, Lp also contains p − 1 tiles. Moreover, starting from t3 , Lp successively crosses Lp−1 , Lp−2 . . . .L1 . Starting from t2 , L successively crosses L1 , L2 . . . .Lp−1 . An important point for the following is that u2 is adjacent to a tile of A2 . This fact allows to discover that we are in this case. Let X3 denote the set {t ∈ A1 , dist(t, t1 ) = dist(t3 , t1 )} and Xmin denote the set of elements of X3 of minimal degree. We have: t3 ∈ Xmin , card(Xmin ) = 2, and the element t4 of Xmin different from t3 is the other endpoint of Lp . Notice that dist(t4 , tL ) = 2, and dist(t3 , tL ) = p − 1, which is at least 3, since we have dropped the particular cases when the border is not a cycle. (2) dist(tL , t1 ) = dist(t3 , t1 ). In this case, from the previous situation, a de Bruijn line L non-parallel to L, L and Lp is added to the tiling, since L contains all the tiles ui as above and one other tile. This situation can be seen in Fig. 17. The space between L and L only contains some tiles of L , and those tiles are in A= . With the notations above card(Xmin ) 2, and, if card(Xmin ) = 2, the element of Xmin different from t3 is tL . One can notice that the tile of L adjacent to t1 is adjacent to a tile of A2 ∪ A= , and that the tile of the fan adjacent to t1 has not the same property, since it is in T − .
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
243
tL
t3
t1
t2
Fig. 16. The particular case in which tL is closer to t1 than t3 , and all the tiles of Lp (in gray) are at same distance of t1 .
tL
t
L"
t' t3
t2
t1
Fig. 17. Particular case with a line crossing L. Notice that the tile adjacent to t (in gray) is in A= ∪ A2 , while none of the tiles adjacent to t .
3.3.2. Particular case: t2 ∈ L Now we have seen how to find the successor of a tile on the border in the case t2 ∈ T + , we have to study the particular case t2 ∈ L. We proceed as in the general case. The difference comes from the criterion allowing to exclude tiles in T + . Lemma 8. Considering the fan search situation, if t2 ∈ L, then: (1) let tx be a tile of T + ∪ L\{t1 }. Then tx ∈ A2 . More precisely, each geodesic from t1 to tx contains t2 , (2) t3 ∈ A1 ∪ A= . Proof. (1) If tx ∈ L, then the geodesic from tx to t1 is included in L. Since the only tile of L adjacent to t1 is t2 , tx ∈ A2 . Hence L\{t1 } ⊆ A2 . If tx ∈ T + , consider a shortest path from t1 to tx . Assume this path does not start by (t1 , t2 , . . .). Then it starts by (t1 , t , ..), with t ∈ T − . Thus the path contains a tile t (different from t1 ) which is in L, since tx ∈ T + . By Lemma 1, the unique shortest path from t1 to t follows L, which contradicts the assumption, and tx ∈ A2 .
244
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
(2) It is clear that ind L (t2 , t3 ) = ind Lp (t2 , t3 ) = 1/2. Moreover, for 3i p − 1, ind L+ (t2 ,t3 ) = 1, and ind L+ (t2 , t3 ) 1/2. Thus, considering the set B of all these lines, we 2 i obtain: ind B (t2 , t3 ) p − 3 + 3 × 1/2. This gives dist(t2 , t3 ) p − 1. Lemma 9. Let A1,=,hull = {t ∈ A1 ∪ A= , deg(t) < 4}. Then: (1) ∀t ∈ A1,=,hull , dist(t, t1 ) dist(t3 , t1 ), (2) If dist(t, t1 ) = dist(t3 , t1 ) then t ∈ Lp . We do not give the proof since it is very similar to Lemma 4. This lemma induces in particular that card(Xmin ) 2, where Xmin is defined in an analogous way as in the previous case. Since the elements such that dist(t, t1 ) = dist(t3 , t1 ) are in Lp , the two possible elements of Xmin are t3 and tLp . If card(Xmin ) = 2, we are in a case similar to Fig. 16, and there is a unitary zonotope between L and Lp . Lemma 9 underlines the fact that L \ {t1 } ∈ A2 . By construction dist(tLp , tL ) = 2, i.e. dist(tLp , A2 ) = 2. Moreover, with the same notations as previously, taking B as the set {L− i |1i p − 1} together with Lp , we have ind B (t3 , tL ) p − 1 + 1/2, since ind Lp (t3 , tL ) = 1/2, ∀i, ind L− (t3 , tL ) = 1. Moreover, p − 1 2 (otherwise there i is one tile in the fan, which is adjacent to t1 , t3 , tL and tLp , and this particular case has been excluded). Then dist(t3 , A2 ) 3, since all other tiles of A2 are further from t3 than L (see Lemma 8).
3.3.3. Algorithm for constructing the border We have now all the preliminary results necessary to write an algorithm which constructs the border of the adjacency graph of a 2D-gon tiling (Algorithm 2). In the fan search situation, we make a breadth first search in A1 , starting from t1 , and select the tiles closest to t1 with degree < 4. This gives a set of tiles, one of which is t3 in most of the cases; we call these candidates. In the general case, either there is only one candidate, and it is t3 , or there are several, and the one with minimal degree is t3 . The preceding study enlightens particular cases: • There may exist a unique candidate which is not t3 (see Lemma 7). This is the case of Fig. 16, and the candidate is tL . Then there exists a tile neighbor to both t2 and the successor of t1 on the path from t1 to tL . We can perform another breadth first search in A1 \L, since L is the path from t1 to tL . • There may exist two candidates with minimal degree, one of them is t3 . Two cases occur: ◦ if the other candidate is tLp , then we are in the case of Fig. 16 (after having performed a breadth first search in A1 \L). Thus there is a 2-long path from tLp to tL , which allows to find t3 . This can also occur in the particular case of Lemma 9, and the wrong candidate is a distance-2 neighbor of a tile of A2 . ◦ in the other case, the candidate is tL , and we are in the case of Fig. 17. Then one can find t3 in the search tree induced by the breadth first search, by starting at t1 and selecting at each step the successor having degree 3 (i.e. having 2 successors). One thus obtains two vertices, the one having degree < 4 is t3 .
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
245
These remarks lead to the following procedure: (1) if t3 and t1 are adjacent, then the result is obvious, (2) if t2 and t1 are adjacent, and t1 has degree 2, then t2 ∈ L. We make a breadth first search to find Xmin = {t ∈ A1,= , deg(t) < 4, dist(t, t1 ) minimal}. We have the alternatives below: (a) Xmin is reduced to one single element, and this one is t3 , (b) Xmin has two elements. Thus, L and Lp are parallel, and Lemma 7 induces that there exists a unique t in Xmin such that dist(t, A2 ) 3. This one is t3 . (3) in other cases, t2 ∈ T + , we make a breadth first search to find Xmin = {t ∈ A1 , deg(t) < 4, dist(t, t1 ) minimal}. We have the following alternatives: (a) Xmin has one element t. We make a test to know whether this element is t3 . Let ttest be the first tile in the shortest path from t1 to t found previously. (i) If ∃t = t1 such that t is adjacent to t2 and ttest , then t = t3 : we are in the case of Fig. 17. We make a new breadth first search to find Xmin2 = {t ∈ A1 \ L, deg(t) < 4, dist(t, t1 ) minimal}. Then Xmin2 has two elements. One of them is at distance 2 of t. The other one is t3 . (ii) otherwise, t = t3 . (b) Xmin has two elements. Then Xmin = {t3 , tL }, and L, L and Lp are parallel. We make a test to recognize t3 . Let t be a tile of Xmin and ttest be the first tile in the shortest path from t1 to t found previously. If there exists one tile of A= ∪ A2 adjacent to ttest , then t = tL , otherwise t = t3 . Theorem 2. Given the adjacency graph of a 2D-gon tiling, Algorithm 2 computes its border in time O(m · n) where n is the number of vertices of the graph, and m is the sum of the multiplicities defining the 2D-gon. Proof. The basic complexity of this greedy algorithm is O(n · m), where n is the number of vertices and m the sum of the multiplicities, because it is just visiting all the vertices with degree at most 3, and builds a breadth first search in the rest of the graph, where every vertex has degree at most 4. Then, starting with one origin, it only has to follow the distance 1 vertices until there is none. The treatment of the particular cases can also be done in O(n · m). This leads to a global time complexity O(n · m). 3.4. Constructing de Bruijn lines We will now show that, when one knows the border of the graph with origins of a 2Dgon tiling T, then one can construct the de Bruijn lines of T by computing shortest paths in the graph. Indeed, when the border is constructed, one knows the succession of tiles along the hull of the tiling. Then, one can find the jth tile for each j ∈ 1, . . . , m, m being the sum of the multiplicities (with the convention that a tile with two edges on the hull is simultaneously the jth and the (j + 1)th of the sequence, the first tile is the origin v1 ). By the construction of the tiling, one can easily check that the jth and the (m + j )th tile correspond to endpoints of lines of a same family.
246
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
Algorithm 2: Construction of the border of the adjacency graph of a 2D-gon tiling. Input: G = (V , E, v1 , v2 ) the graph with origins of a 2D-gon tiling. Output: The border of G, B(G), as an ordered list of vertices. begin // we assume the function BF S(X, t) computes the set of // closest vertices to t in X with degree <4 and minimal. Let B be the set of vertices in V of degree< 4; t 1 ← v2 , t 2 ← v1 ; B ← shortestpath(t2 , t1 ) excluding t1 ; repeat if ∃t ∈ B, t = t2 , (t1 , t) ∈ E then t3 ← t; //case 1. t1 and t3 are adjacent else if (t1 , t2 ) ∈ E and deg(t1 ) = 2 then Xmin = BF S(A1 ∪ A= , t1 ); //case 2. t2 ∈ L if card(Xmin ) = 1 then t3 ← Xmin ; //case 2(a) else Let t ∈ Xmin , dist(t, A2 ) 3; // case 2(b) t3 ← t; else Xmin = BF S(A1 , t1 ); //case 3 if card(Xmin ) = 1 then let ttest be the first tile on the path (t1 , Xmin ); //case 3(a) if ∃t = t1 ∈ V , (ttest , t ) ∈ E, (t1 , t2 ) ∈ E and (t2 , t ) ∈ E then Xmin2 = BF S(A1 \ path(t1 , Xmin ), t1 ); // case3(a)i. t3 ← t, t ∈ Xmin2 , dist(t, Xmin ) 3; else t3 ← Xmin ; //case 3(a)ii. else // case 3(b); let t ∈ Xmin , and ttest the first tile on the shortest path (t1 , t); let t be the other vertex in Xmin ; if ∃t ∈ V , (t, ttest ) ∈ E, t ∈ A= ∪ A2 then t3 = t else t3 = t; Add the shortest path from t1 to t3 (excluding t3 ) at the end of B; t2 ← t1 , t1 ← t3 ; until t3 = v1 ; Return(B); end
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
Lt
247
t' 5 L' 4 3 1
0 t
2 Lt'
Fig. 18. The general case, and the values associated with one path from t to t .
The two following lemmas show that taking one tile on one side of the tiling and computing the shortest paths to all the tiles on the opposite side of the tiling, one finds the de Bruijn line as being the one with minimal length. Notice that m can be easily computed from the adjacency graph: we have 2m = 2T2 + T3 , where T2 denotes the number of tiles of degree 2 and T3 denotes the number of tiles of degree 3. Lemma 10. Let T be a tiling of a 2D-gon, t and t be two tiles of T, with t on the side i and t on the side m + i of the 2D-gon. This induces that t and t are endpoints of lines of the ith family. Let Lt (respectively Lt ) be the line of the ith family containing t (resp. t ). Assume r is the number of lines of the ith family not placed between Lt and Lt . Then dist(t, t ) = m − r − 2 (where m is the sum of the multiplicities). See Fig. 18. Proof. We consider the line value associated with all the de Bruijn lines except the r lines of the ith family which are not between Lt and Lt . Each of these lines has to be crossed, except those containing t of t . Then the line value is (m − r) − 4 × 1/2 = m − r − 2 (1/2 is removed each time a line contains t or t ). Thus the length of the path from t to t is at least m − r − 2. Let now L be the de Bruijn line crossing Lt at t. Consider the path consisting in following L until Lt is reached, then following Lt until t is reached. Each step consists in leaving one line and reaching another, so it increases the line value by 1. Hence this path is m−r −2 steps long. Lemma 11. Let T be a tiling, t, t be two tiles, which are endpoints of a de Bruijn line L, and t be a tile such that there exists a fan from t to t . We have dist(t, t ) dist(t, t ). See Fig. 19. Proof. Let (t = t0 , t1 , . . . , tr = t ) be the path induced by L starting in t. For each integer i such that 1i < r, let Li denote the de Bruijn line crossing L in ti , and bi the value 1 if i = 0, and b0 = 1/2. Remark that ind Li (t, t ) = bi if t is not on Li and ind Li (t, t ) = bi −1/2 if t is on Li . Thus, taking the family B of lines Li , we have: ind B (t, t ) ri=0 br − 1, since t is on at most two lines Li . Therefore, ind B (t, t ) r − 1/2. Moreover dist(t, t ) = r.
248
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
L t"
t'
t
Fig. 19. The positions of the tiles for Lemma 11.
Thus dist(t, t ) ind B (t, t ) dist(t, t ) − 1/2, which gives the result, since dist(t, t ) is an integer. We then have a criterion to find the endpoints of each de Bruijn line. It is clear that taking one tile t1 and the tile t2 placed at the opposite of t1 in the border (i.e. t1 is at the th position, and t2 is at the ( + m)th, m being the sum of multiplicities), one obtains two endpoints of lines of a same family. Moreover we assume that the ( − 1)th position is not in the same side as the th position. We consider the tile t3 , placed after t2 in the hull. If t3 is in the same family as t2 , then dist(t1 , t3 ) = dist(t1 , t2 ) − 1. In the other case, then dist(t1 , t3 ) dist(t1 , t2 ). This gives an algorithmic criterion to find the de Bruijn lines. Precisely, the algorithm computes the de Bruijn lines as follows: it first computes the distance dist(t1 , t2 ). Then, it moves from t2 to its successor tile in the hull (following the border along a fan), say t3 , and computes dist(t1 , t3 ). If dist(t1 , t3 ) = dist(t1 , t2 ) − 1, we are in the same side (Lemma 10). Then we go on until dist(t1 , tj ) dist(t1 , tj −1 ), where tj is the (j − 2)th successor of t2 in the border. At this point, we know that t2 , . . . , tj −1 and t1 are the endpoints of lines of the same family (from Lemma 11). Then the de Bruijn lines of this family are the shortest paths between successively (t1 , tj −1 ), (t1 , tj −2 ), . . . , (j −2) (k) , t2 ), where the t1 is the kth successor of t1 in the hull. and (t1 This allows to compute an entire de Bruijn family, and processing for each family, we obtain the whole tiling. This remarks lead directly to the following theorem. Theorem 3. Given the graph with origins of a 2D-gon tiling T and its border, Algorithm 3 computes the de Bruijn graph of T in time O(n · m) where n is the number of vertices of the graph and m is the sum of all the multiplicities which define the 2D-gon. Starting from the graph with origins of a 2D-gon tiling T, it is now clear that one can construct a tiling equivalent to T by computing the border of the graph with Algorithm 2,
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
249
Algorithm 3: Construction of the de Bruijn graph of a 2D-gon tiling from its graph with origins. Input: G = (V , E, v1 , v2 ) the graph with origins of a 2D-gon tiling T and B(G) its border. Output: G = (V , E, , ), the de Bruijn graph of T. begin i ← 1; //computation of m = size(B)/2 foreach x ∈ B(G) do if deg(x) < 4 then B[i] ← x, i ← i + 1; if deg(x) = 2 then B[i] ← x, i ← i + 1; ← 1; repeat ← + size(B)/2; // and are the indices of the endpoints dist[0] ← distance(B[], B[]); //dist[i]:length of the ith path currentpath ← shortest path(B[], B[]); endfamily ← false; //currentpath contains the last computed path l ← 0; // loop for determining the size l of a de Bruijn family while endfamily=false and + l < size(B) do l ← l + 1; tmp ← shortest path(B[], B[ + l]); dist[l] ← distance(B[], B[ + l]); if dist[l] < dist[l − 1] then currentpath ← tmp else endfamily ← true //computation of the lines of the current family foreach vertex v of currentpath do (v) ← (v) ∪ {}; l ← l − 2; ← + 1; while l 0 do build the shortest path between B[] and B[ + l]; foreach vertex v of the path do (v) ← (v) ∪ {}; l ← l − 1; ← + 1; until > size(B)/2; Return (V , E, , v1 ); end
250
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
Fig. 20. A tiling of an octagon (D = 4) (left) and two other tilings of the same octagon obtained from the first one by a flip (the shaded tiles are the ones which moved during the flip).
then compute the de Bruijn graph with Algorithm 3, and finally obtain the tiling using Algorithm 1. Therefore, we can finally combine Theorems 1–3 to obtain: Theorem 4. Given the graph with origins of a 2D-gon tiling T, there is an algorithm which constructs a 2D-gon tiling equivalent to T in time O(m · n), where n is its number of tiles, and m the sum of the multiplicities of the vectors used to define the 2D-gon. This result not only gives an efficient and simple way to encode and manipulate 2D-gon tilings; it also clarifies the relation that exists between the adjacency graph of a tiling and the tiling itself. In particular, it proves that, despite the fact that there is no one-to-one correspondence between adjacency graphs and tilings, the adjacency graph contains almost all the information on the tiling. 4. An application: random tilings Tilings of 2D-gons are an important model of quasicrystals in physics. In this context, it is very important to be able to sample random tilings, which helps the study of the entropy of the quasicrystal [15]. The sampling uses the key notion of flip: given a 2D-gon tiling, one may rearrange locally three tiles (which form an hexagon) in order to obtain a new tiling of the same 2D-gon (see Fig. 20). This enables the random generation of tilings of a 2D-gon: it is shown in [9,10] that one can obtain all the tilings of a 2D-gon from a given one by iterating the flip operation. When one wants to obtain a random tiling, one then has to choose a particular tiling and then iterate the flip operation until the obtained tiling can be considered as random. This notion of when one can stop the process is central when one wants to sample random tilings with the uniform distribution. It is possible to sample perfectly random tilings of hexagons because of the distributive lattice structure of the set of all the tilings [12]. This technique can no longer be used for octagon, but a recent study explains how long the process has to be continued in order to be as close as one may want of the uniform distribution [8]. For the other 2D-gons, i.e. when D > 4, there are no known results [15]. Therefore, when one wants to sample a random tiling of a given 2D-gon P, the only solution is to construct a particular tiling of P and iterate the flip operation. To achieve this, one can use the graphs encodings we proposed above: the flip operation can be encoded on the graph, as shown in Fig. 21. The vertices which correspond to the tiles to flip form a triangle in the graph, and conversely, all the triangles in the graph correspond to a possible flip
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
251
Fig. 21. A flip on a 2D-gon, and on its graph.
Fig. 22. A random tiling of a 5 → 2 tiling with side size 16, obtained after 100 million flips.
in the tiling. Moreover, the transformation on the graph is a local rearrangement of vertices. The flip just exchanges the links of edges having the same label. Indeed, it just corresponds to exchanging the order between tiles within each de Bruijn line. Hence, considering a line, the tiles are exchanged during a flip, which corresponds to linking each tile with the preceding neighbor of the other tile. Notice however that this operation needs the labels, and cannot be performed on the adjacency graph, which is unlabeled. This makes it possible to implement the flip operation very efficiently and so to iterate it a very high number of times. We show in Fig. 22 a random tilings of a decagon obtained this way.
252
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
5. Perspectives The algorithmic study of tilings of 2D-gons is only at its beginning, and many open problems still exist. We cited the problem of knowing how many flips have to be done in order to obtain random tilings with a distribution close to the uniform distribution. Another important area is the generation of all the tilings of a 2D-gon, and their enumeration. The encodings with graphs may be used to study these problems. For example, one may obtain a characterization of which graphs are the graphs associated with a 2D-gon tiling: these graphs are planar, the degree of each vertex is at most four, and they may have many other properties which could help in generating and counting them. Moreover, 2D-gons are a special class (the dimension 2 case) of a very important class of objects, namely zonotopes [16]. These objects can be viewed as generalizations of 2D-gons in higher dimensions, and they play an important role in combinatorics and physics. They are also strongly related to oriented matroid theory [13]. Many studies already deal with these objects, but their algorithmic manipulation is still a problem, while it would help a lot in verifying conjectures, compute special tilings, and compute some statistics over them. The results presented here may be extended to this more general case, leading to other classes of graphs with interesting properties. Notice however that this generalization is not obvious, since our proofs deeply use properties related to the dimension 2. It is well known in zonotopes theory that there is a gap of complexity between 2-dimensional zonotopes (2D-gons) and 3-dimensional ones [16].
Acknowledgments The authors are very grateful with the anonymous referee, who suggested a lot of improvements and accepted to carefully and quickly read the successive manuscripts.
References [1] E. Babson, L. Finschi, K. Fukuda, Cocircuit graphs and efficient orientation reconstruction in oriented matroids, European J. Combin. 22 (2001) 587–600. [2] G.D. Bailey, Coherence and enumeration of tilings of 3-zonotopes, Discrete Comput. Geom. 22 (1999) 119–147. [3] R. Berger, The undecidability of the domino problem, Mem. Amer. Math. Soc. 66 (1966). [4] A. Björner, M. Las Vergnas, B. Sturmfels, N. White, G.M. Ziegler, Oriented Matroids, Encyclopedia of Mathematics, Vol. 46, second ed., Cambridge University Press, Cambridge, 1999. [5] R. Codovil, K. Fukuda, A. Guedes de Oliveira, On the cocircuit-graph of an oriented matroid, Discrete Comput. Geom. 24 (2000) 257–265. [6] N.G. de Bruijn, Dualization of multigrids, J. Phys. France C 47 (1981) 3–9. [7] N. Destainville, Entropie configurationnelle des pavages aléatoires et des membranes dirigées, Ph.D. Thesis, University Paris VI, 1997. [8] N. Destainville, Mixing times of plane random rhombus tilings, in: Proc. Conf. DM-CCG: Discrete Models: Combinatorics, Computation, and Geometry, 2001, pp. 1–22. [9] S. Elnitsky, Rhombic tilings of polygons and classes of reduced words in Coxeter groups, J. Combin. Theory 77 (1997) 193–221. [10] R. Kenyon, Tiling a polygon with parallelograms, Algorithmica 9 (1993) 382–397.
F. Chavanon et al. / Theoretical Computer Science 346 (2005) 226 – 253
253
[11] M. Latapy, Generalized integer partitions, tilings of zonotopes and lattices, in: A.A. Mikhalev, D. Krob, E.V. Mikhalev (Eds.), Proc. 12th Internat. Conf. on Formal Power Series and Algebraic Combinatorics, FPSAC’00, Springer, Berlin, 2000, pp. 256–267, preprint available at http://www.liafa.jussieu.fr/∼latapy/. [12] J. Propp, Generating random elements of finite distributive lattices, Electron. J. Combin. 4 (1998). [13] J. Richter-Gebert, G. Ziegler, Zonotopal tilings and the Bohne–Dress theorem, Contemp. Math. 178 (1994) 211–232. [14] M. Senechal, Quasicrystals and Geometry, Cambridge University Press, Cambridge, 1995. [15] M. Widom, R. Mosseri, N. Destainville, F. Bailly, Arctic octahedron in three-dimensional rhombus tilings and related integer solid partitions, J. Statist. Phys. 109 (2002) 945–965. [16] G. Ziegler, Lectures on Polytopes, Graduate Texts in Mathematics, Springer, Berlin, 1995.
Theoretical Computer Science 346 (2005) 254 – 264 www.elsevier.com/locate/tcs
A solution to the tennis ball problem夡 Anna de Mier∗ , Marc Noy Departament de Matemàtica Aplicada II, Universitat Politècnica de Catalunya, Jordi Girona 1-3, 08034 Barcelona, Spain
Abstract We present a complete solution to the so-called tennis ball problem, which is equivalent to counting the number of lattice paths in the plane that use North and East steps and lie between certain boundaries. The solution takes the form of explicit expressions for the corresponding generating functions. Our method is based on the properties of Tutte polynomials of matroids associated to lattice paths. We also show how the same method provides a solution to a wide generalization of the problem. © 2005 Elsevier B.V. All rights reserved. Keywords: Lattice path; Tutte polynomial; Kernel method
1. Introduction The statement of the tennis ball problem is the following. There are 2n balls numbered 1, 2, 3, . . . , 2n. In the first turn, balls 1 and 2 are put into a basket and one of them is removed. In the second turn, balls 3 and 4 are put into the basket and one of the three remaining balls is removed. Next, balls 5 and 6 go in and one of the four remaining balls is removed. The game is played n turns and at the end there are exactly n balls outside the basket. The question is how many different sets of balls we may have at the end outside the basket. It is easy to reformulate the problem in terms of lattice paths in the plane that use steps E = (1, 0) and N = (0, 1). It amounts to counting the number of lattice paths from (0, 0) to 夡
Research partially supported by projects BFM2001-2340 and CUR Gen. Cat.1999SGR00356.
∗ Corresponding author.
E-mail addresses:
[email protected] (A. de Mier),
[email protected] (M. Noy). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.017
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
255
P π
Fig. 1. The path = EEN N N EEEEN N N N N EE not above P = (N 2 E 2 )4 . It has i() = 3 and e() = 2, corresponding to the steps underlined.
(n, n) that never go above the path N E · · · N E = (N E)n . Indeed, if = 1 2 . . . 2n−1 2n is such a path, a moment’s thought shows that we can identify the indices i such that 2n−i+1 is a N step with the labels of balls that end up outside the basket. The number of such paths is well-known to be a Catalan number, and this is the answer obtained in [4]. The problem can be generalized as follows [6]. We are given positive integers t < s and sn labelled balls. In the first turn, balls 1, . . . , s go into the basket and t of them are removed. In the second turn, balls s + 1, . . . , 2s go into the basket and t among the remaining ones are removed. After n turns, tn balls lie outside the basket, and again the question is how many different sets of balls we may have at the end. Letting k = t, l = s − t, the problem is seen as before to be equivalent to counting the number of lattice paths from (0, 0) to (ln, kn) that use N and E steps and never go above the path N k E l · · · N k E l = (N k E l )n . This is the version of the problem we solve in this paper. From now on we concentrate on lattice paths that use N and E steps. To our knowledge, the only cases solved so far are k = 1 and k = l = 2. The case k = 1 is straightforward, the answer being a generalized Catalan number 1/(l(n + 1) + 1) (l+1)(n+1) . The case n+1 k = l = 2 (corresponding to the original problem when s = 4, t = 2) is solved in [6] using recurrence equations; here we include a direct solution. This case is illustrated in Fig. 1, to which we refer next. A path not above (N 2 E 2 )n is “almost” a Catalan path, in the sense that it can raise above the dashed diagonal line only through the dotted points. But clearly between two consecutive dotted points hit by we must have an E step, followed by a Catalan path of odd semilength, followed by a N step. Thus, is a sequence 2nessentially n of Catalan paths of odd semilength. If G(z) = n 1/(n + 1) n z is the generating function for the Catalan numbers, take the odd part Go (z) = (G(z) − G(−z))/2. Then expand 1/(1 − zGo (z)) to obtain the sequence 1, 6, 53, 554, 6363, . . . , which agrees with the results in [6]. Let P be a lattice path from (0, 0) to (m, r), and let b(P ) be the number of paths from (0, 0) to (m, r) that never go above P. If P N denotes the path obtained from P by adding a N step at the end of P, then clearly b(P ) = b(P N ). However, it is not possible to express
256
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
b(P E) simply in terms of b(P ), where P E has the obvious meaning. As is often the case in counting problems, one has to enrich the objects under enumeration with additional parameters that allow suitable recursive decompositions. This is precisely what is done here: Eqs. (2) and (3) in the next section contain variables x and y, corresponding to two parameters that we define on lattice paths not above a given path P. These equations are the key to our solution. The basis of our approach is the connection between lattice paths and matroids established in [2], where the link with the tennis ball problem was already remarked. For completeness, we recall the basic facts needed from [2] in the next section. In Section 3, we present our solution to the tennis ball problem, in the form of explicit expressions for the corresponding generating functions; see Theorem 1. In Section 4, we show how the same method can be applied to a more general problem. We conclude with some remarks.
2. Preliminaries The contents of this section are taken mainly from [2], where the reader can find additional background and references on matroids, Tutte polynomials, and lattice path enumeration. A matroid is a pair (E, B) consisting of a finite set E and a nonempty collection B of subsets of E, called bases of the matroid, that satisfy the following conditions: (1) no set in B properly contains another set in B, and (2) for each pair of distinct sets B, B in B and for each element x ∈ B − B , there is an element y ∈ B − B such that (B − x) ∪ y is in B. Let P be a lattice path from (0, 0) to (m, r). Associated to P there is a matroid M[P ] on the set {1, 2, . . . , m + r} whose bases are in one-to-one correspondence with the paths from (0, 0) to (m, r) that never go above P. Given such a path = 1 2 . . . m+r , the basis corresponding to consists of the indices i such that i is a N step. Hence, counting bases of M[P ] is the same as counting lattice paths that never go above P. For any matroid M there is a two-variable polynomial with nonnegative integer coefficients, the Tutte polynomial t (M; x, y). It was introduced by Tutte [9] and presently plays an important role in combinatorics and related areas (see [11]). The key property in this context is that t (M; 1, 1) equals the number of bases of M. Given a path P as above, there is a direct combinatorial interpretation of the coefficients of t (M[P ]; x, y). For a path not above P, let i() be the number of N steps that has in common with P, and let e() be the number of E steps of before the first N step, which is 0 if starts with a N step. See Fig. 1 for an illustration. Then we have (see [2, Theorem 5.4]) t (M[P ]; x, y) =
x i() y e() ,
(1)
where the sum is over all paths that do not go above P. A direct consequence is that t (M[P ]; 1, 1) is the number of such paths. Furthermore, for the matroids M[P ] there is a rule for computing the Tutte polynomial that we use repeatedly (see [2, Section 6]). If P N and P E denote the paths obtained from
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
257
P by adding a N step and an E step at the end of P, respectively, then t (M[P N ]; x, y) = x t (M[P ], x, y), t (M[P E]; x, y) =
x x t (M[P ], x, y) + y − t (M[P ]; 1, y). x−1 x−1
(2) (3)
The right-hand side of (3) is actually a polynomial, since x − 1 divides t (M[P ]; x, y) − t (M[P ]; 1, y). The key observation here is that we cannot simply set x = y = 1 in (3) to obtain an equation linking t (M[P E]; 1, 1) and t (M[P ]; 1, 1). For those familiar with matroid theory, we remark that i() and e() correspond to the internal and external activities of the basis associated to with respect to the order 1 < 2 < · · · < m + r of the ground set of M[P ]. Also, the matroids M[P N ] and M[P E] are obtained from M[P ] by adding an isthmus and taking a free extension, respectively; it is known that formulas (2) and (3) correspond precisely to the effect these two operations have on the Tutte polynomial of an arbitrary matroid. From (1) and the definition of i() and e(), Eq. (2) is clear, since any path associated to M[P N ] has to use the last N step. For completeness, we include a direct proof of Eq. (3). We first rewrite the right-hand side of (3) as x (t (M[P ]; x, y) − t (M[P ]; 1, y)) + yt (M[P ]; 1, y) x−1 x = y e() (x i() − 1) + y e()+1 x − 1 = y e() (y + x + x 2 + · · · + x i() ),
where the sums are taken over all paths that do not go above P. To prove the formula, for each path not above P we find i() + 1 paths not above P E such that their total contribution to t (M[P E]; x, y) is y e() (y + x + x 2 + · · · + x i() ). Consider first the path 0 = E; it clearly does not go above P E and its contribution to the Tutte polynomial is y e()+1 . Now, for each j with 1 j i(), define the path j as the path obtained from by inserting an E step after the jth N step that has in common with P (see Fig. 2). The path j has exactly j N steps in common with P E, and begins with e() E steps. Observe also that, if the jth N step of is the kth step, then and j agree on the first k and on the last m + r − k steps. It remains only to show that each contribution to the Tutte polynomial of M[P E] arises as described above. Let be a path that never goes above P E and consider the last N step that has in common with P E; clearly the next step must be E (in the case where and P E have no N steps in common, this would be the initial E step of ). Let be the path obtained after removing this E step. Since had no N steps in common with P E after the removed E step, the path does not go above P. Thus, the path can be obtained from by adding an E step after the i( )th N step that has in common with P, and hence arises from as above. By the remarks at the end of the previous paragraph, it is clear that cannot be obtained in any other way by applying the procedure described above, and this finishes the proof.
258
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
P π
PE
PE
PE π1
π0
π2
Fig. 2. Illustrating the combinatorial proof of formula (3).
3. Main result Let k, l be fixed positive integers, and let Pn = (N k E l )n . Our goal is to count the number of lattice paths from (0, 0) to (ln, kn) that never go above Pn . From the considerations in the previous section, this is the same as computing t (M[Pn ]; 1, 1). Let An = An (x, y) = t (M[Pn ]; x, y). By convention, P0 is the empty path and A0 = 1. In order to simplify the notation we introduce the following operator on two-variable polynomials: x x A(x, y) = A(x, y) + y − A(1, y). x−1 x−1 Then, by Eqs. (2) and (3) we have An+1 = l (x k An ), where i denotes the operator applied i times. For each n0 and i = 1, . . . , l, we define polynomials Bi,n (x, y) and Ci,n (y) as Bi,n = i x k An (x, y) , Ci,n = Bi,n (1, y). We also set C0,n (y) = An (1, y). Note that Bl,n = An+1 and C0,n (1) = An (1, 1) is the quantity we wish to compute.
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
259
Then, by the definition of , we have x x k x An + y − C0,n , B1,n = x−1 x−1 x x B2,n = B1,n + y − C1,n , x−1 x−1 .. . x x Bl,n = Bl−1,n + y − Cl−1,n , x−1 x−1 An+1 = Bl,n . In order to solve these equations, we introduce the following generating functions in the variable z (but recall that the coefficients are polynomials in x and y): An zn , Ci = Ci,n zn , i = 0, . . . , l. A= n0
n0
We start from the last equation An+1 = Bl,n and substitute repeatedly the value of Bi,n from the previous equation. Taking into account that n An+1 zn = (A − 1)/z, a simple computation yields l A−1 x i−1 x k+l A + (yx − y − x) C . = l i l−i z (x − 1) i=1 (x − 1)
(4)
We now set y = 1 and obtain l x i−1 (x − 1)l−i Cl−i , A (x − 1)l − zx k+l = (x − 1)l − z i=1
(5)
where it is understood that from now on we have set y = 1 in the series A and Ci . By Puiseux’s theorem (see [8, Chapter 6]), the algebraic equation in w (w − 1)l − zw k+l = 0
(6) has k + l solutions in the field Cfra ((z)) = { n n0 an zn/N } of fractional Laurent series. Proposition 6.1.8 in [8] tells us that exactly l of them are fractional power series (without negative powers of z); let them be w1 (z), . . . , wl (z). We substitute x = wj in (5) for j = 1, . . . , l, so that the left-hand side vanishes, and obtain a system of l linear equations in C0 , C1 , . . . , Cl−1 , whose coefficients are expressions in the wj , namely l i=1
wji−1 (wj − 1)l−i zCl−i = (wj − 1)l ,
j = 1, . . . , l.
(7)
Note that, in order of the product in the left-hand side of (5) to be defined, the solutions of (6) that we substitute in (5) cannot have negative powers of z, hence they must be w1 , . . . , wl . The method of pairing two variables so that one side of an equation vanishes is presently called the kernel method; in our case, the kernel of the equation is (x − 1)l − zx k+l .
260
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
We refer the reader to [1] for a list of references on the kernel method, and also to [3,7] for further examples and variations. It remains only to solve (7) to obtain the desired series C0 = n An (1, 1)zn . System (7) can we written as i l−1 wj zCl−i−1 = wj − 1, j = 1, . . . , l. i=0 wj − 1 The left-hand equations can be viewed as the result of evaluating the sides of the previous i of degree l − 1 at X = w /(w − 1), for j with 1 j l. polynomial l−1 (zC )X l−i−1 j j i=0 Using Lagrange’s interpolation formulas, we get that the coefficient of X l−1 in this polynomial is zC0 =
l j =1
i=j
wj − 1 wj wj −1 −
wi wi −1
.
By straightforward manipulation this last expression is equal to −
l
j =1
(1 − wj )
l (wj − 1)l−1 (1 − wj ), =− j =1 j =1 i=j (wj − wi ) l
where the last equality follows from an identity on symmetric functions (set r = 0 in Exercise 7.4 in [8]). Thus, we have proved the following result. Theorem 1. Let k, l be positive integers. Let qn be the number of lattice paths from (0, 0) to (ln, kn) that never go above the path (N k E l )n , and let w1 , . . . , wl be the unique solutions of the equation (w − 1)l − zw k+l = 0 that are fractional power series. Then the generating function Q(z) = given by Q(z) =
n 0 qn z
n
is
−1 (1 − w1 ) · · · (1 − wl ). z
Remark that, by symmetry, the number of paths not above (N l E k )n must be the same as in Theorem 1, although the algebraic functions involved in the solution are roots of a different equation. In the particular case k = be expressed directly in terms of the can l, the solution n for the Catalan numbers, which satisfies generating function G(z) = n 1/(n + 1) 2n z n the quadratic equation G(z) = 1 + zG(z)2 . Indeed, (6) can be rewritten as w = 1 + z1/k w 2 ,
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
261
whose (fractional) power series solutions are G(j z1/k ), j = 0, . . . , k − 1, where is a primitive kth root of unity. For instance, for k = l = 3 (corresponding to s = 6, t = 3 in the original problem), = exp(2i/3) and we obtain the solution −1 (1 − G(z1/3 ))(1 − G(z1/3 ))(1 − G(2 z1/3 )) z = 1 + 20z + 662z2 + 26780z3 + 1205961z4 + 58050204z5 + · · · . In the same way, if l divides k and we can be expressed set p = (k + l)/ l, the solution n in terms of the generating function n 1/((p − 1)n + 1) pn n z for generalized Catalan numbers; the details are left to the reader. As an example, for k = 4, l = 2, we obtain the series −1 (1 − H (z1/2 ))(1 − H (−z1/2 )) z = 1 + 15z + 360z2 + 10463z3 + 337269z4 + 11599668z5 + · · · , 3 where H (z) = n 1/(2n + 1) 3n n satisfies H (z) = 1 + zH (z) .
4. A further generalization In this section, we solve a further generalization of the tennis Given fixed ball problem. positive integers s1 , t1 , . . . , sr , tr with ti < si for all i, let s = si , t = ti . There are sn labelled balls. In the first turn we do the following: balls 1, . . . , s1 go into the basket and t1 of them are removed; then balls s1 + 1, . . . , s1 + s2 go into the basket and among the remaining ones t2 are removed; this goes on until we introduce balls s − sr + 1, . . . , s, and remove tr balls. In each successive turn we perform r steps in a similar manner, putting a total of s balls into the basket and removing t. After n turns there are tn balls outside the basket and the question is again how many different sets of tn balls we may have at the end. The equivalent path counting problem is: given k1 , l1 , . . . , kr , lr positive integers with k = ki , l = li , count the number of lattice paths from (0, 0) to (ln, kn) that never go above the path Pn = (N k1 E l1 · · · N kr E lr )n . The solution parallels the one presented in Section 3. We keep the notation and let An = t (M[Pn ]; x, y), so that An+1 = lr (x kr · · · l1 (x k1 An ) · · ·). As before, we introduce l polynomials Bi,n (x, y) and Ci,n (y) = Bi,n (1, y), but the definition here is a bit more involved: Bi,n = i (x k1 An ), i = 1, . . . , l1 , Bl1 +i,n = i (x k2 Bl1 ,n ), i = 1, . . . , l2 , Bl1 +l2 +i,n = i (x k3 Bl1 +l2 ,n ), i = 1, . . . , l3 , .. . Bl−lr +i,n = i (x kr Bl−lr ,n ), i = 1, . . . , lr .
(8)
262
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
We also set C0,n (y) = An (1, y). Again, from the definition of , we obtain a set of equations involving An , An+1 = Bl,n , the Bi,n and the Ci,n . We define generating functions A and Ci (i = 0, . . . , l) as in Section 3. Starting with An+1 = Bl,n , we substitute repeatedly the values of the Bi,n from previous equations and set y = 1. After a simple computation we arrive at A (x − 1)l − zx k+l = (x − 1)l + z U (x, C0 , . . . , Cl−1 ),
(9)
where U is a polynomial in the variables x, C0 , . . . , Cl−1 that depends linearly on each Ci . Observe that the difference between (9) and Eq. (5) is that now U is not a concrete expression but a certain polynomial that depends on the particular values of the ki and li . Let w1 , . . . , wl be again the power series solutions of (6). Substituting x = wj in (9) for j = 1, . . . , l, we obtain a system of linear equations in the Ci . Since the coefficients are rational functions in the wj , the solution consists also of rational functions; they are necessarily symmetric since the wj , being conjugate roots of the same algebraic equation, are indistinguishable. Thus, we have proved the following result. Theorem 2. Let k1 , l1 , . . . , kr , lr be positive integers, and let k = ki , l = li . Let qn be the number of lattice paths from (0, 0) to (ln, kn) that never go above the path (N k1 E l1 · · · N kr E lr )n , and let w1 , . . . , wl be the unique solutions of the equation (w − 1)l − zw k+l = 0 that are fractional power series. Then the generating function Q(z) = given by Q(z) =
n 0 qn z
n
is
1 R(w1 , . . . , wl ), z
where R is a computable symmetric rational function of w1 , . . . , wl . As an example, let r = 2 and (k1 , l1 , k2 , l2 ) = (2, 2, 1, 1), so that k = l = 3. Solving the corresponding linear system we obtain R=
(1 − w1 )(1 − w2 )(1 − w3 ) 2w1 w2 w3 − (w1 w2 + w1 w3 + w2 w3 )
and Q(z) =
1 R = 1 + 16z + 503z2 + 19904z3 + 885500z4 + 42298944z5 + · · · . z
It should be clear that for any values of the ki and li the rational function R can be computed effectively. In fact, a simple computer program could be written that on input k1 , l1 , . . . , kr , lr , outputs R.
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
263
5. Concluding remarks It is possible to obtain an expression for the generating function of the full Tutte polynomials An (x, y) defined in Section 3. We outline the proof of the formula n0
An (x, y)zn =
−(x − w1 ) · · · (x − wl ) . (zx k+l − (x − 1)l )(y + w1 − yw1 ) · · · (y + wl − ywl )
(10)
Note that taking x = y = 1 we recover the formula stated in Theorem 1 and that this formula generalizes Theorem 5.6 of [2]. From (4), we obtain A((x − 1)l − zx k+l ) = (x − 1)l + z(yx − y − x)
l i=1
x i−1 (x − 1)l Cl−i ,
(11)
where A and the Ci are power series in z whose coefficients are polynomials in x, y and y, respectively. Note that the kernel of the equation is the same as in (5), so it has l roots that are fractional power series, w1 , . . . , wl . Observe that the right-hand side of (11) is a polynomial in x of degreel that vanishes at w1 , . . . , wl ; the leading coefficient of this polynomial is 1 + z(y − 1) l−1 i=0 Ci . Hence, (x − w1 ) · · · (x − wl )(1 + z(y − 1) l−1 i=0 Ci ) A= . (x − 1)l − zx k+l To show thatthis expression is indeed equal to (10), we use again polynomial interpolation to evaluate l−1 i=0 zCi . We obtain that l−1 i=0
zCi =
l i=1
1 − wi ywi − y − wi
wj wj −1 wj wi j =i wi −1 − wj −1
1−
.
After some algebraic manipulation and using again [8, Exercise 7.4], we get that this last expression equals
1 1 −1 + l , y−1 j =1 (y + wj − ywj ) from which (10) follows. On the other hand, Refs. [5,6] also study a different question on the tennis ball problem, namely to compute the sum of the labels of the balls outside the basket for all possible configurations. For a given lattice path Pn , this amounts to computing the sum of all elements in all bases of the matroid M[Pn ]. We remark that this quantity does not appear to be computable from the corresponding Tutte polynomials alone. References [1] C. Banderier, M. Bousquet-Mélou, A. Denise, P. Flajolet, D. Gardy, D. Gouyou-Beauchamps, Generating functions for generating trees, Discrete Math. 246 (2002) 29–55.
264
A. de Mier, M. Noy / Theoretical Computer Science 346 (2005) 254 – 264
[2] J. Bonin, A. de Mier, M. Noy, Lattice path matroids: enumerative aspects and Tutte polynomials, J. Combin. Theory Ser. A 104 (2003) 63–94. [3] M. Bousquet-Mélou, Walks in the quarter plane: Kreweras’ algebraic model, arXiv:math.CO/0401067. [4] R. Grimaldi, J. Moser, The Catalan numbers and the tennis ball problem, Congr. Numer. 125 (1997) 65–71. [5] C.L. Mallows, L.W. Shapiro, Balls in the lawn, J. Integer Sequences 2 (1999). [6] D. Merlini, R. Sprugnoli, M.C. Verri, The tennis ball problem, J. Combin. Theory Ser. A 99 (2002) 307–344. [7] H. Prodinger, The kernel method: a collection of examples, Séminaire Lotharingien Combinatoire 50 (2004) Article B50f. [8] R.P. Stanley, Enumerative Combinatorics, Vol. 2, Cambridge University Press, Cambridge, 1999. [9] W.T. Tutte, A contribution to the theory of chromatic polynomials, Canad. J. Math. 6 (1954) 80–91. [11] D.J.A. Welsh, Complexity: Knots, Colourings and Counting, Cambridge University Press, Cambridge, 1993.
Theoretical Computer Science 346 (2005) 265 – 280 www.elsevier.com/locate/tcs
A multidimensional critical factorization theorem夡 Chiara Epifanio∗ , Filippo Mignosi Dipartimento di Matematica ed Applicazioni, Università degli Studi di Palermo
Abstract The Critical Factorization Theorem is one of the principal results in combinatorics on words. It relates local periodicities of a word to its global periodicity. In this paper we give a multidimensional extension of it. More precisely, we give a new proof of the Critical Factorization Theorem, but in a weak form, where the weakness is due to the fact that we loose the tightness of the local repetition order. In exchange, we gain the possibility of extending our proof to the multidimensional case. Indeed, this new proof makes use of the Theorem of Fine and Wilf, that has several classical generalizations to the multidimensional case. © 2005 Elsevier B.V. All rights reserved. Keywords: Combinatorics on words; Periodicity; Multidimensional words
1. Introduction As Professor M.P. Schutzenberger wrote in 1983, “Periodicity is an important property of words that is often used in applications of combinatorics on words. The main results concerning it are the theorem of Fine and Wilf [. . .] and the Critical Factorization Theorem” (cf. [27]). Since then, combinatorics on words has expanded a great deal and now other results may be added to the previous ones. Among them even an older result that became important because the well-known Sturmian words represent an extremal case for it, the
夡 Partially supported by MIUR National Project PRIN “Linguaggi Formali e Automi: teoria ed applicazioni” and University of Palermo Research Project (ex 60%) “Tecniche per lo sviluppo e l’analisi di algoritmi e strutture dati”.
∗ Corresponding author.
E-mail addresses:
[email protected] (C. Epifanio),
[email protected] (F. Mignosi). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.012
266
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
Morse-Hedlund Theorem (cf. [35] and see also [28,17,37,23] and references therein). Another important result is a periodicity theorem proved in [31] (cf. also for instance [11,26]), which is a “tight evolution” of a combinatorial lemma firstly proved in [20], used in the design and analysis of a famous string matching algorithm described in the same article (cf. also [13]). In this paper, we will focus on one of the results mentioned by Schutzenberger, the critical factorization theorem, found out by Césari and Vincent in [10] and developed by Duval in [15]. It relates local periodicities of a word to its global periodicity. For a reference on it and on other combinatorial results, see also [11, Chapter 6], [28, Chapter 8], [7, Chapter 3], [26,25], and references therein. For what concerns Computer Science and the theory of Combinatorics on Words, this problem has a long tradition and it is an active research field (cf. for instance [11,27,7,9,15,16,28,26,31,36] and references therein).Among the applications of the critical factorization theorem in this field we recall a famous string matching algorithm, described in [12], and an algorithm that finds a short superstring (cf. [8]). This theorem is also deeply linked with longest unbordered factors of a word and a recently solved famous conjecture by Duval (cf. [22,27,28,33] and references therein). Concerning other fields, the same problem appears also in the theory of long-range order for discrete structures in Rd . Indeed, the recent discovery and study of quasicrystals (cf. [41] and [14]) raises the question: what geometric and physical conditions force a structure to be crystalline rather than quasi-crystalline. Some answers to previous question have been given in [14] where some conditions on “local rules” imply a “global” crystalline structure. (cf. also [14,41,34,38,39,5,24] and references therein). The same problem appears also in [6] with applications in Biology and in the study of spatial structure of proteins. The solution proposed in this paper has been applied in several research studies. The aim of this paper is to give a first generalization of the critical factorization theorem to the multidimensional domain. Up to our knowledge, no such generalization exists in the scientific literature. The techniques used here for proving the first generalization to multidimensional words come from the theory of multidimensional periodicities, that was introduced in their seminal and fundamental work by Amir and Benson in [1–3] (cf. also [4,19,21,40,43,17]). In particular our techniques make use of some results developed in [21]. Recently, we have been able to give a proof of a weak form of the Critical Factorization Theorem, by using the Theorem of Fine and Wilf. For this last theorem, which is the tight version of the periodicity lemma, there exist generalizations to the multidimensional case (cf. [21,32,40,42]). This fact has suggested us to try to extend our proof to the multidimensional case. The paper is organized as follows. In the next section we give some basic definitions and state some fundamental theorems in the unidimensional case. Moreover, we state and prove a weak form of the critical factorization theorem. This proof, as already stressed, will be essential for the demonstration of the main result of the paper. In Section 3, we examine the multidimensional case. Firstly, we give some fundamental definitions and we extend some unidimensional lemmas to this case. Afterwards, we prove our main theorem in the bidimensional case. In fact the proof in this case is simpler to read
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
267
and the one in the d-dimensional case is only a trivial generalization of it that follows the same steps. In Section 4, we describe some research directions that are related to the results of this paper and we state some open problems.
2. Basic definitions and the unidimensional case For any notation not explicitly defined in this paper we refer to [21,27–29]. We begin this paper by considering unidimensional case for words, because it is in some sense the simpler and most deeply studied case and it can help the intuition. Indeed, we will state a weak form of the critical factorization theorem. The alphabet we are considering here is any set, but it is usually finite. We want just to observe that the main results of this paper are alphabet-independent. A bi-infinite word w is a function from Z to the alphabet A. Therefore w(i) is a letter of A that is the image of i by the function w. The set of all bi-infinite words is AZ . Definition 1. Let w be a bi-infinite word. A factor of length n (or block of n consecutive letters, or subword of length n) of w is a word of the form x = w(l)w(l + 1) · · · w(u), such that u − l = n − 1. We accept l to be −∞ and u to be +∞, and not just integers, i.e. we consider also, as factors of w, infinite words. A bi-infinite word w has period p ∈ N, p > 0, or equivalently, p is a period of w if for any i ∈ Z, w(i) = w(i + p). A finite word x has period p if it is a factor of a bi-infinite word having period p, or, equivalently, if w(i) = w(i + p), for any i ∈ Z such that both w(i) and w(i + p) belong to x. If the bi-infinite word w has a period, the smallest of all its periods is called the period of w. If w has no periods, w is called aperiodic and its period is considered to be +∞. Note that for a finite word x, the above definition of periodicity differs from the classical one by the fact that any p greater than the length of x is considered to be a period of x, while it is not in the classical definition. If x is a finite word, we denote by x(i) the ith letter of x. Thus we can write x = x(1) . . . x(n), where n is the length of x. We define the numbers from 1 up to n − 1 to be the positions of x. Roughly speaking, position i lies between letters x(i) and x(i + 1). The set of positions of a bi-infinite word is Z. We now define repetitions and central local periods. Definition 2. Let w be a finite or infinite word.A factor of length n (or block of n consecutive letters) of w, w(j )w(j + 1) · · · w(j + n − 1), is a repetition of order , with 1 a real number, if there exists a natural number p, 0 < p n such that w(i) = w(i + p) for i = j, . . . , j + n − 1 − p and such that n/p . The number p is called a period of the repetition. The smallest of all periods is called the period of the repetition. Note that if a factor of length n is a repetition of order then it is trivially also a repetition of order for any 1 of the same period, because the definition of repetition involves an
268
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
inequality. Any word of length n and period p n has order n/p. Note also that a repetition can have more than one period. Consequently, if a factor x of length n is a repetition of order and period p and if it has also period q, then factor x is a repetition of order (p/q) and period q. As an example let us consider the word w = abaaba. It is a repetition of length 6 and has order 1 with period 6, order 65 with period 5 and order 2 with period 3. In particular the length of the repetition is always a period and, so, any factor is a repetition of order 1 and period its length. We refer to [28] for a formal definition of local period c (w, i) of order in position i of the word w. Roughly speaking c (w, i) is the period of the smallest repetition of order that matches w when the center of the repetition is placed in position i. The match can be virtual, in the sense that it is considered valid also when there are no more letters to match in w. Definition 3. A position i is -critical (or just critical, when is fixed) if c (w, i) coincides with the period of the whole word w. Above definition slightly differs from the corresponding one given in [28], where a critical position represents the maximum of the local periods. Remark 1. Note that if w has period p (where p can also be +∞) then for any and for any i ∈ Z, c (w, i) p. This inequality can be strict for all i, i.e. it may be that there are no -critical points. For instance, if w is the periodic word with period 4 w = . . . 1000100010001000 . . . and if = 43 , then no position is -critical. Indeed the period of w is 4, while w has in every position i a central repetition of order greater than or equal to 43 and period smaller than or equal to 3. In fact, if i is between two 0s, then the central repetition in position i of order greater than or equal to 43 is 00, that has order 2 and period equal to 1. If i has a 1 immediately to the right (resp. left), then the central repetition in position i of order greater than or equal to 43 is 0010 (resp. 0100), that has order exactly equal to 43 and period 3. For another more complex example, we refer to Chapter 8 of [28] where it is shown that if w is the Fibonacci bi-infinite word (that has period +∞), then for any , 1 < 2 and for any i one has that c (w, i) k (w), where k (w) is a constant depending on . In this section, we give a new proof of a weak form of the critical factorization theorem. The weakness is due to the fact that we loose the tightness of the local repetition order. In exchange, we gain the possibility of extending our proof to two dimensions. Indeed, this new proof makes use of the Theorem of Fine and Wilf, that has several classical generalizations to the bidimensional case. Let us, firstly, state two lemmas and the Theorem of Fine and Wilf, that will be helpful for our new proof (see [28, Lemma 8.1.2, Lemma 8.1.3, Theorem 8.1.4]). Lemma 1. Let u, v, w be words such that uv and vw have period p and | v | p. Then the word uvw has period p.
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
269
Lemma 2. Suppose that w has period q and that there exists a factor v of w with | v | q that has period r, where r divides q. Then w has period r. Theorem 1 (Fine and Wilf [18]). Let w be a word having periods p and q, being q p two positive integers. If |w|p + q − gcd(p, q), then w has also period gcd(p, q). Before stating and proving the weak form of the critical factorization theorem, let us give a definition that we will use in our proof. Definition 4. Let w be a word and i, j be two positions of w. We define P (i, j ) = sup{c (w, l) | i l j }. If i and j coincide, respectively, with the first and last positions in w (including the case i = −∞ and j = +∞), we denote P (w) = P (i, j ). The following theorem is, for = 2, the critical factorization theorem. We will prove it for = 4, because under this hypothesis we will be able to use the Theorem of Fine and Wilf. An interval of positions [i, j ], i j of a word w is the set of integers {i, . . . j } that are also positions of w. Its size is its cardinality, that is j − i + 1. Theorem2. Let w be a (finite or infinite) word, [i, j ] be an interval of positions in w, i, j ∈ Z {−∞, +∞} and = 4. (1) Every interval [t1 , t2 ] ⊆ [i, j ], t1 , t2 ∈ Z, of size t2 − t1 + 1 = max(1, P (i, j ) − 1) contains a position l such that c (w, l) = P (i, j ). (2) If i = inf l − · c (w, l) i l j, 2 where l is such that c (w, l) = P (i, j ) , · c (w, l) − 1 i l j, j = sup l + 2 where l is such that c (w, l) = P (i, j ) , then w has period P (i, j ) in [i , j ], where if i is a position in w, i i = the first position in w otherwise, if j is a position in w, j j = the first position in w otherwise. Proof. The proof is by induction on P (i, j ). • If P (i, j ) = 1, c (w, l) = 1 whenever in [i, j ] and then there is only one letter labelling all the positions in this interval. Thus, w has period P (i, j ) = c (w, l) = 1 in the whole [i, j ] and the assertion is trivially true. ˆ jˆ] such • Let us suppose that both assertions of the theorem hold true for all intervals [i, ˆ jˆ)n, n1. Let [i, j ] be an interval such that P (i, j ) = n. We shall prove that that P (i, both statements hold true even in [i, j ].
270
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
Let us assume that there exists, by contradiction, an interval [t1 , t2 ] ⊆ [i, j ] of size equal to max(1, P (i, j ) − 1) = n − 1 that does not contain any position k such that c (w, k) = n. Let us slide this interval to the left or to the right until we find [t1 , t2 ] of size t2 − t1 + 1 = n − 1 such that the first position k , i k j to the left or to the right of [t1 , t2 ] verifies c (w, k ) = n and P (t1 , t2 ) = q < n. This k must exists because P (i, j ) = n. Let us suppose that k is to the left (the proof being analogous in the other case) of the interval, i.e. k = t1 − 1. By the inductive hypothesis we know that each subinterval of size max(1, q − 1) contains a position l such that c (w, l) = P (t1 , t2 ) = q. In particular, there exists at least one such l among the first max(1, q − 1) positions of [t1 , t2 ]. Let l be the smallest among them. By the inductive hypothesis, on the interval [i , t2 ], with if i is a position in w, i i = the first position in w otherwise and
i = inf l − · c (w, l) i l j, where l is such that c (w, l) = P (i, j ) , 2
w is periodic of period q. Claim. Position i belongs to the domain of the word w and, therefore, i = i . Proof of the Claim. Let us suppose, on the contrary, that the claim is false. Since i is the first position in w and l t1 > k , there exists in position k an -local repetition of period q, contradicting the fact that c (w, k ) = n and the claim is proved. By hypothesis, i = l − /2 · c (w, l) = l − 2q. Thus, interval [i , t2 ] has size t2 −i +1 = t2 −(l−2q)+1 t2 −(t1 +q−1−2q)+1 = t2 −t1 +q+2 n−2+q+2 = n+q. Hence the word x = w(i ) . . . w(t2 ) has length greater than or equal to n + q. But x has also period n because it is contained in the repetition of order centered in k . Therefore, we can apply the Theorem of Fine and Wilf to x and we conclude that the word x has period an integer d that divides both n and q. By Lemma 2 this implies that the whole word centered in k has period d, which is absurd because of the minimality of c (w, k ) = n. Therefore, the distance between two different positions l1 and l2 such that c (w, l1 ) = c (w, l2 ) = P (i, j ) = n is at most n − 1 and the first assertion of the theorem is proved. By Lemma 1 the word w has period n in the interval [i , j ], and this concludes the proof. Recall that a critical position l is defined, in this paper, to be a position where the local period c (w, l) is equal to the global period p(w) of the word w. The first part of previous theorem tell us that in every interval of length max(1, P (w) − 1) there is a critical position, while the second part implies that P (w) is equal to p(w). Therefore, the following corollary is straigtforward. Corollary 1. Every interval [t1 , t2 ], with t1 , t2 ∈ Z positions in w, of size t2 − t1 + 1 = max(1, p(w) − 1) contains a critical position.
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
271
3. The multidimensional case and the critical factorization theorem Let us consider, now, the multidimensional case. Analogously to the unidimensional case we may define a d-dimensional word w as a function from a subset X ⊆ Zd to an alphabet A. The set X is called the shape of w and it is denoted by sh(w). A factor v of a multidimensional word w is any restriction of w to any subset Y ⊆ X and clearly sh(v) = Y . A word w is called an n-cubic word or simply a cubic word if its shape sh(w) is either an hypercube of Zd , i.e. it is of the form {j1 , . . . , j1 + n − 1} × · · · × {jd , . . . , jd + n − 1} for some natural number n, or a translate of a quadrant, or the whole Zd . Let us give the definition of multidimensional periodicity for words. Definition 5. Let H be an additive subgroup of Zd , different from 0d = {0d } (the zero subgroup). A multidimensional word w having shape Zd has period H, or equivalently H is a period of w, if for any i ∈ Zd and for any element g of the subgroup H one has that w(i) = w(i + g). A multidimensional word w has period H if it is a factor of a multidimensional word w having shape Zd that has period H. If w has no periods, w is called aperiodic and its period is considered to be +∞. Note that for d = 1, the above definition of periodicity is equivalent to the one given in the unidimensional case, if we consider equivalent the two properties of having period p and having period the subgroup H = p generated by p > 0 (recall that all subgroups of Z can be generated by only one element, that is unique up to a factor ±1). The non-zero subgroups of Zd can only have dimension an integer d , with 1 d d. For instance the word w from Z2 to A = Z defined by w(i1 , i2 ) = i2 has period H1 , where H1 is generated by the element (1, 0) (in short H1 = (1, 0)) and has dimension 1. The word w from Z2 to A = {0, 1, 2, 3} defined by w(i1 , i2 ) = x, where x is the decimal corresponding to the binary number composed of two digits, the first being i1 (mod 2) and the second i2 (mod 2), has period H2 , where H2 is generated by the elements (2, 0) and (0, 2) (in short H2 = (2, 0), (0, 2)). Subgroup H2 has dimension 2. The subgroups of Zd of dimension d are called lattices or fully dimensional subgroups. They are the only subgroups that have finite index. If a factor has period a lattice H, it is called fully periodic. Another remarkable class of subgroups is that of subgroups of dimension 1. They are generated by only one element. Trivially, if H = q then H = −q, and q and −q are the only generators of H. Suppose that H has dimension 1, q is its generator and it is also a period of a factor v. The element q is called periodicity vector of v. It is easy to see that q ∈ Zd is a periodicity vector of v if and only if for any z ∈ Z and for any i ∈ sh(v), such that i + zq ∈ sh(v), one has that v(i) = v(i + zq). Remark 2. If a factor v has period H and if H is a subgroup of H then v has also period H . In particular, if v has period H, for any q ∈ H one has that q is a periodicity vector of v. In the unidimensional case this is equivalent to say that if v has period p then every multiple of p is a period.
272
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
Note that if w is an application from Zd to A and has period H and if g is an application from A to any set B, the word g · w, composition of w and g, from Zd to B has also period H. In other terms, projections preserve the period. Recall that any subgroup H of dimension d > 1 has infinitely many bases, where a basis of H is any set consisting of a minimal number of generators. We give now the classical definition of transversal of a subgroup. Definition 6. Given a subgroup H, a transversal TH of H is a subset of Zd such that for any element i ∈ Z d , there exists an unique element j ∈ TH such that i − j ∈ H . Remark 3. Note that if TH is a transversal of H then for any q ∈ Zd the set q + TH is also a transversal of H. Indeed for any element i ∈ Z d , let us consider i − q. Since TH is a transversal there exists an unique element j ∈ TH such that i − q − j = i − (q + j ) ∈ H . The unique element j = q + j belongs to q + TH , and so q + TH satisfies previous definition. We now define the order of periodicity of factors of w that have an “hypercube” as “shape”. These factors will be used to define what is a local periodicity in the multidimensional case of words. Definition 7. An n-cubic factor v is a repetition of order , with 1 a real number, (or an -repetition), if (1) v is L periodic, where L is a full dimensional subgroup of Zd ; (2) n is such that n/ hL , where hL is the smallest integer such that every hypercube of side length hL contains a transversal of L. The lattice L is called a period of the -repetition v. Definition 8. The word w has a central repetition v of order in position j = (j1 , . . . , jd ) ∈ Zd , if v is a 2n-cubic word that is a repetition of order and shape {−n + 1, . . . , n − 1, n}d that matches w when its center is placed in position j, i.e., more formally, if for any i ∈ sh(v) such that j + i ∈ sh(w) one has that w(j + i) = v(i). We say also that the repetition v is centered in position j. If w has at least a central repetition of order and period L in position j ∈ Zd , the set H of all hL such that every hypercube of side length hL contains a transversal of L is non-empty. We will denote by c (w, j ) the minimum of this set H. If w has no central repetitions of order in position j, we set c (w, j ) = +∞. Note that if an n-cubic factor is a repetition of order then it is also a repetition of order for any 1 of same period because we used an inequality in the definition of repetition. Note also that a factor, and, as well, repetitions can have more than one period. Note also that it is possible to give geometrical properties of the basis vectors of L to satisfy condition 2. For instance, in dimension d = 1, L = p and the property is that hL p. For dimension d = 2, L = (a, b), (c, d), with a > 0 and c > 0 and the requirement is that hL a + c and hL | b | + | d | (cf. [1]).
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
273
We have now all notions necessary to state and prove the main result of the paper. We only need some more “tools” that will play an important role in the proof of it. Let us start by stating a result that is analogous for the multidimensional case to the Periodicity Lemma (cf. [30]). It is an immediate consequence of the generalization to the multidimensional case of the Theorem of Fine and Wilf given in [21]. Let H be a subgroup of Zd , q an element of Zd and v a word and let sh(v) be its shape. Theorem 3. Suppose that v is H-periodic and that q is a periodicity vector for v. If sh(v) ∩ (sh(v) + q) contains a transversal of H then v is also H -periodic, where H = H, q is the lattice generated by H and q. Next two lemmas are the d-dimensional generalizations, respectively of Lemmas 1 and 2. They will be necessary for the proof of Theorem 4, as the unidimensional corresponding ones were necessary for proving Theorem 2. Lemma 3. Let v1 and v2 be two factors of same word w of Zd that have both period the subgroup H. If sh(v1 ) ∩ sh(v2 ) contains a transversal of H then the factor v that has shape sh(v) = sh(v1 ) ∪ sh(v2 ) has also period H. Proof. We have to prove that for any i, j ∈ sh(v), if i − j ∈ H then v(i) = v(j ). Previous equality trivially holds if both i, j belong to sh(v1 ) or to sh(v2 ). We can suppose now, without loss of generality, that i ∈ sh(v1 ) and j ∈ sh(v2 ). Since sh(v1 ) ∩ sh(v2 ) contains a transversal of H, there exists i ∈ sh(v1 ) ∩ sh(v2 ) such that i − i ∈ H . Since v1 has period H and also i ∈ sh(v1 ), v(i) = v1 (i) = v1 (i ) = v(i ). But i belongs also to sh(v2 ), and, moreover i − j = i − i + i − j that belongs to H because both i − i and i − j belong to H. Since v2 has period H and also i ∈ sh(v2 ), v(i ) = v1 (i ) = v1 (j ) = v(j ) and the lemma is proved. Lemma 4. Let v1 and v2 be two factors of the same word w on Zd with sh(v2 ) ⊆ sh(v1 ). Suppose that v1 has period H1 and that v2 has period H2 , with H1 a subgroup of H2 , and that sh(v2 ) contains a transversal of H1 . Under these hypotheses v1 has period H2 . Proof. We have to prove that for any i, j ∈ sh(v1 ), if i − j = h ∈ H2 then v1 (i) = v1 (j ). Since sh(v2 ) contains a transversal of H1 , there exist i , j ∈ sh(v2 ) such that i − i = li ∈ H1 and j −j = lj ∈ H1 . Since sh(v2 ) ⊆ sh(v1 ) and since v1 has period H1 , v1 (i) = v1 (i ) and v1 (j ) = v1 (j ). But i − j = i − i + i − j + j − j = li + lj + h. Since H1 is a subgroup of H2 , li + lj + h ∈ H2 . Since i , j ∈ sh(v2 ), i − j ∈ H2 and v2 has period H2 , v1 (i ) = v2 (i ) = v2 (j ) = v1 (j ) and the lemma is proved. From now on we will deal with bidimensional words and we will state and prove the main result of this paper in that case. In fact, the proof is in this case simpler to read. The proof in the d-dimensional case follows the same steps and it will be not reported here. Moreover, we will focus on squared words. Our result will be proved only in this case.
274
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
X
sh(w) Fig. 1. -repetitions such that c (w, l) = P (X), for = 2.
Definition 9. Let w be a word and X be a square contained in sh(w). We define P (X) = sup{c (w, l) | l ∈ X}. We call a position l critical if there exists a period L of w such that every square of side length c (w, l) contains a transversal of L. Remark 4. We notice that lattice L in above definition depends only on w and c (w, l) and not directly on . Roughly speaking, a position is critical if a local period is also a global period. Theorem 4. Let w be a (finite or infinite) squared bidimensional word, X be a square contained in the shape of w and = 4. (1) Every square T ⊆ X, of side length sd(T ) = max(1, P (X) − 1) contains a position l such that c (w, l) = P (X). (2) Let v be the factor of w the shape of which is the intersection of sh(w) and the union of the shapes of the -repetitions centered in positions l ∈ X such that c (w, l) = P (X). Then v has period L, where L is a subgroup such that every square of side length P (X) contains a transversal of L (Figs. 1, 2). Proof. The proof is by induction on P (X). Let X be the union of the shapes of the repetitions centered in position l ∈ X. If P (X) = 1, there is only one letter labelling all the positions in X and the assertions are trivially true.
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
275
X′
sh(w) Fig. 2. Intersection of sh(w) and the union of the shapes of the -repetitions centered in position l ∈ X.
Let us suppose that the statements of the theorem hold true for all squares T such that P (T )n, n1. Let X be a square such that P (X) = n. Let us assume that there exists, on the contrary, a square T ⊆ X having side length equal to max(1, P (X) − 1) = n − 1 that does not contain any position k such that c (w, k) = n. Let us slide this square in any possible direction until we find a square T such that there exists a position k ∈ X just out, at distance one (by using the distance induced by the sup norm) from the perimeter of T, such that c (w, k) = n. This k must exist because P (X) = n. Notice that P (T ) is smaller than n. We denote this value P (T ) by q. By the inductive hypothesis we know that v has period L2 , where v is the factor of w the shape of which is the intersection of sh(w) and the union T of the shapes of the repetitions centered in position l ∈ T such that c (w, l) = P (T ) = q and L2 is such that every square of side length q contains a transversal of it. Again by the inductive hypothesis, the square C, that has side length sd(T ) + 2(q + 1) and centre T (see Fig. 3) is contained in T . We know that the factor of w that has shape C ∩ sh(w) has period L2 . We know that sh(w) contains both T and the position k. We want to prove that C ∩ sh(w) encloses a square of side length at least sd(T ) + q + 1.
276
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
k
q+1 T
C Fig. 3. Square C, that has side length sd(T ) + 2(q + 1) and center T.
Claim 1. sh(w) is not contained in C. Proof of the Claim 1. Let us suppose, on the contrary, that the claim is false. Since sh(w) is contained in C ∩ sh(w), it has period L2 . Therefore, there exists in position k an local repetition of period L2 , where L2 is such that every square of side length q contains a transversal of it. This contradicts the fact that c (w, k) = n > q and the claim is proved. The shape sh(w) is not contained in C, but encloses T. Hence, it extends at least beyond one side of C. Therefore the side length of sh(w) must be greater than sd(T ) + q + 1. Any intersection of C and a square of side length greater than sd(T ) + q + 1 that contains T must contain a square of side length at least sd(T ) + q + 1. This implies that the intersection of sh(w) and C contains a square C1 of side length at least sd(T ) + q + 1 (see Fig. 4). Notice that C1 can be chosen in such a way that it contains position k. Let us consider the intersection C2 between C1 and the shape of the central -repetition in position k. This is a square of side length 4n, because = 4 and k is such that c (w, k) = n. Since k belongs to C1 and since sd(T )n, this intersection is a square of side length greater than or equal to n + q + 1. This square has periods both L and L2 . The scheme is the same as in the unidimensional case, even if a bit more complicated. We want to apply Theorem 3 in order to prove that this square has a period lattice L4 = L, L2 , generated by both L and L2 and this is proved in the following claim. Claim 2. C2 has period L4 = L, L2 . Proof of the Claim 2. Since every square of side length n contains a transversal of L, there exists a basis {b1 , b2 } of L, L = b1 , b2 , such that every coordinate of both b1 and b2 has
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
k
277
k
q+1
q+1 T
T
C
C sh(w)
sh(w)
k k q+1
q+1 T T
sh(w) sh(w)
C C Fig. 4. All possible locations of C and sh(w). All intersections between C and sh(w) contain a square C1 of side length at least sd(T ) + q + 1.
absolute value smaller than or equal to n. This implies that both b1 and b2 are periodicity vectors for the restriction v of w to the shape C2 . Hence C2 ∩ (C2 + b1 ) and C2 ∩ (C2 + b2 ) contain a square of side length q. We can now apply Theorem 3 to the factor v, having shape C2 , periodicity vector b1 and period lattice L2 and we obtain that v has period lattice the lattice L3 = L2 , b1 . Since L2 is a subgroup of L3 , every square of side length q contains a transversal of L3 . We can again apply Theorem 3 to the factor v, but this time referring to periodicity vector b2 and period lattice L3 . We obtain that v has lattice periodicity the lattice L4 = L3 , b2 = L, L2 and Claim 2 is proved. Since L is a subgroup of L4 and v contains a transversal of L, by Lemma 4 we have that the whole central -repetition in position k has period L4 . This is absurd because, since L2
278
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
is a subgroup of L4 , every square of side length q contains a transversal of L4 , and this contradicts the minimality of c (w, k) = n > q. Therefore, we have proved statement 1 of the theorem. Let l1 and l2 be a couple of positions such that the distance (induced by the sup norm) between them is at most n−1, such that c (w, l1 ) = c (w, l2 ) = P (X) = n. Denote by L1 and L2 the two periods corresponding to the two central -repetitions v1 and v2 . We want to prove that v1 and v2 are -repetitions with the same period L . Since the intersection of the shapes of the two central -repetitions in positions l1 and l2 contains a square having side length at least 3n, we can apply the reasoning used above to prove Claim 2 to conclude that this intersection has period L = L1 , L2 . By Lemma 4 both v1 and v2 are -repetitions with period L . Since every square T ⊆ X, of side length sd(T ) = max(1, P (X)−1) contains a position l such that c (w, l) = P (X), we can iteratively apply this result and conclude that there exists a lattice L that is a period for all -repetitions with centre in a position l ∈ X such that c (w, l) = P (X). We can now iteratively apply Lemma 3 and obtain that L is a period for the restriction of w to sh(w) ∩ X , where X is the union of the shapes of the -repetitions centered in position l ∈ X such that c (w, l) = P (X). Corollary 2. Every square T, with T enclosed in sh(w), of side length sd(T ) = max(1, P (sh(w)) − 1) contains a critical position. 4. Conclusions and open problems It is known that in the unidimensional case the tight value for the critical factorization theorem is = 2. It still remains an open problem to find the tight value of for any dimension d > 1. Is it = 2, as in the unidimensional case? The original critical factorization theorem was the main theoretic tool in a famous string matching algorithm (see [12]) that works with constant additional space. We hope that our results can be helpful in the design and analysis of multidimensional pattern matching algorithms. A further problem is to extend results from the case of multidimensional words to the case of Delone sets, in particular, to extend Theorem 4 (cf. [14] and references therein). Last, but not least, it would be interesting to see if it is possible to extend the Duval Conjecture, or Harju–Nowotka Theorem, to the multidimensional case. This problem is not trivial because it involves the generalization of unidimensional notions, such as the one of unbordered words (cf. [22] and references therein). References [1] A. Amir, G.E. Benson. Two-Dimensional Periodicity and its Applications. Proc. third ACM-SIAM Symp. on Discrete Algorithms, 1992, pp. 440–452.
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
279
[2] A. Amir, G.E. Benson, Alphabet Independent Two-Dimensional Pattern Matching. Proc. 24th ACM Symp. Theory on Computation, 1992, pp. 59–68. [3] A. Amir, G.E. Benson, Two-dimensional periodicity in rectangular arrays, SIAM J. Comput. 27 (1) (1998) 90–106. [4] A. Amir, G.E. Benson, M. Farach, An alphabet independent approach to two dimensional pattern matching, SIAM J. Comput. 23 (2) (1994) 313–323 (preliminary version appeared in STOC 92). [5] F. Axel, D. Gratias, Beyond Quasicrystals, Springer-Verlag and Les Editions de Physiques Les Ulis, 1995. [6] B. Berger, P. Shor, L. Tucker-Kellogg, J. King, Local rule-based theory of virus shell assembly, Proc. Natl. Acad. Sci. USA 91 (1994) 7732–7736. [7] J. Berstel, J. Karhumäki, Combinatorics on Words—A Tutorial, TUCS Technical Report, No. 530, 2003. [8] D. Breslauer, T. Jiang, Z. Jiang, Rotations of Periodic Strings and Short Superstring, J. Algorithms 24 (2) (1997) 340–353. [9] V. Bruyère, G. Hansel, C. Michaux, R. Villemaire, Logic and p-recognizable sets of integers, Bull. Belgium Math. Soc. 1 (1994) 191–238. [10] Y. Césari, M. Vincent, Une caractérisation des mots périodiques, C. R. Acad. Sci. Paris 286A (1978) 1175–1177. [11] C. Choffrut, J. Karhumäki, Combinatorics on Words, in: G. Rozenberg, A. Salomaa (Eds.), Handbook of Formal Languages, Springer, Berlin, 1997. [12] M. Crochemore, D. Perrin, Two-way string-matching, J. Assoc. Comput. Mach. 38 (3) (1991) 651–675. [13] M. Crochemore, W. Rytter, Squares, cubes and time-space efficient string-searching, Algorithmica 13 (1995) 405–425. [14] N. Dolbilin, J. Lagarias, M. Senechal, Multiregular point systems, Discrete & Comput. Geom. 20 (4) (1998) 477–498. [15] J.P. Duval, Périodes et répétitions des mots du monoı¨de libre, Theoret. Comput. Sci. 9 (1979) 17–26. [16] J.P. Duval, Périodes locales et propagation de périodes dans un mot, Theoret. Comput. Sci. 204 (1–2) (1998) 87–98. [17] C. Epifanio, M. Koskas, F. Mignosi, On a conjecture on bidimensional words, Theoret. Comput. Sci. 299 (1–3) (2003) 123–150. [18] N.J. Fine, H.S. Wilf, Uniqueness Theorem for Periodic Functions, Proc. Amer. Math. Soc. 16 (1965) 109–114. [19] Z. Galil, K. Park,Alphabet-independent two-dimensional witness computation, Siam J. Comput. 25 (5) (1996) 907–935. [20] Z. Galil, J. Seiferas, Time-space optimal string matching, J. Comput. and Systems Sci. 26 (1983) 280–294. [21] R. Giancarlo, F. Mignosi, Generalizations of the Periodicity Theorem of Fine and Wilf, CAAP94, Lecture Notes in Computer Science, Vol. 787, pp. 130–141. [22] H. Harju, D. Nowotka, Periodicity and Unbordered Words—A Proof of Duval’s Conjecture, Lecture Notes in Computer Science, Vol. 2996, 2004, pp. 294–304. [23] R. Klette, A. Rosenfeld, Digital straightness—a review, Discrete Appl. Math. 139 (1–3) (2004) 197–230. [24] D. Lenz, Aperiodic linearly repetitive Delone sets are densely repetitive, Discrete & Comput. Geom. 31 (2004) 323–326. [25] A. Lepistö, On Relations between local and global periodicity, Ph.D. Thesis, TUCS Dissertation No. 43, 2002. [26] A. Lepistö, Relations between local and global periodicity of words, in: J. Wiedermann, P. vam Emde Boas, M. Nielsen (Eds.), Proc. ICALP’99, Lecture Notes in Computer Science, Springer, Berlin, Vol. 1664, 1999. [27] M. Lothaire, Combinatorics on Words, Encyclopedia of Mathematics and its Applications, Vol. 17, AddisonWesley, Reading, MA, 1983. [28] M. Lothaire, Algebraic Combinatorics on Words, Encyclopedia of Mathematics and its Applications, Vol. 90, Cambridge University Press, Cambridge, 2002. [29] R.C. Lyndon, P.E. Schupp, Combinatorial Group Theory, Springer, Berlin, 1977. [30] R.C. Lyndon, M.P. Schutzenberger, The equation a m = bn cp in a Free Group, Michigan Math. J. 9 (4) (1962) 289–298. [31] F. Mignosi, A. Restivo, S. Salemi, Periodicity and the golden ratio, Theoret. Comput. Sci. 204 (1–2) (1998) 87–98. [32] F. Mignosi, A. Restivo, P.V. Silva, On fine and Wilf’s theorem for bidimensional words, Theoret. Comput. Sci. 292 (2003) 245–262.
280
C. Epifanio, F. Mignosi / Theoretical Computer Science 346 (2005) 265 – 280
[33] F. Mignosi, L. Zamboni, A note on a Conjecture of Duval and Sturmian Words, RAIRO Theoret. Inform. Appl., 36 (1) (2002) 1–3. [34] R.V. Moody, The Mathematics of long-range aperiodic order, NATO ASI Series, Vol. 489, Kluwer Academic Publishers, Dordrecht, 1997. [35] M. Morse, G.A. Hedlund, Symbolic dynamics II. Sturmian trajectories, Amer. J. Math. 62 (1940) 1–42. [36] A. Muchnik, The definable criterion for definability in Presburger arithmetic and its applications, Theoret. Comput. Sci. 290 (3) (2003) 1433–1444. [37] A. Quas, L. Zamboni, Periodicity and local complexity, Theoret. Comput. Sci. 319 (2004) 229–240. [38] C. Radin, Global order from local sources, Bull. Amer. Math. Soc. 25 (2) (1991) 335–364. [39] C. Radin, The pinwheel tilings of the plane, Ann. Math. 139 (1994) 661–702. [40] M. Regnier, L. Rostami, A Unifying Look at d-Dimensional Periodicities and Space Coverings, Proc. fourth Symp. on Combinatorial Pattern Matching, 1993, pp. 215–227. [41] M. Senechal, Quasicrystals and Geometry, Cambridge University Press, Cambridge, 1995. [42] R.J. Simpson, R. Tijdeman, Multi-dimensional versions of a theorem of Fine and Wilf and a Formula of Sylvester, Proc. Amer. Math. Soc., to appear. [43] L. Vuillon, Local configurations in a discrete plane, Bull. Belgium Math. Soc. 6 (1999) 625–636.
Theoretical Computer Science 346 (2005) 281 – 299 www.elsevier.com/locate/tcs
Implicit surface visualization of reconstructed biological molecules夡 Edgar Garduñoa,∗ , Gabor T. Hermanb a National Center for Microscopy and Imaging Research at the University of California, San Diego, CA, USA b Department of Computer Science, The Graduate Center, City University of New York, New York, USA
Dedicated to the memory of Alberto Del Lungo, friend and collaborator. We miss his smile
Abstract An implicit surface of a density function is the set of points at which the value of the function is equal to a fixed threshold. An object that is defined as the collection of points at which the density function value is above the threshold can be visualized by displaying the implicit surface. Some methods for the reconstruction of biological macromolecules from their electron microscopic projections produce density functions that are specified by a linear combination of smoothly-varying radially-symmetric basis functions of finite support, also known as blobs. When density functions are determined by such a blob representation, the implicit surfaces are smoothly varying and the normal at any point on such a surface can be analytically calculated. This property can be utilized to produce high-quality visualizations by raycasting. While raycasting tends to be computationally expensive, we present a methodology that uses techniques of computer graphics and image processing to significantly reduce the cost of visualization. © 2005 Elsevier B.V. All rights reserved. Keywords: Implicit surfaces; Body-centered cubic grid; Spherically symmetric basis functions; Generalized Kaiser–Bessel functions; Blobs; Algebraic reconstruction techniques; Raycasting
夡
This work has been supported by NIH Grant HL70472.
∗ Corresponding author.
E-mail addresses:
[email protected] (E. Garduño),
[email protected] (G.T. Herman). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.027
282
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
1. Introduction An essential tool toward the understanding of how living systems function is the visualization of the molecules from which they are constructed. Such molecules cannot be seen directly. A standard device for collecting information about them is the electron microscope. This instrument can be used to obtain projected images of a particular kind of molecule from a number of directions; such images are similar in nature to X-ray images of the human body (but are much noisier and, relative to the size of the molecules, are much less detailed). Multiple images of a molecule are then processed by a reconstruction algorithm, the output of which is a function of three variables that approximates the electron-density distribution in space associated with the molecule. (The molecule is typically distinguishable from its background by having a higher electron density.) Such a function is typically represented as a linear combination of some fixed basis functions; in order to obtain the necessary details, the number of such basis functions tends to be well over a million. A successful choice for the basis functions are the so-called blobs (to be defined below); these are spatially limited and continuously differentiable functions for which closed-form formulas exist to calculate their gradients at any point in space. A consequence of this is that, once the coefficients of the blob decomposition have been obtained by the reconstruction algorithm, the gradient of the reconstructed electron-density distribution can be analytically calculated at any point of the implicit surface that separates the values associated with the molecule from the values associated with its background. This provides us with the ability to visualize the shape of the molecule without having to make approximations in addition to those that were unavoidably introduced by the electron microscopic reconstruction process. (Compare this, for example, with a polygonal approximation of the implicit surface prior to visualization: the display of such a polygonal approximation contains additional inaccuracies both in the location of the implicit surface and in the normal to it.) This paper is devoted to the discussion of how computer graphics techniques can be applied to achieve accurate visualization of biological molecules based on reconstructions that are presented to us as linear combinations of well over a million blobs. This application is essentially different from the constructive solid geometry applications that are the main motivations for many implicit surface visualization papers in the literature (e.g., [16]): we are not trying to design a surface, rather we are trying to accurately visualize a particular surface that exists in nature, based on a representation that is imposed on us by the electron microscopic reconstruction process. What we present below in detail will be one approach to visualizing density functions by two-dimensional (2D) images (generated on a computer screen) that use depth cues to deliver the three-dimensional (3D) information contained in the density functions. Volume and surface rendering (also referred to as direct and indirect volume rendering, respectively) are commonly used in biomedical imaging to create such representations of density functions. Volume rendering is a technique that assumes that the density function to be imaged is made up of one or several translucent objects. The resulting 2D image is a projection of the translucent density function onto the screen. To create this image, the reconstructed density function is discretized into small volume elements (voxels, which can be simple abutting cubes or overlapping ellipsoids [51]), and then the opacities and colors of every object in the density function are computed locally for every voxel.
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
283
Surface rendering assumes that the objects embodied in the density function can be represented by the surfaces enclosing them. The estimation of the surfaces defining the objects generally requires some preprocessing of the density function. One of the common approaches to surface rendering is the polygon-projection method that explicitly approximates an object’s surface by a collection of polygons or other patches [2,5,14,19,20,36,48]. The advantages of one of these two approaches over the other are open to question; both have their strengths and weaknesses [44,46]. A preliminary process of object delineation and identification is assumed in surface rendering, this task is typically challenging and in many occasions does not produce the desired results. Moreover, there are natural objects whose surface representation does not accurately reflect its real structure (e.g., a cloud of particles). Volume rendering, on the other hand, leaves the task of structure recognition to the observer by projecting all the voxels onto the screen; in this case, the identification of structures may be difficult due to the presence of occluding objects. (However, some approaches allow automatic assignment of opacities to voxels so that there is no obstruction to “important” regions of the volume and also provide clues for better interpretation of the information contained within the visible regions [24,25]). In computational terms, identifying the surface of an object can be costly, but once the surface representation is available it is possible to rapidly generate images from any viewpoint (this is particularly true for surfaces approximated by polygons as there exists specialized hardware for polygon projection operations). As opposed to surface rendering, volume rendering is in general a computationally demanding task as it requires the projection of all the voxels in the data set every time the observer’s point of view changes and the computation of absorption, emission and color for every object in the density function can be challenging [43]. Techniques exist, nevertheless, for the combination of object rendering and surface rendering to produce a single image [17,26]. In this paper we use a modality of an algorithm known as raycasting for surface rendering which uses implicit surfaces. This approach is known to produce high quality images (a reason why we selected this modality), but also for its slow performance. (Other approaches using raycasting, but with polygons modeling the surfaces, have been shown to produce high quality images in interactive times [47].) We present a methodology that uses techniques of computer graphics and image processing to significantly reduce the cost of visualizing macromolecular complexes by raycasting. The methodology slightly increases the use of memory but, as we show later, the cost is minimal as compared to the memory use by polygonal methods. In the next section we introduce some basic concepts such as implicit surfaces, basis functions, linear approximation by basis functions, grids, and projections. In Section 3 we present our particular choice for the basis functions. In Sections 4 and 5 we introduce a basic method to visualize implicit surfaces by raycasting with smooth basis functions and apply it to electron microscopy. Section 6 presents our approach to improving the raycasting method and some results. We summarize the paper in Section 7. 2. Background and related work Several techniques have been used to model surfaces, e.g., fractals, hypertextures, particle systems, parametric surfaces. Here we adopt the use of implicit surfaces (also
284
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
called isosurfaces or isointensity surfaces). These are appropriate for objects with complex topologies and geometries, such as organic objects or man-made shapes (see [10] and its references), and therefore have been used to visualize objects of interest in many areas of science. An implicit surface S of a density function is defined as S = {x | (x) = t},
(1)
where x denotes a point in space (mathematically x ∈ R3 ). The assumption is that there is a threshold t such that the object of interest consists of exactly those points at which the value of is greater than the threshold. If the total volume of the object of interest is known (as is the case in some applications, such as electron microscopy), then t is uniquely determined by the criterion that S should enclose exactly the known volume. Consequently, it is sufficient to display the surface S, as defined by (1), of the object of interest for its visualization. A standard way of specifying a density function is by a linear combination (x) =
J
cj bj (x) ,
(2)
j =1
where bj is a set of basis functions, each of which is weighted by a coefficient cj . While the basis functions are selected a priori, the coefficients vary with the density function . In the computer graphics field Blinn introduced the so-called blobby model [9] that uses Gaussians for the basis function. Other basis functions have been suggested since; some examples include multiscale wavelets [39], piecewise quadratics [40], splines [45] and polynomials [49]. In practice, the basis functions have to drop to a negligible value beyond a moderate radius. The idea of using basis functions that are smooth (in the sense of being multiply differentiable everywhere) has been suggested by several authors, motivated by the belief that implicit surfaces of the resulting density functions would reflect more accurately the smoothness of natural objects. This idea has been also adopted in the field of reconstructing surfaces from point sets, typically generated by high resolution scanners, where (2) is used to smoothly approximate the surface represented by the data [3,11,19,30,50]. In the field of reconstruction from projections Lewitt [28,29] and Matej [35] proposed the generalized Kaiser–Bessel window functions, also referred to as blobs, as basis functions. These are functions with compact support, spherical symmetry, and a smooth transition from one to zero. They have proved to be efficacious for a number of reconstruction tasks [18,23,34] and, in particular, the authors of [31,33] obtained results suggesting that the combined use of the so-called algebraic reconstruction techniques (ART) and blobs produce better reconstructions than (or at least as good reconstructions as) those produced by other algorithms. (In both papers, the authors compare ART with other reconstruction algorithms, based on transform methods, using several figures of merit—FOMs—that permit the quantification of the quality of reconstructions of mathematical phantoms. Such FOMs can measure the mean error between a phantom and its reconstruction and, as is more relevant in practice, the success in recovering interesting features of the phantom. For each FOM, a level of statistical significance is assigned to the claim of superiority of one reconstruction method over another.)
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
285
Fig. 1. In the series expansion methods a density function is approximated by the linear combination of basis functions. Smooth basis functions, such as blobs, may reflect more accurately the smoothness of natural objects. The support of a blob is a sphere that we indicate transparently. To approximate a density function, each basis functions bj is weighted by a coefficient cj . The coefficients cj are associated with points p j , which are the centers of the basis functions bj ; we represent these points by small solid spheres. Under this model, a line along which the integral [P ]i is calculated will intersect only a few basis functions.
While the basis functions of (2) are preselected and fixed, the coefficients have to be determined by the reconstruction algorithm. For reconstruction purposes, we consider a projection to be a collection of line integrals. For a function over R3 we define the ray transform as o, x) = (x + o) d. (3) [P] ( R
The operator P provides all the integrated densities along all the lines defined by x + o, where o is a unit vector and ∈ R (see Fig. 1). It follows from (3) and (2) that, for any o, x), ( o, x) = [P] (
J
o, x) . cj Pbj (
(4)
j =1
Suppose that our measurements are made for I lines, characterized by ( oi , x i ), for 1 i I . Then we get yi ≈
J
i,j cj ,
j =1
(5)
where yi is the ith measurement and i,j = Pbj ( oi , x i ), a value that can usually be determined analytically. The reason for the ≈ in (5) is that yi is not exactly [P] ( oi , x i ),
286
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
due to noise in the measurements and the fact that the physical object can only be approximated by an expansion of the form given in (2). Thus (5) is approximately a system of linear equations y = Lc that can be solved either by some sort of direct inversion method or by an iterative method. In practice, the system y = Lc is often overdetermined (to compensate for the noise in the measurements, typically many more measurements are taken than there are unknowns cj ). A particular iterative method to solve the system y = Lc is a generalization of Kaczmarz’s method [21] for solving both over- and underdetermined linear systems of equations. For this generalization, we consider that the matrix L can be divided in N blocks (n denotes the number of a block, 1 n N ) with M rows in each block, and so I = M × N . The kth iterative step of the method is c(k+1) = c(k) + (k)
nM
y −i ,c(k) 2 i=(n−1)M+1 j =1 i,j i J
i , for n = [k (mod N )] + 1,
(6)
where i is a J-dimensional vector whose jth component is i,j and (k) is a relaxation parameter that determines how much the solution is updated in the kth iteration. In practice, the blocks are chosen to correspond to single projections; thus oi has the same value for all i’s in a single block. (N is the number of projections and M is the number of sample points in a projection.) It turns out that, in our application, solving the linear system by (6) is faster than inverting the matrix L because a line intersects only a very few basis functions (see Fig. 1), resulting in a matrix that is sparse (most of its entries are zero valued) whereas a generalized inverse L+ [7] (typically L is not invertible) has mostly non-zero entries. The sparsity of L implies that (6) can be efficiently implemented [35]. When this approach is taken, the result is a representation of a biological molecule that uses blobs to specify density functions. To visualize the molecule we need to render an implicit surface (1), the threshold t for which is determined by the total volume of the molecule (known to us from other sources). To avoid introducing approximations in addition to those that had to be made in the electron microscopic reconstruction process, we desire to visualize the implicit surface directly, without making additional approximations to it. This can be achieved by raycasting, similar to that suggested in [9], with adjustments suitable for data sets produced by reconstruction methods such as ART. 3. Blobs and grids The general form of a single blob is [28]: ⎧ ⎪ ⎨ Im 1 − r 2 r 2 m a b(m, , a; r) = 1− , if ⎪ ⎩ Im () a
0 r a,
(7)
where r is the radial distance from the blob center, Im denotes the modified Bessel function of order m, a is the radius of the blob (the value of b is zero for r > a), and is a parameter controlling the blob shape. The three parameters m (a non-negative integer), a and (nonnegative real numbers) control the smoothness and shape of a blob and influence the results
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
287
yielded by reconstruction and visualization algorithms; therefore, the appropriate selection of them is highly important. Hereafter we set m equal to 2, which makes the blobs to have continuous first derivatives everywhere. The individualblobs bj of (2) are shifted versions of the blob b defined in (7). We refer to the set of points pj to which the centers of the blobs are shifted in such a representation as a grid. As an example for (2) using blobs as basis functions we refer to Fig. 1, in which a density function describing the donut-shaped object is to be approximated by a linear combination of blobs. The grid is represented by the small spheres in Fig. 1. The choice of the grid pj is important. It is shown in [38,42] that the body-centered cubic (bcc) grids provide the most “efficient” sampling of R3 . The bcc grids are defined by B = {k | k ∈ Z3 and k1 ≡ k2 ≡ k3 (mod 2)},
(8)
where k is the transpose of the 3-tuple (k1 , k2 , k3 ) (i.e., a three-dimensional vector), whose components belong to the set of integers denoted by Z and is a positive real number (the sampling distance). In order to visualize this grid, we can use a small portion of it and take advantage of its periodic repetition; see Fig. 2. For reconstruction purposes, Matej and Lewitt [35] demonstrated that whenever a linear combination of blobs is employed to obtain a reconstruction, the bcc grids provide desirable sets of locations for the centers of the blobs. In what follows we will use for p j the set obtained by the intersection of some finite convex region of space with a B of (8). Having decided that we use m = 2 and the bcc grid, there are three parameters to be chosen: , a, and . Clearly, to be able to approximate arbitrary distributions using (2), the value of should be small. However, in a fixed volume of space, the number of grid points (and consequently the cost of a reconstruction algorithm) is proportional to 13 and so practical considerations do not allow us to choose to be very small. The cost of reconstruction (in our implementation using footprints [29,35]) is also proportional to a 2 . The computational cost does not depend on , and so this parameter may be chosen purely based on the quality of the resulting reconstructions. In [35] a method was proposed for the selection of the parameters , a, and with the aim of ensuring that ART will produce “good” reconstructions. This method selects the blob parameters by assuming that a linear combination of blobs with cj = 1, for 1j J , should approximate a constant valued function. For this case, the right hand side of (2) is a convolution of the blob b in (7) with a truncated version of the train of pulses IIIB (pulses arranged on the bcc grid). The Fourier transform of such convolution is approximately F b ∗ IIIB = F {b} × F IIIB . Since F IIIB is also a train of pulses (on a so-called face-centered cubic grid), for this to best approximate the Fourier transform of a constantvalued function (an impulse at the origin) it is useful to select b in such a way that F{b} is zero-valued at the locations of the pulses in F IIIB that have the smallest positive distance from the origin. It follows from this discussion and from the analytic formula for F{b}, available from [29], that we should select =
22
a 2
− 6.9879322 .
(9)
288
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
Fig. 2. Points in the body-centered cubic grid in a 2 × 2 × 2 portion of space (assuming = 1). The rest of the points can be obtained by filling in space by the most natural repetition of the indicated 2 × 2 × 2 portion.
In [15] it was reported that the parameters yielded by the methodology suggested in [35] produced in some cases nonconvex reconstructions from data obtained from convex density functions; causing a significant inaccuracy in the visualization of the resulting implicit surfaces, see Fig. 3. To correct this problem [15] proposes an additional criterion for the selection of the parameters , a, and : a should be chosen as small as possible consistent with both satisfying (9) √ and achieving that if two blobs at nearest grid points in the grid B (those separated by 3) are given coefficients 1 with all other blobs given coefficients 0, then the implicit surface thresholded at t = 0.5 should enclose a convex set, see Fig. 4. The selection of the latter criterion is not arbitrary but is based on the principle that the grid spacing should limit the resolution: nearest grid points should not be resolvable from each other. Using such a second criterion determines a single pair (a, ) among all those that satisfy (9). This is the methodology used in the rest of this paper. 4. A basic raycasting-blobs technique for visualization A suitable method for visualizing the surface in (1) is raycasting. In general, raycasting is slower than the polygon-projection methods. However, an accurate visualization of an implicit surface requires a careful selection of polygons, something that is avoided by raycasting whose accuracy is automatically determined by the pixel locations on the computer screen. Furthermore, implicit surfaces are particularly well suited for ray-intersection processing, since the density function defining the implicit surface enables us to compute the intersection between a ray and the surface by standard numerical zero-finding methods. Raycasting produces a projection of S onto the screen by casting a finite number of rays toward S. In one of its forms, the rays are perpendicular to the plane representing the plane of view, typically the computer screen. In order to produce a foreshortening effect in the
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
289
Fig. 3. Visualization of the implicit surfaces of a reconstructed sphere-shaped “molecule” using parameters (a) = √1 , a = 1.25 and = 3.60 and (b) = √1 , a = 2.40 and = 13.36. (Both these choices satisfy (9).) 2
2
The reconstructed values for the two choices are practically identical, see (c) and (d) for gray-value displays of the central slices of the reconstructions. The artifact in (a) is due not so much to the location of the implicit surface (which is nearly identical for the two cases), but to the directions of the normals at the implicit surface.
final image (the farther the object, the smaller it appears) it is possible to use a perspective projection in which all the rays cast from the screen intersect in a point called the center of projection [48]. Because for the visualization of biological molecules foreshortening does not appear to be important, we present only orthogonal projections. For every ray R that intersects S, we need to find the point q in R ∩ S nearest to the screen, and compute its distance from the screen and the normal to S at q (these are used to assign an intensity value on the computer screen [48]). In practice, the finding of the points q is computationally expensive. In general there is no prior estimate of how far q is from the screen. Clever procedures have been published in the literature that guarantee finding the intersection (if there is one). In most cases these require calculating derivatives associated with the density function ; this, in principle, is not a problem for us since is defined by (2) and the basis functions bj can be analytically differentiated based on (7). Such procedures include ones based on interval analysis [37] and ones that compute a (local) Lipshitz constant [16,22]. A practical difficulty that we perceived with such approaches when applied to our application is that we may end up with such small step sizes for the search as to make the procedure computationally unacceptable. For example, the sphere tracing procedure as described in [16] produces a step size that is inversely proportional to the Lipschitz constant. For our choices of the parameters , a, and , there maybe more than 50 basis functions
290
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
Fig. 4. Representations of the implicit surface at level t = 0.5 for the combination of two blobs whose centers are immediate neighbors in the bcc grid B1/√2 and whose coefficients are 1. We show three surfaces with different values of a and satisfying (9) that produce a concave, a “just convex” and a “too convex” objects, respectively. The parameters , a, and used for (a) and (b) are the same as used for (a) and (b) in Fig. 3. The parameters used for (c) would also result in a smooth-looking visualization of the reconstructed sphere-shaped “molecule,” but it would appear larger than it should be.
making a nonzero contribution to (x) as defined by (2). Using the estimate provided by the fact that the Lipshitz constant of the sum is bounded by the sum of the Lipshitz constants (as suggested in Appendix D.1 of [16]), we get that the step size to be used in the search is inversely proportional to the sum of the 50 or so largest absolute values of the coefficients cj in (2). For this reason we looked for an alternative methodology that makes specific use of the nature of the representation (2) that is the output of the electron microscopic reconstruction process. We first do a preprocessing of the set of grid points pj at the end of which, for every pixel on the screen from which we cast a ray, we have the list of those grid points (arranged in order of increasing distance from the screen) whose associated coefficients can possibly influence the value of the distribution anywhere along the ray. (These grid points all lie within a cylinder of radius a whose central axis is the ray in question.) This preprocessing is easily done by identifying on the screen the shadows of the blobs centered at the grid points, one-by-one in an appropriate order. In locating q for a particular ray, we make use of the associated list of grid points. For all grid points in the list (recall that these are arranged in order of increasing distance from the screen), we evaluate at the projection of the grid point onto the ray (for this we need the blob coefficients for only a few grid points, all of which are at similar positions in the list), until we find (if ever) two consecutive projections onto the ray, qa and qb , such that the value of is below the threshold at qa and is above it at qb . In fact, with the previously discussed methodology for the selection of the parameters , a, and , there are up to only 51 values cj that contribute to the value of at any given point along a ray. Thanks to the radial symmetry and compact support of our basis functions, it is possible to create (just once) a 1D look-up table to represent the blob (7) at a very fine sampling of the radial distance r and so rapidly compute the cj contributions. (Note that it is theoretically possible that there are two consecutive projections of grid points onto the ray such that the value of is below the threshold at both and yet it is above the threshold at some point between them. In this situation, our algorithm will miss this point of the surface and this will cause an inaccuracy in the displayed image of the surface. However the nature
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
291
of our blobs, as defined by (7), makes such an event unlikely: the values of the blobs peak at the grid points and they are circularly symmetric, consequently the contribution of any blob to the value of on the ray is strongest at the projection onto the ray of the grid point that is at the center of the circular support of that blob.) This initial search for qa and qb is limited by a not very large constant (that is the same for all rays). Once two such points qa and qb are found, then q is located by a combination of the Newton–Raphson and the bisection methods [41] within the interval [qa , qb ] (for this we need the coefficients of only those blobs which were used for calculating at qa and at qb ). Under the right circumstances, the Newton–Raphson method has a quadratic rate of convergence, but it can also happen that it moves outside the interval [qa , qb ]. In such a case, we continue our search for q using the bisection method (which is slower but guarantees convergence) within the refined interval produced by the Newton–Raphson method. With our choice of the basis functions bj , a function defined by (2) is continuously differentiable and its gradient, at any point x, is given by ∇ (x) =
J
cj ∇bj (x) .
(10)
j =1
In our application, the set cj is produced by the reconstruction algorithm and we have a closed formula to compute the ∇bj [28]. The visualization obtained by raycasting is therefore an accurate representation of the object of interest, limited only by the reconstruction process and the accuracy of the t in (1). 5. Visualization of reconstructed molecules We obtained from the authors of [6] electron microscopic projections of the complex DnaB·DnaC of Escherichia coli; see Fig. 5. (DnaB and DnaC are two proteins that dock during DNA replication.) We applied the reconstruction method ART with blobs to these data using = √1 , a = 2.40 and = 13.36 (the selection of these values is justified by 2 the discussion in Section 3; see, especially, Figs. 3 and 4). The reconstruction process took 65 h 22 min 48 s and produced a set cj with 1,600,065 values. After reconstruction we applied the raycasting-blobs method just described. The display of the surface, at 512 × 512 pixels resolution, took 1 h 28 min 12 s (all times are for a single-Pentium4䉸 -processor based computer with 2 GHz and 1 Gbytes of RAM operated under Linux© ); see Fig. 6. (We consider that displaying the implicit surface at a resolution higher than 512 × 512
Fig. 5. Four of the images obtained by transmission electron microscopy (i.e., micrographs) of specimens of the DnaB ·DnaC complex of Escherichia coli [6].
292
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
Fig. 6. Three dimensional representation of the reconstructed macromolecular complex DnaB·DnaC produced by the raycasting-blobs method.
is not justified by the quality of the data from which the reconstructions were produced; see Fig. 5.) Because the exact shape of the DnaB·DnaC complex is unknown (i.e., there is no alternative gold-standard methodology which identifies the exact positions of its atoms), we decided to obtain also data from the molecule bacteriorhodopsin [27], for which there is a model of its atoms available in the protein data bank (PDB) [8]. This allows us to compare the rendering of the reconstructed surface with that based on the atomic model. We used the PDB description file to simulate the acquisition process in transmission electron microscopy [12] with programs that permit us to calculate projections with noise from PDB models [13,32]. We utilized the conical tilt scheme (a common geometry in electron microscopy [12]) to create the projections. For the uncertainty of angles we used ±5 degrees for rotation and ±1 degree for tilt, these values are suggested in [31]. For the level of noise in the pixels, we selected the value of 0.5 SNR (see Fig. 7), a value within the range presented in [12] for uncorrelated additive noise with zero mean. We applied ART with blobs to the bacteriorhodopsin data (using the same parameters as used for the DnaB·DnaC reconstruction). The reconstruction process took 36 h 13 min 36 s and produced a set cj with 1,482,624 values. Once again, we applied the raycasting-blobs method described above. In this case, the display of the surface took 1 h 37 min 55 s; see Fig. 8(b). The raycasting method of Section 4 for visualizing implicit surfaces is computationally demanding because of the search, for every ray, for the intersection point q. The times just reported above (over 90 min in both cases) are too long for routine generation of multiple views. In the next section we consider a method to accelerate the raycasting-blobs technique by taking advantage of the properties of the representation in (2) when the bj s are blobs based on (7).
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
293
Fig. 7. Projections (a) without noise and (b) with noise of the molecule bacteriorhodopsin created using an atomic description [8] and simulation programs [13,32].
Fig. 8. (a) Rendering of an implicit surface of the bacteriorhodopsin reconstructed from noiseless projections, some of which are shown in Fig. 7(a). The surface has the same orientation and encloses the same volume as that shown in (b), and serves as the representation of truth. (b) Rendering of an implicit surface of the bacteriorhodopsin reconstructed from noisy projections, some of which are shown in Fig. 7(b). We can compare (b) with the “real” shape of the molecule in (a).
6. Method to speed up the raycasting-blobs technique Our original implementation of the raycasting-blobs method searches, for every pixel of the image displaying the surface, for two points qa and qb that are end points of a line segment containing the point q such that (q) = t. This search is computationally expensive as there are no prior estimates of how far the points qa and qb are from the screen. In fact, the most computationally intensive part of the whole raycasting process is the identification of the interval [qa , qb ] that contains an intersection (if there is such an interval); the actual search for the intersection within the interval can be done in a stable and efficient manner.
294
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
We now introduce a preprocessing method that finds an estimate of the point q, for every casted ray in the image. It first calculates, for every grid point pj , vj = p j and then proceeds to utilize both the set vj and a list of all the j, such that vj t in a z-buffer algorithm [48] that operates as follows. A value is assigned to every ray of the original raycasting-blobs algorithm of Section 4. Initially this value is “infinity” (in practice, a very large number). Then we loop through all j such that vj t. For each corresponding blob, we calculate the distance dj of pj from the screen and, for all rays which intersect the blob, we replace the currently assigned value by dj if, and only if, dj is smaller than the currently assigned value. Upon completion of this process, the value assigned to any ray will be an approximation to the distance qb for that ray in the raycasting algorithm. The new raycasting-blob method utilizes only those rays whose corresponding value in the z-buffer is different from infinity. For every ray of this set, we assume that the value stored in the z-buffer provides a point qc that in most of the cases is near to point qb . We check whether the condition (qc ) t is true. When the condition is not true, we search for qa and qb as we did in the original implementation but starting from the point qc (which is a projection of a grid point in the list associated with the casted ray). In the alternate case, we search for the points qa and qb in the direction toward the plane, again starting from qc . Once the points qa and qb are found, the point q is located as in the original implementation in Section 4. The preprocessing (the calculation of the vj ) took 5 s for the set cj corresponding to the DnaB·DnaC and 6 s for the bacteriorhodopsin. After creating the set vj , we used our modified raycasting method to obtain the computer representation of both the macromolecular complexes DnaB·DnaC and bacteriorhodopsin. When compared pointby-point with those created with the raycasting-blobs method introduced in Section 4 (see Figs. 6 and 8(b)), we found that the images are exactly the same. However, the times to generate the images in Figs. 6 and 8(b) by the original method are around 1.5 h, while the times to generate them by the new method are 94 s and 86 s, respectively; thus reducing the computing time by a factor between 57 and 69, see Table 1. In order to analyze the speed of the new ray casting algorithm, we assume that there are J blobs produced by the reconstruction algorithm and N × N pixels in the image to be displayed. The z-buffer algorithm runs linearly in J. After that, for each of the N 2 rays, we do calculations that is proportionately bounded above by the number of blobs intersected 1 by the ray, and this is of the order J 3 . Assuming, as is reasonable, that N is also of the order 1 J 3 , the whole algorithm is seen to be linear in J. We also compared the results of our approach to those produced by two software packages: OpenDX [1] (a freely-available and popular package, formerly IBM DataExplorer) and Amira䉸 [4] (an integrated software package for 3D visualization and volume modeling that is frequently used in engineering, biological and medical laboratories). Both of these can produce renderings of polygonal approximations of surfaces. The input to the programs requires evaluating at points of a simple cubic grid; such can easily be achieved using (2). We found that in order to obtain image quality similar to what was obtained using our raycasting-blobs algorithms, we needed to create the input to both programs at a minimum of 400 × 400 × 400 points. The resulting images (to be compared
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
295
Table 1 Times necessary to generate images of the complex DnaB·DnaC and the bacteriorhodopsin by both raycastingblobs implementations and by two programs for scientific visualization: OpenDX and Amira䉸 Time Method
Process
DnaB·DnaC
Bacteriorhodopsin
OpenDX
Loading Polygonization Rendering Loading Polygonization Rendering Loading Raycasting Rendering Loading PreProcessing Raycasting Rendering
12 s 43 s 1s 6s 34 s 1s 1s 1 h 28 min 12 s 1s 1s 5s 1 min 27 s 1s
10 s 45 s 1s 6s 33 s 1s 1s 1 h 37 min 55 s 1s 1s 6s 1 min 18 s 1s
Amira䉸
Raycasting-blobs original
Raycasting-blobs speeded
with Figs. 6 and 8(b)) are shown in Fig. 9. The timings for this software are also reported in Table 1. While the total time for generating a single view is only about twice as fast when using OpenDX or Amira䉸 than when using the speeded raycasting-blobs method, if multiple views are desired then the polygon-based techniques are much faster, since (once the polygonization is completed) the projection of the polygons for a new point of view requires only approximately a second. We also compared the memory requirements of the various approaches; see Table 2. We found that our new (speeded) implementation requires actually less memory than the original raycasting-blobs approach and that both raycasting-blobs methods require significantly less memory than the programs OpenDX and Amira䉸 . It is easy to see that, under the same assumptions that were made for the time-complexity analysis, the space-complexity of the raycasting-blobs algorithms is also linear in J.
7. Summary At the end of the electron microscopic reconstruction process, biological macromolecules are often represented as linear combinations of well over a million special basis functions called blobs. The implicit surface separating the reconstructed molecule from its background can be accurately visualized by raycasting. Our initial implementation of this was too slow to allow user interaction. However, one can take advantage of the nature of the blob representation to reduce the time required to visualize molecules by more than a factor of fifty. Compared to popular visualization programs that produce renderings of polygonal approximations of the surfaces, our new implementation is slower but requires less memory to display the implicit surface (rather than a polygonal approximation of it).
296
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
Fig. 9. Visualizations of the explicit surfaces obtained from the reconstructions of the macromolecular complexes DnaB·DnaC (upper row) and bacteriorhodopsin (bottom row). Images in (a) and (c) were produced using the software OpenDX [1] while those in (b) and (d) were produced with Amira䉸 [4], based in both cases on a 400 × 400 × 400 voxelized distribution.
An important advantage of using direct methods to visualize implicit surfaces is that surfaces in nature are frequently highly complex and in some circumstances the programs in charge of polygonization of the implicit surface might generate the wrong representation of the underlying surface or violate the underlying topology of the natural surface. Since the method presented here relies in the model used to reconstruct the biological object, the final representation will depend only on the sampling used between pixels; thus producing, in principle, an accurate representation of the biological surface.
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
297
Table 2 Memory used to generate images of the complex DnaB·DnaC and the bacteriorhodopsin by both raycasting-blobs implementations and by two programs for scientific visualization: OpenDX and Amira䉸 Memory Method
Process
DnaB·DnaC
Bacteriorhodopsin
OpenDX
Digitization
Amira䉸
Loading Polygonization Rendering Digitization
Raycasting-blobs original
Loading Polygonization Rendering Set of coefficients
Raycasting-blobs speeded
Loading Raycasting Rendering Set of coefficients
400 × 400 × 400 16-bit floats 254 Mbytes 514 Mbytes 518 Mbytes 400 × 400 × 400 16-bit floats 245 Mbytes 292 Mbytes 292 Mbytes 1,600,065 16-bit floats 9028 bytes 47,152 bytes 11,956 bytes 1,600,065 16-bit floats 12,062 16-bit floats 15,312 bytes 16,164 bytes 45,292 bytes 18,248 bytes
400 × 400 × 400 16-bit floats 254 Mbytes 512 Mbytes 516 Mbytes 400 × 400 × 400 16-bit floats 245 Mbytes 293 Mbytes 293 Mbytes 1,482,624 16-bit floats 8536 bytes 43,596 bytes 11,548 bytes 1,482,624 16-bit floats 10,566 16-bit floats 14,484 bytes 15,284 bytes 41,688 bytes 17,364 bytes
Reduced set of coeff. Loading PreProcessing Raycasting Rendering
Acknowledgements We thank Carlos Oscar Sánchez Sorzano and José Jesús Fernández for helpful advice regarding this manuscript. We appreciate the assistance of Montserrat Bárcena in providing us with data and information regarding the macromolecular complex DnaB·DnaC.
References [1] G.D. Abram, L. Treinish, An extended data flow architecture for data analysis and visualization, in: Proceedings of IEEE Visualization 1995, IEEE Computer Society, 1995, pp. 263–269. [2] S. Akkouche, E. Galin, Adaptive implicit surface polygonization using marching triangles, Comput. Graphics Forum 20 (2001) 67–80. [3] M. Alexa, J. Behr, D. Cohen-Or, S. Fleishman, D. Levin, C.T. Silva, Computing and rendering point set surfaces, IEEE Trans. Visualization Comput. Graphics 9 (2003) 3–15. [4] Amira: An advanced 3D visualization and volume modeling system, Department for Scientific Visualization of the Konrad-Zuse-Zentrum für Informationstechnik, Berlin, 2001 (http://www.amiravis.com). [5] C.L. Bajaj, G. Xu, Spline approximations of real algebraic surfaces, J. Symbolic Comput. 23 (1997) 315–333.
298
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
[6] M. Bárcena, T. Ruiz, L.E. Donate, S.E. Brown, N.E. Dixon, M. Radermacher, J.M. Carazo, The DnaB·DnaC complex: a structure based on dimers assembled around an occluded channel, European Mol. Biol. Organization J. 20 (2001) 1462–1468. [7] A. Ben-Israel, T.N.E. Greville, Generalized Inverses: Theory and Applications, second ed., Wiley, New York, 2001. [8] F.C. Bernstein, T.F. Koetzle, G.J. Williams, E. Meyer, M.D. Brice, J.R. Rodgers, O. Kennard, T. Shimanouchi, M. Tasumi, The protein data bank, a computer-based archival file for macromolecular structures, J. Mol. Biol. 112 (1977) 535–542. [9] J.F. Blinn, A generalization of algebraic surface drawing, ACM Trans. Graphics 1 (1982) 235–256. [10] J. Bloomenthal, Introduction to Implicit Surfaces, Morgan Kaufmann, San Francisco, 1997. [11] J.C. Carr, R.K. Beatson, J.C. Cherrie, T.J. Mitchell, W.R. Fright, B.C. McCallum, Reconstruction and representation of 3D objects with radial basis functions, in: Proc. 28th Ann. Conf. on Computer Graphics and Interactive Techniques, 2001, pp. 67–76. [12] J. Frank, Three-Dimensional Electron Microscopy of Macromolecular Assemblies, Academic Press, New York, 1995. [13] J. Frank, M. Radermacher, P. Penczek, J. Zhu, M. Ladjadj, A. Leith, SPIDER and WEB: processing and visualization of images in 3D electron microscopy and related fields, J. Struct. Biol. 116 (1996) 190–199. [14] E. Galin, S. Akkouche, Incremental polygonization of implicit surfaces, Graphical Models 69 (2000) 19–39. [15] E. Garduño, G.T. Herman, Optimization of basis functions for both reconstruction and visualization, Discrete Appl. Math. 139 (2004) 95–111. [16] J.C. Hart, Sphere tracing: a geometric method for the antialiased ray tracing of implicit surfaces, Visual Comput. 12 (1996) 527–545. [17] H. Hauser, L. Mroz, G.I. Bischi, M.E. Groller, Two-level volume rendering, IEEE Trans. Visualization Comput. Graphics 7 (2001) 242–252. [18] G.T. Herman, Algebraic reconstruction techniques in medical imaging, in: C.T. Leondes (Ed.), Medical Imaging Systems Techniques and Applications—Computational Techniques, Gordon and Breach Science Publishers, Amsterdam, 1997, pp. 1–42. [19] M. Jackowski, M. Satter, A. Goshtasby, Approximating digital 3D shapes by rotational Gaussian surfaces, IEEE Trans. Visualization Comput. Graphics 9 (2003) 56–69. [20] X. Jin, H. Sun, Q. Peng, Subdivision interpolating implicit surfaces, Comput. Graphics 27 (2003) 763–772. [21] S. Kaczmarz, Angenäherte Auflösung von Systemen Linearer Gleichungen, Bull. Acad. Polonaise Sci. Lett. Ser. A 35 (1937) 355–357. [22] D. Kalra, A.H. Barr, Guaranteed ray intersections with implicit surfaces, ACM SIGGRAPH Comput. Graphics 23 (1989) 297–306. [23] P.E. Kinahan, S. Matej, J.S. Karp, G.T. Herman, R.M. Lewitt, A comparison of transform and iterative techniques for a volume-imaging PET scanner with a large acceptance angle, IEEE Trans. Nucl. Sci. 42 (1995) 2281–2287. [24] G. Kindlmann, D. Weinstein, Hue-balls and lit-tensors for direct volume rendering of diffusion tensor fields, in: Proceedings of IEEE Visualization 1999, IEEE Computer Society, 1999, pp. 183–189. [25] G. Kindlmann, D. Weinstein, D. Hart, Strategies for direct volume rendering of diffusion tensor fields, IEEE Tran. Visualization Comput. Graphics 6 (2000) 124–138. [26] K. Kreeger, A. Kaufman, Mixing translucent polygons with volumes, in: Proceedings of IEEE Visualization 1999, IEEE Computer Society, 1999, pp. 191–199. [27] W. Kühlbrandt, Bacteriorhodopsin—the movie, Nature 406 (2000) 569–570. [28] R.M. Lewitt, Multidimensional digital image representations using generalized Kaiser–Bessel window functions, J. Opt. Soc. Amer. A: Opt. Image Sci. Vision 7 (1990) 1834–1846. [29] R.M. Lewitt, Alternatives to voxels for image representation in iterative reconstruction algorithms, Phys. Med. Biol. 37 (1992) 705–716. [30] Q. Li, D. Wills, R. Phillips, W.J. Viant, J.G. Griffiths, J. Ward, Implicit fitting using radial basis functions with ellipsoid constraint, Comput. Graphics Forum 23 (2004) 55–69. [31] R. Marabini, G.T. Herman, J.M. Carazo, 3D reconstruction in electron microscopy using ART with smooth spherically symmetric volume elements (blobs), Ultramicroscopy 72 (1998) 53–65. [32] R. Marabini, I.M. Masegosa, M.C. San Martin, S. Marco, J.J. Fernández, L.G. de la Fraga, C. Vaquerizo, J.M. Carazo, Xmipp: an image processing package for electron microscopy, J. Struct. Biol. 116 (1996) 237–240.
E. Garduño, G.T. Herman / Theoretical Computer Science 346 (2005) 281 – 299
299
[33] R. Marabini, E. Rietzel, R. Schröder, G.T. Herman, J.M. Carazo, Three-dimensional reconstruction from reduced sets of very noisy images acquired following a single-axis tilt schema: application of a new threedimensional reconstruction algorithm and objective comparison with weighted backprojection, J. Struct. Biol. 120 (1997) 363–371. [34] S. Matej, G.T. Herman, T.K. Narayan, S.S. Furuie, R.M. Lewitt, P.E. Kinahan, Evaluation of task-oriented performance of several fully 3D PET reconstruction algorithms, Phys. Med. Biol. 39 (1994) 355–367. [35] S. Matej, R.M. Lewitt, Practical considerations for 3-D image reconstruction using spherically symmetric volume elements, IEEE Trans. Med. Imaging 15 (1996) 68–78. [36] K.H. Min, I.-K. Lee, C.-M. Park, Component-based polygonal approximation of soft objects, Comput. Graphics 25 (2001) 245–257. [37] D.P. Mitchell, Robust ray intersection with interval arithmetic, in: Proceedings of Graphics Interface, 1990, pp. 68–74. [38] H. Miyakawa, Sampling theorem of stationary stochastic variables in multi-dimensional space, J. Inst. Electron. Commun. Eng. Jpn. 42 (1959) 421–427. [39] S. Muraki, Multiscale volume representation by a DoG wavelet, IEEE Trans. Visualization Comput. Graphics 1 (1995) 109–116. [40] H. Nishimura, M. Hirai, T. Kawai, T. Kawata, I. Shirakawa, K. Omura, Object modeling by distribution function and a method of image generation, Trans. Inst. Electron. Commun. Eng. Jpn. J68-D (4) (1985) 718–725. [41] C.E. Pearson, Numerical Methods in Engineering and Science, Van Reinhold Company, Inc., New York, 1986. [42] D.P. Petersen, D. Middleton, Sampling and reconstruction of wave-number-limited functions in N-dimensional Euclidean spaces, Inform. Control 5 (1962) 279–323. [43] H. Pfister, B. Lorensen, C. Bajaj, G. Kindlmann, W. Schroeder, L.S. Avila, K.M. Raghu, R. Machiraju, J. Lee, The transfer function bake-off, IEEE Comput. Graphics Appl. 21 (3) (2001) 16–22. [44] R. Shahidi, Surface rendering versus volume rendering in medical imaging: techniques and applications (panel), in: Proceedings of IEEE Visualization 1996, IEEE Computer Society, 1996, pp. 439–440. [45] G. Turk, J.F. O’Brien, Shape transformation using variational implicit functions, in: Proc. 26th Ann. Conf. on Computer Graphics and Interactive Techniques, 1999, pp. 335–342. [46] J.K. Udupa, H. Hung, K. Chuang, Surface and volume rendering in three-dimensional imaging: a comparison, J. Digital Imaging 4 (1991) 159–168. [47] I. Wald, P. Slusallek, C. Benthin, M. Wagner, Interactive rendering with coherent ray tracing, in: Proceedings of EUROGRAPHICS 2001, Vol. 20, 2001, pp. 153–164. [48] A.H. Watt, 3D Computer Graphics, second ed., Addison-Wesley Pub. Co., Reading, Mass., 1993. [49] G. Wyvill, C. McPheeters, B. Wyvill, Data structure for soft objects, Visual Comput. 2 (1986) 227–234. [50] M. Zwicker, H. Pfister, J. van Baar, M. Gross, Surface splatting, in: Proc. 28th Ann. Conf. on Computer Graphics and Interactive Techniques, 2001, pp. 371–378. [51] M. Zwicker, H. Pfister, J. van Baar, M. Gross, EWA splatting, IEEE Trans. Visualization Comput. Graphics 8 (2002) 223–238.
Theoretical Computer Science 346 (2005) 300 – 306 www.elsevier.com/locate/tcs
Reduction from three-dimensional discrete tomography to multicommodity flow problem Y. Gerard∗ LLAIC, IUT, Ensemble Universitaire des Cézeaux, 63172 Aubière, France
Abstract The reduction from two-dimensional-discrete tomography to max-flow problem is well-known [Gale, A theorem on flows in networks, Pacific J. Math. 7 (1957) 1073–1082]. This approach is based on the natural correspondence between two-dimensional lattices and bipartite graphs. We extend this result in dimension 3 by reducing three-dimensional discrete tomography to multicommodity flow problems. Two reductions are presented, one considering discrete tomography with multisets while the other one works with sets. © 2005 Elsevier B.V. All rights reserved. Keywords: Multiset; Flow-max problem; Integer multicommodity flow problem
1. Introduction The expression of two-dimensional-discrete tomography in terms of graphs is known since the first steps of this field [4,6,8]. The numbers of points of a lattice set belonging to each row and column correspond with the numbers of edges issued from the vertices of the corresponding subgraph (Fig. 1). This correspondence provides a reduction from two-dimensional-discrete tomography to flow-max problem (Fig. 2). The purpose of this paper is to extend this reduction to three-dimensional discrete tomography according to three linearly independent directions (a problem that we call 3DT) (Fig. 3). ∗ Tel./fax: +33 (0)4 73 17 71 39.
E-mail address:
[email protected]. 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.016
Y. Gerard / Theoretical Computer Science 346 (2005) 300 – 306
301
Fig. 1. A two-dimensional lattice set and its corresponding graph. The number of points of the lattice set in row Ri (with 1 i 5) is equal to the number of edges of the graph issued from vertex Ri . The number of points of the lattice set in column Cj (with 1 j 6) is the number of edges of the graph issued from vertex Cj .
Fig. 2. An instance of two-dimensional discrete tomography and its encoding in a flow-max instance. The capacities of the edges of the bipartite graph (from the left to the right) are all 1. With this instance, the maximal flow is bounded by 1 + 3 + 2 + 3 + 1 = 1 + 2 + 1 + 2 + 2 + 2 = 10. A solution of the discrete tomography problem is given by the set of edges involved in a flow equal to 10.
Fig. 3. An instance of 3DT.
Problem 1 (3DT). Given: three positive integers m, n, l and three positive integer matrices (ri,k )1 i m,1 k l , (cj,k )1 j n,1 k l and (vi,j )1 i m,1 j n verifying lk=1 ri,k = m l n m n j =1 vi,j , i=1 vi,j = k=1 cj,k and j =1 cj,k = i=1 ri,k . Question: existence of a lattice set of [1..m] × [1..n] × [1..l] having for any (i, j, k) ∈ [1..m] × [1..n] × [1..l] exactly ri,k points verifying x = i and z = k, cj,k points verifying y = j and z = k and vi,j points verifying x = i and y = j ?
302
Y. Gerard / Theoretical Computer Science 346 (2005) 300 – 306
We reduce problem 3DT to an extension of flow-max problem called integer multicommodity flow (MCF) [1] problem. We begin in next section with a natural reduction from 3DT to MCF. This reduction works if l = 2 or if one of the matrices is binary but unfortunately, in the general case, it provides multisets instead of sets. This result being not satisfying, we provide in Section 3 another reduction supplying real sets of solutions with a heavier device.
2. Reduction from 3DT to MCF in the framework of multisets 2.1. Multicommodity flow problem The source and the terminal of a flow-max instance are not enough for encoding the variable number of levels of a 3DT instance. A reduction requires more sources and more terminals. It is the framework of a classical problem of combinatorial optimization called integer multicommodity flow and denoted MCF: Problem 2 (MCF). Given: (1) G(V , E) a directed finite graph of vertices V and of edges E (the edge from u to v is denoted u → v). (2) a capacity function (capacity : E → N). (3) an integer K providing the number of commodities. (4) a list of K vertices (sk )1 k K called “sources”. (5) a list of K vertices (tk )1 k K called “terminals”. (6) a list of K positive integers (f mink )1 k K providing the required flow of each commodity. Question: Does there exist a function fk : E → N of indices between 1 and K verifying (a) for any edge u → v ∈ E, K k=1 fk (u → v)capacity(u → v) (b) for any vertex v ∈ V /{sk ,tk /1 k K} and any index k ∈ {1 · · · K}, we have u→v∈E × fk (u → v) = v→w∈E fk (v → w) (c) Fk = sk →v∈E f (sk → v) f mink (we have also Fk = u→tk ∈E fk (u → tk )). MCF is a problem of flow where each commodity issued from a given source sk is directed towards the corresponding terminal tk , the final value of the flow being Fk (Fig. 4). This class of problems is proved to be NP-complete since 1976 by Even, Itai, and Shamir in a paper also proving the NP-completeness of 3DT with l = 3 and binary matrices [2,5]. The original proofs of these two results are independent, whereas we are going to show that 3DT can be reduced to MCF.
Fig. 4. An instance of MCF with three commodities and a solution represented with three grey levels on the right.
Y. Gerard / Theoretical Computer Science 346 (2005) 300 – 306
303
Fig. 5. The instance of MCF built from the 3DT instance drawn in Fig. 3.
2.2. Reduction with multiplicities From an instance of three-dimensional discrete tomography 3DT, we build an instance of MCF problem (we assume that l > 1) as follows: • Take K = l − 1 as number of commodities. • Put in V the vertices Ri corresponding to the rows (with 1 i m), the vertices Cj corresponding to the columns (with 1 j n) and 2.K other vertices denoted sk and tk with 1k K. • Put in E the mK edges going from vertices sk (with 1 k K) to the vertices Ri (with 1 i m) and choose capacity(sk → Ri ) = ri,k . • Add in E all the nK edges going from the vertices Cj (with 1 j n) to the vertices tk (with 1k K) and choose Cj → tk namely capacity(Cj → tk ) = cj,k . • Add in E the mn edges going from the vertices Ri to the vertices Cj with 1 i m, 1 j n and choose capacity(R n i → Cj ) = vi,j . r = • Take f mink = m i,k i=1 j =1 cj,k for any index k between 1 and l − 1. It provides a multicommodity instance of MCF (Fig. 5). Let us assume now that the MCF instance built from the 3DT instance has a solution (fk )1 k K . We define from this solution a multiset S of the lattice [1..m]×[1..n]×[1..l]: the multiplicity (i, j, k) of the point (i, j, k) in S is (i, j, k) = fk (Ri → Cj ) if 1 k l − 1 while (i, j, l) = vi,j − K k=1 fk (Ri → Cj ) if k = l (condition (a) guarantees that it is a positive integer). Let us prove that the multiset S is a solution of the instance of 3DT. The satisfaction of the vertical constraints lk=1 (i, j, k) = vi,j is a direct consequence of the definition of the multiplicities of thepoints (i, j, l). For any index 1k l − 1, the satisfaction m of the horizontal constraints m i=1 (i, j, k) = cj,k comes from the opposite inequalim ties k (Ri → Cj ) = fk (Cj → tk ) capacity(Cj→ tk ) = i=1 (i, j, k) = i=1 f m,n n cj,k and m,n (i, j, k) = j =1 cj,k . i=1,j =1 i=1,j =1 fk (Ri → Cj ) = Fk f mink = m l−1 m About the points in level k = l, we have i=1 (i, j, l) = i=1 (vi,j − k=1 fk (Ri → m,l−1 m l Cj )) = m i=1 vi,j − i=1 (i, j, l) = k=1 cj,k − i=1,k=1 fk (Ri → Cj ). It leads to l−1,m l l−1 n (i, j, k) = c − c = c . Symmetric arguments prove j,l k=1 j,k j =1 k=1 j,k k=1,i=1 (i, j, k) = ri,k for any pair of indices (i, k) ∈ [1..m] × [1..l].
304
Y. Gerard / Theoretical Computer Science 346 (2005) 300 – 306
Conversely, there is no difficulty to verify that a multiset solution of a 3DT instance provides a flow fk (Ri → Cj ) = (i, j, k) verifying all conditions (a)–(c) of the corresponding MCF instance. As the time of computation of the MCF instance is linear in the size of the 3DT instance, we have proved the following proposition: Proposition 3. 3DT with multisets can be polynomially reduced to MCF with l − 1 commodities. In several cases, this reduction allows to obtain multisets with binary multiplicities namely sets. It is the case if one of the matrices (ri,k ), (ci,k ) or (vi,j ) is binary. Then a corollary of Proposition 3 and of the NP-completeness of 3DT with l = 3 and binary matrices [2] is the NP-completeness of MCF with only two commodities (see [2] for the original proof). Another case where this reduction can be used is l = 2. In this framework, the feasible values vi,j are 0, 1 and 2, but when a value vi,j is 2, there is no ambiguity about the points: we can delete them temporarily by replacing the value vi,j by 0 and decrementing ri,k and cj,k . It reduces problem 3DT with l = 2 to an instance of 3DT with l = 2 and a binary matrix (vi,j ). The reduction to MCF leads to an instance of MCF problem with only one commodity. This problem can be solved in polynomial time by any max-flow algorithms and, for instance, by the augmenting path method [3]. It proves the following result: Proposition 4. 3DT with l = 2 can be solved in polynomial time. This result was already given in [2], where a direct polynomial algorithm is presented without any reference to max-flow algorithms.
3. Reduction from 3DT to MCF in the framework of sets If l > 2 and if there is no binary matrix in (ri,k ), (ci,k ) or (vi,j ), the previous reduction from 3DT to MCF provides multisets. The constraint to supply sets requires another reduction based on a more complex device. This new reduction is again built on the principle of reduction of two-dimensional-discrete tomography but it requires now more vertices and more edges (Fig. 6): • Take K = l as number of commodities. • Put in V 2.l vertices denoted sk and tk with 1 k l, lm vertices Ri,k corresponding to the rows (with 1i m and 1k l), ln vertices Cj,k corresponding to the columns (with corresponding to the vertical lines 1 j n and 1k l), and 2mn vertices Vi,j and Vi,j (with 1i m and 1 j n). • Put in E the ml edges going from vertices sk to the vertices Ri,k with capacity capacity(sk → Ri,k ) = ri,k . • Add in E the nl edges going from the vertices Cj,k to the vertices tk with capacity capacity(Cj,k → tk ) = cj,k . • Add in E the mnl edges going from the vertices Ri,k to the vertices Vi,j with capacity capacity(Ri,k → Vi,j ) = 1.
Y. Gerard / Theoretical Computer Science 346 (2005) 300 – 306
305
Fig. 6. The MCF instance built from the 3DT instance drawn in Fig. 3.
with capacity • Add in E the mn edges going from the vertices Vi,j to the vertices Vi,j )=v . capacity(Vi,j → Vi,j i,j to the vertices C • Add in E the mnl edges going from the vertices Vi,j j,k with capacity capacity(Vi,j → Ck,j ) = 1. n • Take f mink = m i=1 ri,k = j =1 cj,k for any index k between 1 and l. Each commodity corresponds to a level k of the 3DT instance and we are not very far to solve each one independently as in dimension 2 with vertices sk , Ri,k , Cj,k and tk . For any pair (i, j ), we take care of the vertical projection by concentrating the flows going from whose capacity is exactly v vertices Ri,k to vertices Cj,k through the edge Vi,j → Vi,j i,j (Fig. 6). This structure controls the numbers of points in the vertical lines. A solution of the 3DT instance is obtained from a solution of the corresponding MCF instance by taking as ) = f (V → C ). The multiplicities (i, j, k) = fk (Ri,k → Vi,j ) = fk (Vi,j → Vi,j k i,j k,j multiplicity of (i, j, k) is now guaranteed to be 0 or 1 by the capacities of edges Ri,k → Vi,j → C or Vi,j k,j equal to 1. Conversely, a solution of the 3DT instance provides a solution of the corresponding MCF instance by taking the flows fk (Ri,k → Vi,j ) = fk (Vi,j → ) = f (V → C ) = (i, j, k). This sketch of proof leads to the following result: Vi,j k i,j k,j
Proposition 5. 3DT with sets can be polynomially reduced to MCF with K = l commodities.
306
Y. Gerard / Theoretical Computer Science 346 (2005) 300 – 306
4. Conclusion The second reduction from 3DT to MCF is more complicated than the first method but it yields only sets, whereas the first coding provides multisets. In the cases where they both provide sets namely if one of the matrices of the instance of 3DT is binary or if l = 2, the first reduction should be chosen rather than the other one because it requires one commodity less without speaking about the numbers of edges and vertices which are significantly smaller. This reduction is more efficient. These two encodings translate three-dimensional discrete tomography instances in MCF problems which can be solved by any method of this field. References [1] R.K. Ahuja, T.L. Magnanti, J.B. Orlin, Network Flows: Theory, Algorithms, and Applications, Prentice-Hall, Englewood Cliffs, NJ, 1993. [2] S. Even, A. Itai, A. Shamir, On the complexity of timetable and multicommodity flow problems, SIAM J. Comput. 5 (1976) 691–703. [3] L.R. Ford, D.R. Fulkerson, Flows in Networks, Princeton University Press, Princeton, NJ, 1962. [4] D. Gale, A theorem on flows in networks, Pacific J. Math. 7 (1957) 1073–1082. [5] M.R. Garey, D.S. Johnson, Computer and Intractability: A Guide to the Theory of NP-Completeness, W.H. Freeman, New York, 1979. [6] G.T. Herman, A. Kuba, Discrete Tomography: Foundations, Algorithms and Applications, Birkhaüser, Basel, 1999. [8] H.J. Ryser, Combinatorial properties of matrices of zeros and ones, Canad. J. Math. 9 (1957) 371–377.
Theoretical Computer Science 346 (2005) 307 – 334 www.elsevier.com/locate/tcs
Enumeration of symmetry classes of convex polyominoes on the honeycomb lattice夡 Dominique Gouyou-Beauchampsa , Pierre Lerouxb,∗ a LRI, CNRS—Université Paris-Sud 11, France b LaCIM, UQAM, Dept. de Mathematiques, C.P. 8888 Succursale Centre-Ville, Montreal (QC),
Canada H3C 3P8
Abstract We enumerate the symmetry classes of convex polyominoes on the hexagonal (honeycomb) lattice. Here convexity is to be understood as convexity along the three main column directions. We deduce the generating series of free (i.e. up to reflection and rotation) and of asymmetric convex hexagonal polyominoes, according to area and half-perimeter. We give explicit formulas or implicit functional equations for the generating series, which are convenient for computer algebra. Thus, computations can be carried out up to area 70. © 2005 Elsevier B.V. All rights reserved.
1. Introduction A hexagonal polyomino is a finite connected set of basic cells of the honeycomb lattice in the plane. Note that the hexagons of our lattice have two sides parallel to the horizontal axis. See Fig. 1. Unless otherwise stated, all the polyominoes considered here are hexagonal. The area of a polyomino is the number of cells composing it. Its perimeter is the number of line segments on its boundary. We say that a polyomino is convex along a direction if the intersection with any line parallel to this direction and passing through the center of a cell 夡 With the partial support of CNRS (France), NSERC (Canada) and FCAR (Québec). This is the full version of a paper presented at the FPSAC Conference in Vancouver, Canada, June 28–July 2, 2004 (see [3]).
∗ Corresponding author. Tel.: 514 987 3000 3236; fax: 514 987 8274.
E-mail address:
[email protected] (P. Leroux). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.025
308
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
Fig. 1. A convex polyomino and its convexity directions.
is connected. The convexity directions are characterized by the angle (0 ) which they form with the positive horizontal axis. Various convexity concepts have been introduced in the literature for hexagonal polyominoes, depending on the required convexity directions. Following the nomenclature of Denise et al., [2], we mention the EG-convex polyominoes, where = 0 and /2, studied by Guttmann and Enting [5] and by Lin and Chang [10], the C 1 -convex polyominoes, where = /2, enumerated according to many parameters by Lin and Wu [11] and by Fereti´c and Svrtan [4], the strongly convex polyominoes, where = 0, /3 and 2/3, introduced by Hassani [7] and studied in [7,2], and finally the C- or C 3 -convex polyominoes, where = /6, /2 and 5/6, introduced and enumerated according to perimeter in [7,2]. In particular, Hassani gives explicitly the algebraic generating function for C-convex polyominoes according to half perimeter. It is this last class that interests us here, and that we call simply convex polyminoes. See Fig. 1 for an example. This concept is a natural extension of (row and column) convexity on the square lattice. These polyominoes are traditionally taken up to translation. However it is natural to consider them also up to rotation and reflection, as objects living freely in space. Following Vöge et al. [6], we call these equivalence classes free polyominoes. In organic chemistry, free polyminoes (without holes) represent benzenoid hydrocarbons. See [6] where these molecules (without the convexity property) are enumerated by an exhaustive generation approach. Our objective is to enumerate free convex polyominoes, according to area and half perimeter. Following the approach of Leroux et al. [9] for the square lattice, we consider them as orbits of the dihedral group D6 (the group of isometries of the regular hexagon), acting on convex polyominoes. The Cauchy–Frobenius Formula (alias Burnside’s Lemma) can be used to count the orbits and we are thus lead to enumerate the symmetry classes Fix(h) of convex polyominoes, for each element h of the group D6 . It is also possible to enumerate convex polyominoes which are asymmetric or which have exactly the symmetries of a given subgroup H of D6 , using Möbius inversion in the lattice
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
309
of subgroups of D6 . For this purpose, we also enumerate the symmetry classes F H for each subgroup H of D6 . For any class F of convex polyominoes, we denote its generating series by F(x, q, u, v, t), where the variable x marks the number of columns, q marks the area, u marks the size of the first column (on the left), v the size of the last column, and t the half perimeter; for example, the polyomino of Fig. 1 has weight x 14 q 64 u2 v 3 t 35 . It is possible that some variables do not appear in some generating series. The generating series will be given by explicit formulas or implicit functional equations, which are convenient for computer algebra. Thus, computations can be carried out up to area 70. The rest of the paper is organized as follows. In the next section, we present some preliminary results. This includes the enumeration of familiar classes of convex polyominoes on the square lattice which are also found on the honeycomb lattice, such as partition and staircase polyominoes and a special class of stack polyominoes. Also, the dihedral group D6 is presented here, together with its lattice of subgroups and the associated Möbius function. Finally, the growth phases, from left to right, of the upper and lower boundaries of convex polyominoes are examined and enumerated. In Section 3, we enumerate the complete class of convex polyominoes according to area and half-perimeter, following essentially the method of Hassani [7], and also a special class of directed convex polyominoes which is needed afterwards. The reflexive symmetry classes, the rotational symmetry classes, and the two-generator symmetry classes are treated successively in the following sections. All these results are put together in a concluding section, where some tables are given. 2. Preliminaries 2.1. Particular classes of convex polyominoes Some familiar classes of convex polyominoes of the square lattice are naturally found on the honeycomb lattice and are useful. It is the case notably of partition and staircase (or parallelogram) polyominoes and of a variant of stack polyominoes. 2.1.1. Partition polyominoes Fig. 2a represents the partition (4, 2, 2) contained in (a shape equivalent to) a rectangle of size 5 × 4 in the honeycomb lattice. It is well known that the area-generating for function partitions that fit in a k × n rectangle is given by the q-binomial coefficient k+n . k q
Fig. 2b represents the distinct part partition (5, 4, 2, 1), with parts bounded by 6. We denote by Dm (u, q) the generating polynomial of distinct part partitions with parts bounded by m. Here the variable u marks the number of parts. We have Dm (u, q) = (1 + uq)(1 + uq 2 ) · · · (1 + uq m ) and D0 (u, q) = 1.
(1)
2.1.2. Staircase polyominoes Fig. 3 represents a staircase polyomino from the square lattice (see for example [1] or [8]) redrawn on the honeycomb lattice. Observe that the half perimeter is equal to 2p −1 where p is the half perimeter on the square lattice. It is known that these polyominoes are enumerated
310
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
(a)
(b) Fig. 2. Partition polyominoes.
Fig. 3. A staircase polyomino.
according to half perimeter by the Catalan numbers and according to area by the sequence M1175 of [14] (A006958 of [13]) whose generating series is a quotient of two q-Bessel functions. We review this latter result here. Let Pa denote the set of staircase polyominoes (Pa for Parallelogram) on the honeycomb lattice and Pa(x, q, u, v, t), their generating series. An analysis of the situation where a column is added on the right, following the method of Bousquet–Melou (compare with [1, Lemma 3.1]), gives, for Pa(v) = Pa(x, q, u, v, t), the functional equation Pa(v) =
xquvt 3 xqvt 2 + (Pa(1) − Pa(vq)) . 1 − quvt 2 (1 − qvt 2 )(1 − qv)
(2)
Indeed, the first term of (2) corresponds to polyominoes with a single column. If a staircase polyomino P has more than one column, then, as shown in Fig. 4, the last (right) column can be obtained by adding first a single cell to the northeast of the previous column and then by xqvt 2 completing arbitrarily on top and bottom of this cell. This gives the term (1−qvt 2 )(1−qv) Pa(1). However, the bottom part is not aloud to exceed the previous column and a correction term, xqvt 2 counting the cases where an excess does occur, namely (1−qvt 2 )(1−qv) Pa(vq), must be subtracted.
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
311
−
=
3 Fig. 4. Pa(v) = xquvt 2 +
1−quvt
xqvt 2 (Pa(1) − Pa(vq)). (1−qvt 2 )(1−qv)
It follows (see [1]) that Pa(v) =
J1 (1) + J1 (v)J0 (1) − J1 (1)J0 (v) , J0 (1)
(3)
where J1 (v) =
(−1)n
n+2 x n+1 v n+1 ut 2n+3 q ( 2 ) (qvt 2 ; q)n (qv; q)n (1 − q n+1 uvt 2 )
(−1)n
n+1 x n v n t 2n q ( 2 ) . (qvt 2 ; q)n (qv; q)n
n0
and J0 (v) =
n0
Here we have used the familiar notation (a; q)n = (1 − a)(1 − aq) · · · (1 − aq n−1 ). We set Pa(x, q, u, v, t) = Pai,j (x, q, t)ui v j . (4) i 1j 1
2.1.3. Stack polyominoes There exists a specific variant of stack polyominoes on the honeycomb lattice. They consist of pyramidal stackings of hexagons, viewed sideways for our purposes. A first class (see Fig. 5a), denoted by T (for French tas), appears in the literature under the name of pyramidal stacking of circles; see [12]. Their generating series according to area is referenced as number M0687 in [14] and A001524 in [13]. Let T (x, u, q) be the generating series of stack polyominoes according to the number of columns (the width, marked by x), the size of the first column (the height, marked by u) and the area, and let Tn (x, q) = [un ]T (x, u, q) be the generating series of stacks whose first
312
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
(a)
(b)
(c)
(d)
Fig. 5. Stacks and symmetric stacks.
column is of size n. Note that the half perimeter is equal to twice the height plus the width so that the series T (xt, ut 2 , q) also keeps track of this parameter. It can be readily seen that
T (x, u, q) =
m1
m+1 x m q ( 2 ) um , (uq; q)m−1 (uq; q)m
(5)
where m denotes the number of columns, and also that Tn (x, q) =
n
m n+(m 2)
x q
m=1
n−m j =0
m+j −1 n−j −2 m−1 q m−2 q
.
(6)
The polynomials Tn (x, q) can be rapidly computed using the class T0n of stack polyominoes whose first column is of size n, including possibly empty cells (not contributing to the area) at the two extremities. See Fig. 5b. Indeed, we have Tn (x, q) = xq n T0n−1 (x, q).
(7)
with T00 (x, q) = 1, T01 (x, q) = 1 + xq, and, arguing on the existence of empty cells at each extremity, T0n (x, q) = (2 + xq n )T0n−1 − T0n−2 .
(8)
Notice that the T0n are q-analogues of a variant of Tchebichev polynomials. 2.1.4. Symmetric stacks Horizontally symmetric stacks (see Figs. 5c and d), constitute the families TS and TS0. Using the same notation as for stacks, we have TS(x, u, q) =
m1
x m um q m(m+1)/2 (1 + uq m ) . (1 − u2 q 2 )(1 − u2 q 4 ) · · · (1 − u2 q 2m )
(9)
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
ds1
da2 = v
313
ds2 da3
da1
ds3 = h
Fig. 6. The reflections of D6 .
Moreover, TSn (x, q) = xq n TS0n−1 (x, q).
(10)
where TS00 (x, q) = TS0−1 (x, q) = 1, and TS0n (x, q) = xq n TS0n−1 (x, q) + TS0n−2 (x, q).
(11)
2.2. The dihedral group D6 The dihedral group D6 is defined algebraically by D6 = , | 6 = 1, 2 = 1, = −1 . Here D6 is realized as the group of isometries of a regular hexagon, with = r = the (clockwise) rotation of /3 radian and = ds3 = h, the horizontal reflection. We have D6 = {id, r, r 2 , r 3 , r 4 , r 5 , da1 , da2 , da3 , ds1 , ds2 , ds3 }, where ds2 = r 2 , ds1 = r 4 , reflections according to vertex–vertex axes, and da3 = r, da2 = r 3 , and da1 = r 5 , reflections according to the edge–edge axes. See Fig. 6. The dihedral group D6 acts naturally on (hexagonal) polyominoes, by rotation or reflection. For any class F of polyominoes, with a monomial weigh w corresponding to certain parameters, we denote by |F|w the total weight (i.e. the generating series) of this class. If F is invariant under the action of D6 , then the set of orbits of this action is denoted by F/D6 . Burnside’s Lemma enumerates these orbits in terms of the sets Fix(g) of fixed points of each of the elements g of D6 , the symmetry classes of F. We write fix(g) = |Fix(g)|w . Clearly we have fix(r) = fix(r 5 ), fix(r 2 ) = fix(r 4 ) and, for symmetry reasons, fix(da1 ) = fix(da2 ) = fix(da3 ) and fix(ds1 ) = fix(ds2 ) = fix(ds3 ). In the following, we will choose v = da2 , the vertical axis, and h = ds3 , the horizontal axis. By Burnside’s Lemma, we have 1 fix(g) |F/D6 |w = 12 g∈D6 1 |F|w + 2 fix(r) + 2 fix(r 2 ) + fix(r 3 ) + 3 fix(v) + 3 fix(h) . (12) = 12
314
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
2.2.1. The lattice of subgroups of D6 It is also possible to enumerate the convex polyominoes which are asymmetric or which have exactly the symmetries of a given subgroup H of D6 , with the help of Möbius inversion in the lattice of subgroups of D6 . This lattice and its Möbius function are well described in Stockmeyer’s Ph.D. Thesis [15], for any dihedral group Dn . We follow his nomenclature. Apart from the trivial subgroups 0 = {id} and 1 = D6 = r, h, we have the cyclic subgroups C6 = r = {1, r, r 2 , r 3 , r 4 , r 5 }, C3 = r 2 = {1, r 2 , r 4 } and C2 = r 3 = {1, r 3 }, F1,1 = ds2 = {1, ds2 }, F1,2 = ds1 = {1, ds1 }, and F1,3 = h = {1, h}, H1,1 = da3 = {1, da3 }, H1,2 = v = {1, v} and H1,3 = da1 = {1, da1 }, as well as the two generator subgroups F3,1 = r 2 , ds2 = {1, r 2 , r 4 , ds1 , ds2 , h} = r 2 , h, H3,1 = r 2 , da3 = {1, r 2 , r 4 , da1 , v, da3 } = r 2 , v, and the D2,j = r 3 , r 2j , j = 1, 2, 3, that is D2,1 = r 3 , ds2 = {1, r 3 , ds2 , da1 }, D2,2 = r 3 , ds1 = {1, r 3 , ds1 , da3 }, and D2,3 = r 3 , h = {1, r 3 , h, v} = r 3 , h. The lattice of subgroups of D6 is represented in Fig. 7. For any subgroup H of D6 (H D6 ), we set F H = |{s ∈ F | stab(s)H }|w = |{s ∈ F | h ∈ H ⇒ h · s = s}|w
(13)
F=H = |{s ∈ F | stab(s) = H }|w = |{s ∈ F | h ∈ H ⇔ h · s = s}|w
(14)
and
We have clearly, for any H D6 FH = F=K H K D6
and, by Möbius inversion, F=H = (H, K)F K . H K D6
In particular, the total weight of asymmetric polyominoes is given by F=0 = (0, K)F K .
(15)
K D6
Note that F 0 = |F|w and that for any cyclic subgroup H = h, F H = fix(h). For reasons of symmetry (or by conjugation), we have F D2,1 = F D2,2 = F D2,3 .
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
315
Fig. 7. The lattice of subgroups of D6 ((0, H ) in parenthesis).
In the following, we will take D2,3 = r 3 , h. Formula (15) then yields F=0 = |F|w − 3 fix(h) − 3 fix(v) − fix(r 2 ) − fix(r 3 ) + fix(r) +6F D2,3 + 3F F3,1 + 3F H3,1 − 6F D6 .
(16)
For any subgroup H of D6 , we sometimes write |Fix(H )|q,t = F H when the weight is given by the area and the half perimeter. 2.3. Growth phases of convex polyominoes Any convex polyomino can be decomposed into blocks according to the growth phases, from left to right, of its upper and lower profiles. Fig. 8 gives an example of this decomposition. The upper profile is represented by the path from A to B along the upper boundary, and the lower profile, by the path from C to D. On the upper profile, we speak of a weak increase if the level rises by a half hexagon only with respect to the preceding column, and of a strong increase if the level rises by more than a half hexagon. We define analogously a weak or strong decrease. On the lower profile, an increase corresponds to a descent and a decrease, to a rise. The state in which a column lies is described by an ordered pair (i, j ), i, j = 0, 1, 2; the first component corresponds to the upper profile and the second, to the lower profile. The state 0 corresponds to a (weak or strong) increase, at the start of the polyomino, the state 1 to a weak increase or decrease, in an oscillation phase, and the state 2, to a strong or weak
316
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
Fig. 8. Growth phases of a convex polyomino.
decrease, in the last part of the polyomino. To pass from the state 0 to the state 1, there must be a first weak decrease, and to pass from the state 0 or 1 to the state 2, there must be a strong decrease. Finally, the transitions from the state 1 to the state 0 and from the state 2 to the state 1 or 0 are impossible. Now, a block Hij is characterized by a maximal sequence of consecutive columns which are in the state (i, j ). We can then view a convex polyomino as an assemblage of blocks and we will first enumerate these blocks Hij . In what follows, we give the various generating series of the form Hij (x, q, u, v, t). 2.3.1. The families H00 and H22 The two classes of polyominoes H00 and H22 are equivalent since one can be obtained from the other by a vertical reflection. They are easy to enumerate since H22 -polyominoes are in fact stack polyominoes (see Fig. 5a). Here, only one of the two variables u and v is used at a time. We have H22 (x, q, u, t) = T (xt, ut 2 , q) and H00 (x, q, v, t) = T (xt, vt 2 , q),
(17)
where T (x, u, q) is given by (5). 2.3.2. The families H01 , H10 , H12 , and H21 The classes H01 , H10 , H12 , and H21 of polyominoes are in bijection with each other by horizontal and vertical reflections and are thus equinumerous. Fig. 9 shows a polyomino in H10 . An analysis of the situation where a column is added on the right to an H10 -polyomino leads to the functional equation H10 (x, q, u, v, t) =
xquvt 3 xt 2 (1 + qvt) + H10 (x, q, u, vq, t). 2 1 − quvt 1 − qvt 2
(18)
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
317
i
m
h
j
Fig. 9. Polyomino of H10 .
Solving by iteration, we find x m q m uvt 2m+1 (−qvt; q)m−1 . H10 (x, q, u, v, t) = (1 − q m uvt 2 )(qvt 2 ; q)m−1
(19)
m1
Formula (19) can be seen directly on Fig. 9. Indeed, with m columns an H10 -polyomino x m q m uvt 2m+1 consists of a central rectangle of size m × h, h 1 the factor (1−q m uvt 2 ) , with a distinct part partition on top and a general partition underneath, with parts at most m − 1 (the factors (−qvt; q)m−1 and 1/(qvt 2 ; q)m−1 , respectively. We also see that H10 (x, q, u, v, t) =
uh v h
h1
×
j 0
m1
x m q mh
m−1 i=0
i+1 vi q ( 2 )
m−2+j v j q j t 2m+2h+i+2j −1 j q
m−1 i q
.
(20)
Finally H01 (x, q, u, v, t) = H10 (x, q, u, v, t) and H12 (x, q, u, v, t) = H21 (x, q, u, v, t) = H10 (x, q, v, u, t).
2.3.3. The families H02 and H20 The class H02 coincides with staircase polyominoes (see Fig. 3) and the two classes H02 and H20 are equivalent to each other, via an horizontal reflection: H02 (x, q, u, v, t) = Pa(x, q, u, v, t) = H20 (x, q, u, v, t).
(21)
2.3.4. The family H11 The class H11 contains the convex polyominoes whose upper and lower profiles are both oscillating. When we examine the diagonal row of hexagons in the da3 axis (see Fig. 6)
318
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
i
j n
(a)
(b) Fig. 10. Polyominoes of H11 .
containing the first column’s lower cell, two subclasses of H11 appear. In the first class, denoted by H11a , this diagonal row and those to its right (up to the last column) form a staircase polyomino (rotated clockwise by a /3 angle); see Fig. 10a. In the second class, denoted by H11b , this diagonal is the basis of a rectangle of height at least 2; see Fig. 10b. In both cases, we find, above and below these objects (staircase or rectangle), distinct part partitions which are left and right justified, respectively. Recall that in the series Pai,j (x, q, t), defined by (4), the variable x marks the number of columns of the (unrotated) staircase polyomino. We rather use the link between its width , when rotated, and its half-perimeter p: p = 2 + 1. Hence we have H11 (x, q, u, v, t) = H11a (x, q, u, v, t) + H11b (x, q, u, v, t) with H11a (x, q, u, v, t) =
1
(22)
1
x − 2 uv Pai,j (1, q, tx 2 )Di−1 (ut, q)Dj −1 (vt, q) (23)
i 1j 1
and H11b (x, q, u, v, t) =
x n q 2n u2 v 2 t 2n+3 Dn−1 (ut, q)Dn−1 (vt, q) . 1 − q n uvt 2
(24)
n1
3. Convex and directed convex polyominoes 3.1. Convex polyominoes We denote by C, the class of all convex polyominoes and by Cij , the subclass of polyominoes whose last column is in the state (i, j ), i, j = 0, 1, 2. This determines a partition of C. To enumerate C, we must enumerate each of the classes Cij . We give the generating series Cij (x, q, v, t), using the growth phase decomposition of a convex polyomino, following essentially the method of Hassani [7]. We use the notation Cij ⊗ Hi j for the set of convex polyominoes obtained by gluing together in all possible legal ways a polyomino of Cij with one of Hi j . We introduce the
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
319
series Cij,n (x, q, t) and Hij,n (x, q, v, t) by the coefficient extractions Cij,n (x, q, t) = [v n ]Cij (x, q, v, t) and Hij,n (x, q, v, t) = [un ]Hij (x, q, u, v, t).
(25)
For example, we have C00 = H00 , C10 = C00 ⊗ H10 and n 1 C10 (x, q, v, t) = C00,k (x, q, t) H10,n (x, q, v, t) t 2k−1 n 1 k=1 n = tTk (xt, q) H10,n (x, q, v, t) n1
k=1
= C01 (x, q, v, t).
(26)
Likewise, C11 = (C00 + C10 + C01 ) ⊗ H11 = C00 ⊗ H11 + C10 ⊗ H11 + C01 ⊗ H11 and C00 ⊗ H11 (x, q, v, t) =
n2
C10 ⊗ H11 (x, q, v, t) =
1 C00,n (x, q, t)H11,n−1 (x, q, v, t), t 2n−2
(27)
1 C10,n (x, q, t)H11,n (x, q, v, t) t 2n−1 n1 1 + C10,n (x, q, t)H11,n−1 (x, q, v, t). t 2n−2
(28)
n2
We have also C02 = (C00 + C01 ) ⊗ H02 , C12 = (C00 + C01 + C10 + C11 + C02 ) ⊗ H12 , C22 = (C00 + C01 + C10 + C11 + C02 + C02 ) ⊗ H22 . Finally, C(x, q, v, t) = (C00 + 2C10 + C11 + 2C02 + 2C12 + C22 )(x, q, v, t).
(29)
Using these equations, the area generating function A(q) = C(1, q, 1, 1) of convex polyominoes on the honeycomb lattice can be computed easily up to area 70: A(q) = 93521821034090198077138307 q 70 + 40500739671610157834435402 q 69 +17539328210367276357231264 q 68 + 7595615205191062899011838 q 67 +3289371728119140331192848 q 66 + 1424501646472485669061275 q 65 +616897422526383132078929 q 64 + 267154784175652277208577 q 63 +115694564610291544986219 q 62 + 50102910647125753823048 q 61 +21697662840186809215730 q 60 + 9396431597658317037336 q 59 +4069236738707717909198 q 58 + 1762231488064295148820 q 57 +763155357452132873277 q 56 + 330493526907262008000 q 55 +143124162458250124557 q 54 + 61981625120377313718 q 53
320
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
+26841881829357335687 q 52 + 11624197004721262104 q 51 +5033997137232724122 q 50 + 2180032500563641911 q 49 +944089080678393018 q 48 + 408849042325490952 q 47 +177056959135248647 q 46 + 76676631829002129 q 45 +33205732845460311 q 44 + 14380140755028117 q 43 +6227492958077133 q 42 +2696891148564180 q 41 + 1167921607616731 q 40 +505782887350567 q 39 +219035659925172 q 38 + 94856243572216 q 37 + 41078790416848 q 36 +17789770663899 q 35 + 7704147029616 q 34 + 3336422923431 q 33 +1444911247194 q 32 + 625758286777 q 31 + 271006745255 q 30 +117372288297 q 29 + 50835685427 q 28 + 22018993552 q 27 +9538127076 q 26 +4132195707 q 25 + 1790486717 q 24 + 775996665 q 23 + 336418179 q 22 +145903992 q 21 + 63308532 q 20 + 27485271 q 19 + 11939804 q 18 +5189577 q 17 +2256420 q 16 + 980961 q 15 + 426036 q 14 + 184588 q 13 + 79602 q 12 +34056 q 11 +14394 q 10 + 5973 q 9 + 2412 q 8 + 939 q 7 + 348 q 6 + 120 q 5 + 38 q 4 +11 q 3 +3 q 2 + q.
If only the half-perimeter is taken into account, then the preceding equations can be explicitly solved: Theorem 3.1 (Hassani, [7]). The generating function of convex hexagonal polyominoes according to perimeter is algebraic. It is explicitly given by C(1, 1, 1, t) =
√ t 3 ( − 3t 4 (1 + t)2 (1 − 2t)2 1 − 4t 2 ) , 2((1 − 2t)(1 + t))4
where = 2 − 8t + 2t 2 + 20t 3 + t 4 − 34t 5 − 19t 6 + 28t 7 + 32t 8 − 12t 9 − 6t 10 .
Here are the first terms of this series: t 3 + 3t 5 + 2t 6 + 12t 7 + 18t 8 + 59t 9 + 120t 10 + 318t 11 + 714t 12 +1743t 13 + · · · .
(30)
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
321
H2
H1 H0
Fig. 11. Directed convex polyomino.
Corollary 3.2 (Hassani [7]). The asymptotic number of convex hexagonal polyominoes according to perimeter is equal to 1 2 n n3 . 27 × 210
3.2. Directed convex polyominoes There is a special class of convex polyominoes which will be particularly useful below, namely those which are directed according to the North direction with a diagonal basis. See Fig. 11. We call them simply directed convex, and denote this class by D. Analogously to convex polyominoes, any polyomino in D can be decomposed into blocks Hi according to the growth phases i = 0, 1, or 2, of its upper profile. Their generating series can be computed directly by observation. Since the half perimeter can be deduced from the other parameters, the variable t does not appear here. For example, a polyomino in H0 is identified with a partition and we find H0 (x, q, v) =
v l x k q l+k−1
l 1 k 1
l+k−2 l−1 q
.
(31)
A polyomino in H1 can be decomposed into pieces as shown in Fig. 12a, yielding H1 (x, q, u, v) =
l 1
vl
m0
ul+m
k m+1
x k q kl+
(m)(m+1) 2
k−1 m
q
.
(32)
322
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
m m
l
l k k
(a)
(b)
Fig. 12. Directed convex polyominos in H1 and in H2 .
Likewise, for H2 , we find (see Fig. 12b) H2 (x, q, u, v) ⎛ ⎞ k(k+2l−1) ⎠. = v l ⎝xq l ul + xk ul+k+m−1 q 2 +m m+k−2 k−2 l 1
k 2
m0
q
(33)
We denote by Di , the class of directed convex polyominoes whose last column is in the state i, i = 0, 1, 2, and we introduce the notation Di,n (x, q, t) = [v n ]Di (x, q, v, t) and Hi,n (x, q, v) = [un ]Hi (x, q, u, v).
(34)
We have D0 (x, q, v, t) =
1 H0 (xt 2 , q, vt 2 ), t
(35)
1 D0,m+1 (x, q, t)H1,m (xt 2 , q, vt), tm
(36)
D1 = D0 ⊗ H1 and D1 (x, q, v, t) =
m1
and finally, D2 = (D0 + D1 ) ⊗ H2 and D2 (x, q, v, t) 1 = (D0,m+h (x, q, t) + D1,m+h (x, q, t))H2,m (xt 2 , q, vt). tm m1 h2
(37)
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
323
K
v Fig. 13. v-symmetric convex polyomino.
4. Reflexive symmetry classes 4.1. Vertical symmetry Consider a vertically symmetric (v-symmetric) convex polyomino P. We see that the symmetry axis goes through a central column. Denote by K the left fundamental region of P, including the central column. See Fig. 13. Then K is a convex polyomino which can only belong to the classes C00 , C10 , C01 , or C11 and we have K(x, q, v, t) = C00 (x, q, v, t) + 2C10 (x, q, v, t) + C11 (x, q, v, t) = Km (x, q, t)v m
(38)
m1
and |Fix(v)|q,t =
m1
1 q m t 2m+1
Km (1, q 2 , t 2 ).
(39)
4.2. Horizontal symmetry The class S of h-symmetric convex polyominoes is partitioned into three classes: Sa and Sb , whether or not we can find an arrowhead polyomino in the oscillating part (see Figs. 14a and b) and the class Sc , if there does not exist an oscillating part. In order to construct a polyomino of the class arrrowhead, denoted by A, we start with a triangle of side n, to which a symmetric stack is possibly attached to form the H22 phase; denote by B, this starting class of polyominoes. From B, we construct A by successively attaching V-shaped bands on the left, as illustrated in Fig. 14a. Let the variable s mark the size of the last attached V’s upper left part. We have B(s, x, q, t) = sxqt 3 + s n x n q n(n+1)/2 t 3n T SOn−3 (xt, q) (40) n2
324
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
h n h m n
B
A
k
(a)
(b) Fig. 14. h-symmetric convex polyominoes.
and the generating series A(s) = A(s, x, q, t) is characterized by the following functional equation, which can be solved by the usual method: s2x2q 3t 4 A(1) − A(sq 2 ). (41) 1 − sq 2 We set A(s, x, q, t) = m 1 Am (x, t, q)s m . To complete the polyomino, we must take into account the parity of the first oscillating column. The first case, illustrated in Fig. 14a, is when this column is of odd size. In the second case, this even column is placed in front of the arrrowhead. In conclusion, we obtain m−1 q h(h+1) t 2h+2 TS2h+2 (xt, q) Am (x, t, q) Sa (x, t, q) = h 2 A(s) = B(s) +
h0
+
q
m h+1
q h(h+1) t 2h+3 TS2h+1 (xt, q)
m
mh
h1
h q2
Am (x, t, q).
(42)
The computations for Sb (x, t, q) and Sc (x, t, q) are simpler. For Sb , there are also two parity cases and we find directly n+1 x n q ( 2 ) t 3n q 2kn t 4k TS0n+2k−3 (xt, q) Sb (x, t, q) = n1
×
n−1
k 1
t 2h+2 q h(h+1)
h=0
+ ×
xnq (
n0 n
n+1 2
) t 3n
t 2h+2 q h(h+1)
h=0
n−1 h q2
TS2k+2h+2 (x, t, q)
q 2k(n+1) t 4k+1 TS0n+2k−3 (xt, q)
k 1
n
h q2
TS2k+2h+1 (x, t, q)
(43)
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
325
and
Sc (x, t, q) =
t 2h TSh (xt, q)TS0h−3 (xt, q).
(44)
h1
Finally, |Fix(h)|q,t = Sa (1, t, q) + Sb (1, t, q) + Sc (1, t, q).
(45)
5. Rotational symmetry classes 5.1. Symmetry with respect to the /3 radian rotation r The polyominoes which are symmetric with respect to the /3 rotation (r-symmetric) are essentially formed of large hexagons decorated by stack polyominoes of the class T0. See Fig. 15. We find |Fix(r)|q,t =
t 3(2h−1) q 3h(h−1)+1 T0h−1 (t 6 , q 6 ),
(46)
h1
the series T0n (x, q) being defined by (8). 5.2. Symmetry with respect to the 2/3 radian rotation r 2 The situation is more complex here. First we must distinguish the case where the rotation center is in the middle of an hexagon from the one where it is on a vertex. This determines two subclasses, denoted by P and Q. 5.2.1. The rotation center is in the middle of an hexagon When the rotation center is in the middle of an hexagon, we consider the fundamental region formed by the upper third of the r 2 -symmetric polyomino. The parameters h1 and h2 are defined as the extent of the fundamental region in the directions da2 = v and da1 (or da3 ), respectively. There are three subcases according to whether h1 > h2 , h2 > h1 or h1 = h2 , giving three subclasses denoted by P1 , P2 and P3 . Fig. 16 illustrates the first subcase P1 . In this figure, there is a basis formed of (one third of) a super-hexagon of radius h = h2 , on top of which are placed a directed convex polyomino D (see Section 3.2) and the image D ∗ under v of another directed convex polyomino, these two polyominoes sharing a common column. Let be the size of this common column, so that h1 = h + . We must consider all such legal combinations D ⊗ D∗ and take into account the added area and half perimeter over that of the super-hexagon. For i = 0, 1, 2, we set Di,r,n (q, t) =
1 1 [x r ]Di,n (x, q, t) = 2r+n−1 [x r ][v n ]Di (x, q, v, t) t 2r+n−1 t
326
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
Fig. 15. An r-symmetric convex polyomino.
D
D* s
r h1
h2
h2
Fig. 16. Fundamental region of an r 2 -symmetric convex polyomino in P1 .
and Dr,n (q, t) = (D0,r,n + D1,r,n + D2,r,n )(q, t). We then have P1 (q, t) = t 3(2h−1) q 3h(h−1)+1 h1
×
h h 1 D0,r,l (q 3 , t 3 )D0,s,l (q 3 , t 3 ) q 3l
l 1 r=1 s=1
+2D0,r,l (q 3 , t 3 )D1,s,l (q 3 , t 3 ) + 2D0,r,l (q 3 , t 3 )D2,s,l (q 3 , t 3 ) +D1,r,l (q 3 , t 3 )D1,s,l (q 3 , t 3 ) .
(47)
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
C
B
C
327
Bh D
A
A
r
A∩B
D C∩D r h
h h
h
h
h
(a)
(b) Fig. 17. Fundamental regions of r 2 -symmetric convex polyominoes in P3 .
For reasons of symmetry (a /3 rotation), we see that P2 (q, t) = P1 (q, t). Let us now consider the class P3 of r 2 -symmetric convex polyominoes with h1 = h2 = h. In this case, the added decorations on the super-hexagon can only occupy one of the sectors A, B, C or D shown in Fig. 17, with the exception of the sectors A ∩ B and C ∩ D which can be simultaneously occupied. Denote by Bh the class of admissible decorations in the sector B over an hexagon of side h, and by Bh (q, t) its generating series, where the variables q and t mark the added area and half perimeter, respectively. We have Bh (q, t) =
h−1
⎛
⎝(h − r) q r t + D1,r,1 (q, t) + D2,r,1 (q, t) +
⎞ t j −1 Dr,j (q, t)⎠ . (48)
j 2
r=1
The generating series will be the same for the decorations located in the sectors A, C or D, for symmetry reasons. However, in the term 4Bh (q, t), the decorations which, like the one shown in Fig. 17b, are located in the intersection sectors A ∩ B or C ∩ D, are counted twice. Observe that these decorations are in fact stack polyominoes of the class T0 with generating series T0h−1 (t, q) − 1, whence the correcting term −2(T0h−1 (t, q) − 1). Lastly, the term (T0h−1 (t, q) − 1)2 counts the simultaneous decorations in the sectors A ∩ B and C ∩ D and the term 1 is added for the empty decoration. Globally, we obtain P3 (q, t) = t 3(2h−1) q 3h(h−1)+1 h1
2 × 4Bh (q 3 , t 3 ) − 4T Oh−1 (t 3 , q 3 ) + T Oh−1 (t 3 , q 3 ) + 4 .
(49)
5.2.2. The rotation center is on a vertex The class of r 2 -symmetric convex polyominoes whose rotation center is on a vertex is denoted by Q. There are three cases: h1 > h2 , h2 > h1 and h1 = h2 to which correspond three series Q1 (q, t), Q2 (q, t) and Q3 (q, t) and two types of central vertices as in
328
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
h1 h2
Fig. 18. r 2 -symmetric convex polyominoes in Q1 .
Fig. 18. The computations are similar to the preceding case. The decorations are placed over a pseudo-hexagon and we find Q1 (q, t) = 2
2
t 6h q 3h
h1
h+1 h 1 (D0,r,l (q 3 , t 3 )D0,s,l (q 3 , t 3 ) q 3l
l 1 r=1 s=1 +D0,r,l (q , t )D1,s,l (q 3 , t 3 ) +D0,r,l (q 3 , t 3 )D2,s,l (q 3 , t 3 ) + D1,r,l (q 3 , t 3 )D1,s,l (q 3 , t 3 ) +D1,r,l (q 3 , t 3 )D0,s,l (q 3 , t 3 ) + D2,r,l (q 3 , t 3 )D0,s,l (q 3 , t 3 )) 3
3
= Q2 (q, t) and Q3 (q, t) = 2
(50) 2
t 6h q 3h
4 + 2Bh (q 3 , t 3 ) + 2Bh+1 (q 3 , t 3 ) − 2T Oh−1 (t 3 , q 3 )
h1
− 2T Oh (t 3 , q 3 ) + T Oh−1 (t 3 , q 3 )T Oh (t 3 , q 3 ) .
(51)
5.2.3. Global result Finally, |Fix(r 2 )|q,t = 2P1 (q, t) + P3 (q, t) + 2Q1 (q, t) + Q3 (q, t).
(52)
5.3. Symmetry with respect to the radian rotation r 3 Here, the rotation center can be in the middle of an edge or of an hexagon. See Fig. 19. If the rotation center is in the middle of an edge, there are three similar cases corresponding to the three types of edges. Consider the case of the horizontal edge and denote by A, the corresponding class. Such a polyomino P is shown in Fig. 19a. Denote by K the left fundamental region of P, including the central column. Note that this column is of even length.
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
329
K K
(a)
(b) Fig. 19. r 3 -symmetric convex polyominoes.
If the rotation center is the middle of an hexagon, we denote by H the corresponding class. In this case, the central column is of odd length. See Fig. 19b. The polyominoes K which can occur as a fundamental region in one of these two cases are K = C00 + C01 + C10 + C11 + C02 + C20 .
(53)
Recall that the series Cij,n (x, q, t) is defined by Eq. (25), with the index n representing the size of the last column. We then have 1 A(x, q, t) = (C00,2k + 2C01,2k + C11,2k + 2C02,2k )(x 2 , q 2 , t 2 ). (54) 2k xq t 4k+1 k 1
and H(x, q, t) =
k 0
1 xq 2k+1 t 4k+3
×(C00,2k+1 + 2C01,2k+1 + C11,2k+1 + 2C02,2k+1 )(x 2 , q 2 , t 2 ).
(55)
Finally, |Fix(r 3 )|q,t = 3A(1, q, t) + H(1, q, t).
(56)
6. Two-generator symmetry classes 6.1. Symmetry with respect to D6 Since D6 = r, ds2 , convex polyominoes belonging to Fix(D6 ) consist of super-hexagons with symmetric stack decorations (see the Section 5.1). We obtain |Fix(D6 )|q,t = t 3(2h−1) q 3h(h−1)+1 T S0h−1 (t 6 , q 6 ). (57) h1
330
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
A∩B C∩D
h h h
Fig. 20. Fundamental region of an F3,1 -symmetric convex polyominoes in P3 .
6.2. Symmetry with respect to F3,1 = r 2 , ds2 We are guided by the 2/3 rotation symmetry class studied in Section 5.2. The cases h1 > h2 and h2 > h1 are impossible because of the ds2 -symmetry. There remains the case h1 = h2 = h. If the rotation center is in the middle of an hexagon (case P3 ), the sides of the superhexagon are decorated by symmetric stacks of type TS0. Moreover the ds2 -symmetry implies that the decorations are in the sectors A ∩ B and C ∩ D. See Fig. 20. By r 2 -symmetry, three of these stacks are identical and the three others also, whence the formula (T SOh−1 (t 3 , q 3 ))2 . If the rotation center is a vertex (case Q3 ), we rather find T SOh−1 (t 3 , q 3 )T SOh (t 3 , q 3 ). Consequently, t 3(2h−1) q 3h(h−1)+1 (T SOh−1 (t 3 , q 3 ))2 |Fix(F3,1 )|q,t = h1
+2
2
t 6h q 3h T SOh−1 (t 3 , q 3 )T SOh (t 3 , q 3 ).
(58)
h1
6.3. Symmetry with respect to H3,1 = r 2 , v We refer again to Section 5.2. The case where the center is a vertex is impossible because of the vertical symmetry. There remains the case where the center is an hexagon and the three subcases h1 > h2 , h2 > h1 and h1 = h2 define three subclasses R1 , R2 and R3 , respectively. For the case where h1 > h2 , the part D ∗ of the decoration (see Fig. 16) is in fact the mirror image v · D of D. Hence we obtain R1 (q, t) =
h1
t 3(2h−1) q 3h(h−1)+1
= R2 (q, t).
h 1 D0,r,l (q 6 , t 6 ) + D1,r,l (q 6 , t 6 ) 3l q
l 1 r=1
(59)
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
331
If h1 = h2 = h, the decorations in the sectors A ∩ B and C ∩ D are mirror images of each other and we find R3 (q, t) =
t 3(2h−1) q 3h(h−1)+1 T0h−1 (t 6 , q 6 ).
(60)
h1
Finally, |Fix(H3,1 )|q,t = 2R1 (q, t) + R3 (q, t).
(61)
6.4. Symmetry with respect to D2,3 = r 3 , h Observe that D2,3 = h, v. We thus refer to Sections 4.1 and 4.2 on v- and h-symmetric polyominoes, respectively. In order to obtain a D2,3 -symmetric convex polyomino, it suffices to take a v-symmetric polyomino whose fundamental region K (see Fig. 13) is itself h-symmetric. The series CS00 (x, q, v, t), HS11 (x, q, u, v, t) and CS11 (x, q, v, t) are the h-symmetric analogues of the series C00 (x, q, v, t), H11 (x, q, u, v, t) and C11 (x, q, v, t) of Sections 2.3.4 and 3.1. We have CS00,k (x, q, t) = [v k ]CS00 (x, q, v, t) = t 2k TSk (xt, q),
(62)
xquvt 3 + xqvt 3 HS11 (x, q, u, vq, t) 1 − quvt 2 HS11 (x, q, u, v, t) xt HS11 (x, q, u, vq, t) − v + v qv v=0 = HS11,k (x, q, v, t)uk , (63)
HS11 (x, q, u, v, t) =
k 1
CS11 (x, q, v, t) =
i 2
=
1 t 2i−2
CS00,i (x, q, t)HS11,i−1 (x, q, v, t)
CS11,k (x, q, t)v k ,
(64)
k 1
and finally |Fix(D2,3 )|q,t =
i 1
1 q i t 2i+1
CS00,i (1, q 2 , t 2 ) + CS11,i (1, q 2 , t 2 ) .
(65)
332
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
7. Conclusion It is now possible to use Burnside’s formula (12), with F = C, to enumerate the free convex polyominoes, according to area and half perimeter. Some numerical results are given in Tables 1 and 2, according to area only (up to area 20) or to half perimeter only (up to half perimeter 16). See under the column “Orbits”. Computations can be carried out up to area 70. For example, the area generating function O(q) for free convex polyominoes is given by O(q) = 7793485086177320116383190 q 70 + 3375061639302474977759459 q 69 +1461610684198631521434604 q 68 + 632967933766627146424740 q 67 +274114310677183339289743 q 66 + 118708470539679217896007 q 65 +51408118544120036869792 q 64 + 22262898681436619043371 q 63 +9641213717634629469342 q 62 + 4175242553984424220331 q 61 +1808138570063349142550 q 60 + 783035966496331488936 q 59 +339103061579669091397 q 58 + 146852624016100144541 q 57 +63596279796639028453 q 56 + 27541127246923937999 q 55 +11927013542068382458 q 54 + 5165135428712800678 q 53 +2236823487460490930 q 52 + 968683084599288074 q 51 +419499762163951475 q 50 + 181669375424844915 q 49 +78674090371781710 q 48 + 34070753690782346 q 47 +14754746731145007 q 46 +6389719389968340 q 45 + 2767144462931933 q 44 +1198345093623976 q 43 +518957772128292 q 42 + 224740942349340 q 41 + 97326811736713 q 40 +42148579710335 q 39 + 18252976472430 q 38 + 7904689463224 q 37 +3423234621528 q 36 + 1482481972527 q 35 + 642013158078 q 34 +278035714218 q 33 + 120409664036 q 32 + 52146728481 q 31 +22584066680 q 30 +9781113135 q 29 + 4236381815 q 28 + 1834955080 q 27 + 794876602 q 26 +344366727 q 25 + 149221608 q 24 + 64673919 q 23 + 28041203 q 22 +12162019 q 21 + 5278535 q 20 + 2291941 q 19 + 996255 q 18 + 433140 q 17 +188607 q 16 + 82057 q 15 + 35759 q 14 + 15525 q 13 + 6751 q 12 + 2902 q 11 +1250 q 10 + 528 q 9 + 222 q 8 + 91 q 7 + 38 q 6 + 15 q 5 + 6 q 4 + 3 q 3 +q 2 + q It is also possible to enumerate asymmetric convex polyominoes with the help of formula (16), with F = C. Some results are found in Tables 1 and 2. It is clear from these tables that almost all convex polyominoes are asymmetric. These numerical results were verified experimentally by an exhaustive computerized enumeration up to area 20.
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
333
Table 1 Symmetry classes of convex (hexagonal) polyominoes according to area Area
id
h
v
r
r2
r3
Orbits
D6
F31
H31
D21
Asym
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 3 11 38 120 348 939 2412 5973 14 394 34 056 79 602 1 84 588 4 26 036 9 80 961 2 256 420 5 189 577 11 939 804 27 485 271 63 308 532
1 1 3 2 6 6 9 12 17 20 30 38 46 62 69 100 115 154 175 238
1 1 3 4 10 12 27 30 63 66 142 140 310 286 665 580 1441 1184 3145 2458
1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0
1 0 2 2 0 6 3 0 12 6 0 18 13 0 30 18 0 50 27 0
1 3 3 12 12 42 37 126 99 336 252 840 616 2028 1461 4788 3435 11 142 8005 25 800
1 1 3 6 15 38 91 222 528 1250 2902 6751 15 525 35 759 82 057 1 88 607 4 33 140 9 96 255 2 291 941 52 78 535
1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0
1 0 2 0 0 2 1 0 0 2 0 2 1 0 2 0 0 2 1 0
1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0
1 1 1 2 2 2 3 4 3 4 6 4 8 8 7 8 11 12 13 16
0 0 0 24 72 264 816 2184 5640 13 836 33 324 78 240 1 82 952 4 23 012 9 77 316 2 249 640 5 181 540 11 924 676 27 467 376 63 274 740
Table 2 Symmetry classes of convex (hexagonal) polyominoes according to half perimeter 1 2 per.
id
h
v
r
r2
r3
Orbits
D6
F31
H31
D21
Asym
3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 0 3 2 12 18 59 120 318 714 1743 4008 9433 21 672
1 0 1 2 2 2 5 8 10 14 25 36 53 76
1 0 1 0 4 0 9 0 24 0 59 0 143 0
1 0 0 0 0 0 1 0 0 0 0 0 2 0
1 0 0 2 0 0 5 0 0 12 0 0 28 0
1 0 3 0 6 0 19 0 48 0 129 0 323 0
1 0 1 1 3 2 11 12 39 65 177 343 867 1825
1 0 0 0 0 0 1 0 0 0 0 0 2 0
1 0 0 2 0 0 3 0 0 4 0 0 6 0
1 0 0 0 0 0 3 0 0 0 0 0 8 0
1 0 1 0 2 0 3 0 6 0 7 0 15 0
0 0 0 0 0 12 24 96 204 672 1368 3900 8616 21 444
References [1] M. Bousquet-Mélou, A method for the enumeration of various classes of column-convex polygons, Discrete Math. 154 (1996) 1–25.
334
D. Gouyou-Beauchamps, P. Leroux / Theoretical Computer Science 346 (2005) 307 – 334
[2] A. Denise, C. Dürr, F.I.-M. Hassani, Enumération et génération aléatoire de polyominos convexes en réseau hexagonal, in: Proc. Ninth Conf. on Formal Power Series and Algebraic Combinatorics, FPSAC’97, Universität Wien, 1997, pp. 222–234. [3] Dominique Gouyou-Beauchamps et Pierre Leroux, Dénombrement des classes de symétries des polyominos hexagonaux convexes, in: Proc. 16th Conf. on Formal Power Series and Algebraic Combinatorics, FPSAC’04, University of British Columbia, Canada, 2004. [4] S. Fereti´c, D. Svrtan, On the number of column-convex polyominoes with given perimeter and number of columns, in: Proc. Fifth Conf. on Formal Power Series and Algebraic Combinatorics, FPSAC’93, University of Florence, 1993, pp. 201–214. [5] A.J. Guttmann, I.G. Enting, The number of convex polygons on the square and honeycomb lattices, J. Phys. A 21 (1988) L467–L474. [6] A.J. Guttmann, M. Vöge, I. Jensen, On the number of benzenoid hydrocarbons, J. Chem. Inform. Comput. Sci. 42 (2002) 456–466. [7] F. Ibn-Majdoub-Hassani, Combinatoire des polyominos et des tableaux décalés oscillants, Ph.D. Thesis, Université de Paris Sud, Orsay, November, 1996. [8] P. Leroux, É. Rassart, Enumeration of symmetry classes of parallelogram polyominoes, Ann. Sci. Math. Québec 25 (1) (2000) 71–90. [9] P. Leroux, É. Rassart, A. Robitaille, Enumeration of symmetry classes of convex polyominoes in the square lattice, Adv. in Appl. Math. 21 (1998) 343–380. [10] K.Y. Lin, S.J. Chang, Rigorous results for the number of convex polygons on the square and honeycomb lattices, J. Phys. A 21 (1988) 2635–2642. [11] K.Y. Lin, F.Y. Wu, Unidirectional convex polygons on the honeycomb lattice, J. Phys. A 23 (1990) 5003–5010. ˇ [12] V. Privman, N.M. Svraki´ c, Directed models of polymers, interfaces, and clusters: scaling and finite-size properties, Lecture Notes in Physics, Vol. 338, Springer, Berlin, 1989. [13] N.J.A. Sloane, The On-Line Encyclopedia of Integer Sequences, Published electronically at http://www.research.att.com/∼njas/sequences/, 2003. [14] N.J.A. Sloane, S. Plouffe, The Encyclopedia of Integer Sequences, Academic Press Inc., New York, 1995. [15] P.K. Stockmeyer, Enumeration of graphs with prescribed automorphism group, Ph.D. Thesis, University of Michigan, Ann Arbor, 1971.
Theoretical Computer Science 346 (2005) 335 – 357 www.elsevier.com/locate/tcs
A sufficient condition for non-uniqueness in binary tomography with absorption Attila Kubaa,∗ , Murice Nivatb a Department of Image Processing and Computer Graphics, University of Szeged, Árpád tér 2,
H-6720 Szeged, Hungary b Laboratoire d’Informatique Algorithmique: Fondements et Applications, Université Paris 7 Denis-Diderot,
Paris, France
Abstract A new kind of discrete tomography problem is introduced: the reconstruction of discrete sets from their absorbed projections. A special case of this problem is discussed, namely, the uniqueness of the binary matrices with √ respect to their absorbed row and column sums when the absorption coefficient is = log((1 + 5)/2). It is proved that if a binary matrix contains a special structure of 0s and 1s, called alternatively corner-connected component, then this binary matrix is non-unique with respect to its absorbed row and column sums. Since it has been proved in another paper [A. Kuba, M. Nivat, Reconstruction of discrete sets with absorption, Linear Algebra Appl. 339 (2001) 171–194] that this condition is also necessary, the existence of alternatively corner-connected component in a binary matrix gives a characterization of the non-uniqueness in this case of absorbed projections. © 2005 Elsevier B.V. All rights reserved. Keywords: Discrete tomography; Binary matrices; Absorbed projection
1. Introduction Discrete tomography (DT) deals with the problem of reconstructing functions with given discrete ranges from weighted sums/integrals over subsets/subspaces (e.g., straight lines
∗ Corresponding author.
E-mail addresses:
[email protected] (A. Kuba),
[email protected] (M. Nivat). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.024
336
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
or planes) of their domain. It has applications, for example, in electron microscopy [7,13] and medicine [9]. The book [6] provides an overview of the foundations, algorithms, and applications of discrete tomography. In this paper we consider a generalisation of the DT problem. Let us suppose that the function to be reconstructed represents a discrete set, which is in some known absorbing material and, accordingly, the measurements are the absorbed sums taken on straight lines. It can be considered as the basic model of the emission discrete tomography, or EDT, where the elements of the discrete set are discrete sources emitting unit energy and the measurements represent the partially absorbed energy detected along straight lines. (In this sense the classical model of DT can be considered as the special case of the EDT when there is no absorption.) In the last 2 years a few other papers have been published related to EDT, see, for example [2,3]. First, we pose the reconstruction problem of discrete sets with absorption in Section √ 2. Then we select a mathematically interesting special absorption value = log((1 + 5)/2) and investigate the question of uniqueness when the discrete set can be represented by a binary matrix and the absorbed row and column sums of this matrix are given. In Section 3 we show that in this case the absorbed row and column sums can be considered as finite 0 -representations (a terminology used in numeration systems), where 0 = e . Section 4 deals with those transformations, called switchings, when the 0s and 1s of a certain subset (called switching pattern) are switched to each other but the absorbed projections of the subset remain the same. Clearly, if a binary matrix contains a switching pattern then it is non-unique, because we can get another binary matrix with the same absorbed projections by switching transformation. We determine the switching patterns in both one-dimensional (1D) and two-dimensional (2D) cases. It is also shown how more complex switching patterns, like alternatively corner-connected components, can be created from simple, elementary switching patterns. In another paper [10] we have proved that the existence of alternatively corner-connected components in a binary matrix is necessary for the non-uniqueness, therefore it is necessary and sufficient for the non-uniqueness of binary matrices with respect to their absorbed row and column sums.
2. Absorption and reconstruction of discrete sets 2.1. Absorption Consider a ray (e.g, light or X-ray) passing through a homogeneous material. It is wellknown that a part of the ray will be absorbed in the material. Quantitatively, let I0 and I denote the initial and the detected intensities (number of photons/s) of the ray. Then I = I0 e−x ,
(1)
where 0 denotes the absorption coefficient of the material and x is the length of the path of the ray in the material (see Fig. 1).
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357 x I0
u
337
detector I
Fig. 1. A part of the initial intensity I0 of the ray is absorbed in the homogeneous material having absorption coefficient .
2.2. The reconstruction problem for discrete sets Let Zd denote the d-dimensional integer lattice (d 2). The non-zero vectors of Zd are the lattice directions. The lattice lines are the lines of the d-dimensional Euclidean space which are parallel to a lattice direction and pass through at least one lattice point in Zd . The finite subsets of Zd are called discrete sets. Let F be a discrete set. The projection of F along a lattice line is defined as [PF ]() = |F ∩ |, where |.| denotes the cardinality of the argument set. Let E be a class of discrete sets and L be a finite collection of lattice lines. Then the reconstruction problem for E and L can be posed as RECONSTRUCTION D(E, L). Given: Function p : L −→ N0 (N0 denotes the set of nonnegative integers). Task: Construct a discrete set F ∈ E such that [PF ]() = p() for all ∈ L. Many results connected to this reconstruction problem have been published in the last years. A summary of these results are in [6]. Consider, for example, the problem of uniqueness in the case of (2D) binary matrices. UNIQUENESS D2D(A). Given: m, n ∈ N, and a binary matrix A with size m × n. Question: Does there exist a different binary matrix A with the same size such that the row and column sums of A and A are the same? It has been shown [12] that a binary matrix is non-unique with respect to its row and column sums if and only if it has a sub-matrix 0 1 1 0 or 1 0 0 1 called switching component. A new kind of DT problem, the reconstruction of discrete sets from their absorbed projections, was introduced in [10]. A special case of this problem was discussed, namely, the
338
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
G1 x(G1)
F G2 x(G2)
detector Fig. 2. Computation of the projection of the discrete set F along the lattice line . The elements of F are denoted by bold points. Here F ∩ = {G1 , G2 }.
uniqueness of 2D binary matrices with respect to their absorbed row and column sums when the absorption is represented by the constant 0 of (7). 2.3. The reconstruction problem for discrete sets with absorption Consider now the corresponding reconstruction problem in the case of absorption. For the sake of simplicity we suppose that the whole d-dimensional Euclidean space is uniformly filled with the material having absorption coefficient 0. Then the projection with absorption of a discrete set F along a lattice line is defined according to (1) by −·x(G) e , (2) [P F ]() = G∈F ∩
where x(G) denotes the distance between the point G and the detector placed on the lattice line (see Fig. 2). The reconstruction problem with absorption for a class of discrete sets, E, knowing the projections along all directed lines of L (we have to have a detector location for each line ) can be posed as RECONSTRUCTION DA(, E, L). Given: Function p : L −→ R0 (R0 denotes the set of nonnegative real numbers). Task: Construct a discrete set F ∈ E such that [P F ]() = p() for all ∈ L. 2.4. Reconstruction of 2D discrete sets with absorption Consider now the 2D integer lattice Z2 . Let m and n be positive integers. A discrete rectangle with size m × n is a special discrete set of Z2 determined as the intersection of m consecutive horizontal lattice lines with n consecutive vertical lattice lines. If F is a
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357 s1
detectors r1 F
1
s2 s3 s4 0
1
0
r2
0
1
1
0
r3
1
0
0
1
339
S(A)
A
R(A) (b)
(a)
Fig. 3. A 2D discrete set F, the corresponding binary matrix A, and their horizontal and vertical projections. (a) The set F and the detectors measuring its horizontal and vertical projections. (b) The binary matrix A and its absorbed row and column sums.
discrete set in Z2 , then there is an m×n discrete rectangle containing F, it is called containing (discrete) rectangle. (For the sake of simplicity we can take the smallest containing rectangle in the following.) Let us suppose that the horizontal and vertical projections of F are measured by detectors placed in the next column to left and in the next row to above, respectively, of the containing rectangle (see Fig. 3(a)). Then the absorbed projections can be computed according to (2). For example, in the case of the discrete set F given in Fig. 3(a), the absorbed projections along the horizontal lattice lines of the containing rectangle are r1 = e−·1 + e−·3 , r2 = e−·2 + e−·3 , and r3 = e−·1 + e−·4 . Now, we introduce an equivalent representation of the 2D discrete sets and their absorbed horizontal and vertical projections. The containing rectangle including F can be represented by a binary matrix A = (aij )m×n as follows: aij = 1 if the lattice point corresponding to (i, j ) is an element of F, aij = 0 otherwise. In order to use the generally accepted notation of numeration systems [11], let us introduce = e .
(3)
Clearly, 1. Then we can define the absorbed row and column sums of A, R (A) and S (A), respectively, as R (A) = (r1 , . . . , rm ),
(4)
where ri =
n j =1
aij −j ,
i = 1, . . . , m
and S (A) = (s1 , . . . , sn ), where sj =
m i=1
aij −i ,
j = 1, . . . , n.
(5)
340
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
For example, in the case of matrix A given in Fig. 3(b) R (A) = (−1 + −3 , −2 + −3 , −1 + −4 ) and S (A) = (−1 + −3 , −2 , −1 + −2 , −3 ). We say that two binary matrices with the same sizes are tomographically equivalent if they have the same absorbed row and column sums. Then the uniqueness problem of 2D discrete sets (or, equivalently, of binary matrices) with absorption knowing the absorbed projections along horizontal and vertical lines can be posed as UNIQUENESS DA2D(, A). Given: 1, m, n, and a binary matrix A with size m × n. Question: Does there exist a different binary matrix A with the same size such that A and A are tomographically equivalent with respect to their absorbed projections R and S ? If = 1 then we have the classical uniqueness problem of binary matrices without absorption (see e.g. [4,8]). Binary matrices with absorption can be reconstructed even only from their row sums in certain cases. For example, if and n have the following property: for any positive integers t, z, and 1p1 < · · · < pt n, 1q1 < · · · < qz n −p1 + · · · + −pt = −q1 + · · · + −qz implies that t =z
and
p1 = q1 , . . . , pt = qt .
In this case each row of A is uniquely determined by its absorbed row sum, and so A is uniquely determined by R (A). For example, if 2 then we have this property for any n1. But how can we do reconstruction if and n do not have this property? Select, for example, the case = 0 , where −2 −3 −1 0 = 0 + 0
(6)
giving √ 1+ 5 . 0 = 2
(7)
√ (The other solutions of (6), namely √ (1 − 5)/2 and 0, are not applicable in this case; c.f., (3).) In this case = log((1 + 5)/2) which gives a mathematically interesting case that will be analysed in detail in this paper.
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
341
3. 0 -representation Consider the absorbed row and column sums of the binary matrix A in the case of = 0 : ri =
n j =1
−j
aij 0 ,
i = 1, . . . , m
(8)
aij −i 0 ,
j = 1, . . . , n.
(9)
and sj =
m i=1
Using the terminology of numeration systems [11] we can say that the finite (binary) word ai1 · · · ain is a (finite) representation in base 0 (or a finite 0 -representation) of ri for each i = 1, . . . , m, and, similarly, a1j · · · anj is a 0 -representation of sj for each j = 1, . . . , n. The Eqs. (8) and (9) mean also that the absorbed row and column sums of A are nonnegative real numbers having a finite 0 -representation with n and m binary digits, respectively (including the eventually ending zeros). Since we deal only with finite length 0 -representations in this paper, the 0 -representation always means finite length 0 -representation. Let Bk denote the set of nonnegative real numbers having a 0 -representation with k binary digits (k > 1), formally, Bk =
k i=1
ai −i 0 | ai ∈ {0, 1} .
Then ri ∈ Bn ,
i = 1, . . . , m
and s j ∈ Bm ,
j = 1, . . . , n,
are necessary conditions for the existence of a matrix A with R0 (A) = (r1 , . . . , rm ) and
S0 (A) = (s1 , . . . , sn ).
4. Switchings Switching is, roughly, a transformation of 0 -representations by which certain 0s and 1s are replaced to each other such that the represented values remain the same. As it will be proven in this section, switchings play a basic role in the uniqueness problem DA2D(0 , A). 4.1. 1D switchings The 0 -representation is generally nonunique, because there are binary words with the same length representing the same number. For example, on the base of (6), it is easy to
342
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
check the following equality between the 3-digit-length 0 -representations of 1/0 100 = 011
(10)
which is the most simple example of switching. Furthermore (6) may allow us to define more general switchings: Let a1 · · · ak be a kdigit-length 0 -representation and let I be a subset of {1, . . . , k}. We say that I is a set of switching positions of a1 · · · ak if by replacing (switching) the 1s and 0s to each other in the positions of I the new (switched) word represents the same number as a1 · · · ak . This transformation of the 0 -representations is called 1D switching. As an example, let us take Eq. (10). Here all positions, 1, 2, and 3, are switching positions of 100. Another example can be shown by using 100 00. Since 100 00 = 010 11, I = {1, 2, 4, 5} is a set of switching positions of 100 00 (and of 010 11). If there is one of the sub-words 011 and 100 in a 0 -representation then it can be replaced by the other one without changing the value of the representation, i.e., it is a special kind of switching. It is called 1D elementary switching. For example, a 1D elementary switching can be done in the positions 2, 3, and 4 of the word 010 00 getting the word 001 10 representing the same number. The words 011 and 100 are called 0-type and 1-type 1D elementary switching words, respectively, also the switching pair expression can be used. As direct consequences of (10), it is easy to see that 011 01x3 11 01x3 1x5 11 01x3 1x5 1x7 11
= = = =
100, 10x3 00, 10x3 0x5 00, 10x3 0x5 0x7 00, . . .
(11)
where x3 , x5 , x7 , . . . denotes the positions where both 0 -representations have the same (but otherwise arbitrary) binary digit. For example, the second equality of (11) can be proved as follows: if then
x3 = 0, 01x3 11 = 010 11 = 011 00 = 100 00 = 10x3 00,
if then
x3 = 1, 01x3 11 = 011 11 = 100 11 = 101 00 = 10x3 00,
(12)
that is, we got the necessary representation after two consecutive 1D elementary switchings in both cases. The third, fourth, etc. equalities of (11) can be proved similarly by applying three, four, etc. 1D elementary switchings. Accordingly, if in a 0 -representation there is one of the words listed in either side of the Eq. (11) then it can be replaced (switched) by the word on the other side of the corresponding Eq. (11) without changing the value of the representation. This transformation of binary words is called 1D composite switching. The words starting with 0 (resp. 1) in the Eq. (11) will be called 0-type (resp., 1-type) 1D composite switching words, respectively.
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
343
For example, 101 00 is a 1-type composite switching word being on the left side of the second equation of (11). Now we are going to show that the 1D composite switchings can be composed from 1D elementary switchings as follows. Let a1 · · · ak and b1 · · · bl (k and l are positive odd integers) be two 1D switching words of the same type (i.e., either a1 = b1 = 0 or a1 = b1 = 1). Their composition, denoted by ∗, is defined as a1 · · · ak ∗ b1 · · · bl = a1 · · · ak−1 _ _b2 · · · bl , where _ _ indicates that the kth position of the resulting composition word is undefined. For example, 011 ∗ 011 100 ∗ 100 01x3 11 ∗ 011 10x3 0x5 0x7 00 ∗ 10y3 0y5 00
= = = =
01_ _11, 10_ _00, 01x3 1_ _11, 10x3 0x5 0x7 0_ _0y3 0y5 00,
where x3 , x5 , x7 , and y3 , y5 denotes the positions where both 0 -representations have the same (but otherwise arbitrary) binary digit. Now, we are going to prove that any finite 0 -representation of a number can be got from its any other 0 -representation by 1D elementary switchings. Lemma 1. Let a1 · · · ak and b1 · · · bk be different, k-digit-length 0 -representations of the same number. Then b1 · · · bk can be get from a1 · · · ak by a finite number of switchings. Proof. We are going to give a procedure by which suitable switching sub-words can be found in a1 · · · ak and, by switching them, the number of different positions between a1 · · · ak and b1 · · · bk can be decreased until there is no different position. Let i be the first position (1 i k) where the two representations are different, that is, a1 · · · an = x1 · · · xi−1 ai · · · ak = x1 · · · xi−1 bi · · · bk = b1 · · · bk ,
(13)
where x1 , . . . , xi−1 denote positions where the two representations have the same binary digit. Furthermore, let us suppose that ai = 1 and bi = 0, that is, ai · · · ak = 1ai+1 · · · ak , bi · · · bk = 0bi+1 · · · bk . Note that k = i (for otherwise it would follow from (13) that 1 = 0) and that k = i + 1 (for otherwise it would follow from (13) that 0 is an integer). Hence k > i + 1. Then ai+1 = 0 and bi+1 = 1, as it can be seen indirectly in the following. Otherwise there are two cases: Case 1: If ai+1 = 1 then ai · · · ak = 11ai+2 · · · ak 110 · · · 0.
(14)
Let us write as many 0’s to the end of the binary word on the right side of (14) (if it is not so yet) that the length of the padded binary word is an even number being not less than 4.
344
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
Then 1100 · · · 00 = 1010 · · · 011 > 1010 · · · 001 = 011 · · · 11,
(15)
where we have equalities by switchings and strict inequality by changing the 1 to 0 in position last but one (denoted by underlined digit). Since 011 · · · 11bi · · · bk
(16)
from (14)–(16) we got the contradiction ai · · · ak > bi · · · bk . Case 2: If bi+1 = 0 then let us follow a similar idea as in Case 1: ai · · · ak = 1ai+1 · · · ak 100 · · · 0.
(17)
Let us write as many 0’s to the end of the binary word on the right side of (17) (if it is not so yet) that the length of the padded binary word is an even number being not less than 4. Then 1000 · · · 00 = 0101 · · · 0110 > 0101 · · · 0100 = 0011 · · · 11,
(18)
where we have equalities by switchings and strict inequality by changing the 1 to 0 in position last but one (denoted by underlined digits). Since 0011 · · · 1100bi+2 · · · bk = bi · · · bk
(19)
from (17)–(19) we got again the contradiction ai · · · ak > bi · · · bk . Therefore, ai+1 = 0 and bi+1 = 1. That is, if ai · · · ak and bi · · · bk represent the same number then ai · · · ak = 10ai+2 · · · ak , bi · · · bk = 01bi+2 · · · bk necessarily. Consider now the next position, i + 2, in ai · · · ak and bi · · · bk . Then there are three cases to be studied. Case 1: If ai+2 = 0 and bi+2 = 1 then we have the switching sub-words ai ai+1 ai+2 = 100 and bi bi+1 bi+2 = 011. Therefore ai ai+1 ai+2 can be switched to bi bi+1 bi+2 getting a new representation a1 · · · ai−1 bi bi+1 bi+2 ai+3 · · · ak which can be different from b1 · · · bk only from the position i + 3. If a1 · · · ai−1 bi bi+1 bi+2 ai+3 · · · ak and b1 · · · bk are different then we can start the same procedure to find a switching in ai+3 · · · ak and bi+3 · · · bk , but now we have shorter representations to prove the lemma. Otherwise the two representations are the same, so we got b1 · · · bk from a1 · · · ak by one switching which means that the lemma is satisfied. Case 2: If ai+2 = 1 and bi+2 = 0 then ai · · · ak = 101ai+3 · · · ak 101 00 · · · 0.
(20)
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
345
Let us write as many 0’s to the end of the binary word on the right side of (20) (if it is not so yet) that the length of the padded binary word is an even number being not less than 6. Then 101 00 · · · 00 = 011 10 · · · 0110 > 011 10 · · · 0100 = 011011 · · · 111 > 010111 · · · 11,
(21)
where we have equalities by switchings and strict inequalities by changing the corresponding underlined digits in both sides. Since 010 11 · · · 11 010bi+3 · · · bk = bi · · · bk
(22)
from (20)–(22) we got the contradiction ai · · · ak > bi · · · bk . That is, this case is impossible. Case 3: The last case is when ai+2 = bi+2 , that is ai+2 = bi+2 = 0 or ai+2 = bi+2 = 1. Let us denote this common binary digit by xi+2 . In this case we have to continue the search for a composite switching word. That is, let us continue the procedure with the sub-words ai · · · ak = 10xi+2 ai+3 · · · ak , bi · · · bk = 01xi+2 bi+3 · · · bk , where xi+2 denotes the position where the two representations have the same binary digit. Now, we are going to show that ai+3 = 0 and bi+3 = 1 (note that k > i +2, for otherwise it would follow that 10xi+2 = 01xi+2 ). Otherwise, there are two cases. Case 1: If ai+3 = 1 then ai · · · ak = 10xi+2 1ai+4 · · · ak 10xi+2 10 · · · 0.
(23)
Let us write as many 0’s to the end of the binary word on the right side of (23) (if it is not so yet) that the length of the padded binary word is an even number being not less than 6. Then 10xi+2 100 · · · 000 = 10xi+2 010 · · · 011 > 10xi+2 010 · · · 001 = 10xi+2 0011 · · · 11 = 01xi+2 111 · · · 11,
(24)
where we have equalities by switchings and strict inequality by changing the 1 to 0 in position indicated by underlined digit. Since 01xi+2 11 · · · 1101xi+2 bi+3 · · · bk = bi · · · bk
(25)
from (23)–(25) we got the contradiction ai · · · ak > bi · · · bk . That is, this case is impossible. Case 2: If bi+3 = 0 then let us follow a similar idea as in Case 1: ai · · · ak = 10xi+2 ai+3 · · · ak 10xi+2 0 · · · 0.
(26)
Let us write as many 0’s to the end of the binary word on the right side of (26) (if it is not so yet) that the length of the padded binary word is an even number being not less than 7.
346
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
Then 10xi+2 0000 · · · 000 = 01xi+2 1100 · · · 000 = 01xi+2 1010 · · · 011 > 01xi+2 1010 · · · 001 = 01xi+2 0011 · · · 111,
(27)
where we have equalities by switchings and strict inequality by changing the 1 to 0 (in position indicated by underlined digit). Since 01xi+2 011 · · · 11 = 01xi+2 0bi+4 · · · bk bi · · · bk
(28)
from (26)–(28) we got the contradiction ai · · · ak > bi · · · bk . That is, this case is also impossible. Therefore, ai+3 = 0 and bi+3 = 1. In the following we have to study the possibilities when ai · · · ak = 10xi+2 0ai+4 · · · ak , bi · · · bk = 01xi+2 1bi+4 · · · bk . Consider now the next position, i + 4, in ai · · · ak and bi · · · bk (note that k > i + 3, for otherwise it would follow that 10xi+2 0 = 01xi+2 1). Then there are three cases to be studied. Case 1: If ai+4 = 0 and bi+4 = 1 then we have the switching sub-words ai ai+1 ai+2 ai+3 ai+4 = 10xi+2 00 and bi bi+1 bi+2 bi+3 bi+4 = 01xi+2 11 (see (11)) and we can switch ai ai+1 ai+2 ai+3 ai+4 and bi bi+1 bi+2 bi+3 bi+4 getting a new representation, a1 · · · ai−1 bi bi+1 bi+2 bi+3 bi+4 ai+5 · · · ak , which can be different from b1 · · · bk only from the position i + 5. If the new representation is different from b1 · · · bk then we can start the same procedure to find a switching in ai+5 · · · ak and bi+5 · · · bk , but now we have shorter representations to prove the lemma. Otherwise, the two representations are the same, so we got b1 · · · bk from a1 · · · ak by one switching which means that the lemma is satisfied. Case 2: If ai+4 = 1 and bi+4 = 0 then we get a contradiction in the same way as in the case of ai+2 = 1 and bi+2 = 0. That is, this case is impossible. Case 3: The last case is when ai+4 = bi+4 . In this case we have to continue the search for a composite switching word. That is, we have to continue the procedure according to Case 3 with the sub-words ai · · · ak = 10xi+2 0xi+4 ai+5 · · · ak , bi · · · bk = 01xi+2 1xi+4 bi+5 · · · bk , where xi+2 and xi+4 are in the positions where the two representations have the same binary digits. Then we can show that ai+5 = 0 and bi+5 = 1 as it was in the case of ai+3 = 0 and bi+3 = 1. That is, ai · · · ak = 10xi+2 0xi+4 0ai+6 · · · ak , bi · · · bk = 01xi+2 1xi+4 1bi+6 · · · bk . And so on. Generally, ai+2l = bi+2l (= xi+2l ), ai+2l+1 = 0, and bi+2l+1 = 1 for l = 1, 2, . . . . But this procedure is finished after a finite number of steps, therefore, there is an
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
347
index value l such that ai+2l+1 = ai+2l+2 = 0 and bi+2l+1 = bi+2l+2 = 1: ai · · · ak = 10xi+2 0xi+4 0 · · · 0xi+2l 00ai+2l+3 · · · ak , bi · · · bk = 01xi+2 1xi+4 1 · · · 1xi+2l 11bi+2l+3 · · · bk . Then we have the switching sub-words 10xi+2 0xi+4 0 · · · 0xi+2l 00 and 01xi+2 1xi+4 1xi+6 1 · · · 1xi+2l 11 (see (11)) and we can switch ai · · · ai+2l+2 and bi · · · bi+2l+2 getting a new representation, a1 · · · ai−1 bi bi+1 · · · bi+2l+2 ai+2l+3 · · · ak which can be different from b1 · · · bk only from the position i + 2l + 3. If the new representation is different from b1 · · · bk then we can start the same procedure to find a switching in ai+2l+3 · · · ak and bi+2l+3 · · · bk , but now we have shorter representations to prove the lemma. Otherwise, the two representations are the same after this switching. As a result of this procedure we can say that since the number of different positions of a1 · · · ak and b1 · · · bk decreases by each switchings, we get b1 · · · bk from a1 · · · ak after a finite number of switchings. Consequences (i) If a1 · · · ak and b1 · · · bk are different, k-digit-length 0 -representations of the same number, then there are positions i, . . . , i + 2l + 2 (l 0, 1 i, i + 2l + 2 k − 2) such that there is a switching between a1 · · · ak and b1 · · · bk on these positions. (ii) Let a1 , . . . , ak ∈ {0, 1} (k 3). a1 · · · ak is the only k-digit-length 0 -representation of a real number if and only if it has no switching, or equivalently, it has no sub-word 100 or 011. 4.2. 2D switchings In this subsection we determine the 2D switchings, i.e., the transformations of binary matrices by which some of their 0s and 1s can be switched to each other such that the absorbed row and column sums remain the same. 4.2.1. Connectedness Consider now the class of m × n (m, n 3) binary matrices with given row and column sum vectors in the case of absorption 0 . Let Q(i,j ) (1 < i < m, 1 < j < n) denote the 3 × 3 discrete square Q(i,j ) = {i − 1, i, i + 1} × {j − 1, j, j + 1}. Let be a set of 3×3 discrete squares of {1, . . . , m}×{1, . . . , n} and let Q(i,j ) , Q(i ,j ) ∈ . Two kinds of connectedness will be defined on 3 × 3 discrete squares: side-connectedness and corner-connectedness. There is a side-connection between Q(i,j ) and Q(i ,j ) if (i , j ) ∈ {(i − 2, j ), (i, j − 2), (i, j + 2), (i + 2, j )}. The four squares being side-connected to Q(i,j ) are called the side-neighbours of Q(i,j ) . As an illustration see Fig. 4(a). Q(i,j ) and Q(i ,j ) are corner-connected if (i , j ) ∈ {(i −2, j −2), (i −2, j +2), (i +2, j −2), (i +2, j +2)}. The four squares being corner-connected to Q(i,j ) are called the corner-neighbours of Q(i,j ) (see Fig. 4(b)). There is a side-chain between Q(i,j ) and Q(i ,j ) in if a sequence of elements of can be selected such that the first element is Q(i,j ) and the last element is Q(i ,j ) and any two
348
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
(i,j)
(i,j)
(a)
(b)
Fig. 4. Q(i,j ) and (a) its side-neighbours and (b) its corner-neighbours.
Q(i, j)
Q(i', j')
(a)
(b)
Fig. 5. Side-connected sets of discrete squares. The set (a) is not strongly side connected because Q(i,j ) ∩ Q(i ,j ) = ∅ but they are not side-connected and they have no common side-neighbour. (b) A strongly side-connected set.
consecutive elements of the sequence are side-connected. (A sequence consisting of only one square is a side-chain by definition.) The set is side-connected if there is a side-chain in between its any two different elements (see Fig. 5(a)). A maximal side-connected subset of is called a side-connected component of . Clearly, the side connected components of give a partition of . A side-connected set is strongly side-connected if whenever Q(i,j ) , Q(i ,j ) ∈ and Q(i,j ) ∩ Q(i ,j ) = ∅ then they are side-connected or they have a common side-connected neighbour (see Fig. 5(b)). Let be a set of strongly side-connected components (1) , . . . , (k) (k 1) of the same set . Let (l) , (l ) ∈ (1l, l k). (l) and (l ) are corner-connected if whenever Q ∈ (l) and Q ∈ (l ) have a common position then Q and Q are corner-connected squares. (Since (l) and (l ) are maximal, Q and Q cannot be side-connected squares.) There is a corner-chain between (l) and (l ) in if a sequence of elements of can be selected such that the first element is (l) and the last element is (l ) and any two consecutive elements of the sequence are corner-connected. (A sequence consisting of only one component is a corner-chain by definition.) The set is corner-connected if there is a corner-chain in between its any two elements (see Fig. 6(a)). 4.2.2. Switching patterns In order to identify not necessarily rectangular parts of binary matrices, we introduce the concept of the binary pattern (or shortly, pattern) as binary valued function defined on an
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
(a)
349
(b)
Fig. 6. Two corner-connected sets, both of them have two strongly side-connected components.
arbitrary non-empty subset of {1, . . . , m} × {1, . . . , n}. (In this terminology binary matrices are binary patterns on discrete rectangles.) Let P be a binary pattern, its domain will be denoted by dom(P ). The absorbed row and column sums of P are denoted by R0 (P ) and S0 (P ), respectively, where the ith component of R0 (P ) is −j P (i, j )0 (i,j )∈dom(P )
for 1i m and the jth component of S0 (P ) is P (i, j )−i 0 (i,j )∈dom(P )
for 1j n. Let us define the binary pattern P as P (i, j ) = 1 − P (i, j ) on dom(P ). By definition, P is a switching pattern if R0 (P ) = R0 (P )
and
S0 (P ) = S0 (P ).
In this case we say that P and P are a switching pair. That is, the patterns of a switching pair can be get from each other by switching their 0s and 1s and still they have the same absorbed row and column sums. As an example, consider the following binary patterns: 0 (0) E(i,j ) = 1 1
1 0 0
1 0 0
and
1 (1) E(i,j ) = 0 0
0 1 1
0 1 1
(29) (0)
both of them are defined on the discrete square Q(i,j ) . It is easy to check that E(i,j ) and (1)
E(i,j ) are a switching pair. They play an important role in the generation of switching
350
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357 (0)
(1)
patterns, E(i,j ) and E(i,j ) are called the 0-type and 1-type elementary switching patterns, respectively. 4.2.3. Composition of patterns The composition of two patterns P and P is the function P ∗ P : dom(P) dom(P ) −→ {0, 1} ( denotes the symmetric difference) such that P (i, j ), if(i, j ) ∈ dom(P ) \ dom(P ), [P ∗ P ](i, j ) = P (i, j ), if(i, j ) ∈ dom(P ) \ dom(P ). (That is, P ∗ P is undefined on dom(P ) ∩ dom(P ).) For example,
(0)
(0)
E(i,j ) ∗ E(i+2,j )
0 1 1 1 0 0 = __ __ __ 1 0 0 1 0 0
(30)
defined on Q(i,j ) Q(i+2,j ) = {i − 1, i, i + 2, i + 3} × {j − 1, j, j + 1}. (Just for the sake of simple presentation, on the right side of (30) the whole sub-matrix on the rectangle {i −1, . . . , i +3}×{j −1, j, j +1} is indicated and—denotes the positions in the sub-matrix where the composition is undefined.) Similarly, 0 (0) (0) E(i,j ) ∗ E(i,j +2) = 1 1
1 0 0
__ 1 __ 0 __ 0
1 0 0
(31)
defined on Q(i,j ) Q(i,j +2) = {i − 1, i, i + 1} × {j − 1, j, j + 2, j + 3}. It is easy to see (0)
(0)
(0)
(0)
that E(i,j ) ∗ E(i+2,j ) and E(i,j ) ∗ E(i,j +2) are switching patterns, their switching pairs are (1)
(1)
(1)
(1)
E(i,j ) ∗ E(i+2,j ) and E(i,j ) ∗ E(i,j +2) , respectively, where 1 0 0 0 1 1 (1) (1) E(i,j ) ∗ E(i+2,j ) = _ _ _ _ _ _ 0 1 1 0 1 1
and
1 (1) (1) E(i,j ) ∗ E(i,j +2) = 0 0
0 1 1
__ 0 __ 1 __ 1
0 1 1.
(32)
These examples show how new switching patterns can be created from elementary switching patterns by composition. The following lemma gives a more general way to show how two (not only elementary) switching patterns can be used to generate another switching pattern.
Lemma 2. Let P1 and P2 be switching patterns. If P1 = 1 − P 2 on dom(P1 ) ∩ dom(P2 ) then P1 ∗ P2 is also a switching pattern.
(33)
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
351
Proof. Let I1 = dom(P1 ), I2 = dom(P2 ), and P = P1 ∗ P2 on I = I1 I2 . Let, furthermore, P1 = 1 − P1 ,
P2 = 1 − P2
P = 1 − P
and
on I1 , I2 , and I, respectively. It is easy to see that P = P1 ∗ P2 , on I, and P1 = 1 − P2 ,
(34)
on I1 ∩ I2 . We are going to show that R0 (P ) = R0 (P ).
(35)
According to the definitions, the ith components of R0 (P ) = (1 , . . . , m ), 1 i m, can be written as −j −j i = P (i, j )0 = [P1 ∗ P2 ](i, j )0 I
(i,j )∈I
=
I \I2
−j P1 (i, j )0
1
=
−
I1
I1 ∩I2
+
I2 \I1
−j
P2 (i, j )0
−j P1 (i, j )0
+
−
I2
−j
P2 (i, j )0 .
I2 ∩I1
P1
Since P1 and are a switching pair on I1 and P2 and P2 are a switching pair on I2 , we get that −j −j −j −j i = P1 (i, j )0 − P1 (i, j )0 + P2 (i, j )0 − P2 (i, j )0 I1 ∩I2
I1
=
I1
−j P1 (i, j )0
+
I2
I2
−j P2 (i, j )0
−
I1 ∩I2
I1 ∩I2
−j P1 (i, j ) + P2 (i, j ) 0 .
After partitioning I1 and I2 and ordering the new terms we get
−j −j −j i = P1 (i, j )0 + P2 (i, j )0 + P1 (i, j ) + P2 (i, j ) 0 I1 \I2
−
I2 \I1
I1 ∩I2
I1 ∩I2
P1 (i, j ) + P2 (i, j )
−j 0 .
Then from the definition of the composition (33), and (34) we have −j −j −j i = [P1 ∗ P2 ](i, j )0 + 10 − 10 I
=
(i,j )∈I
I1 ∩I2
P
I1 ∩I2
−j (i, j )0 .
That is, the ith component of R0 (P ) is the same as the ith component of R0 (P ). In this way (35) is proved. The equality S0 (P ) = S0 (P ) can be proved similarly.
352
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
Remark 1. In the case of the compositions of (30) the condition (33) is satisfied, i.e., (0)
(0)
E(i,j ) = 1 − E(i+2,j ) (0)
(0)
on Q(i,j ) ∩ Q(i+2,j ) , therefore E(i,j ) ∗ E(i+2,j ) is a switching pattern, as we have seen it soon before the proof of Lemma 2. Similar statements are true in the cases of (31) and (32). 4.2.4. Composition of elementary switching patterns Let E = {E1 , . . . , Ek } (k 1) be a set of elementary switching patterns of the same type on a strongly side-connected set = {Q1 , . . . , Qk }. The composition of E on , denoted by C(E), is defined as follows. If k = 1 then C(E) = E1 . If k > 1 then let us suppose that Q1 , . . . , Qk are indexed such that for each l(< k) {Q1 , . . . , Ql } is a strongly side-connected set and one of its squares is side-connected with Ql+1 . (It is easy to see that such an indexing exists.) Then let C = C(E) = ((E1 ∗ E2 ) ∗ · · ·) ∗ Ek . Now, we are going to show that this definition is independent from the indexing of = {Q1 , . . . , Qk }. There are four cases depending on how many times a position (i, j ) is in the sets {Q1 , . . . , Qk }: (i) If there is exactly one l such that (i, j ) ∈ Ql , then (l)
C(i, j ) = eij , (l)
where eij denotes the value of El in the position (i, j ). (ii) If there are exactly two different l1 and l2 such that (i, j ) ∈ Ql1 and (i, j ) ∈ Ql2 , then C(i, j ) is undefined. (iii) If there are exactly three different l1 , l2 , and l3 such that (i, j ) ∈ Ql1 ∩ Ql2 ∩ Ql3 , then two of the elementary switching patterns (say, El1 and El3 ) has the same value in the position (i, j ) and the other one (El2 ) has a different value in the position (i, j ), i.e., (l ) (l ) (l ) eij1 = eij3 = 1 − eij2 . In this case (l )
(l )
C(i, j ) = eij1 = eij3 . (iv) If there are exactly four different l1 , l2 , l3 , and l4 such that (i, j ) ∈ Ql1 ∩Ql2 ∩Ql3 ∩Ql4 , then C(i, j ) is undefined. That is, the value of C(i, j ) can be decided simply on the base of the parity of the number of discrete squares of covering (i, j ) (independently from the indexing of ). Accordingly, if E is the set of 2D elementary switching patterns of the same type on a strongly sideconnected set, then we can simply write C(E) to denote the compositions of the elements of E. As an example, see Fig. 7. Lemma 3. Let E be a set of elementary switching patterns of the same type on a strongly side-connected set of 3 × 3 squares. Then C(E) is a switching pattern. Proof. The lemma will be proved by induction according to the number of elementary switching patterns in E. Let E1 , . . . , Ek (k 1) denote the elementary switching patterns
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
0
1
1
0
1
0
1 0 1
1 0 0
0 0
1 1
0 1 0
353
1 1 0
0
0
0
0 0
(0)
(0)
(0)
(0)
(0)
Fig. 7. The composition of the elementary switching patterns E(2,2) , E(2,4) , E(4,4) , E(4,6) , and E(6,4) . _ _ denotes the positions where the composition is undefined.
(0)
of E on the strongly side-connected set = {Q1 , . . . , Qk }. If k = 1, i.e., E = {E(i,j ) } or (1)
E = {E(i,j ) } for some (i, j ), then Lemma 3 is trivially true. (If k = 2 then the possible compositions are just given by (30), (31), and (32), all of them are switching patterns.) Generally, let us suppose that Lemma 3 is proved for any set E consisting of k number of elementary switching patterns. Let Ek+1 be an elementary switching pattern having the same type as E1 , . . . , Ek such that {Q1 , . . . , Qk , Qk+1 } is also a strongly side-connected set. Let C = C(E) and D = C ∗ Ek+1 . By induction C is a switching pattern on dom(C). In order to apply Lemma 2 we have to show that C(i, j ) = 1 − Ek+1 (i, j )
(36)
for all (i, j ) ∈ dom(C) ∩ Qk+1 . There are two cases depending on how many times such a position (i, j ) is in the sets Q1 , . . . , Qk : (i) There is exactly one l(∈ {1, . . . , k}) such that (i, j ) ∈ Ql . Then Ql and Qk+1 are side-connected. Since El and Ek+1 are elementary switching patterns of the same type, it is easy to check that (36) is satisfied if Qk+1 is either north, east, south, or west side-connected to Ql (see Fig. 8). (ii) There are exactly three l1 , l2 , and l3 , all of them from {1, . . . , k}, such that (i, j ) ∈ Ql1 ∩Ql2 ∩Ql3 . Then one of them, say, Ql2 is side-connected to the other two squares and Ql1 and Ql3 are corner-connected squares. Since El1 , El2 , El3 , and Ek+1 are elementary switching patterns of the same type, it is easy to check that (36) is satisfied if Qk+1 is either north-east, south-east, south-west, or north-west corner-connected to Ql (see Fig. 9). (If (i, j ) is in even number of squares of Q1 , . . . , Qk then (i, j ) ∈ dom(C) ∩ Qk+1 , see the cases (ii) and (iv) in the paragraph introducing the definition of the composition of elementary switching patterns.) That is, (36) is proved for every possible cases. Then Lemma 2 can be applied, therefore, D is a switching pattern. Henceforth, the switching patterns constructed from elementary switching patterns of the same type by composition are called composite switching patterns. We say that the
354
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
El 1 0
1 0
11 0 0
0 C
0
0 0 1 0 0
C 0 1 1 0 0 0 0 0 0 1 0 00 00 1 0 El
0 1 1 1 0 0 1 0 0 Ek+1
0 1 1 10 0 1 00 Ek+1
El Ek+1 01 1 1 0 0 10 0
Ek+1 0 1 1 10 0 10 0
El 01 1 0 1 1 0 0 1 C
11 0 0
0 1 1 0
1 0
0 0 0 0
1 0 0 1 0 0 10 C
Fig. 8. Illustration of the fact that Eq. (36) is satisfied if exactly one of the elementary switching patterns of C, say El , has common positions with the elementary switching pattern Ek+1 (the binary values at the common positions are indicated by bold digits) and El and Ek+1 have the same type (here: 0-type; 1-type patterns can be checked similarly). The positions indicated by “_ _” do not belong to the domain of C.
C 0
0
0
0
0
0 0 1 0 0 0 0
0
0 0
0
0 0
0
0 0 0 1 1 0 0 0
0 C 0
0
1 0
0 0 Ek+1
0 1 1 1 0 0 1 0 0
0 1 1 1 0 0 1 0 0 Ek+1
0 1 1 1 0 0 1 0 0 Ek+1
0 0
0 C
1 0 0 1 0 0 1 0
0
1 0
0
1 0
1 0
0 1 1 0 1 1 0 0
0
0
0
0
Ek+1
0 1 1 1 0 0 1 0 0
0
0
0
C
Fig. 9. Illustration of the fact that Eq. (36) is satisfied if exactly three of the elementary switching patterns of C have common positions with the elementary switching pattern Ek+1 (the binary value at the common position is indicated by bold digit) and all three elementary switching patterns of C and Ek+1 have the same type (here: 0-type; 1-type patterns can be checked similarly). The positions indicated by “_ _” do not belong to the domain of C.
composite switching pattern has 0-type/1-type if it is the composition of 0-type/1-type elementary switching patterns, respectively. For example, (30)–(32) and Fig. 7 show composite switching patterns of types 0, 0, 1, 1, and 0, respectively. 4.2.5. Composition of corner-connected components Lemma 4. Let (0) and (1) be corner-connected components. Let C (0) and C (1) be 0-type and 1-type 2D composite switching patterns on (0) and on (1) , respectively. Then C (0) ∗ C (1) is a switching pattern.
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357 C (0) 0 0 0
00
1 0
0 C (0)
0 0 0 0
1 0 1 0
0 0
1 0 0 1
0 1
0 1
0 1
0 0 1 1
1 C (1)
C (1) 1
1 1
0 1
1 C (1)
C (1) 1
1 1
0 1 0 11
1
1 1
1 1 1 1
355
C (0)
C (0) 1 0
1 1 0 0
0 1 1 0
1 0
0
0 0
1 0
0
Fig. 10. Illustration of the fact that Eq. (37) is satisfied in the common position of corner-connected components. The domains of E and E are indicated in C (0) and C (1) , respectively, by bold squares with solid lines.
Proof. In order to use Lemma 2 we have to show that C (0) = 1 − C (1)
(37)
on dom(C (0) ) ∩ dom(C (1) ). Since (0) and (1) are corner-connected components, dom(C (0) ) ∩ dom(C (1) ) consists of the common positions of corner-connected squares of (0) and (1) . Formally, if (i, j ) ∈ dom(C (0) ) ∩ dom(C (1) ) then there are 2D elementary switching patterns E and E such that (i, j ) ∈ dom(E ) ∩ dom(E ). It is easy to check that for such a position (i, j ) E (i, j ) = 1 − E (i, j ) in all possible cases (see Fig. 10). That is, (37) is satisfied. Then applying Lemma 2 to the 2D composite switching patterns C (0) and C (1) we get that C (0) ∗ C (1) is a switching pattern. Let be a corner-connected set of the strongly side-connected components (1) , . . . , (k) (k 1). Let C (1) , . . . , C (k) be 0- or 1-type composite switching patterns on (l) , . . . , (k) , respectively. Let us suppose also that if (l) and (l ) are corner-connected then C (l) and C (l ) have different type. In this case we say that = {C (1) , . . . , C (k) } is a set of alternatively corner-connected components on . The composition of on , denoted by C(), is defined as follows. If k = 1 then C() = C (1) . If k > 1 then let us suppose that (1) , . . . , (k) are indexed such that for each l (l < k) {(1) , . . . , (k) } is a corner-connected set and one of its elements is corner-connected with (l+1) . (It is easy to see that such an indexing exists.) Then let C = C() = ((C (1) ∗ C (2) ) ∗ · · ·) ∗ C (k) .
356
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
1 0 0 1 0 1 0 1
0 1 1 0 0 1 1 0 1 1
1 0
1 1 0 0
0 1 0 0 1 1
0 0 00
Fig. 11. Composition of two alternatively corner-connected components.
It is easy to show that this definition is independent from the indexing of , because dom(C) = ∪l (l) \ ∪l,l ((l) ∩ (l ) ) and C(i, j ) = C (l) (i, j ), where l ∈ {1, . . . , k} is the only index such that (i, j ) ∈ (l) . Henceforth, we may simply write C() to denote the composition of the elements of . As an example, see Fig. 11. Theorem 1. Let = {C (1) , . . . , C (k) } (k 1) be a set of alternatively corner-connected components. Then C() is a composite switching pattern. Proof. It follows from Lemma 4 directly.
5. Discussion A new kind of discrete tomography problem was introduced, the reconstruction of discrete sets from their absorbed projections. A special case of this problem was discussed in this paper, namely, the uniqueness of 2D binary matrices with respect to their absorbed row and column sums when the absorption is represented by the constant 0 of (7). It was shown that the uniqueness in this case could be characterised similarly as in the classical case of reconstruction without absorption, because similar elementary switchings could be given (0) (1) by E(i,j ) and E(i,j ) . We have shown that there is a hierarchy of 2D switching patterns in the case of absorption. The most simple kind of switching patterns are the 0-type and 1-type elementary switching patterns given by (29). More complicated switching patterns, so-called 0- and 1-type composite switching patterns can be constructed from 0-type and 1-type elementary switching patterns, respectively, defined on strongly side-connected components of 3 × 3 discrete squares by composition (Lemma 3). Finally, we get the most complex composite switching patterns as the composition of alternatively corner-connected components (Lemma 4). Theorem 1 also means that if a binary matrix contains an alternatively corner-connected component then it is non-uniquely determined with respect to its absorbed row and column sums. That is, the existence of an alternatively corner-connected component is sufficient for the non-uniqueness in the case of problem UNIQUENESS DA2D(0 , A). In another paper [10] we could prove that this condition is also necessary for the non-uniqueness, that is, since this condition is necessary and sufficient for the non-uniqueness, we have also that the compositions of alternatively corner-connected components are the most general switching patterns.
A. Kuba, M. Nivat / Theoretical Computer Science 346 (2005) 335 – 357
357
Acknowledgements A part of this research was done while the first author visited the Laboratoire d’Informatique Algorithmique: Fondements et Applications, Université Paris 7 Denis-Diderot, Paris, France. Special thanks to Prof. Gabor T. Herman (Graduate College, City University of New York) and Laurent Vuillon (LIAFA, Université Paris 7) for their valuable comments and discussions. This work was supported by the Grant OTKA T 032241 and NSF Grant DMS 0306215 (Aspects of Discrete Tomography). References [2] E. Balogh, A. Kuba, A. Del Lungo, M. Nivat, Reconstruction of binary matrices from absorbed projections, in: A. Braquelaire, J.-O. Lachaud, A. Vialard (Eds.), Discrete Geometry for Computer Imagery, Lecture Notes in Computer Science, Vol. 2301, Springer, Berlin, 2002, pp. 392–403. [3] E. Barcucci, A. Frosini, S. Rinaldi, Reconstruction of discrete sets from two absorbed projections: an algorithm, Electron. Notes Discrete Math. 12 (2003) 12. [4] R.A. Brualdi, Matrices of zeros and ones with fixed row and column sums, Linear Algebra Appl. 33 (1980) 159–231. [6] G.T. Herman, A. Kuba (Eds.), Discrete Tomography: Foundations, Algorithms and Applications, Birkhäuser, Boston, 1999. [7] G.T. Herman, R. Marabini, J.-M. Carazo, E. Garduno, R.M. Lewitt, S. Matej, Image processing approaches to biological three-dimensional electron microscopy, Int. J. Imaging Syst. Technol. 11 (2000) 12–29. [8] A. Kuba, G.T. Herman, Discrete tomography: A historical overview, in: Discrete Tomography: Foundations Algorithms and Applications, Birkhäuser, Boston, 1999, pp. 3–34. [9] A. Kuba, G.T. Herman, S. Matej, A. Todd-Pokropek, Medical applications of discrete tomography, in: D.Z. Du, P.M. Pardalos, J. Wang (Eds.), Discrete Mathematical Problems with Medical Applications, DIMACS Series in Discrete Mathematics and Theoretical Computer Science, Vol. 55, AMS, Rhode Island, 2000, pp. 195–208. [10] A. Kuba, M. Nivat, Reconstruction of discrete sets with absorption, Linear Algebra Appl. 339 (2001) 171–194. [11] M. Lothaire, Combinatorics on Words, Cambridge University Press, Cambridge, 1997. [12] H.J. Ryser, Combinatorial properties of matrices of zeros and ones, Canad. J. Math. 9 (1957) 371–377. [13] P. Schwander, C. Kisielowski, M. Seibt, F.H. Baumann, Y. Kim, A. Ourmazd, Mapping projected potential, interfacial roughness, and composition in general crystalline solids by quantitative transmission electron microscopy, Phys. Rev. Lett. 71 (1993) 4150–4153.
Theoretical Computer Science 346 (2005) 358 – 387 www.elsevier.com/locate/tcs
Monotone runs of uniformly distributed integer random variables: A probabilistic analysis Guy Louchard∗ Département d’Informatique, Université Libre de Bruxelles, CP 212, Boulevard du Triomphe, B-1050 Brusselles, Belgium
Abstract Using a Markov chain approach and a polyomino-like description, we study some asymptotic properties of monotone increasing runs of uniformly distributed integer random variables. We analyze the limiting trajectories, which after suitable normalization, lead to a Brownian motion, the number of runs, which is asymptotically Gaussian, the run length distribution, the hitting time to a large length k run, which is asymptotically exponential, and the maximum run length which is related to the Gumbel extreme-value distribution function. A preliminary application to DNA analysis is also given. © 2005 Elsevier B.V. All rights reserved. Keywords: Monotone increasing runs; Markov chains; Polyominoes
1. Introduction We consider i.i.d. integer random variables with the distribution I (s) given by p(i) = 1/s, i = 1 . . . s. Assume that we have a sequence x[i], i = 1 . . . n, constructed from independent I (s) random variables. A run is a maximal (contiguous) increasing monotone subsequence. A maximum is a position i such that x[i − 1] x[i] > x[i + 1]. For instance, with s = 4, the sequence 23241321224421321242 has 10 runs, with a maximal run length of 5. A first approach to the runs analysis was given in Crescenzi et al. [5]. We observe that a Markov chain approach can lead to asymptotic results on the runs. In this paper, continuing an approach we had started in [15,17–20], we consider the runs either as a stochastic ∗ Tel./fax: +322 6505613.
E-mail address:
[email protected]. 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.015
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
359
process or as a polyomino. This allows the derivation of several asymptotic distributions of random variables and processes such as: the limiting trajectories, which after suitable normalization, lead to a Brownian motion, the number of runs, which is asymptotically Gaussian, the run length distribution, the hitting time to a large length k run, which is asymptotically exponential, and the maximum run length, which is related to the Gumbel extreme-value distribution function. Our results are in some sense similar to what we have obtained in [18] where we analyzed geometrically distributed random variables, and [19], where we considered Carlitz compositions. Let us already mention that, as s → ∞, all properties related to the ranked I (s) random variables have the same distributions as in the model of random permutations. For more details on the analysis of algorithms on sequences, the interested reader should consult Szpankowski [23]. The paper is organized as follows: in Section 2, we present the associated Markov chain and the limiting trajectories. Section 3 is devoted to some simulations and the maximum run length distribution. Section 4 provides a preliminary application to DNA analysis. Section 5 concludes the paper. Appendix A–C provide some technical tools which are useful in Section 3.1. This work emaned from the fruitful discussions we had with A. Del Lungo, during the 2003 summer. The paper was nearly completed when Alberto suddenly died on June 1, 2003. We present this work as a tribute to his memory. 2. Associated Markov chain and limiting trajectories In this section, we first describe the runs process as a Markov chain. We then study the run length distribution. We finally analyze the limiting trajectories and the number of runs distribution. 2.1. Stochastic analysis It is immediately checked that we can see the runs as a Markov chain, the states of which are given by the possible values i of the I (s) random variables starting a run, together with the run length. The following notations will be used in the sequel: L(i) := length of an ascending run starting with value i, (i, l, j ) := Pr[L(i) = l, x[l + 1] = j ] l 1 = , s i i2 ··· il >j (i, l) := Pr[L(i) = l] = (i, l, j ) j
= l
i i2 ··· il
(i, l) = 1,
l−1 il − 1 1 , s s
note that
360
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
[i, l], [j, ] := Pr[next run starts at j, has length , given that the previous run was starting at i and had length l] = (i, l, j )(j, )/(i, l). Two other transition matrices are given by [i, l], j := Pr[next run starts at value j, given that the previous run was starting at i and had length l] = [i, l], [j, ]
= (i, l, j )/(i, l), hence
[i, l], [j, ] = [i, l], j (j, ), [i, j ] := Pr[next run starts at j, given that the previous run was starting at i] = (i, l, j ). l
The stationary distribution of [i, j ] will be denoted by (j ). Note that (i, l) can be computed directly. Indeed set, 1 l−1 1 1 (i, l) := (i, w) = s wl i i2 ··· il s−i+1 1 1 s−i+l−1 l−1 . = [z ] = l−1 l−1 1 − z/s s We derive (i, l) = 1 (i, l) − 1 (i, l + 1) =
1 s l−1
s−i+l s−i+l−1 1− . l−1 ls
(1)
(2)
Also, for further use, we define 2 (i, l) := 1 (i, w), wl
3 (i, l) :=
2 (i, w).
wl
These expressions are easily seen to converge. Also, by Stirling formula, or better, by singularity analysis, (see [9]), with the well-known formula 1 1 n−1 n [z ] 1+O , n → ∞, ∼ 1−z () n 1 We use the notation [zk ]f (z) to denote the coefficient of zk in the power expansion of f (z).
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
361
we obtain
1 (k − 1)s−i 1+O . 1 (i, k) ∼ k−1 (s − i)!s k
(3)
Let us denote by Fj (z) the generating function of j (i, l). We know already that
1 F1 (i, z) = z 1 − z/s
s−i+1 (4)
.
The generating function of 2 (i, l) is given by F2 (i, z) = z
F1 (i, z) − F1 (i, 1) z−1
and, by singularity analysis (the dominant singularity of F2 is at z = s), we obtain 1 (k − 1)s−i 1+O 2 (i, k) ∼ . k−2 (s − 1)(s − i)!s k
(5)
Similarly, we derive 3 (i, k) ∼
1 (k − 1)s−i 1 + O . 2 k−3 (s − 1) (s − i)!s k
(6)
2.2. Some generating functions and their applications In this subsection, we first construct the generating functions of some probability transition matrices and stationary distributions. Next, we compute some stationary parameters distributions related to run lengths. Then we analyze the asymptotics of m successive runs. 2.2.1. One ascending run We build a corresponding polyomino as follows: we choose a starting integer i, and construct a monotone sequence of l integers, i = i1 · · · il , followed by a last integer j with j < il . We mark each integer by z, the last monotone integer il is marked by , and j is marked by . (For this kind of construction, see, for instance, [16].) The trivariate generating function (, , z|i) that comprises all such polyominoes, labelled as described, can be computed as follows: set g1 := zi ,
and, for k 1, ⎤ ⎡ s s
−1 gk+1 (, , z) = [ ]gk (, 0, z)z ⎣ r + j ⎦
=1
r=
j =1
1 − s = gk (1, 0, z)z 1−
s s− +1 s− +1 − 1 −1
+ − . [ ]gk (, 0, z)z −1 −1
=1
362
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
This sequence describes the effect of “adding a new slice.” The generating function gk corresponds to a polyomino of k integers (each integer marked by z), where the last integer is marked either by , if it is still monotone, or by , if it is smaller than the previous integer. Hence (, , z|i) :=
∞
gk (, , z)
k=1
1 − s s+1 +z (1, 0, z|i) 1− −1 s+1 z z (, 0, z|i) − (1, 0, z|i) + (, 0, z|i). − −1 −1 −1
= g1 + (1, 0, z|i)z
Set A1 := (1, 0, z|i). (To ease the notation, we usually drop the variables list, except when the context is not sufficiently clear). Setting = 0, = 0, we immediately check that (0, 0, z|i) = 0. Set now = 0. We obtain z s+1 A1 − (, 0, z|i), (, 0, z|i) = z i + −1 −1 which gives s+1 −1 i + A1 (, 0, z|i) = z −1+z −1 and
s+1 1 A1 + (, 0, z|i) (, , z|i) = z + −1 −1 A1 z z2 s+1 i + − + A1 . 1− −1+z −1
(7)
i
(8)
We also derive from (7)
s+1 z( − 1) i + A1 (, 0, z|i) = −1+z −1 and, finally
z2 s+1 s+1 i A1 − + A1 (, , z|i) = z + −1 −1+z −1
z2 A1 z s+1 + i + A1 + −1+z −1 1− s+1 z( − 1) = i + A1 −1+z −1
z2 A1 z s+1 i + + A1 + . −1+z −1 1−
i
(9)
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
363
It remains to compute A1 . But the first part of (9) has a singularity in the denominator at = 1 − z. This leads to (1 − z)s+1 ∗i A1 = 0 + 1−z−1 or A1 = z(1 − z)i−s−1
(which leads again to (1)),
and is completely determined. Set now (, z|i) = (0, , z|i)
A1 z s+1 z2 i = + + A1 1− −1+z −1
(10)
and, as → 1, this leads to (1, z|i) = z + (zs − 1)A1 . The generating function “contains” the quantities of interest, as described in the next proposition which gives all useful distributions in terms of Proposition 1.
1 l+1 j z (, z|i), sl 1 (i, l) = l zl+1 (1, z|i), s [i, j ] = j s(, 1/s|i).
(i, l, j ) =
It is convenient to set A2 (|i) := (1 − /s)i−s−1 ,
/s s+1 /s i A3 (, |i) := A2 + + A2 , 1 − − 1 + /s −1 s A4 (|i) := A3 (1, |i) = 1 + ( − 1)A2 . This leads to (i, l, j ) = [l j ]A3 (, |i), (i, l) = [l ]A4 (|i) (which leads again to (2)), [i, j ] = [j ]A3 (, 1|i), A3 (, 1|i) = (1 − 1/s)i−s−1 s(1 − )
s+1 1 i i−s−1 . + + (1 − 1/s) s( − 1 + 1/s) s( − 1)
364
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
It is an easy check to derive that j [i, j ] = 1, which follows from j [i, j ] = s(1, 1/s|i). To obtain (i), we start from the stationary equation (j ) = (i)[ j ]A3 ( , 1|i). i
We now compute the generating function of (i), () := sj =1 (j )j , and (1) = 1
() = (i)A3 (, 1|i) = (1 − 1/s)−s−1 ((1 − 1/s)) s(1 − ) i
1 s+1 −s−1 +
() + (1 − 1/s)
((1 − 1/s)) . (11) s( − 1 + 1/s) s( − 1) Solving (11) w.r.t. () and letting → 1; we obtain
((1 − 1/s)) = 2(1 − 1/s)s and, finally,
() = 2
s − s + s − 1 , s(1 − )2 (s − 1)
(12)
from which we derive s−i . s(s − 1) Of course, (s) = 0 and s−1 (i) = 1. 1 (i) = 2
2.2.2. Some stationary parameters distributions related to the run length As in [18], we need to compute the following averages and second moments: ¯ = (i, l)l, L(i) l
L2 (i) =
(i, l)l 2 ,
l
L¯ =
¯ (i)L(i).
i
For instance (differentiation is w.r.t. ), we obtain the following results: Proposition 2.
i−s−1 ¯ = A4 , L(i) =1 = (1 − 1/s) (1 − 1/s)i−s s(−2i + 3s + 1) ¯ L2 (i) = A4 =1 + L(i) = , (s − 1)2
(13)
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
365
and L¯ = L2 =
¯ (i)L(i) = 2/(1 − 1/s), (i)s 2 (i) =
2s(2(1 − 1/s)−s − 3) . s−1
The expressionfor L¯ is easy to check: this corresponds, by examining couples of random variables, to s 2 / si=2 (i − 1). The stationary generating function of the run length is given by H () =
(i)A4 = 1 + ( − 1)(1 − /s)−s−1 (1 − /s),
(14)
from which we derive, for instance, the following first three values of the stationary run length distribution: Proposition 3. Pr[L = 1] =
s−2 , 3s
5s 2 − s − 6 , 12s 2 (11s − 12)(s + 1)(s + 2) Pr[L = 3] = . 60s 3
Pr[L = 2] =
The stationary run length probability is geometrically decreasing. Note that, as s → ∞, ¯ L ∼ 2, L2 ∼ 4e −6. This is clear from the following result: as s → ∞, our model turns into the model of random permutations, with the stationary expressions L¯ = 2, L2 = 4e − 6. (see [20] for details). For further use, let us define the truncated mean run length, starting from i: ¯ l) := L(i,
w(i, w).
w
By partial summation and (2), we obtain ¯ k) = L(i) ¯ − G(i, k), L(i, G(i, k) =
with G(i, k) :=
(l + 1)1 (i, l + 1) −
l>k−2
w(i, w),
w>k−1
l1 (i, l + 1)
l>k−1
= (k − 1)1 (i, k) + 2 (i, k) = k1 (i, k) + 2 (i, k + 1).
(15)
366
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
A next useful quantity is given, with (12) and (4), by s+1 1 k−1 H1 (k) := (i)1 (i, k) = [z ]
(1 − z/s) 1 − z/s s 1 = [zk+1 ]2s 1 + (z − 1) (s − 1) 1 − z/s 2 s+k−1 s+k = s − (s − 1)s k k k+1 2k s+k−1 = . s−2 (s − 1)s k Asymptotically, singularity analysis leads to 1 2 s−1 1 + O k , H1 (k) ∼ (s − 1)!s k k
k → ∞.
(16)
(17)
(18)
A last useful equivalent concerns (i, l, j )/1 (i, k), k → ∞, l≥k
i.e. the asymptotic distribution of a run starting value, J, after a long run. Setting A5 (, |i) :=
(A3 (, |i) − A3 (, 1|i)) , −1
we see that (i, l, j ) = [k j ]A5 (, |i). l≥k
But it is readily checked that neither = s(1 − ) nor = 1 are singularities of A5 , the only singularity is at = s. Hence we obtain the equivalent A5 (, |i) ∼
s(s − ) (1 − /s)i−s−1 , (s − 1)( − 1)
→ s.
Now, 1 (i, k) ∼ [k−1 ](1 − /s)i−s−1 ,
k→∞
and the generating function of J is asymptotically given by s − 1 1+O . (s − 1)( − 1) k
(19)
But this intuitively evident: the long runs are followed by an integer asymptotically uniformly distributed on [1 . . . s − 1]. We could continue the asymptotics: the next correction
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
367
term is given by a matrix (we do not need its explicit value here): (20)
εN (i, j )
with ε := ((k − 1)s−1 )/s k−1 (the choice of ε is justified in Section 3.1). Note that N1 = 0. 2.2.3. m ascending runs We will analyze the total length X(m) (number of I (s) random variables) of m runs. We have X(m) =
m
L(ik ),
k=1
where ik is the starting value of run k. This corresponds to the length of a word where each letter is a I (s) random variable. By the ergodic theorem, we know that ¯ E(X(m)) ∼ mL, VAR(X(m)) ∼ m L2 − L¯ 2 + 2mS = m2 , say (see, for instance, [3, p. 172]), where S :=
∞
¯ v [[i, l], [j, ]]( − L) ¯ (i)(i, l)(l − L)
v=1 i,l,j,
=
¯ (i)(i, l)(l − L)
[[i, l], w1 ][w1 , w2 ] · · · [wv−2 , wv−1 ]
w1 ,w2 ,...,wv−1
v,i,l
×
¯ ) − L). ¯ [wv−1 , j ](L(j
j
To compute S, we first analyze f0 () :=
(i)(i, l, k)lk =
(i) A3 =1 .
k,i,l
To simplify further expressions, we set = (1 − 1/s). This leads to f˜0 () =
2 s((1 − 1/s) − 1)
s−1 −1 −s . +s (s − 1) − (1 − 1/s) −1
The first term of S is related to ¯ [k ]f˜0 ()L(k)/(1 − 1/s)k = (1 − 1/s)−s−1 f˜0 (1). k
368
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
Now define
f˜1 () :=
(i)(i, l, k)l(k, j )j
k,i,l,j
=
(1 − 1/s)−s ˜ f0 (1) s(1 − (1 − 1/s)) 1 s+1 ˜ ˜ + f0 () + f0 (1) , s(1 − 1/s)( − 1) s((1 − 1/s) − 1)
by (11). The second term of S is now related to (1 − 1/s)−s−1 f˜1 (1). We see now how to proceed: S is given by ˜ 1) − L¯ 2 /(1 − w) , S = lim (1 − 1/s)−s−1 (w, w→1
where ˜ (w, ) :=
∞
w i f˜i ().
0
˜ (w, ) can be computed as follows. We obtain w(1 − 1/s)−s ˜ ˜ (w, ) = f˜0 () + (w, 1) s(1 − (1 − 1/s)) w s+1 ˜ ˜ + (w, 1) (w, ) + s((1 − 1/s) − 1) s(1 − 1/s)( − 1) or (1 − 1/s)( − 1) − w/s ˜ (w, ) (1 − 1/s)( − 1) s w −s ˜ ˜ (w, 1). = f0 () + − (1 − 1/s) s((1 − 1/s) − 1) s(1 − 1/s)( − 1) ˜ ˜ To compute (w, 1), we note that the denominator of the expression for (w, ) has a singularity at = 1 + w/(s(1 − 1/s)), hence the numerator must be 0 for this value, which leads to −(1 − 1/s)s + w(1 − 1/s)s + ((s + w − 1)/s)s − w ˜ (w, 1) = 2 . w[w − ((s + w − 1)/s)s ] This gives ˜ 1) = L¯ 2 /(1 − w) (1 − 1/s)−s−1 (w, 2s[3(1 − 1/s)−s (s − 1) − 8s + 4] − + O(1 − w), 3(s − 1)2
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
369
and the singularity (at w = 1) in S is removed. Finally, 2s(s + 1) 2 = L2 − L¯ 2 + 2S = . 3(s − 1)2 Again, as s → ∞, we obtain the limiting value 2/3 which corresponds to a permutation. 2.3. Limiting trajectories Let us denote by M the number of runs. Let us first fix M to m and let us consider the total length X(m) (the number of I (s) random variables, i.e. the length of the word) of m runs X(m) =
m
L(ik ),
k=1
where i1 , . . . , im are the successive starting values of the runs. We can check that our Markov chain is -mixing (see, for instance, [3, p. 168] and the Appendix) and we apply the Functional Central Limit Theorem [3, p. 174, Theorem 20.1]. We obtain the following result, where B(t) is the standard Brownian Motion and ⇒ denotes the weak convergence of random functions in the space of all right-continuous functions that have right limits and are endowed with the Skorohod metric. This gives the limiting trajectories corresponding to a fixed number of runs. Theorem 4. ¯ X(mt ) − Lmt ⇒ B(t), √ m
m → ∞, t ∈ [0, 1].
(21)
Let us now condition on X(m) = n. M becomes a random variable. A realization of X for fixed n is given by Theorem 4, where we stop at a random time m such that X(m) = n. Proceeding as in [15] it is easy to check that this amounts to fix m = n/L in the denominator of (21), and we obtain the following result related to n random variables, with m runs. Theorem 5. Conditioned on X(m) = n, ¯ X(mt ) − Lmt ⇒ B(t). n/L¯ Moreover, from [22], the random variable M := number of runs satisfies the following Gaussian property: Proposition 6. M ∼ N (n1 , n21 ),
(22)
370
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
0.4
0.3
0.2
0.1
0
1
2
3
4
5
6
7
8
Fig. 1. Run length distribution (observed = circle, asymptotic = line).
10000
8000
6000
4000
2000
0
1000
2000
3000
4000
Fig. 2. Unnormalized X(·).
where N := a Gaussian (normal) random variable, s−1 , 1 = 1/L¯ = 2s 21 = 2 /L¯ 3 . This is actually an application of the generalized Renewal Theorem: the hitting time of ¯ is easily seen to lead the Brownian Motion B(t) of (21) to the barrier n(1 − t)/( n/L) asymptotically to a Gaussian random variable.
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
371
0.4 0.2 1000
0
2000
3000
4000
-0.2 -0.4 -0.6 -0.8
Fig. 3. Normalized X(·), with run length.
270
260
250
240
230
100
105
110
115
120
Fig. 4. Unnormalized X(·), with run length (zoom).
When s → ∞, we obtain 1 ∼ 1/2, 21 ∼ 1/12. We have done a simulation of U = 2000 sequences of n = 10 000 I (10) random variables (this simulation will be extensively used in Section 3), leading to 9 002 231 runs. The observed and limiting run length distributions are given in Fig. 1. (The limiting distribution is given by Proposition 3). The fit is quite good. A typical trajectory for X(i) for n = 10 000, s = 10 has given M = 4499 runs. The unnormalized trajectory is given in√ Fig. ¯ 2, which shows a “filament √ silhouette.” The normalized trajectory for (X(i) − Li)/ M ¯ and (X(i − 1) − Li)/ M, showing the run length is given in Fig. 3. Of course, both trajectories are asymptotically equivalent for n → ∞. A zoom on i = [100 . . . 120] is given in Fig. 4. We have also checked the asymptotic Gaussian property of M as given by (22). This
372
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
1
0.8
0.6
0.4
0.2
0 4400
4450
4500 x
4550
4600
Fig. 5. Observed and limiting Gaussian M distribution function.
is shown in Fig. 5. The asymptotic mean and variance 1 , 21 are given by 0.4500, 0.0825 . . . and the observed mean and variance by 0.4501 . . . , 0.0840 . . . .
3. Hitting time and maximum run length distribution In this section, we study the hitting time to a large length k run and the maximum run length distribution. All vectors and matrices will be written in bold. 3.1. Large run in a sequence constructed from independent I (s) random variables, for fixed s Let us define Tk := the time (counted in terms of number of I (s) random variables, i.e. the length of the word) necessary to obtain a run of large length k. We set hi := Ei (Tk ), (when possible, we drop the k for ease of notation). We derive ¯ k) + k1 (i, k)] + (i, l, u)hu hi = [L(i, l
¯ k) + k1 (i, k)] + = [L(i,
u
(i, u)hu −
l k
u
¯ k) + k1 (i, k)] + = [L(i,
(i, l, u)hu
u
(i, u)hu
u
−1 (i, k)
(i, l, u) hu . 1 (i, k) u
(23)
l k
By (3), we observe that 1 (i, k) = O(ε), ε := ((k − 1)s−1 )/s k−1 , k → ∞, uniformly on i, (for some reasons that will be clear later on, it is better to use the given form for ε), and
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
373
by standard properties of Markov chains (see [2,12]), we know that the hitting time to k is such that (we write Di for Di (k)): Di + (i) + O(ε) hi = ε (Actually a Laurent series exists for ε sufficiently small), Pri [Tk x] ∼ e−x/ hi , x → ∞. (24) We will soon check that D is independent of i. First we note that, by (15) and (5), ¯ + O(ε). ¯ k) + k1 (i, k) = L(i) L(i, Eq. (23), with (3), leads to
¯ + Di + ε(i) = ε L(i)
(i, u)[Du + ε(u)]
u
−1 (i, k)
(i, l, u) [Du + ε(u)] + O(ε 2 ) (i, k) 1 u
l k
= D(i) + O(ε).
(25)
Identification of ε powers in (25) leads to [I−]D = 0, which confirms that D is independent of i. Now we premultiply (23) by . This leads to h = L¯ + h −
∞
(i)1 (i, k)
i=1
D + O(ε) ε
or, with (17) 0 = L¯ − H1 (k) Set
D + O(ε). ε
s+k−1 2k . G3 (k) := H1 (k)/ε = s−2 s(s − 1)(k − 1)s−1
(26)
This leads to 0 = L¯ − DG3 (k). Therefore, we obtain D = s (k − 1) 2
s−1
s+k−1 k . s−2
(27)
We proceed now as in [17]. Let M(n) := maximum run length based on n I (s) random variables. We know that Pr[M(n) < k] = Pr[Tk n + 1].
374
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
1
0.8
0.6
0.4
0.2
-4
-2
0
2
4
6
8
10
x Fig. 6. Observed and limiting M distribution function.
We start our asymptotic analysis by first using (24) Pr[M(n) < k] ∼ exp[− exp[log n + (s − 1) log(k − 1) −(k − 1) log(s) − log D]], when n → ∞. (j + 1) s+j Set now k := j + 1 (which explains the choice of ε), D(j ) := s 2 j s−1 s−2 . We derive the following proposition, which gives the asymptotic distribution of the maximum run length. Proposition 7. Let := j log(s) − [log n + (s − 1) log j − log(D(j ))]. Then, with integer j and = O(1), Pr[M(n) j ] ∼ G1 (),
n → ∞,
where G1 () := exp[− exp[−]]. We also have Pr[M(n) = j ] ∼ f1 (), where f1 () := G1 () − G1 ( − 1). G1 (.) is actually the Gumbel extreme-value distribution function. (See, for instance, Kotz and Nadarajah [14].) The observed and limiting distribution functions are given in Fig. 6 (observed = circle, asymptotic = line).
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
375
Let us make a few remarks: • As j → ∞, which is a consequence of n → ∞, we have, by (18), D(j ) → D1 = s 2 (s − 2)!. But n = 10 000 is not large enough to entail this limit: in Fig. 6, we have kept the true D(j ) value. • Again, as n → ∞, log j ∼ log log n − log log s, but n must be large enough. • We have a linear dependence on j in . This is also found, for instance, in columnconvex animals [17], Carlitz compositions [19], and runs of geometrically distributed random variables [18]. A quadratic dependence is found in ascending runs of sequences of geometrically distributed random variables [20], and in diagonally convex animals (see [17]), leading to a quite different behavior. So we finally obtain the following theorem, which presents another form of the limiting distribution: Theorem 8. Let 1 := j − log n + (s − 1)(log log n − log log s) − log(D1 ) / log s. Then, with integer j and 1 = O(1), Pr[M(n)j ] ∼ G2 (1 ),
n → ∞,
where G2 (1 ) := exp[− exp[−1 log s]]. Let 1 (n) := [log n + (s − 1)(log log n − log log s) − log(D1 )]/ log s and 1 = j − 1 (n) − {1 (n)}. Asymptotically, the distribution is a periodic function of 1 (n) (with period 1), which can be written as log Pr[M(n) 1 (n) + l]e−{1 (n)} log s
−→ n→∞
− e−l log s .
We also have Pr[M(n) = j ] ∼ f2 (1 ), where f2 (1 ) := G2 (1 ) − G2 (1 − 1). 3.2. The moments If we had a rate of convergence property for Theorem 8, the asymptotic moments of M(n) would also be given by periodic functions of 1 (n). They could be written as Harmonic sums which are usually analyzed with Mellin transforms: see Flajolet et al. [8]. The asymptotic non-periodic term in the moments of M(n) would be given by the following conjecture. Conjecture 9. The constant term E¯ in the Fourier expansion (in 1 (n)) of the moments of M(n) is asymptotically given by +∞ ¯ E[M(n) − 1 (n)]i ∼ i [G2 (1 ) − G2 (1 − 1)] d1 . −∞
376
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
Indeed, the analysis of this type of Harmonic sums is detailed in Flajolet [7], where the author uses bounds for tail estimates. In our case, if our Markov chain were reversible, we would obtain, from Keilson [12], that (2)
1/4 hi −x/ hi −1 C Pr i [Tk x] ∼ e 2h2i (2)
for some constant C, uniformly on x and hi
:= Ei (Tk2 ). Now, by (A.1), (A.8) and (A.5),
(2)
hi
2h2i
− 1 = O(ε).
For k log s, respectively, given by log n − log log n, log n and 2 log n, the error bounds are ((log n)s /n)1/4 , ((log n)s−1 /n)1/4 and (2 log n)(s−1)/4 /n1/2 , which would be sufficient to establish our conclusions, following the lines of Flajolet [7]. It is well known that the −x extreme-value distribution function e−e has mean and variance 2 /6. From this, we would for instance derive 1 ¯ . E[M(n)] ∼ 1 (n) + + 2 log s The other periodic terms have very small amplitude (see [8]). From Hitczenko and Louchard [11], we would also derive 2 + 1/12. 6(log s)2
VAR[M(n)] ∼
If we fix s to some given integer, then we can numerically derive a suitable rate of convergence. Indeed, from Aldous [1], we know that, if we define a time measure for the chain to approach stationarity: ⎫ ⎧ ⎡ ⎤ s−1 ⎬ ⎨ n [i, j ] − (j )⎦ 1/e, ∀i , := min n : ⎣1/2 ⎭ ⎩ j =1
then
(i)Pri [Tk x] − exp −x sup x
i
where = C1
(i)hi 1 + log+
i
and C1 is a numerical constant.
i
! (i)hi ,
i
!
(i)hi /
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
377
As our chain is finite, is related to 1/|2 |, where 2 is the second (in module) largest eigenvalue of . For instance, √ √ for s = 4, 2,1 = −7/81 + 4/81 2, 2,2 = −7/81 + 4/81 2, |2 | = 1/9; for s = 20, |2 | = 0.1179696324.... Here we have hi ∼ D/ε and (Ci denote constants) " # D D ∼ C2 1 + ln C3 ε ε ∼ C4 ε/(− ln(ε)) ∼ C5 ε/(k ln(s)) ∼ C6 k s−2 /s k and now, we have suitable error bounds and convergence of the moments. This is considered, in a much more general setting, in [21] 3.3. Maximum run length starting with value u Let us now consider the maximum run length of type u (i.e. starting with value u). We derive ¯ + hi (u) = L(i) (i, j )hj (u), i = u, j
¯ hu (u) = [L(u, k) + k1 (u, k)] +
(u, j )hj (u)
j
−1 (u, k)
(u, l, j ) hj (u). 1 (u, k)
l k
j
Proceeding as above, with now ε :=
(k − 1)s−u , (s − u − 1)!s k−1
we obtain D(u, j ) = and
s 2 (k − 1)s−u , (s − u)! s−u+k−1 k−1
:= j log(s) − log n + (s − u) log j − log[(s − u − 1)!] − log(D(u, j )) .
Note that, as n → ∞, D(u, j ) → s 2 . For u = 1, the limiting distribution is given by Theorem 8. This means that the maximum run length is asymptotically only made of runs of type 1. For u = 2, the simulation is given in Fig. 7. 3.4. Large run in a sequence constructed from independent I (s) random variables, s→∞ Let us first consider (14). As s → ∞, we obtain the stationary generating function lim H () = 22 e + 2 − 4e + 2 + 2e − 2 /2 , s→∞
which is exactly the corresponding formula for permutations (see [20]).
378
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
1
0.8
0.6
0.4
0.2
-4
-2
0
2
4
6
8
10
x Fig. 7. Observed and limiting M distribution function, u = 2.
Also lims→∞ L¯ = 2 and, from (17), we easily derive, with Stirling, 2k lim H1 (k) = . s→∞ (k + 1)! Note that this can also be obtained from (16): as s → ∞, this leads to a generating function G4 () =
2(1 + e − e ) , 2
and 2k (k + 1)! which, again corresponds to the random permutation model: as in [20], we obtain (k + 1)! D/ε ∼ . k [k−1 ]G4 () =
4. Application: A preliminary analysis of a DNA sequence As a simple example of DNA genome, we have first taken AL445469 (Human genomic DNA sequence from clone RP11-254N18), from which we have extracted a string S of lt = 129 480 letters. We use the arbitrary transcription to integers: a → 1, c → 2, g → 3, t → 4. To obtain enough samples, we have divided S into 10 substrings of 12 948 integers each. Moreover, we have used all the 4! = 24 permutations of letters order, leading to 240 strings, which give a reasonable estimate of the histograms we need. First of all, on the complete string S, we have computed the observed distribution of integers, which is not uniform: this gives p ∗ (1) = 0.34 . . . , p∗ (2) = 0.19 . . . , p∗ (3) = 0.18 . . . , p∗ (4) = 0.29 . . . . Moreover, the integers are not independent: an estimated
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
379
0.08 0.07 0.06 0.05 0.04 0.03 0.02 2
4
6
8 10 12 14 16 18 20 22 24 26 28 30
Fig. 8. Genome: observed correlation coefficient.
0.36 0.34 0.32 0.3 0.28 0.26 0.24 0.22 0.2 0.18 0.16 0.14 0.12 0.1 0.08 0.06 0.04 0.02 0
2
4
6
8
10
Fig. 9. Genome: limiting (line) and observed (circle) run length distribution.
correlation coefficient [k] on the string S is given in Fig. 8, with [1] = 0.088 . . . , [2] = 0.055 . . . . The other values are rather small. Next we have analyzed the run length: this leads to a total of 1 07 3964 runs. The fit with the limiting distribution is given in Fig. 9. The fit is reasonable. Now we look at the maximal run length, based on the 240 substrings. The fit with the limiting distribution is given in Fig. 10, with a shift of 12 units!. The fit is very bad. Now we must try to analyze this discrepancy. First we have checked whether it could come from the non-uniformity of the letters distribution. So we have generated lt independent, random integers with distribution p∗ .
380
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
1
0.8
0.6
0.4
0.2
5
0
10
15
20
25
Fig. 10. Genome: limiting (line) and observed (circle) maximal run length distribution, shift = 12.
0.36 0.34 0.32 0.3 0.28 0.26 0.24 0.22 0.2 0.18 0.16 0.14 0.12 0.1 0.08 0.06 0.04 0.02 0
2
4
6
8
10
Fig. 11. i.i.d.: limiting (line) and observed (circle) run length distribution.
This leads to a total of 1 134 888 runs. The fit of the run length with the limiting distribution is given in Fig. 11. The fit is good: our asymptotic equivalents are robust. Next we look at the maximal run length, based on the 240 substrings. The fit with the limiting distribution is given in Fig. 12, with a small shift of 0.3 units. The fit is rather good. So the bad fit in the genome is not due to the non-uniformity. Then we have checked whether it could come from a first-order correlation. So we have computed from S a Markov chain P [i, j ] based on observed couples S[k − 1], S[k]. We have then constructed a random string of lt random variables with this Markov chain. The observed first correlation coefficient is given by [1] = 0.082. The fit of the run length with the limiting distribution
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
381
1
0.8
0.6
0.4
0.2
–2
–1
1
2
3
4
5
6
Fig. 12. i.i.d.: limiting (line) and observed (circle) maximal run length distribution, shift = 0.3.
1
0.8
0.6
0.4
0.2
–2
0
2
4
6
8
Fig. 13. Markov chain(order 1): limiting (line) and observed (circle) maximal run length distribution, shift = 1.9.
is again reasonable. The fit of the maximal run length with the limiting distribution is given in Fig. 13, with a shift of 1.9 units. The fit is rather good. Finally, we have we have checked whether the discrepancy could come from a secondorder correlation. So we have computed from S a Markov chain P [i, j, l] based on observed triples S[k − 2], S[k − 1], S[k] giving the probability that S[k] = l, given S[k − 2] = i, S[k − 1] = j . We have then constructed a random string of lt random variables with this Markov chain. The observed first two correlation coefficients are given by [1] = 0.064, [2] = 0.028. The fit of the run length with the limiting distribution is reasonable.
382
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
1
0.8
0.6
0.4
0.2
–2
0
2
4
6
8
Fig. 14. Markov chain(order 2): limiting (line) and observed (circle) maximal run length distribution, shift = 2.9.
The fit of the maximal run length with the limiting distribution is given in Fig. 14, with a shift of 2.9 units. Again the fit is rather good. So it seems that the discrepancy is due to some long range dependency, which is not observable from the correlation coefficients nor from the run length distribution, but discernable from the maximal run length. The biological explanation of this discrepancy will be investigated in some further work. Let us mention some related work: in [6], Denise et al. have analyzed the random generation of structured genomic sequences. We have analyzed several other genomes: 6 470 333, 2 944 426, 2 627 293, 2 443 900, 15 620 559, 15 281 412. The results are very similar.
5. Conclusion Using a Markov chain approach and a polyomino-like description, we have studied some asymptotic properties of monotone runs of uniformly distributed integer random variables. Some preliminary application to DNA analysis has revealed a long-range dependency. The biological explanation of this phenomena will be the object of some future work.
Acknowledgments The author wishes to thank the Scienze Matematiche e Informatiche “Roberto Magari” for its warm hospitality. In particular, the cooperation with Alberto was quite agreeable and fruitful. He will be deeply regretted by his numerous friends.The careful reading and pertinent comments of the referee led to improvements in the presentation.
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
383
(2)
Appendix A. A detailed analysis of hi and hi
We must first be more precise in the analysis of hi . With (3), (5), (6), we obtain, when l = k + O(1), 1 (k − 1)−i+1 1 (i, l) = g1 (i, l)ε with g1 (i, l) ∼ l−k 1+O , s (s − i)! k (k − 1)−i+1 1 2 (i, l) = g2 (i, l)ε with g2 (i, l) ∼ l−k−1 1+O , s (s − 1)(s − i)! k (k − 1)−i+1 1 1+O . 3 (i, l) = g3 (i, l)ε with g3 (i, l) ∼ l−k−2 2 s (s − 1) (s − i)! k Set hi =
D(i) + (i) + ε(i) + O(ε 2 ). ε
(A.1)
We will now compute the dominant term of (i). We note that ¯ k) + k1 (i, k) = L(i) ¯ − 2 (i, k + 1). L(i, We obtain, from (23), (19), (20), D(i) + ε(i) + ε 2 (i) ¯ − ε 2 g2 (i, k + 1) + D(i) + ε(i) + ε 2 (i) = ε L(i)
s−1 1 1 −1 (i, k) D + ε(u) 1 + O + εND(i) + O(ε 2 ). s−1 k 1
(A.2) The ε term leads, for large k (apart from D, we neglect all O(1/k) error terms) to ¯ + (i) − Dg1 (i, k) (i) = L(i) or [I − ] = ,
(A.3)
where when k → ∞, ¯ (1) = L(1) − Dg1 (1, k), ¯ (i) = L(i), i > 1. Now we premultiply (A.2) by . This leads, with G3 defined by (26), to L¯ = DG3 (k), which conforms to (27). Next (A.3) leads to = M + 1 , where 1 := and M := n 0 (n − 1 × ). M is the Drazin inverse of I − . We refer to Campbell and Meyer [4] for a detailed definition and analysis of the Drazin inverse. We have M = Z−1×
384
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
where Z := [I − + 1 × ]−1 = n 0 [ − 1 × ]n is the potential used in Kemeny et al. [13]. First, by (B.1) (see the next appendix), we know that M is finite. Next, to derive 1 , we premultiply again (A.2) by . When k → ∞, this leads to D + ε + ε 2 = ε L¯ − ε 2 (1)g2 (1, k + 1) + D + ε + ε 2
s−1 1 −εg1 (1, k)(1) D + ε(u) + O(ε 2 ) + O(ε 3 ). s−1 1
The ε term leads of course again to D . The ε2 term leads to 0 = −(1)g2 (1, k + 1) − g1 (1, k)(1)
s−1 1 (u) s−1 1
which allows the determination of 1 . (2) We must now compute the first terms in the expansion of hi := Ei (Tk2 ). We derive (2) (i, w)w 2 hi = k 2 1 (i, k) + +2
u
−2
w
u
w
(i, w, u)whu +
(i, u)h(2) u
u
(i, w, u)whu −
u
w≥k
(i, w, u)h(2) u .
(A.4)
w≥k
We obtain, after some algebra, for large k, (i, w)w 2 = L2 (i) + ε [−2kg2 (i, k + 1) − 2g3 (i, k + 1) k 2 1 (i, k) + w
+g2 (i, k + 1)] + O(ε 2 ), where L2 (i) is given by (13). We set (2)
hi
=
D (2) (i) (2) (i) + (2) (i) + O(ε). + ε2 ε
(A.5)
The next terms of (A.4) lead to (again, apart from D, we neglect all O(1/k) error terms) ¯ (i, w, u)w(u) 2L(i)D/ε +2 u
w
+D(2) (i)/ε 2 + (2) (i)/ε + (2) (i) s−1 1 −2DG(i, k)/ε − 2G(i, k) (u) − 2εG(i, k)N(2) 1(i)D/ε s−1 1
s−1 1 −1 (i, k) D (2) (u)/ε 2 + (2) (u)/ε + εND(2) (i)/ε 2 , s−1 1
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
where G(i, k) is given by (15) and N(2) is again a correction matrix related to u)w. Eq. (A.4) leads, for large k, to
385
w≥k
(i, w,
D (2) (i) + ε(2) (i) + ε 2 (2) (i) ¯ + 2ε 2 = ε2 L2 (i) + 2εD L(i) (i, w, u)w(u) u
w
+D(2) (i) + ε(2) (i) + ε 2 (2) (i) − 2εD[1 (i, k) + 2 (i, k + 1)] s−1 1 (2) −1 (i, k) D (u) + ε(2) (u) + O(ε 3 ). (A.6) s−1 1
The constant term leads to [I − ]D(2) = 0, which confirms that D(2) is independent of i. The ε term leads, for large k, to ¯ + (2) (i) − D (2) g1 (i, k) (2) (i) = 2L(i)D or [I − ](2) = (2) ,
(A.7)
where when k → ∞, (again, apart from D (2) , we neglect all O(1/k) error terms) ¯ − D (2) g1 (1, k), (2) (1) = 2L(1)D ¯ (2) (i) = 2L(i)D, i > 1. Now we premultiply (A.6) by . This leads to ¯ − D (2) G3 (k). 0 = 2LD Hence D (2) ≡ 2D 2
(A.8)
as it should. Next (A.7) leads to (2) = M(2) + 2 ,
where 2 := (2) .
First, by (B.1), we know that M(2) is finite. Next, to derive 2 , we premultiply again (A.6) by . This leads to D (2) + ε(2) + ε 2 (2) = ε2 L2 + 2εD L¯ + 2ε 2 (i) (i, w, u)w(u) u
i
+D
(2)
+ ε
(2)
+ ε 2
(2)
w
− 2ε D kG3 (k) + 2
(i)g2 (i, k + 1)
i
−εG3 (k)D (2) − ε 2 G3 (k)
s−1 1 (2) (u) + O(ε 3 ). s−1 1
386
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
The ε term leads of course again to D (2) = 2D 2 . The ε 2 term leads, when k → ∞, to 0 = s2 + 2 (i) (i, w, u)w(u) − 2D(1) [kg1 (1, k) + g2 (1, k + 1)] u
i
−(1)g1 (1, k)
1 s−1
w s−1
(2) (u),
1
which allows the determination of 2 . Appendix B. An explicit expression for M We proceed as in Section 2.2.3. We must compute M := that S := n 1 (n − 1 × ) can be written as ⎡ ⎤ w S(i, j ) = lim ⎣ w n n (i, j ) − (j )⎦ . w→1 1−w
n 0 (
n
− 1 × ). We see
n1
But this amounts to compute ˜ S(i, j ) = lim i [j ]((w, ) − i )/w + w→1
1 (j ) , 1−w
˜ where (w, ) (see Section 2.2.3) is now computed with the starting value f˜0 () = i . After all computations, and resubstituting = /, this gives a first term ()/(1 − w) (see (12)), which cancels the singularity at w = 1, and finally, we obtain S(i, j ) = [j ]R(), where R() = −3i /(s(1 − ) − {2s+1 [(−s − 4 + 3i) + (1 + s − 3i)] +2[[4 + 3i(s − 1) − s(s + 3)] + [−1 + 3i + s(2s − 6i + 4)] +s(3i − 1 − s)2 ]}/[(s − 1)s 2 (1 − )3 ]. And finally, 2 M(i, j ) = S(i, j ) + [[i = j ]] − (j ).
(B.1)
Appendix C. The -mixing property Let . . . , x−1 , x0 , x1 , . . . be a strictly stationary sequence of random variables. For a b, define Mba as the -field generated by the random variables xa , . . . , xb . Consider a nonnegative function of positive integers. We shall say that the sequence xn is -mixing if, 2 Here we use the indicator function notation proposed by Knuth et al. [10].
G. Louchard / Theoretical Computer Science 346 (2005) 358 – 387
387
for each k, −∞ < k < ∞, and for each n, n1, E1 ∈ Mk−∞ and E2 ∈ M∞ k+n together imply $ | Pr(E1 E2 ) − Pr(E1 − Pr(E2 )|(n) Pr(E1 ). If the Markov chain is finite, irreducible and aperiodic, then xn is -mixing, with (n) = an , < 1. References [1] D. Aldous, Markov chains with almost exponential hitting times, Stochast. Process. Appl. 13 (1982) 305–310. [2] D. Aldous, Probability Approximations via the Poisson Clumping Heuristic, Springer, Berlin, 1989. [3] P. Billingsley, Convergence of Probability Measures, Wiley, New York, 1968. [4] S.L. Campbell, C.D. Meyer, Generalized Inverse of Linear Transformations, Pitman, London, 1979. [5] P. Crescenzi, A. Del Lungo, R. Grossi, E. Lodi, L. Pagli, G. Rossi, Text sparsification via local maxima, in: 20th Conf. on the Foundation of Software Technology and Theoretical Computer Science, 2000. [6] A. Denise, Y. Ponty, M. Termier, Random generation of structured genomic sequences, in: Proc. RECOMB2003, 2003. [7] P. Flajolet, Approximate counting: a detailed analysis, BIT 25 (1985) 113–134. [8] P. Flajolet, X. Gourdon, P. Dumas, Mellin transforms and asymptotics: Harmonic sums, Theoret. Comput. Sci. 144 (1995) 3–58. [9] P. Flajolet, B. Sedgewick, Analytic combinatorics, Singularity Analysis of Generating Functions, 2004, to appear (Chapter 6). [10] R.L. Graham, D.E. Knuth, O. Patashnik, Concrete Mathematics, second ed., Addison-Wesley, Reading, MA, 1994. [11] P. Hitczenko, G. Louchard, Distinctness of compositions of an integer: a probabilistic analysis, Random Structures Algorithms 19 (3,4) (2001) 407–437. [12] J. Keilson, Markov Chain Models-Rarity and Exponentiality, Springer, Berlin, 1979. [13] J.G. Kemeny, J.L. Snell, A.W. Knapp, Denumerable Markov Chains, Van Nostrand, Princeton, NJ, 1966. [14] S. Kotz, S. Nadarajah, Extreme Value Distributions, Imperial College Press, 2000. [15] G. Louchard, Probabilistic analysis of some directed animals, Theoret. Comput. Sci. 159 (1) (1996) 65–79. [16] G. Louchard, Probabilistic analysis of column-convex and directed diagonally convex animals, Random Structures Algorithms 11 (1997) 151–178. [17] G. Louchard, Probabilistic analysis of column-convex and directed diagonally-convex animals. II: trajectories and shapes, Random Structures Algorithms 15 (1999) 1–23. [18] G. Louchard, Runs of geometrically distributed random variables: a probabilistic analysis, J. Comput. Appl. Math. 142 (1) (2002) 137–153. [19] G. Louchard, H. Prodinger, Probabilistic analysis of Carlitz compositions, Discrete Math. Theoret. Comput. Sci. 5 (1) (2002) 71–96. [20] G. Louchard, H. Prodinger, Ascending runs of geometrically distributed random variables: a probabilistic analysis, Theoret. Comput. Sci. 304 (2003) 59–86. [21] G. Louchard, H. Prodinger, The moments problem of extreme-value related distribution functions, 2004, http://www.ulb.ac.be/di/mcs/louchard/mom7.ps. [22] G. Louchard, W. Szpankowski, Average profile and limiting distribution for a phrase size in the Lempel–Ziv parsing algorithm, IEEE Trans. Inform. Theory 41 (1995) 478–488. [23] W. Szpankowski, Average Case Analysis of Algorithms on Sequences, Wiley, New York, 2001.
Theoretical Computer Science 346 (2005) 388 – 417 www.elsevier.com/locate/tcs
Efficient iteration in admissible combinatorial classes夡 Conrado Martínez∗ , Xavier Molinero Departament de Llenguatges i Sistemes Informàtics, Universitat Politècnica de Catalunya, E-08034 Barcelona, Spain
Abstract The exhaustive generation of combinatorial objects has a vast range of practical applications and is a common theme in the combinatorial research field. But most previous works in this area concentrate in the efficient generation of particular families of combinatorial objects. The novel approach of the work presented here is to provide efficient generic algorithms, where the input is not just the size n of the objects to be generated but a finite specification of the combinatorial class whose objects we want to list. Since the algorithms are generic, they do not exploit any particular feature of the class to be generated; nevertheless, they work in constant amortized time per generated object, that is, they generate all N objects of a given size in (N) time. These algorithms are useful for both rapid prototyping and for inclusion into general purposes libraries because of their flexibility, with only a relatively modest penalty on efficiency. Furthermore, the framework presented in this paper nicely combines with the framework developed by Flajolet et al. for the enumeration and random generation of combinatorial objects, and with the framework developed by the authors for the unranking of combinatorial objects. © 2005 Elsevier B.V. All rights reserved. Keywords: Generation of combinatorial objects; Iteration in combinatorial classes; Unranking; Generation of combinatorial objects in lexicographic order; Constant amortized time
夡 This research was supported by the Future and Emergent Technologies programme of the EU under contract IST-1999-14186 (ALCOM-FT) and the Spanish Min. of Science and Technology project TIC2002-00190 (AEDRI II).
∗ Corresponding author. Tel.: +34 934137849; fax: +34 934137833.
E-mail addresses:
[email protected] (C. Martínez),
[email protected] (X. Molinero). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.028
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
389
1. Introduction The exhaustive generation of all objects of a given size in a combinatorial class has been the subject of intense research for already four decades (see for instance [10,16,17,22]). Many efforts are still devoted in the quest for efficient algorithms for combinatorial classes for which no such algorithms are known, as well as to the improvement of existing algorithms. Among the numerous researchers that have been attracted by this important topic was Alberto del Lungo [2,3,11], to whom we dedicate this paper. Efficient algorithms exist for the generation of permutations, trees, strings, cycles of k beads, partitions, subsets of k elements out of n, etc. (see, for instance, [10,16,18]). Although it is not always possible to attain it, the ultimate goal in efficiency is to generate all N objects of size n of a given class in time proportional to N; in other words, to achieve constant amortized time (CAT) per generated object. Sometimes it is desired to generate the objects in a particular order, for instance, permutations in lexicographic order or bitstrings in Gray order, but in many other situations we can choose whatever generation order yields the best performance. But in any case the vast majority of results in this area concern particular combinatorial classes or more or less restricted families of them. In this paper we follow a rather different approach, since our goal is to develop a generic algorithm to solve the exhaustive generation problem when the class of the objects to be generated is a parameter itself. Other generic approaches, such as the ECO method (see for instance [1–3,11]) have been proposed, but they differ substantially with the one presented here, each approach imposing different requirements on the classes that can be generated, the way to express them, etc. In particular, our algorithms need to be able to count how many objects there are in a given combinatorial class, hence the combinatorial classes we can deal with are those built using the so-called admissible operators. This approach was fully exploited by Flajolet et al. [5], with their celebrated application to the random generation of combinatorial objects. Later, the authors of this paper showed that this approach can also be successfully used for the unranking of combinatorial objects, that is, given a specification for a combinatorial class, a size n and a rank i, generate the ith object of size n in the given class [13]. One of the main contributions of this paper is to show the viability of this generic approach to cope with the exhaustive generation problem, providing an elegant, effective and efficient solution. Examples of combinatorial classes which can be exhaustively generated using our approach include permutations, functional graphs, integer partitions, integer compositions, surjections, regular languages, simply generated families of trees (including binary trees, Cayley trees and plane general trees, among others), Dyck paths, etc. For instance, to list all partitions of the number n we could supply our algorithm with the specification P = MSet(Z × Seq(Z)) and ask it to exhaustively generate all objects of size n in the class P. The specification above simply says that an integer partition is a multiset—repetitions are thus allowed— of integers; each integer is represented by an atom (Z) followed by a sequence of atoms
390
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
(Seq(Z)), in other words, it is represented by a sequence of at least one atom. The length or size of such a sequence coincides with the represented integer, and the size of the partition is hence the sum of the sizes of its components. Another example is the generation of all words of some given size in a regular language, for instance, the language L = {w ∈ (a + b)∗ | w does not contain two consecutive a’s}. We can express this language using the specification L = M + M × a, M=+M×b+M×a×b and then supply this specification to our algorithm and request the complete list of objects in L of size n. In the equations above, represents the class that only contains an object of size 0, + denotes disjoint unions, × is the usual Cartesian product, and a and b denote atomic classes each containing a single object of size 1. Any regular language can be unambiguously be described in a similar way as this toy example, and hence exhaustively generated using our algorithms. It is also possible to exhaustively generate all words of a given size in a context-free language, provided that we find a suitable unambiguous grammar for the language. Since the algorithms described in this work are generic, they do not take advantage of particular features of the combinatorial class whose objects we want to generate. However, the algorithms achieve constant amortized time per generated object, and thus they are competitive when compared with algorithms specifically designed for the corresponding class. The fact that our algorithms exhibit CAT performance is one of the main results in this paper. Most likely, the price of being general is that the involved constant factors are a bit larger than in their ad-hoc counterparts, but the flexibility of our generic algorithms makes them attractive for rapid prototyping and for their inclusion in general combinatorial libraries, like the combstruct package for MAPLE [4,23], or the MuPAD-combinat package [8]. The interest that such generic algorithms can have is well exemplified by the following situation: the combstruct package provides efficient routines for counting and random generation given a finite specification of a combinatorial class; it also provides a routine allstructs which produces a list of all combinatorial objects of a given size. But, except for a few particular cases where allstructs calls a specialized efficient algorithm, the task is performed by repeatedly drawing objects at random until all them have been generated. Of course, this is useless if the objects have to be processed in some specific order or different executions have to generate the objects in the same order. Furthermore, it is usually not as efficient as using an algorithm specifically designed for exhaustive generation, like the ones in this paper. This paper is organized as follows. In Section 2, we introduce the basic concepts and notation needed in the following sections. Sections 3 and 4 present the algorithms for the generation of labelled and unlabelled classes, respectively. In Section 5 we analyze the performance of our algorithms. Preliminary descriptions of the results in this paper have appeared in [12,14].
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
391
2. Admissible classes, orders and iterators 2.1. Admissible classes A key aspect in the design of our generic iteration algorithms is the ability to determine how many elements of a given size there are in the given combinatorial class. Given a combinatorial class A, we denote by An = { ∈ A | || = n} the subset of objects in A of size n. We use the corresponding lowercase letters to denote the cardinality of such subset. Thus an = #An is the number of objects in An . Since the ability to count the number of objects in An is crucial in our algorithms, we will only consider admissible combinatorial classes. Admissible combinatorial classes include the -class (which only contains an element of size 0, denoted ), atomic classes (those that only contain an element of size 1) and those inductively built using admissible operators on admissible classes (see for instance [6,20,21]). Definition 1. Let be an operator on combinatorial classes A1 , . . . , Ak . The operator is admissible if and only if there exists an operator over the generating functions A1 (z), . . . , Ak (z) corresponding to the classes A1 , . . . , Ak such that the generating function C(z) of the class C = (A1 , . . . , Ak ) satisfies C(z) = (A1 (z), . . . , Ak (z)), where the generating function C(z) of any unlabelled class C is || C(z) = cn z n = z , n0
∈C
whereas the generating function for a labelled class C is C(z) =
n0
cn
z|| zn = . n! ∈C ||!
Examples of admissible operators include disjoint union, Cartesian products, sequences, sets, etc. However, other common combinatorial constructs, like difference and intersections, are not admissible. We will concentrate in a fixed collection of admissible operators. For unlabelled combinatorial classes, where the atoms that compose the objects in the class are not distinguishable, 1 we will consider classes built using disjoint unions (‘+’), Cartesian products (‘×’), sequences of objects (‘Seq’), cycles of objects (‘Cycle’), powersets of objects (‘PSet’) and multisets of objects (‘MSet’). For labelled combinatorial classes, where the atoms of each object of size n bear distinct labels in [1..n], we consider disjoint unions (‘+’), labelled or partitional products (‘’), sequences of objects (‘Seq’), cycles of objects (‘Cycle’) and sets of objects (‘Set’). Since each atom carries a distinct label the notion of a labelled multiset makes no sense. 1 We can have an unlabelled object like the multiset {a, a, a, b, c} with 5 atoms, where there are 3 “distinct” atoms or symbols (a, b, c), but we cannot distinguish between the three a’s, for instance.
392
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
Other admissible operators, like substitutions or sequences, cycles, sets, powersets and multisets with restricted number of components, can also be easily accommodated in our framework. We have actually designed, analyzed and implemented algorithms to cope with classes built using these other operators, but we will not explain them in detail. Even though we are considering a relatively small number of combinatorial operators, a large number of important combinatorial classes can be expressed in terms of these operators, including permutations, Cayley trees, all sorts of simply generated families of trees, surjections, functional graphs, partitions, etc. Let us formalize now the notion of an admissible combinatorial specification. Definition 2. An admissible combinatorial specification is a finite set of equations of the form A1 = 1 (A1,1 , A1,2 , . . . , A1,n1 ), A2 = 2 (A2,1 , A2,2 , . . . , A2,n2 ), ... Ak = k (Ak,1 , Ak,2 , . . . , Ak,nk ), where each Ai,j is either , an atom (generically denoted Z), or the left-hand side A of one of the equations, for some , 1 k. Furthermore, the symbols A in the lefthand side of the equations are all distinct, and all the operators belong to the set {+, ×, Seq, Cycle, PSet, MSet}, in the case of unlabelled specifications, or to the set {+, , Seq, Cycle, Set}, in the case of labelled specifications. The restriction of cardinalities (number of components) of the labelled operators Seq, Cycle, Set and unlabelled operators Seq, Cycle, PSet, MSet is also admissible, i.e., operators of the form X(·, card = k), X(·, card < k) and X(·, card > k) are admissible for any constant k. So a combinatorial class A is admissible if it is an -class, an atomic class or there exists an admissible combinatorial specification such that A is the left-hand side of one of the equations. For instance, the class B of (unlabelled) binary trees is admissible since it can be specified by B = Z + P, P = B × B, which is customarily written B = Z + B × B. As another example, a functional graph is a set of cycles of Cayley trees, so one possible specification for the class F could be F C T S
= Set(C), = Cycle(T ), = Z S, = Set(T ),
or more briefly, F = Set(Cycle(T )), T = Z Set(T ). Fig. 3 in page 10 gives an example of a functional graph of size 9. Other examples of admissible combinatorial classes and their specifications are given in Table 1.
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
393
Table 1 Examples of admissible combinatorial classes and their specifications Class
Specification
Plane general trees Permutations Set partitions Surjections
C = Z × Seq(C) P = Set(Cycle(Z)) S = Set(Set(Z, card > 0)) F = Seq(Set(Z, card > 0))
For the rest of this paper we will assume that given an admissible specification for a class A and a size n, we can efficiently compute an [4] by means of a routine count which receives a finite specification of the class A and the size n. 2.2. Ordering the objects Another key aspect in the design and analysis of the algorithms to generate all the objects in An is the choice of the order that we shall use to generate the objects. We want our algorithms to be deterministic so that they always produce the same list of objects given an admissible specification for A and a size n. Since our algorithms should work for any admissible class A, what we need now is to provide an inductive definition of the order ≺An among the objects of An , in terms of the orders of the classes and operators used to build An . For the rest of the paper, the rank of an object in An is the number of objects that precede in An , according to ≺An . Thus the first object has rank 0 and the last one has rank an − 1. The order for the -class and atomic classes is trivial as they only contain one object. For disjoint unions (either labelled or unlabelled), if C = A + B then we say that, for any n, the objects in An come first, then the objects in Bn . More formally, if and are two objects in Cn then ≺Cn if and only if ∈ An and ∈ Bn , or both belong to An and ≺An , or both belong to Bn and ≺Bn . It is important to point out here that even though A + B B + A the order induced by these two isomorphic specifications is not the same. In general, the order in a class C is not dictated by the combinatorial structure of C itself, but by the specification that we have used—and there will be many different but equivalent ways to specify a given class. Things get more interesting when we consider products. In the case of unlabelled products C = A × B, if we have two objects = (, ) and = ( , ) such that || = | | = j and || = | | = n − j then it is natural to use the lexicographic criterion to order them: ≺Cn if ≺Aj , or if = and ≺Bn−j . But we need also to define the order when || = | |. The most obvious solution, the lexicographic order, is induced by the specification Cn = A0 × Bn + A1 × Bn−1 + A2 × Bn−2 + · · · + An × B0 , although other “exotic” choices are possible, like the boustrophedonic order [5,13] induced by the specification Cn = A0 × Bn + An × B0 + A1 × Bn−1 + An−1 × B1 + · · · .
394
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
For the generation problem, however, the boustrophedonic order yields no performance improvement if compared to the lexicographic order; hence, we shall only consider the lexicographic order, formally defined as follows: = (, ) ≺Cn = ( , ) if and only if || < | |, or || = | | = j and ≺Aj , or = and ≺Bn−j . When labelled products are considered we need to take also into account the labels of the atoms. Recall that given two labelled objects and of sizes j and n − j , respectively, n their labelled product is a set of j labelled objects of size n which result from the nj consistent relabellings of the pair (, ) so that each atom of the pair has a distinct label in the range [1..n] while respecting the order induced by the original labels of and . For example, if = 132 and = 21 (these two objects belong to the labelled class Seq(Z), i.e., permutations) then 2 = {13254, 14253, 14352, . . . , 35421}. Therefore we can write . AB = ∈A,∈B
Given a partition of [1..n] into a j-subset {1 , . . . , j } and a (n−j )-subset {1 , . . . , n−j }, we denote (, , ) the labelled object of size n which results when we relabel the atoms of the pair (, ) according to . For example, if = 21, = 213 and = {1, 3}, {2, 4, 5} then (, , ) = 31425. We say that is a (n, j )-partition. Let Sn,j denote the set of all possible (n, j )-partitions and assume that it is equipped with some well-defined order ≺Sn,j . Two different orders for the objects in Aj Bn−j arise then in a natural way stemming from the following specifications: (, , ) (1) Aj Bn−j = ∈Sn,j ∈Aj ∈Bn−j
and Aj Bn−j =
∈Aj ∈Bn−j ∈Sn,j
(, , ).
(2)
If we use the specification (1) for C = A B, we have that for two objects and of size n, = (, , ) ≺ = ( , , ) if || < | |, or || = | | = j and ≺Sn,j , or = and ≺Aj , or = and = and ≺Bn−j . On the other hand, if we use the specification (2) we have that = (, , ) ≺Cn = ( , , ) if || < | |, or || = | | = j and ≺Aj , or = and ≺Bn−j , or = and = and ≺Sn,j . We will use the name structure-first (or SF for short) for the first order, whereas the second order will be called partition-first (or PF for short). As an example, Figs. 1 and 2 show all Cayley trees of size 3 in SF and PF order, respectively. The orders induced by other combinatorial constructions are similarly inspired. For instance, in the case of sequences, we induce the corresponding order from the isomorphism Seq(A) = + A × Seq(A).
(3)
2 We are making a slight abuse of notation here: we have refrained from writing = (Z , (Z , (Z , ))), 1 3 2 = (Z2 , (Z1 , )), etc., in favor of the usual and more readable form = 132, = 21, . . ..
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
395
Fig. 1. Cayley trees of size 3 in SF order.
Fig. 2. Cayley trees of size 3 in PF order.
The same isomorphism is used for labelled sequences, replacing the unlabelled operators (+, ×) by their labelled counterparts (+, ). We will give all the orders not presented here (sets, cycles, powersets, multisets, etc.) in Sections 3 and 4, as we present the corresponding algorithms. 2.3. Iterators A commonly encountered abstraction in Computer Science is that of an iterator, which is an object that can be used to make a traversal in a collection of other objects. In our case, the collection of objects to be traversed is not explicitly stored anywhere, but has to be computed on-the-fly as the iterator advances through the collection. That means that in our context an iterator must contain itself the current combinatorial object in the collection. Our iterators will also store additional information which will be used to advance the iterator to the next current object. Let us consider the following example of use: FunctGraphSpec:= [F, {F = Set(Cycle(T)), T = Z * Set(T)}, labelled]; itr:= init_iter(FunctGraphSpec, size = 20); while not is_last(itr) do DoSomething(get_object(itr)); itr:= next(itr); endwhile
The first line provides a specification FunctGraphSpec for functional graphs in three parts: the class that we want to generate (F), the set of equations of the specification, 3 and an explicit indication that the specification is for a labelled class. The loop applies (exactly once) the function DoSomething to each functional graph of size 20. 4 We assume that if the iterator itr represents the actual last functional graph of size 20 and we call next upon 3 It is not very difficult to implement the algorithms so that they accept a more flexible syntax than that suggested by our Definition 2. 4 Of course, you will never apply this particular example in practice. The number of functional graphs of size 20 is so big that even if we spent one nanosecond to generate and process each object it will take more than 33 million centuries to finish the task.
396
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
Fig. 3. An example of a functional graph of size 9.
it, then itr will afterwards represent a special fictitious object (this is usually known as past-the-end convention). The Boolean function is_last returns true when the iterator is the fictitious object and returns false otherwise. The most crucial part of our task is the design of the functions init_iter and next. The former sets up the appropriate representation and additional information for the first object, and the latter advances from the current object to the next one. There are many ways in which the current combinatorial object can be represented and the convenience of each one of these will typically depend on the application. Translating the internal representation of the current object used within the iterator itr into the most convenient representation is get_object’s task (or of the combination of DoSomething and get_object). For the time being, we will assume that get_object produces a linear representation of the current object like Set(Cycle(8 * Set(3 * Set(1, 9)), 5 * Set(7), 2, 6), Cycle(4))
to represent the functional graph shown in Fig. 3. But the important aspect here is how the current combinatorial object is internally represented within the iterator: we should look for a suitable internal representation that eases the computation of the next object, while not making it computationally difficult or expensive to “extract” the current object. We use a tree structure to represent combinatorial objects. The leaves of such structure correspond to atomic objects (of size 1) and to (of size 0). Internal nodes are “labelled” by the admissible operators, including those that we have seen so far. In addition of the name of the operator, each internal node contains a wealth of information concerning the (sub)object represented by the subtree rooted at that node: its size n, the rank of the object within its class, the class A the object belongs to, the number an of objects in An , etc. Notice that some of these fields of information will store large integers and we will need to perform arithmetic operations on them. The nodes might also contain information giving direct access to the linear or conventional representation of the object so that the updates in the tree representation can be readily and efficiently be reflected in the linear representation of the object. We will not describe these improvements in detail, though.
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
397
Fig. 4. The internal representation of the permutation = 635241 as an object in the class P = Set(Cycle(Z)).
In the case of labelled objects, internal nodes also contain information about the labels used on the object’s atoms. For instance, each node corresponding to a labelled product contains the (n, j )-partition used to relabel the pair, the rank of the partition among the nj possible partitions, and some additional data structures which allow for fast update of the atoms’ labels. For example, if we are using PF order for labelled objects, in order to move from one object to its successor we should change (if possible) the current partition to the next partition; typically this implies that two labels are exchanged in the partition and thus only a few atoms have to exchange their labels. The trees that we use to represent objects are binary. When an object belongs to a disjoint union A + B the root is labelled ‘+’ and only one of its subtrees is used (in particular, we will systematically use the right subtree). The root of the subtree indicates whether the object actually belongs to A or to B. Internal nodes labelled ‘Seq’, ‘Set’, ‘Cycle’, . . . are binary. The reason is that, except for empty sequences, sets, powersets or multisets, we will decompose each object in such classes in two parts. For instance, a labelled cycle in Cycle(A) will be decomposed in a first component represented by the left subtree which is some object in the base class A, and a second component represented by the right subtree which is a sequence of A’s. Fig. 4 conveys most of the ideas presented so far: the first part of the figure shows the decomposition into cycles of the permutation = 635241; the binary tree below shows how this particular object is internally represented within an iterator. But notice that if we specify the class of permutations by P = Seq(Z) then the internal representation of the same object is totally different. In the algorithms given in the following sections, we use pseudocode to express them. Given a pointer p to an internal node (we will say p is a ptrNode), p → field refers
398
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
to the attribute or field of the given name in the internal node. All internal nodes contain attributes like size (the size of the object), class (the class to which the object belongs), count (the number of objects of that size in the class), rank (the rank of the current object), and several others whose meaning will be explained together with the algorithms. Also, each node contains pointers left and right to the roots of the respective subtrees.
3. Iterating through labelled objects The generation of labelled objects is conceptually easier and more “homogeneous” than the generation of unlabelled objects, mainly thanks to the concept of boxed products [7] which provides an elegant solution to the problem of iterating through labelled sets and cycles. However, for the generation of labelled objects we will need to find an efficient way to generate the labellings of the objects (we address this issue in Section 3.2), a problem which of course does not arise in the generation of unlabelled objects. The subsections ahead consider the iteration through disjoint unions, labelled products, sequences, sets and cycles of labelled objects. At the highest level, though, the next routine is nothing but a switch to determine, on the basis of the current object’s class, which one of the routines (e.g., next_union, next_lprod, . . . ) we need to use. We assume here that next already receives a pointer p to the root node of the current object’s internal representation. procedure next(p: ptrNode) return ptrNode if p → class = then . . . fi if p → class = Atom then . . . fi if p → class = A + B then return next_union(p) fi if p → class = A B then return next_lprod(p) fi ... end 3.1. Iterating through labelled disjoint unions To generate all the objects of size n in A + B is not too difficult (see Algorithm 1). We assume already that the rank r of the current object is strictly smaller than an + bn − 1. If r < an − 1 then the current object is not the last in An and we recursively apply the procedure to obtain the next object in An , in particular, we make a recursive call to function next in the subtree beneath. As we have already said, in the representation of disjoint unions we always use the right subtree and leave the left subtree empty. When r = an − 1 we have to replace the current object (the last one in An ) by the first object in Bn using the initialization routine for B. On the other hand, if the current object’s rank is r > an − 1, since r < an + bn − 1 then it means that we have already generated all objects in An and the current object belongs to Bn , so the same idea applies but now to produce the next object in Bn . Of course, the initialization routine for (A + B)n prepares the root node of the iterator and uses An ’s initialization routine to get the first object in (A + B)n (unless An = ∅; then we would have to use Bn ’s init routine).
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
399
Algorithm 1. Computing the next object in a class A + B procedure next_union(p: ptrNode) return ptrNode {p points to a node representing an object in A + B} p → rank := p → rank + 1 if p → rank p → count then return p fi if p → right → rank = p → right → count − 1 then {p → right must be the last object in An } p → right := init(B, p → size) else {there are still objects in p → right → class} p → right := next(p → right) fi return p end In some implementations the replacement of the right subtree representing An ’s last object by Bn ’s first object will require that the nodes of the subtree representing the last object in An are explicitly released back to the free storage. In other implementations we may have developed an special purpose memory allocator that recycles nodes. This is particularly useful for leaf nodes, since an object of size n will exactly contain n atom nodes and at most n + 1 -nodes. Hence, each time that we need a “new” leaf node we actually reuse one that has just been released. However, in Algorithm 1 and for the rest of this paper, we assume for simplicity that our “programming language” has some garbage collection system that will automatically take care of the unused nodes.
3.2. Iterating through labelled products The algorithm for labelled products is a bit more complicated and depends on the order (SF or PF) that we have chosen. An important component of the algorithm is the method that we use to compute the successor of a given (n, j )-partition, which implicitly imposes the order ≺Sn,j . Let us consider first the generation of labelled products in PF order. For the internal node corresponding to the current object and pointed to by p, the current partition is given by p → partition and its rank by p → partition_rank. If this rank is less than nj −1, then we move onto the next labelled object by changing the (n, j )-partition. This is accomplished by the procedure next_label, which besides changing the current partition by the next one, updates a few additional fields to reflect the change in the labels of the atoms. For instance, we can use Nijenhuis–Wilf’s algorithm [16] or Kemp’s algorithm [9] to compute the next j-subset, as the basis for our algorithm to generate (n, j )-partitions. One important property of the two mentioned algorithms is that they generate all j-subsets in nj time; in other words, both algorithms work in constant amortized time. This property extends to the algorithm that we use in next_label. We will discuss this procedure in more detail later.
400
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
Assume now that the rank of the current partition is nj − 1. That means, that we have to change at least one of the objects in the pair; if the second component of the pair, represented by the subtree p → right is not the last object in Bn−j then we recursively apply the procedure to the right subtree in order to compute the next object in Bn−j . On the other hand, if the object to the right is the last one in its class, we should compute the successor of the object given by p → left in Aj , and change the second component to the first object in Bn−j . But if the first component of the current pair is indeed the last object in Aj , we should find the first j > j such that Aj Bn−j = ∅ and initialize the current object with subtrees representing the first object in Aj and Bn−j , respectively. Notice the explicit use of the function count to find the first j > j such that aj bn−j = 0. A concise description of this algorithm to generate labelled products is given in Algorithm 2. Algorithm 2. Computing the next object in a class A B in PF order procedure next_lprod(p: ptrNode) return ptrNode {p points to a node representing an object in A B} j := p → left → size; n := p → size; A := p → left → class; B := p → right → class p → rank := p → rank + 1 if p → rank p → countthen return p fi
if p → partition_rank < nj − 1 then next_label(p) p → partition_rank := p → partition_rank + 1 return p fi p → partition := {1, 2, . . . , j }, {j + 1, . . . , n} p → partition_rank := 0 if p → right → rank < p → right → count − 1 then p → right := next(p → right); return p fi if p → left → rank < p → left → count − 1 then p → left := next(p → left) p → right := init(B, n − j ) return p fi j := j + 1 while j n and (count(A, j ) = 0 or count(B, n − j ) = 0) do j := j + 1 end p → partition := {1, 2, . . . , j }, {j + 1, . . . , n} p → left := init(A, j ) p → right := init(B, n − j ) return p end
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
401
We complete our description of the generation of labelled products by giving now the missing details of the procedure next_label. The root node of the current object belonging to Aj Bn−j stores the current partition as an array of size n called partition. The contents of the array are stored in ascending order. We will also need an additional array inv_part such that if partition[i] = k then inv_part[k] = i, for 1 i, k n. The node will also contain the permutation of the labels attached to the object’s atoms in an array perm of size n and its inverse in another array inv_perm. Our routine next_label is based upon Kemp’s algorithm for the next j-subset. Nijenhuis–Wilf’s algorithm could have been similarly adapted. One of the modifications that we need is to update the perm and inv_perm arrays to reflect the changes made in partition. Basically, each time the algorithm swaps a label with a label in partition then we have to perform the following changes: p := inv_ perm[]; q := inv_ perm[ ] perm[p] ↔ perm[q] inv_ perm[] ↔ inv_ perm[ ] But other modifications are necessary to be able to iterate through full (n, j )-partitions. Both Kemp’s and Nijenhuis–Wilf’s algorithms maintain only the j-subset of the current partition (the (n − j )-subset in the partition is implicit), and they do it only for j n/2 . Thus we must modify Kemp’s algorithm in order to maintain the full (n, j )-partition for 0 j n, while still guaranteeing that it works in constant amortized time. The situation where j > n/2 can be dealt with reversing the rôles played by the first half and the second half of the partition array (and keeping track of this fact, to maintain the lexicographic order of the partitions). But maintaining the full (n, j )-partition and being able to compute the next one in constant amortized time is more complicated; the array inv_ part is a must here, because it allows us to know where and how do we have to update a label which “moves” from the j-subset to the (n − j )-subset or vice-versa. The bulk of next_label code is given in Algorithm 3. For simplicity, we have not included the code necessary to update perm and inv_ perm arrays; we have also omitted references to the node that stores the corresponding arrays. The cost to generate the nj partitions is proportional to nj ; hence, generating each partition takes constant amortized time. The only difference in performance between Kemp’s algorithm and Algorithm 3 comes from lines (22) to (25). A simple counting argument n−r−2 reveals that there are exactly n−r−j (n, j )-partitions for which the loop (22)–(25) (or its analogue for j > n/2 ) makes exactly r iterations. Hence, the total cost to generate all n j partitions contributed by these lines is proportional to n−j −1
r
r=2
which is O
n−r −2 n−r −j
n j
.
=
n+j −2 n−3 − (n − j ) n−j −2 j
402
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
Algorithm 3. Computing the next (n, j )-partition in next_label 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30.
if j > n/2 then . . . else i := j while i 1 and partition[i] = n − j + i do i := i − 1 end i := partition[i] + 1; i := partition[i] partition[i] ↔ partition[inv_part[i ]] inv_part[i ] ↔ inv_part[i ] {Update also here perm and inv_perm} if partition[i] + 1 = partition[i + 1] − 1 then for k := i + 1 to j do k := partition[k − 1] + 1; k := partition[k] partition[k] ↔ partition[inv_part[k ]] inv_part[k ] ↔ inv_part[k ] if inv_part[k ] < n and partition[inv_part[k ]] > partition[inv_part[k ] + 1] then z := inv_part[k ] for t := k + 1 to j do partition[t] := partition[t − 1] + 1 inv_part[partition[t]] := t end for t := z to n do partition[t] := t inv_part[t] := t end break {finishes loop on k (lines 11 to 28)} fi end fi fi
The generation of labelled products in SF order is quite similar to the generation in PF order, but we do not change the current object’s partition until all pairs (, ) have been generated and the current partition implicitly applied to all them. Algorithm 4 is just an outline, where we have tried to emphasize the (small) differences with Algorithm 2. For both SF and PF order, the initialization for A B is achieved by finding the smallest j 0 such that Aj Bn−j = ∅ and setting up a root node with the initial partition,
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
403
partition_rank = 0, rank = 0, etc. Finally, its subtrees are initialized with the first objects in Aj and Bn−j , respectively. Algorithm 4. Computing the next object in a class A B in SF order procedure next_lprod(p: ptrNode) return ptrNode {p points to a node representing an object in A B} ... if p → right → rank < p → right → count − 1 then p → right := next(p → right); return p fi if p → left → rank < p → left → count − 1 then p → left := next(p → left) p → right := init(B, n − j ) return p fi if p → partition_rank < nj − 1 then next_label(p) p → partition_rank := p → partition_rank + 1 return p fi j := j + 1 while . . . do j := j + 1 end ... end
3.3. Iterating through sequences, sets and cycles Sequence objects are represented by a single leaf corresponding to or a binary tree whose left subtree represents the head of the sequence and whose right subtree represents the remaining sequence, the tail of the sequence. The order for Seq(A) and the algorithm to generate its objects directly stem from the isomorphism Seq(A) = + A Seq(A).
(4)
The reader can readily convince herself that next_lprod works just fine to generate sequences. Also, to initialize a sequence we use similar ideas as before. As we pointed out at the beginning of this section, the generation of labelled sets and cycles is greatly simplified thanks to the isomorphisms they satisfy in terms of the so called boxed product. Boxed products, denoted , are very similar to labelled products, with the condition that each pair in must be relabelled in such a way that the smallest label is attached to some atom in thefirst component. Since the smallest label must be used to label n−1 some -atom there are only j −1 objects in , where j = || and n = || + ||.
404
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
The generalization of the SF and PF orders to boxed products is immediate; we should only remember that the (n, j )-partitions used to relabel the pairs (,) are restricted to contain the smallest label in its first subset and so there are only n−1 j −1 of them. Once boxed product and the order(s) it induces have been introduced, we will use the following isomorphisms in order to generate labelled sets (‘Set’) and labelled cycles (‘Cycle’): Set(A) = + A Set(A),
(5)
Cycle(A) = A Seq(A).
(6)
Notice the similarity of (5) with (4). We represent a labelled set as a single leaf if the set is empty; otherwise, we have a binary tree where the left subtree represents the component of the base class with the smallest label (the leader), and the right subtree represents a set with the remaining components of the set. In other words, the “canonical” form of a set S = {1 , 2 , . . . , k } with i ∈ A is that in which the i ’s have been arranged in ascending order of their respective smallest labels. To represent a cycle, we set up a binary tree whose left subtree represents the leader; once we have “open” the cycle at the leader, the rest is a sequence of objects in the base class. Again the criterion to choose the leader in a cycle is the same as for sets: the component that contains the smallest label among its atoms. From the discussion above, we only need an algorithm next_bprod for boxed products to cope with both Sets and Cycles. Furthermore, next_bprod is almost identical to next_lprod, except for the way it handles the partitions which relabel the atoms (see Algorithm 5).Since the procedure next_label generates them in lexicographic order, the first n−1 j −1 partitions thus obtained are exactly those that contain the smallest label in its first subset, so we can still use the same procedure. In order to initialize a set or a cycle we proceed much in the same manner as for sequences. Algorithm 5. Computing the next object in a class A B in PF order procedure next_lprod(p: ptrNode) return ptrNode {p points to a node representing an object in A B} {Almost all code is identical to that of Algorithm 2} j := p → left → size; n := p → size ... if p → partition_rank < ( n−1 j −1 ) − 1 then next_label(p) p → partition_rank := p → partition_rank + 1 return p fi ...
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
405
4. Iterating through unlabelled objects The generation of unlabelled disjoint unions, unlabelled products and unlabelled sequences poses no special difficulty. The algorithms to cope with these operators are actually easier than the corresponding labelled algorithms in Section 3 since they do not have to update labels, partitions, etc. In addition, we only have to consider one order for products, namely, the lexicographic order. The generation of unlabelled multisets and powersets is based on the decomposition of objects into blocks of components of the same size, with the leading block being the one containing the components of smallest size. If the smallest component in two given sets or powersets is of the same size then the smaller set is that with the greater number of components of that size, i.e., whose leading block has the greater number of components. When two sets or powersets of A’s have leading blocks with components of the same size, say j, and the same number of components, then the components within the block are considered according to the order in Aj and compared lexicographically. Let C = MSet(A). The order in Cn , when n > 0, is induced by the isomorphism Cn =
n
1
j =1 r=n/j
MSet(Aj , card = r) × MSet(A>j )n−j r ,
n > 0,
(7)
where MSet(Aj , card = r) is the class of multisets with exactly r components which are objects in Aj , and MSet(A>j ) is the class of multisets whose components are objects in A of size strictly larger than j. To complete the definition of the order ≺Cn , we need to define the order in MSet(Aj , card = r): given two objects and in that class, ≺ if the sorted sequence of the ranks (with repetitions) of the components of is lexicographically smaller than the sorted sequence of the ranks of the components of . For powersets, the definition of the order is basically the same. In particular, if C = PSet(A) then the order in Cn is induced by the isomorphism Cn =
n
1
j =1 r=n/j
PSet(Aj , card = r) × PSet(A>j )n−j r ,
n > 0,
(8)
together with the definition of order in PSet(Aj , card = r); given two objects and in that class, ≺ if the sorted sequence of the ranks of the components of is lexicographically smaller than the sorted sequence of the ranks of the components of . The only remaining difficulty is to generate multisets and powersets of a fixed cardinality and components of a given size, that is, how to generate the leading blocks of multisets and powersets. From there, we only need a slight modification of the algorithm for products in order to generate multisets and powersets. We also need to represent multisets and powersets in a convenient way. Following the isomorphisms (7) and (8), a non-empty object is seen as a pair (B, ) with B a block of r components of size j in ascending order and a multiset or powerset with components of size > j . The root node is labelled MSet or PSet and contains the usual fields of information; additionally it contains a field min_size that stores the minimal possible size among its components. Thus the structure of the tree and its right child is the same.
406
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
Fig. 5. Internal representation of a PSet-object.
The representation of blocks is different since it must represent a collection of exactly r objects of size j. The root node of such a block is labelled ‘mblock’ (when repetitions are allowed) or ‘pblock’ (when no repetitions are allowed), and it contains the number of objects or cardinality of the block. The left subtree of a mblock of r objects contains a object, that is, the representation of some object in Aj (in particular, the smallest object in the mblock according to ≺Aj ) together with the number of times, say d, that it is present in the mblock; and the right subtree represents a mblock of r − d objects. On the other hand, the left subtree of a pblock of r objects represents the smallest object in the pblock according to ≺Aj , and the right subtree represents a pblock of r − 1 objects. Both mblock and pblock nodes contain an attribute min_rank which corresponds to the smallest possible rank for an object within the block. This attribute is 0 for the first mblock or pblock node in the left subtree of a MSet or PSet node, otherwise is one more than the rank of the (possibly repeated) object represented in a left subtree which is a sibling of the mblock or pblock node. Fig. 5 schematically depicts the internal representation of the powerset = {aa, ba, aba, abb, bbb, abaa, bbba, bbbaab} ∈ PSet(Seq(a + b)). ‘PSet’ nodes are represented by oval nodes, together with the values of the size and min_size attributes. Pblock nodes are represented by circular nodes with thick border; within each pblock node we write the values of the size and min_rank attributes. The components of the powerset belong to Seq(a + b) but we have shown them “collapsed” into single rectangular nodes. For instance, since the leading block of contains two components of size 2, the root node of the right subtree has min_size = 3, as no component of that powerset can be of size smaller than 3. Fig. 6 corresponds to the internal representation of the multiset {aa, aa, ba, aba, aba, abb, bbb, abaa, bbba, bbbaab} ∈ MSet(Seq(a + b)). We use the same set of conventions as in Fig. 5; additionally, the diamond-shaped nodes represent ‘ ’ nodes, and store the total size (i.e., the size of the component times its frequency) and the number of times the component occurs in the multiset. The algorithms to iterate through unlabelled powersets and multisets are very similar and they rely on the algorithms next_pblock and next_mblock, respectively. We give in Algorithm 6 the pseudocode to generate powersets; except for minor details, the code for
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
407
Fig. 6. Internal representation of a MSet-object.
multisets is identical. Notice that next_pset uses the procedure init_pset, which receives a specification of the class A of the components, the total size of the powerset, and the minimum possible size for the components of the powerset. The procedure init_pset initializes the class attribute of the root node to PSet(A) which is not enough, because we have an additional restriction on the size of the components; hence, the special attribute min_size. There is also an analogous procedure init_mset to initialize multisets, with the same three parameters, and similar considerations apply. These procedures use the procedures init_pblock and init_mblock, respectively, each receiving four parameters: a specification for the class A of the components, the total size of the block, the size of the components of the block, and the smallest allowed rank among its components. The implementation of init_mblock and init_pblock relies upon efficient algorithms for unranking in Aj ; we use algorithms such as those developed in [13]. Since the class attribute of a mblock or a pblock is never checked, we do not have to initialize it; if necessary, it could be initialized with something like PSet(A, card = r), as we are not able to express the additional condition that all components are of the same size, say j. Also, both next_pset and init_pset need the specialized counting routine count_PowerSet(A, n, j ). This routine uses the generic counting function count in order to compute the number of powersets of A’s of size >j with total size n. For the generation of multisets, there exists a similar specialized procedure count_MultiSet(A, n, j ) (Fig. 6). Algorithm 8 gives the pseudocode for the generation of mblocks, the pseudocode for pblocks being very similar and in fact simpler. As usual, when computing the next mblock we try to change the right subtree first. If it is not possible, we decrease by one the number of occurrences of the smallest component of the mblock (the object in Aj of smallest rank) and start with the smallest possible mblock in the right. If the number of occurrences of the smallest component is already one, we have to move to the next object in Aj , with maximum number occurrences and initialize the right subtree to an empty mblock. Algorithm 6. Computing the next object in a class PSet(A) procedure next_pset(p: ptrNode) return ptrNode {p points to a node representing an object in PSet(A)} p → rank := p → rank + 1
408
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
if p → rank p → count then return p fi k := p → left → size; n := p → size A := p → left → left → class if p → right → rank < p → right → count − 1 then p → right := next_pset(p → right); return p fi if p → left → rank < p → left → count − 1 then p → left:= next_pblock(p → left) k := p → left → size; j := p → left → left → size p → right := init_pset(A, n − k, j + 1) return p fi {Computes the next powerset by changing the number of} {components r = k/j or their size j in the pblock.} {See Algorithm 7} return change_pblock(p) end Algorithm 7. Computing the next object in a class PSet(A) (II) procedure change_pblock(p: ptrNode) return ptrNode j := p → left → left → size; r := k/j − 1 A := p → left → left → class while r > 0 and count_PowerSet (A, n − j r, j ) = 0 do r := r − 1 end if r > 0 then p → left := init_pblock(A, j · r, j, 0) p → right := init_pset(A, n − j · r, j + 1) return p fi j := j + 1; r := n/j while j n and (count(A, j ) = 0 or count_PowerSet(A, n−j ·r, j ) = 0) do if count(A, j ) = 0 then while r > 0 and count_PowerSet (A, n − j · r, j ) = 0 do r := r − 1 end fi if count(A, j ) = 0 or r = 0 then j := j + 1; r := n/j fi end p → left := init_pblock(A, j · r, j, 0) p → right := init_pset(A, n − j · r, j + 1) return p end
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
409
Algorithm 8. Computing the next mblock procedure next_mblock(p: ptrNode) return ptrNode {p points to a node representing an object in MSet(Aj , card = r)} p → rank := p → rank + 1 if p → rank p → count then return p fi if p → right → rank < p → right → count − 1 then p → right := next_mblock(p → right) return p fi if p → left → occurrences > 1 then j := p → left → left → size rnk := p → left → left → rank p → left → occurrences := p → left → occurrences − 1 p → left → size := p → left → size − j A := p → left → left → class p → right := init_mblock(A, p → size − p → left → size, j, rnk + 1) return p if {p → left → left → rank < p → left → left → count − 1} j := p → left → left → size rnk := p → left → left → rank p → left → occurrences := p → size/j p → left → size := p → size p → left → left := next(p → left → left) p → right := return p end Last but not least, unlabelled cycles do not admit a nice recursive decomposition so we need a rather different approach to iterate through them. Since the algorithm for cycles significantly differs from the other algorithms in this paper and it is not amenable to the same type of analysis, we only describe it very briefly here. It combines Sawada’s algorithm for k-ary cycles of fixed content [19] and the algorithm for multisets which we have described in this section. Even though unlabelled cycles are dealt with in a different way, the representation of cycles and the algorithm have been designed so that they can be integrated and seamlessly work together with the other algorithms. Also, the algorithm works in constant amortized time per generated cycle (provided that the components could be generated in constant amortized time, which indeed is the case, see Section 5). For the complete details, see [15]. 5. The performance We have anticipated already that all the algorithms in our framework work in constant amortized time. In other words, if An denotes the cost of generating all the objects of size n in a class A and an is the number of generated objects then An = (an ).
410
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
We do not take into account the cost of calling count at several places of the algorithms of the previous sections. All the necessary count’s can be computed only once and conveniently stored into tables for later use, either on-demand or in a preprocessing phase. The cost contributed by the computation of counts is O(min{n2 , 0 k n ak }) and can be safely disregarded. Also, we will charge an unitary cost to all non-recursive steps made in each of the algorithms of the previous section. This is clearly an oversimplification; for instance, generating the next object in A + B requires less non-recursive overhead than generating the next object in A × B. In a more realistic setting we should charge each operator the cost of the non-recursive steps to generate an object: to generate one object in A + B this would be c+ , for products it would be c× , and so on, for suitable constants c+ , c× , . . .. But the fact that the algorithms’ performance is CAT is not affected by this simplification, hence we proceed with this simple accounting scheme. Another assumption that we make in our analysis is that the leaf nodes are generated at no cost. There are only to different such nodes: and atoms and we do not have to perform any arithmetic computations to construct them. All that said, let A be some unlabelled class. The cumulating generating function A(z) is A(z) = An zn = c()z|| , (9) n0
∈A
where c() is the cost of generating from its predecessor (or initializing if it is the first object in A|| ). Similarly, for a labelled class A, the cumulating generating function is given by A(z) =
n0
An
zn z|| c() = . n! ||! ∈A
(10)
Once we have introduced cumulating generating functions, the main result of this section can be expressed as An = [zn ]A(z) = ([zn ]A(z)) for any admissible unlabelled class A, and Bn = n! · [zn ]B(z) = (n! · [zn ]B(z)) for any admissible labelled class B. Before going on, we need a few additional definitions. First, for any predicate P, we define [[P ]] = 1 if P is true, and [[P ]] = 0 if P is false. Also, for any unlabelled class C, we define [[C]](z) =
n0
[[cn = 0]]zn ,
whereas for labelled classes the corresponding definition is [[C]](z) =
n0
[[cn = 0]]
zn . n!
For instance, if an unlabelled class A contains objects of all sizes then [[A]](z) = 1/(1 − z).
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
411
5.1. The cost of generating unlabelled classes We consider first the performance of the generation of admissible unlabelled classes. Recall that we assume that leaf nodes can be constructed at no cost, hence, ∅ = = Z = 0. For disjoint unions, the cumulated cost is basically the sum of cumulated costs, but we must take care to charge the cost corresponding to computing the next of the last element in A if A = ∅, and no cost otherwise; this is accounted for by the terms [[A]]+[[B]]−[[A + B]]. Hence, (A + B) = A + B + [[A]] + [[B]] − [[A + B]].
(11)
The rule for products is a bit more complex. Let C = A × B. Applying the rule above for sums, we have n Cn = (Aj × Bn−j ) + [[Aj × Bn−j = ∅]] − [[Cn = ∅]]. j =0
Thus we will have a contribution [[A]] [[B]] − [[A × B]] in (A × B), and the remaining contribution comes from n j =0
(Aj × Bn−j ).
Now, if Aj × Bn−j = ∅ then (Aj × Bn−j ) =
∈Aj ×Bn−j
c() =
∈Aj
c() + aj
∈Bn−j
c()
= Aj + aj Bn−j , since we have to iterate through all objects in Aj once, and for each object ∈ Aj , we iterate through all objects in Bn−j . On the other hand, (Aj ×Bn−j ) = 0 if Aj ×Bn−j = ∅. In general, we may thus write (Aj × Bn−j ) = Aj [[Bn−j = ∅]] + aj Bn−j . Combining the various contributions we finally get (A × B) = AB + A[[B]] + [[A]][[B]] − [[A × B]].
(12)
The cost of generating sequences follows from (11) and (12), since (Seq(A)) = + (A × Seq(A)) + [[]] + [[A × Seq(A)]] − [[Seq(A)]] = ASeq(A) + A[[Seq(A)]] + [[A]][[Seq(A)]] + 1 − [[Seq(A)]]. Isolating A yields (Seq(A)) =
(A + [[A]] − 1)[[Seq(A)]] + 1 . 1−A
(13)
412
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
For multisets and powersets, the corresponding rules can be derived from the rules for sums and products, but they do not take a nice form n n/j aj + r − 1 MSet(A)n = MSet(A>j )n−j r r j =1 r=1 +MSet(Aj , card = r)j r [[MSet(A>j )n−j r = ∅]]
+[[MSet(Aj , card = r) = ∅]][[MSet(A>j )n−j r = ∅]] −[[MSet(A)n = ∅]] and
PSet(A)n =
(14)
n n/j aj PSet(A>j )n−j r r j =1 r=1
+PSet(Aj , card = r)j r [[PSet(A>j )n−j r = ∅]]
+[[PSet(Aj , card = r) = ∅]][[PSet(A>j )n−j r = ∅]] −[[PSet(A)n = ∅]].
(15)
The analysis of the cost of these combinatorial constructions can be further carried on assuming MSet(A>j )n ≈ MSet(A)n and PSet(A>j )n ≈ PSet(A)n (the right-hand sides are in fact upper bounds); we also need to compute the cost of generating mblocks and pblocks, that is, (MSet(Aj , card = r)) and (PSet(Aj , card = r)). Notice that we have to iterate through mblocks and pblocks of size j r, since they have a fixed number r of components which are objects of size j in some class A; therefore, the cumulating generating functions have only one term corresponding to zj r . In particular, each object in Aj is generated exactly once to act as the leader the mblock, and we have the terms for the costs of generating mblocks with components of larger rank when the leader occurs once, twice, three times, etc.: () MSet(Aj , card = r) = Aj + MSet(Aj , card = i), 1 i
()
where Aj is the subset of objects of size j in A preceded by (i.e., whose rank is larger than the rank of ). The rule for pblocks is similar since each object in Aj is generated exactly once to act as the leader the pblock and the rest accounts for the cost of generating the pblock with r − 1 components: () PSet(Aj , card = r) = Aj + PSet(Aj , card = r − 1), ∈Aj
Theorem 1. For any unlabelled admissible class A, A,n =
An = (1). an
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
413
Proof. The statement of the theorem follows from the fact that A(z) = A(z) − [[A]](z)
(16)
for any unlabelled admissible class A which does not involve the operator ‘Cycle’ in its specification, together with the specific proof that we have developed for classes involving unlabelled cycles in [15]. Eq. (16) is trivially true for A = ∅, A = and A = Z. For the other operators, we can establish the results by structural induction. For instance, if C = A + B then C = A + B + [[A]] + [[B]] − [[A + B]] = A + B − [[A + B]] = C − [[C]]. For a product C = A × B, we get C = AB + A[[B]] + [[A]][[B]] − [[A × B]] = A(B − [[B]]) + (A − [[A]])[[B]] + [[A]][[B]] − [[A × B]] = AB − [[A × B]] = C − [[C]]. Since sequences are defined in terms of sums and products the result holds, but we can also check it directly by applying structural induction on (13), so for C = Seq(A), C =
(A + [[A]] − 1)[[C]] + 1 (A − 1)[[C]] + 1 = = C − [[C]], 1−A 1−A
as C(z) = 1/(1 − A(z)). For multisets, using structural induction we have MSet(A>j ) = MSet(A>j )(z) − [[MSet(A>j )]],
(17)
where we have used MSet(A>j )(z) to denote the counting generating function of MSet () (A>j ). On the other hand, assuming that the statement of the theorem holds for MSet(Aj , card = i), 1 i < k, we can conclude that aj + r − 1 j r MSet(Aj , card = r) = z − [[MSet(Aj , card = r)]]. (18) r Actually, the result above is only almost true because the leading object of a mblock occurring d times in the mblock has not to be generated d times but only once. However, assuming that (18) is true does not harm as it would be an overestimation of the real cost. Substituting (17) and (18) into (14) yields MSet(A)n =
n n/j j =1 r=1
#MSet(Aj , card = r) · #MSet(A>j )n−j r
−[[MSet(A)n = ∅]], as we wanted to prove. A similar reasoning applies to powersets. Since (16) implies the weaker statement A = cA(z) + o(A(z)), this translates immediately to coefficients, namely, An = can + o(an ). Finally, we have shown in [15] that for C = Cycle(A) the statement Cn /cn = (1) provided that An /an is also constant. Applying structural induction, we may conclude that the statement of the theorem holds for whatever unlabelled admissible class.
414
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
5.2. The cost of generating labelled classes For labelled classes we can set up a -calculus as we have done for unlabelled classes in the previous subsection. We use the same assumptions as before. For the trivial cases we have again ∅ = = Z = 0, and for disjoint unions we have (A + B) = A + B + [[A]] + [[B]] − [[A + B]], since the argument used before is still valid for labelled classes. Now, for labelled products, the cost of generating (n, j )-partitions can be evenly distributed among the generated objects, and thus “absorbed” in the remaining terms, much in the same manner as we charge a unitary cost to the non-recursive steps performed each time we call next. Structure-first order is slightly more inefficient than partition-first (because it is more efficient to generate labellings while keeping “constant” the two components of a pair), but we will analyze structure-first generation since it is easier. Since the cost of generating all labelled objects of size n in C = Aj Bn−j is n (Aj Bn−j ) = aj bn−j j n n + aj Bn−j + Aj [[Bn−j = ∅]] (19) j j and we can “absorb” the first term corresponding to the generation of labels, the corresponding rule reads (A B) = AB + A[[B]] + [[A]][[B]] − [[A B]] which again coincides with the rule for unlabelled products. Finally, for boxed products and using an analogous reasoning we have for 0 < j n and n>0 n−1 (Aj Bn−j ) = aj bn−j j −1 n−1 n−1 + aj Bn−j + Aj [[Bn−j = ∅]]. j −1 j −1 Multiplying by [n/j ]zn and absorbing the cost of generating the labellings, we can derive the rule for (A B): ϑ(A B) = ϑAB + ϑA[[B]] + ϑ[[A]][[B]] − ϑ[[A B]], where ϑ ≡ z[d/dz]. Given these rules we can obtain rules for labelled sequences, sets and cycles without too much effort. However, the reader will notice that we can also establish here that A = A − [[A]] for any admissible labelled class. In particular we need to show that this is indeed the case for boxed products, since then the result will hold for sets and cycles.
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
415
Let C = A B. We have then, by structural induction, ϑC = ϑAB + ϑA[[B]] + ϑ[[A]][[B]] − ϑ[[A B]] = ϑA(B − [[B]]) + ϑ(A − [[A]])[[B]] + ϑ[[A]][[B]] − ϑ[[A B]] = ϑAB − ϑ[[A B]] = ϑC − ϑ[[C]], where the last equality holds since ϑC = ϑAB. Finally, by linearity of ϑ, we conclude C = C − [[C]]. Theorem 2. For any labelled admissible class A, A,n =
An = (1). an
Generating products and boxed products in PF order needs less work than in SF order; hence, the constant amortized time per generated object also holds in this case—but the constant will be smaller. 5.3. Implementation issues We have implemented all the algorithms described in this paper in MAPLE; we have extensively used the facilities for automatic counting and specification parsing already provided by the combstruct package. Furthermore, we have tried to follow the usual conventions for MAPLE packages in general and for combstruct in particular, so that our programs fit well with their “environment”; also, we wanted that these programs could interact with our generic routines for unranking [13]. We have conducted a few experiments with the implemented programs in order to assess their practical performance. Although not statistically significant, the experiments support the conclusion that the algorithms work in constant amortized time—we have not listed all objects of given large sizes, but say the first million objects of size 100, 200, 300, . . .. The constant depends on the class. For instance, it is around four elementary operations per object in the case of binary trees, and close to 20 elementary operations per object in the case of functional graphs. We have also observed that the performance sometimes approaches the characteristic amortized constant performance slowly; a relatively large number of objects needs to be generated before the (constant) preprocessing and initialization costs do not “mask” the constant that corresponds to the generation proper. In other words, if CN,A,n is the cost of generating the first N objects in An , the experiments show that CN,A,n /N → A,n as N → an , but sometimes this convergence is quite slow. Last but not least, we have incorporated to all our algorithms the possibility of using fingers to improve performance. A finger is a pointer stored in the iterator which points to the last updated internal node in the representation of the current object. When computing the next object we access in one single step that node; most of the times, computing the next object will only need to change the subobject rooted at the node pointed to by the finger, so we can avoid the recursion branching to the right that appears in all the algorithms. If the subobject that we access through the finger is the last in its class then we have to backtrack as much as necessary; hence, we need a pointer to the parent of each node. Also, while
416
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
performing a backtrack we will have to update the ascendants of the node which was pointed to by the finger because several of their attributes (e.g., rank, partition, perm, . . . ) will be outdated. In the case of labelled objects, the iterator stores the “global” labelling of the object and each node stores a pointer to the relevant label: atom nodes point to the corresponding label; internal nodes to the label of their leftmost atom. This allows for an efficient computation of the labelling of the next object, involving no more changes in the global labelling than the number of updated nodes.
6. Conclusions and future work We have shown in this paper the validity of the generic approach for the problem of exhaustively generating all the objects of a given size in an admissible class. The algorithms work for arbitrarily complex classes built using the admissible operators in constant amortized time per generated object (Theorems 1 and 2), making them attractive alternatives for their inclusion in general combinatorial libraries or for rapid prototyping. Furthermore they nicely combine with the existing framework for counting, random generation and unranking. A few problems around this work still remain open. We want to conduct larger and more systematic experiments to study the practical performance of the algorithms developed here. Last but not least, it would be interesting to devise a suitable recursive decomposition of unlabelled cycles; lacking such recursive decomposition, we have come up with an efficient algorithm that departs largely in its design from the other algorithms. This difference in its design also appears at the level of its analysis, where an ad-hoc argument was used to establish CAT performance for the generation of unlabelled cycles. Another line of research is to redesign the algorithms so that there is no need to know the cardinality of the involved classes (basically, the important issue is then to find an efficient and alternative way to compute is_last for any admissible combinatorial class).
Acknowledgements We thank the comments and suggestions made by the referees of the preliminary version of this paper. References [1] S. Bacchelli, E. Barcucci, E. Grazzini, E. Pergola, Exhaustive generation of combinatorial objects by ECO, Acta Inform. 40 (8) (2004) 585–602. [2] E. Barcucci, A. Del Lungo, E. Pergola, Random generation of trees and other combinatorial objects, Theoret. Comput. Sci. 218 (2) (1999) 219–232. [3] E. Barcucci, A. Del Lungo, E. Pergola, R. Pinzani, ECO: a general methodology for the enumeration of combinatorial objects, J. Difference Equations Appl. 5 (1999) 435–490. [4] Ph. Flajolet, B. Salvy, Computer algebra libraries for combinatorial structures, J. Symbolic Comput. 20 (1995) 653–671.
C. Martínez, X. Molinero / Theoretical Computer Science 346 (2005) 388 – 417
417
[5] Ph. Flajolet, P. Zimmerman, B. Van Cutsem, A calculus for the random generation of combinatorial structures, Theoret. Comput. Sci. 132 (1–2) (1994) 1–35. [6] I. Goulden, D. Jackson, Combinatorial Enumeration, Wiley, New York, 1983. [7] D.H. Greene, Labelled formal languages and their uses, Ph.D. Thesis, Computer Science Department, Stanford University, 1983. [8] F. Hivert, N.M. Thiéry, MUPAD-COMBINAT, an open-source package for research in algebraic combinatorics, Séminaire Lotharingien de Combinatoire, Vol. 51, Article B51z, 2004, 70pp. [9] R. Kemp, Generating words lexicographically: an average-case analysis, Acta Inform. 35 (1) (1998) 17–89. [10] D.E. Knuth, The Art of Computer Programming: Combinatorial Algorithms, Addison-Wesley, Reading, 2007, available at http://www-cs-faculty.stanford.edu/∼knuth, in preparation. [11] A. Del Lungo, A. Frosini, S. Rinaldi, ECO method and the exhaustive generation of convex polyominoes, in: C.S. Calude, M.J. Dinneen, V. Vajnovszki (Eds.), Proc. Fourth Internat. Conf. Discrete Mathematics and Theoretical Computer Science (DMTCS), Lecture Notes in Computer Science, Vol. 2731, Springer, Berlin, 2003, pp. 129–140. [12] C. Martínez, X. Molinero, Generic algorithms for the exhaustive generation of labelled objects, in: Proc. Fourth Workshop on Random Generation of Combinatorial Structures and Bijective Combinatorics (GASCOM’01), 2001, pp. 53–58. [13] C. Martínez, X. Molinero, A generic approach for the unranking of labelled combinatorial classes, Random Struct. Algorithms 19 (3–4) (2001) 472–497. [14] C. Martínez, X. Molinero, Generic algorithms for the generation of combinatorial objects, in: B. Rovan, P. Vojtá˘s (Eds.), Proc. 28th Internat. Symp. on Mathematical Foundations of Computer Science (MFCS), Lecture Notes in Computer Science, Vol. 2747, Springer, Berlin, 2003, pp. 572–581. [15] C. Martínez, X. Molinero, An efficient generic algorithm for the generation of unlabelled cycles, in: M. Drmota, Ph. Flajolet, D. Gardy, B. Gittenberger (Eds.), Proc. Third Colloq. on Mathematics and Computer Science: Algorithms, Trees, Combinatorics and Probabilities (MathInfo), Trends in Mathematics, Birkhäuser, Verlag, Basel, 2004, pp. 187–197. [16] A. Nijenhuis, H.S. Wilf, Combinatorial Algorithms, Academic Press, New York, 1978. [17] E.M. Reingold, J. Nievergelt, N. Deo, Combinatorial Algorithms: Theory and Practice, Prentice-Hall, Englewood Cliffs, NJ, 1977. [18] F. Ruskey, The Combinatorial Object Server, http://www.theory.csc.uvic.ca/∼cos. [19] J. Sawada, A fast algorithm to generate necklaces with fixed content, Theoret. Comput. Sci. 301 (1) (2003) 477–489. [20] R. Sedgewick, Ph. Flajolet, An Introduction to the Analysis of Algorithms, Addison-Wesley, Reading, MA, 1996. [21] R.P. Stanley, Enumerative Combinatorics, Vol. I, second ed., Cambridge University Press, Cambridge, 1997. [22] H.S. Wilf, East side, west side, http://www.math.upenn.edu/∼wilf/eastwest.pdf. [23] P. Zimmermann, Gaı¨a: package for the random generation of combinatorial structures, MapleTech 1 (1) (1994) 38–46.
Theoretical Computer Science 346 (2005) 418 – 438 www.elsevier.com/locate/tcs
On computing the coefficients of bivariate holonomic formal series夡 P. Massazzaa,∗ , R. Radicionib a Università degli Studi dell’Insubria, Dipartimento di Informatica e Comunicazione, Via Mazzini 5,
21100 Varese, Italy b Università degli Studi di Milano, Dipartimento di Scienze dell’Informazione, via Comelico 39,
20135 Milano, Italy
Abstract In this work, we study the problem of computing the coefficients of holonomic formal series in two commuting variables. Given a formal series (x, y) = n,k 0 cnk x n y k specified by a holonomic j j system dj 1=0 pj (x, y)jx = 0 and dj 2=0 qj (x, y)jy = 0, with a suitable finite set of initial
conditions {[x a y b ](x, y)}, we show that the coefficient [x i y j ](x, y) can be computed in time O(i + j ) under the uniform cost criterion. © 2005 Elsevier B.V. All rights reserved. Keywords: Formal series; Coefficient problem; Holonomic systems
1. Introduction The problem of computing the coefficients of formal power series (known as the coefficient problem) is of primary interest in many different areas such as combinatorics and theory of languages. For example, the problem of counting objects with a given property that belong to a combinatorial structure S can be reduced to computing the coefficients of suitable formal power series: we represent the property by a weight function w : S → N 夡 This work has been supported by the Project M.I.U.R. COFIN 2003–2005 “Formal languages and automata: methods, models and applications”.
∗ Corresponding author.
E-mail addresses:
[email protected] (P. Massazza),
[email protected] (R. Radicioni). 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.011
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
419
and then we consider the formal series s∈S w(s) s. So, the counting problem associated with S and w consists of computing the function f (n) = {s ∈ S|w(s) = n}. Another setting where the coefficient problem arises is the random generation of combinatorial structures (see, for instance, [7]). Efficient algorithms for the random generation of strings in a language can also be derived by considering the generating function associated with the language (see, for example, [5]). We can also consider a more general version of the coefficient problem for multivariate formal series in commutative variables. More precisely, the coefficient problem for a class A of commutative formal series consists of computing, given a series in k variables f = n∈Nk cn x n ∈ A and a multi-index i ∈ Nk , the coefficient ci of f, [x i ]f (x). When we deal with counting and random generation, this generalization appears whenever a multiple output weight function w : S → Nk is considered. For example, multivariate formal series are used in counting or random sampling words with fixed occurrences of symbols [2] as well as in the random generation through object grammars [6]. In this paper we consider the coefficient problem for the class Q[[{x, y}]]h of the holonomic formal series in two commuting variables. These are power series expansions of suitable holonomic functions defined by systems of linear differential equations with polynomial coefficients. Given a couple of integers (i, j ) and a holonomic system for a formal series (x, y), d1 k=0
pk (x, y)jkx = 0,
d2 k=0
qk (x, y)jky = 0,
we show that the coefficient [x i y j ](x, y) can be computed in time O(i + j ) under the uniform cost criterion. Our method is based on the theory of holonomic functions and extends the result given in [10], where an efficient algorithm for computing the coefficient of a bivariate rational series is given. In order to compute [x i y j ](x, y) in an efficient way, we use suitable recurrence equations with polynomial coefficients associated with the holonomic system for (x, y). This is a remarkable improvement with respect to a more general algorithm presented in [9], where it is shown how to compute [x i y j ](x, y) in time O(i · j ). 2. Preliminaries We denote by N (Q) the set of the natural (rational) numbers. A 2-dimensional sequence c with values in Q is a function c : N2 → Q, usually denoted by {cnk }. We denote by Q(2) the ring of 2-dimensional sequences on Q with the operations of sum, {ank } + {bnk } = {ank + bnk }, and product, {ank } · {bnk } = {cnk } where cnk = l+m=n ali bmj . i+j =k
Moreover, we consider the following operators from Q(2) into Q(2) : • External product by e ∈ Q: e · {ank } = {eank }; • (left) Shift : En {ank } = {an−1 k }, Ek {ank } = {an k−1 }; • Multiplication by n, k : n{ank } = {nank }, k{ank } = {kank }. Then, the so called shift algebra Qn, k, En , Ek is a particular Ore algebra (see, for instance, [4]) and can be interpreted as a (noncommutative) ring of linear operators on
420
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Q(2) , with pseudo-commutative rules given by nk = kn, nEk = Ek n, kEn = En k, nEn = En n + En , kEk = Ek k + Ek .
Ek En = En Ek ,
Note that every normalized polynomial in Qn, k, En , Ek corresponds to a linear recurrence with polynomial coefficients and vice versa. Particular sequences, called P-recursive, satisfy linear recurrences with polynomial coefficients and will be of interest in this paper. A one-dimensional P-recursive sequence is defined as follows: Definition 1. A sequence {an } is called P-recursive if and only if there exists P (n, En ) ∈ Qn, En such that P (n, En ){an } =
d i=0
pi (n)Eni {an } = 0.
The notion of P-recursiveness can be extended to n-dimensional sequences as shown in [9]. We recall here useful definitions for the two-dimensional case (see [9, Definitions 3.1, 3.2] for the general case). Definition 2. Let h ∈ N. An h-section of a sequence {cnk } is a one-dimensional subsequence that is obtained by holding one of the variables n or k fixed at values < h. Then, we have: Definition 3. A sequence {cnk } is called P-recursive if there exists h ∈ N such that (1) for i, j ∈ {0, . . . , h} there are polynomials pij (n) qij (k) such that h pij (n)En i Ek j {cnk } = P (n, En , Ek ){cnk } = 0, i,j =0 h i,j =0
qij (k)En i Ek j {cnk } = Q(k, En , Ek ){cnk } = 0,
where pi1 j1 , qi2 j2 = 0 for some integers i1 , j1 , i2 , j2 ∈ {0, . . . , h}; (2) all the h-sections of {cnk } are P-recursive. 2.1. Formal series, holonomic functions and recurrences Let Xc be the commutative free monoid generated by the alphabet X = {x, y}. A commutative formal series with values inQ and variables in X is a function : X c → Q, usually encoded by the sum (x, y) = n,k 0 cnk x n y k where cnk = (x n y k ). We denote by Q[[X]] the ring of commutative formal series with coefficients in Q equipped with the usual operations of sum (+) and product (·). The support of is the set of monomials {x n y k | (x n y k ) = 0} and Q[X] is the ring of polynomials, that is, formal series with finite support. The coefficient cnk of a formal series will be often denoted by [x n y k ](x, y). We are interested in a particular subclass of Q[[X]] that is the class Q[[X]]h of the holonomic formal series in two commutative variables. This class can be formally defined as follows (see [9, Proposition 2.2]).
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
421
Definition 4. A series (x, y) ∈ Q[[X]] is holonomic if and only if there exist some polynomials pij ∈ Q[X],
1i 2,
0 j di ,
pidi = 0
such that d1 j =0
p1j jjx = 0,
d2 j =0
p2j jjy = 0.
The above equations are said to be a holonomic system for . As a matter of fact, holonomic series are power series expansions of suitable functions that belong to the class of holonomic functions. This class was first introduced by I.N. Bernstein in the 1970s [1] and deeply investigated by Stanley, Lipshitz, Zeilberger and others (see, for instance, [3,8,9,11,12]). Note that there exist holonomic functions that are not holonomic formal series. For example, the function f (x, y) = 1/(x + y) is holonomic since (x + y)jx f + f = 0 and (x + y)jy f + f = 0, while it is not a holonomic formal series since it has a pole in (0, 0). In our setting, we are interested in recurrence equations satisfied by sequences of coefficients of holonomic formal series. Therefore, we recall the following result [9, Theorem 3.7]: Theorem 5. Let (x, y) = {cnk } is P-recursive.
n,k 0 cnk x
nyk
be a holonomic series. Then the sequence
By noting the following correspondence between operators, j i s−j r s i j (n − r + h) (k − s + h) Enr−i Ek x y jx jy ≡ h=1
r > i, s > j,
(1)
h=1
we can easily associate with a holonomic system a system of recurrence equations. In fact, if we left-multiply a holonomic system by a suitable monomial x y and apply the correspondence above, we obtain the recurrences P (n, En , Ek ), Q(k, En , Ek ) given in Definition 3. Moreover, given a holonomic series, we can obtain a system of recurrences that is useful for computing most of the values belonging to h-sections of {cnk } (for arbitrary integers h). Theorem 6. Let (x, y) = n,k 0 cnk x n y k be a holonomic series. Then the sequence of coefficients {cnk } satisfies a system of linear recurrence equations with polynomial coefficients (2) P (n, k, En ){cnk } = 0, Q(n, k, Ek ){cnk } = 0, r where P (n, k, En ) = i=0 pi (n, k)En i and Q(n, k, Ek ) = sj =0 qj (n, k)Ek j belong to Qn, k, En , Ek and p0 , q0 = 0.
422
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Proof. By [9, Lemma 2.4] we know that there exists a system rˆ
P (x, xjx , yjy ) =
i,j sˆ i,j
Q(y, xjx , yjy ) =
pˆ ij (x)(xjx )(i) (yjy )(j ) = 0, qˆij (y)(xjx )(i) (yjy )(j ) = 0,
satisfied by . According to Correspondence (1) we have x ≡ En , y ≡ Ek , xjx ≡ n and yjy ≡ k. Then, the system associated with the sequence {cnk } is rˆ
P (n, k, En ) {cnk } = Q(n, k, Ek ) {cnk } =
i,j
pˆ ij (En )ni k j {cnk } = 0,
i,j
qˆij (Ek )ni k j {cnk } = 0.
sˆ
At last, by using the pseudo-commutative rules of Qn, k, En , Ek , we obtain the system P (n, k, En ){cnk } = Q(n, k, Ek ){cnk } =
r i=0 s
pi (n, k)En i {cnk } = 0,
j =0 qj (n, k)Ek
j
{cnk } = 0,
for suitable polynomials pi , qj and suitable integers r, s.
We point out that the computation of a system of type (2) starting from a holonomic system requires the solution of an elimination problem in Qn, k, En , Ek . As shown in [12, Sections 4.1, 4.2], it is first necessary to consider a system with appropriate initial conditions (some more equations might be added to the system from the annihilation ideal of or {cnk }). Then, an elimination method is applied to the system. In [12, Section 5] Sylvester’s classical dialytic elimination method is adapted to Qn, k, En , Ek . A different elimination method is based on the computation of the Gröbner basis of a set of polynomials in Qn, k, En , Ek (with suitable initial conditions, as indicated before) that we can obtain by mapping the holonomic system into Qn, k, En , Ek . A useful package for such computation, for example, is given by [4].
3. Computing the coefficient Given a holonomic system for a series ∈ Q[[X]]h , we can easily obtain two linear recurrence equations with univariate coefficients, P (n, En , Ek ) and Q(k, En , Ek ), satisfied by {[x n y k ](x, y)}. Then, we can use them for computing an arbitrary coefficient [x i y j ](x, y) once a suitable set of initial conditions is known. On the other hand, because both En and Ek might appear in P and Q, this technique requires in general O(ij ) coefficients in order to determine [x i y j ](x, y). As shown before, the theory of holonomic systems allows us to obtain particular linear recurrence equations with polynomial coefficients that are more suitable for computing coefficients. More precisely, Theorem 6 provides us with two operators of the shift algebra Qn, k, En , Ek that depend on n, k and either En or Ek . So, we can efficiently compute all the coefficients along a line n = n or k = k if the leading and the least coefficients of such recurrences do not vanish on that line.
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
423
Our approach takes advantage of both types of recurrences (those in Definition 3 and Theorem 6) in order to get a method that efficiently computes the coefficient [x i y j ](x, y) by starting with a suitable set I of initial conditions and proceeding by choosing at each step the “right” recurrence to use. So, we formally define the following problem for holonomic series in two variables: Problem: The coefficient problem for Q[[X]]h Input: A tuple Bn , Bk , Sec, Un , Uk , I, i, j where: • Bn , Bk are polynomials in Qn, k, En , Ek , Bn (n, En , Ek ) = Bk (k, En , Ek ) =
h i,j =0 h i,j =0
pij (n)En i Ek j , qij (k)En i Ek j ,
that identify two recurrences satisfied by the sequence {[x n y k ](x, y)} of (x, y) ∈ Q[[X]]h (see Definition 3). • Sec = {Ti (n, En ), Vi (k, Ek ) | 0 i < h} is a family of 2h univariate recurrences for the h-sections of {[x n y k ](x, y)} with Ti (n, En ){[x n y i ](x, y)} = Vi (k, Ek ){[x i y k ](x, y)} =
di j =0 fi j =0
j
tij (n)En {[x n y i ](x, y)} = 0, j
rij (k)Ek {[x i y k ](x, y)} = 0.
• Un , Uk are two polynomials in Qn, k, En , Ek , Un (n, k, En ) = Uk (n, k, Ek ) =
r i=0 s j =0
ai (n, k)En i
ar (n, k) = 0,
bj (n, k)Ek j
bs (n, k) = 0,
that identify two recurrences satisfied by the sequence {[x n y k ](x, y)} (see Theorem 6). • I is a finite set of initial conditions, I = {[x n y k ](x, y) | n, k ∈ {0, . . . , d}}, where: ◦ = (Bn ) = max{n ∈ N | ∃i, j ∈ {0, . . . , h}, pij (n) = 0}; ◦ = (Bk ) = max{n ∈ N | ∃i, j ∈ {0, . . . , h}, qij (n) = 0}; ◦ = (Sec) = max{n ∈ N | ∃i, j, (tij = 0 ∧ tij (n) = 0) ∨ (rij = 0 ∧ rij (n) = 0)}; ◦ d = max{r, s, h, , , , f0 , f1 , . . . , fh−1 , d0 , d1 , . . . , dh−1 }. • (i, j ) ∈ N2 . Output: The coefficient [x i y j ](x, y). Note that several recurrences appears in the previous definition. Therefore, for sake of clarity, we show in Fig. 1 where the different recurrences are used by the algorithm we describe later.
424
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Fig. 1. Initial conditions and use of recurrences.
3.1. Clusters and coefficients Informally, our algorithm works by finding a sequence S of O(i + j ) points from (0, 0) to (i, j ) such that for each (a, b) in S the coefficient [x a y b ](x, y) can be computed by at least one of the known recurrences applied to suitable values [x u y v ](x, y) with (u, v) preceding (a, b) in S. In order to do that, we consider a tiling of N2 with suitable defined parallelograms, together with a set of rules that let us to compute the coefficients associated with the points within a parallelogram from the knowledge of the coefficients associated with parallelograms in the neighbourhood. Hence, we first introduce the definition of parallelogram and some related notations. Definition 7 (P (ab) (x, y)). Let a, b ∈ N. Then, for each (x, y) ∈ N2 such that x (b+1)a and y b, the parallelogram P (ab) (x, y) is the set of points P (ab) (x, y) = {(x , y ) ∈ N2 | y − b y y ∧ x − (b + 1)a + (y − y )a x x + (y − y )a}. (ab)
(ab)
Definition 8 (PStart ). The starting parallelogram PStart is the parallelogram P (ab) × ((b + 1)a, b). We consider a tiling of N2 with parallelograms that are obtained by moving at each (ab) step the starting parallelogram PStart (see Fig. 2) towards North or East according to the following partial functions (see, for instance, Fig. 3): N (P (ab) (x, y)) = P (ab) (x − ba, y + b) (defined if x (2b + 1)a), E(P (ab) (x, y)) = P (ab) (x + (b + 1)a, y). Note that (P (ab) (x, y) ∩ N (P (ab) (x, y))) = (b + 1)a + 1 and (P (ab) (x, y) ∩ E(P (ab) (x, y))) = b + 1. More formally, we are interested in the set of parallelograms defined as follows:
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
425
(2 4)
Fig. 2. The starting parallelogram PStart .
Fig. 3. P and its neighbours. (ab)
Definition 9 (PAR(ab) ). Let a, b ∈ N. The set of parallelograms generated by PStart is (ab) PAR(ab) = P (ab) (x, y) | ∃(u, v) ∈ N2 , P (ab) (x, y) = N u (E v (PStart )) . Note that all the parallelograms in PAR(ab) lie in the first quadrant. Actually, the algorithm deals with sequences of elements in PAR(ab) that are obtained by moving at each step a parallelogram towards North, East, South or West, so we define also the functions S(P (ab) (x, y)) = P (ab) (x + ba, y − b) (defined if y 2b), W (P (ab) (x, y)) = P (ab) (x − (b + 1)a, y) (defined if x 2(b + 1)a). Given a direction T ∈ {N, E, S, W } and P ∈ PAR(ab) , we write T i (P ) for T (T i−1 (P )), T 0 (P ) = P . Moreover, we also consider the shortcuts SW (P ) = W (S(P )), N W (P ) = N (W (P )), SE(P ) = S(E(P )) and N E(P ) = N (E(P )). The neighbours of a parallelogram are defined through the following reflexive and symmetric relations on PAR(ab) . (ab)
(ab)
Definition 10 (♦,). Given P1 , P2 ∈ PAR(ab) , then (ab) (ab) ⇔ ∃T ∈ {N, NE, E, SE, S, SW, W, N W }, • P1 ♦P2 •
(ab) (ab) P1 P2
⇔ ∃T ∈ {N, E, S, W },
(ab) P1
=
(ab)
P1
(ab)
= T (P2
),
(ab) T (P2 ).
We say that P1 is 8-adjacent (4-adjacent) to P2 if and only if P1 ♦P2 (P1 P2 ). Particular sequences of parallelograms will be of interest when considering the behaviour of the algorithm.
426
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Definition 11. Let Seq = P1 , . . . , Pk be a sequence of parallelograms in PAR(ab) . Then, Seq is • 8-connected iff Pi ♦Pi+1 , 0 i < k; • 4-connected iff Pi Pi+1 , 0 i < k; • descending iff Seq is 8-connected or 4-connected and Pi+1 = Ti (Pi ) with Ti ∈ {E, SE, S, SW, W }, 0 i < k; • ascending iff Seq is 8-connected or 4-connected and Pi+1 = Ti (Pi ) with Ti ∈ {W, N W, N, N E, E}, 0 i < k. Henceforward, we fix an instance Bn , Bk , Sec, Un , Uk , I, i, j of the coefficient problem for a series (x, y) ∈ Q[[X]]h and we associate with it the following values: • Z = Z(Un , Uk ) = {(x, y) ∈ N2 | ar (x, y) = 0 ∨ a0 (x, y) = 0 ∨ bs (x, y) = 0 ∨ b0 (x, y) = 0}; • a = a(Un , Bn , Bk ) = max{r, h}; • b = b(Uk , Bn , Bk ) = max{s, h + 1}; (ab)
• P0 = PStart ; • P ∈ PAR(ab) univocally identified by the integers c1 = (i + (j − b)a)/((b + 1)a) − 1,
c2 = j/b − 1
(ab)
such that (i, j ) ∈ P = P (™, E) = N c2 (E c1 (P0 )). Given an instance, we will write P and PAR instead of P (ab) and PAR(ab) whenever the context is clear. Definition 12 (PAR(P ), PARV (P )). Let P = N c (E d (P0 )) ∈ PAR (c, d ∈ N). Given V ⊆ N2 we have PAR(P ) = Q ∈ PAR | ∃u, v ∈ N, u d, v c,
Q = W u (S v (P )) = N c−v (E d−u (P0 )) ,
PARV (P ) = {Q ∈ PAR(P ) | Q ∩ V = ∅}. Note that PARZ (P ) consists of those parallelograms in PAR(P ) that contain at least one point (n, k) such that at least one of the following methods fails: ComputeN (n, k): use Un to compute [x n y k ] from the values [x n−l y k ] or [x n+l y k ], 1l r; ComputeK (n, k): use Uk to compute [x n y k ] from the values [x n y k−l ] or [x n y k+l ], 1l s. The elements of PARZ (P ) can be considered as “obstacles”, in the sense that their associated coefficients can be computed only by using Bn or Bk . Henceforward, we call them singular parallelograms. The size of PARZ (P ) will be of interest in the analysis of the algorithm we propose, in a way that will become clear later. So we state the following:
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
427
Lemma 13. PARZ (P ) = O(™ + E). Proof. We first note that if (x, y) ∈ Q with Q ∈ PARZ (P ) then 0 y E. Note that if (k − y) is not a factor of a0 (n, k), ar (n, k) (in Un ) or b0 (n, k), bs (n, k) (in Uk ), then the univariate polynomials a0 (n, y), ar (n, y), b0 (n, y) and bs (n, y) admit at most Dmaxn = max{degn (a0 (n, k)), degn (ar (n, k)), degn (b0 (n, k)), degn (bs (n, k))} zeroes. Let Z™E = {(x, y) ∈ Z | 0 x ™, 0 y E}. Since the number of factors of type (k − y) and the associated multiplicities are bounded by Dmaxk = max{degk (a0 (n, k)), degk (ar (n, k)), degk (b0 (n, k)), degk (bs (n, k))}, we have Z™E 4Dmaxn (E + 1) + 4Dmaxk (™ + aE) = O(™ + E). Since each parallelogram in PARZ (P ) contains at least one point in Z™E and each point in Z™E belongs to at most four singular parallelograms, we have PARZ (P ) 4Z™E and so PARZ (P ) = O(™ + E). We indicate by Coeff (P ) the family of coefficients of associated with P ∈ PAR, that is, Coeff (P ) = {[x n y k ](x, y) | (n, k) ∈ P }. The following lemmas show how to compute the coefficients in Coeff (P ) from the knowledge of the coefficients associated with neighbours of P. Lemma 14. Let P be a nonsingular parallelogram. If there exists T ∈ {N, W, S, E} such that Coeff (T (P )) is known, then Coeff (P ) can be computed in time O(1). Proof. Let P = P (l, m). We consider two cases: • (T ∈ {E, W }). Without loss of generality let us consider T = E, that is, suppose that Coeff (E(P )) = Coeff (P (l + (b + 1)a, m)) is known. It is immediate to obtain Coeff (P (l + (b + 1)a − 1, m)) by computing b + 1 coefficients in Coeff (P (l + (b + 1)a − 1, m)) \ Coeff (P (l + (b + 1)a, m)): this is done by using Un and the values of the b + 1 “rows” of Coeff (E(P )). We obtain Coeff (P (l, m)) by iterating this computation (b + 1)a times. • (T ∈ {N, S}). Without loss of generality we suppose that Coeff (N (P )) = Coeff (P (l− ba, m + b)) is known. We obtain the coefficients in Coeff (P (l − (b − 1)a, m + b − 1)) in two steps: first, we apply Uk to the “columns” l − ba + 1, . . . , l − ba + a of Coeff (P (l − ba, m + b)) in order to get the leftmost a coefficients in Coeff (P (l − (b − 1)a, m + b − 1)) \ Coeff (P (l − ba, m + b)). Second, from these a values we compute the remaining ba values on the right by applying Un ba times. We obtain Coeff (P (l, m)) by iterating this computation b + 1 times.
428
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Therefore, Coeff (P (l, m)) is computed in time O(1) (independent of l or m) since the computation of one coefficient requires max(a, b) arithmetical operations and we compute ((b + 1)a + 1) · (b + 1) coefficients (a,b constants). The next lemma refers to the integer constant d that appears in the formal definition of the coefficient problem for a series (see the definition of I in the tuple Bn , Bk , Sec, Un , Uk , I, i, j ). Lemma 15. Let P be a singular parallelogram such that if (a, b) ∈ P then a > d and b > d. If Coeff (W (P )), Coeff (SW (P )) and Coeff (S(P )) are known, then Coeff (P ) can be computed in time O(1). Proof. We define an ordering ≺ on P as follows: (, ) ≺ (, ) iff < or = and . Then, we compute the coefficients in Coeff (P ) according to the ≺, starting with [x 0 y 0 ](x, y) ((0 , 0 ) = min(P )) and using Bn or Bk . At each step we compute one coefficient using at most ab arithmetical operations. Since the number of coefficients is (b +1)·(a(b +1)+1), Coeff (P ) can be computed in time O((b +1)·(a(b +1)+1)·ab) = O(1) (independent of l or m). The transitive closure defines an equivalence relation on PARZ (P ), i.e. it defines a partition of PARZ (P ) into equivalence classes that we call clusters. Informally, a cluster can be seen as a group of singular parallelograms that form a connected figure. More precisely, let P = ∩ PARZ (P ) × PARZ (P ) and consider the following: Definition 16 (Cluster). The cluster generated by P ∈ PARZ (P ) is ClPP = [P ] = Q ∈ PARZ (P ) | Q P P . P
It is immediate to observe that we have the partition k PARZ (P ) = · h=1
ClPPh
with Ph ∈ PARZ (P ) and Ph1 /P Ph2 if h1 = h2 . Example 17. Let us consider the function (x, y) = (x + y)ey(x+y) and the recurrences Bn = −En Ek2 − En2 Ek − 2En + nEk + nEn , Bk = −2Ek − En2 Ek − 2Ek3 − 3En Ek2 + kEk + kEn , Un = (14n − 45 + 4k + k 2 − n2 )En2 + 40n2 − 84k − 2n2 k + 26nk − 266n +588 − 2n3 , Uk = (2n + 2k − 2)Ek 2 − 2n + 4k − 3 + n2 − k 2 ,
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Fig. 4. The cluster Cl
429
P (2 3) (70,60) associated with (x +y)ey(x+y). Elements of Z(Un , Uk ) are indicated by crosses. P (2 3) (8,3)
associated with it. Let P = P (2 3) (70, 60) and P = P (2 3) (8, 3). The graphical representation of the cluster ClPP is given in Fig. 4. P ) of nonsingular parallelograms Given a cluster ClPQ we define its border as the set B(ClQ
that are 8-adjacent to parallelograms in ClPQ , P P B(ClQ ) = {P ∈ PAR(P ) \ PARZ (P ) | ∃P ∈ ClQ s.t. P P }. P ) = O(Cl P ) = O(™ + E). It is immediate to verify that B(ClQ Q
3.2. The algorithm As shown in the previous section, an instance Bn , Bk , Sec, Un , Uk , I, i, j univocally identifies a set Z, two integers a, b and two parallelograms P0 , P . So, we compute the coefficient [x i y j ](x, y) through a procedure that starts with the computation of Coeff (P0 ) and halts having computed the family Coeff (P ), with [x i y j ](x, y) ∈ Coeff (P ), after O(i + j ) steps. The basic idea is quite simple: we would like to compute the sequence of families Coeff (P0 ), Coeff (E(P0 )), . . . , Coeff (E c1 (P0 )), Coeff (N (E c1 (P0 ))), . . . , Coeff (N c2 (E c1 (P0 ))) by going first eastwards and then northwards, until Coeff (N c2 (E c1 (P0 ))) = Coeff (P ) is computed. If no singular parallelograms are found, the pth family is easily computed by the (p − 1)th family using Lemma 14. Otherwise, we eventually go through a singular parallelogram Pp and then the only knowledge of Coeff (Pp−1 ), is not sufficient to proceed. To deal with this situation, we go round Pp (clockwise), starting from Pp−1 and computing
430
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Fig. 5. An example of computation. Parallelograms are numbered with respect to the order of computation. The grey parallelogram is singular.
the associated families of coefficients until Coeff (S(Pp )), Coeff (SW (Pp )) and Coeff × (W (Pp )) are known. Then we can apply Lemma 15 and compute Coeff (Pp ). If another singular parallelogram is found while going round Pp we recursively compute the associated family in the same way. Fig. 5 illustrates a sequence of families of coefficients that are computed according to this method. More precisely, we design a procedure that works in two steps. The first step has to be considered as a sort of precomputation: it computes O(i + j ) suitable coefficients in time O(i + j ). Such coefficients act as halting condition for the recursive computations that might occur in the second step. The core of the algorithm is indeed the second step. Step 1: Compute all the coefficients [x n y k ](x, y) with either n max(d, 2(b + 1)a + ba + 1) and d < k E or d < n™ + ba(c2 + 1) and k d. Step 2: For 0 < j c2 , compute the family Coeff (N j (E c1 (P0 ))) having as input Coeff (N j −1 (E c1 (P0 ))) according to the following rule: if N j (E c1 (P0 )) is nonsingular then compute Coeff (N j (E c1 (P0 ))) as shown in Lemma 14, otherwise apply Lemma 15 and compute N j (E c1 (P ))
all the coefficients associated with the cluster ClN j (E c1 (P0 )) (in a suitable order that derives 0 from the recursive method illustrated before). We give here an outline of how to compute the coefficients involved in Step 1. First, we compute the coefficients [x n y k ](x, y) with d < n™ + bac2 and 0 k < h by using Tk (n, En ) in Sec and the initial conditions I. Then, we compute the coefficients [x n y k ](x, y), with d < n ™ + bac2 and h k d, according to the following order: [x y ](x, y) is computed before [x y ](x, y) iff < or = and < . This is done by using Bn and I. We then proceed by computing the coefficients [x n y k ](x, y) with 0 n < h and d < k E (we use the recurrence Vn (k, Ek ) in Sec and the initial conditions I). At last, the coefficients [x n y k ](x, y), with h n max(d, 2(b + 1)a + ba + 1)) and d < k E, are computed by using Bk and I in a way such that [x y ](x, y) is computed before [x y ](x, y) iff < or = and < . Fig. 6 shows where the different recurrences are used. Note that after Step 1 we know all the families Coeff (P (l, m)) with either (b + 1)a l ™+bac2 and b m d or (b +1)a l max(d −ba, 2(b +1)a +1) and b m E. In particular, this means that the sequence Coeff (P0 ), Coeff (E(P0 )), . . . , Coeff (E c1 (P0 )) has been computed.
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
431
Fig. 6. Recurrences, initial conditions, and the target parallelogram P .
Procedure COEFF(i, j ) Begin (ab) P0 := PStart ; c2 := j/b − 1; c1 := (i + (j − b)a)/((b + 1)a) − 1; /* (i, j ) ∈ N c2 (E c1 (P0 )) */ /* Step 1 */ PRECOMPUTE(Sec,Bn ,Bk ,I,i,j); For c from 1 to c2 do /* Step 2 */ if N c (E c1 (P0 )) ∈ / PARZ (P ) then compute Coeff [N c (E c1 (P0 ))] by using Lemma 14 and Coeff [N c−1 (E c1 (P0 ))]; else COMPUTE(N c (E c1 (P0 )), N c−1 (E c1 (P0 ))); return [x i y j ](x, y) from Coeff [N c2 (E c1 (P0 ))]; End; Fig. 7. Procedure COEFF.
In Fig. 7 we define a procedure COEFF(i, j ) that takes two positive integers i, j in input and returns the value [x i y j ](x, y). In the code, two procedures COMPUTE and PRECOMPUTE are called. All the procedures use a suitable data structure Coeff [] for the families Coeff (P ). Moreover, we suppose that all the items given in the instance of the problem are available as global variables, as well as those values univocally associated with the instance (e.g. the integers a and b, defining the size of the parallelogram, independent of i or j). Procedure PRECOMPUTE(Sec, Bn , Bk , I, i, j ) corresponds to Step 1. Procedure COMPUTE(Pout , Pin ) takes two parallelograms Pout , Pin such that Pout Pin and computes Coeff (Pout ) under the assumption that Coeff (Pin ) has been computed. It moves clockwise and uses the coefficients previously computed. In the code we find an indexed
432
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Procedure COMPUTE(Pout , Pin ) Begin While Coeff [S(Pout )], Coeff [SW (Pout )], Coeff [W (Pout )] are not known do P := nextPout (Pin ); if Coeff [P ] is not known then / PARZ (P ) then compute Coeff [P ] by using Lemma 14 and if P ∈ Coeff [Pin ]; else COMPUTE(P , Pin ); Pin := P ; EndWhile compute Coeff [Pout ] by using Lemma 15 and Coeff [S(Pout )], Coeff [SW (Pout )], Coeff [W (Pout )]; End; Fig. 8. Procedure COMPUTE.
function nextPc (P ): this is used to identify the parallelogram P that is 8-adjacent to Pc and follows P (clockwise). More formally: ⎧ NE(Pc ) if P = N(Pc ) ?? ?? ? ? ?? ?? / ??? / ??? ⎪ if P = NE(Pc ) E(Pc ) ⎪ ⎪ ? ? ? ⎪ ?? ?_ ?? ?? ?? ??? ??? ⎨ SE(Pc ) if P = E(Pc ) ?? ? ?? ? ? ? if P = SE(Pc ) S(Pc ) ?? ?_ ?? Pc ??? ? ??? nextPc (P ) = SW (Pc ) if P = S(Pc ) ? ?? ?? ?? ? ⎪ ? ⎪ ?? ?? ?? if P = SW (Pc ) W (Pc ) ⎪ ⎪ ?? o ?? o ??? ? ??? ⎩ NW (Pc ) if P = W (Pc ) ?? ?? ?? ?? if P = NW (P ) N(P ) c
c
Function next
Let us consider, for example, the call COMPUTE(P , S(P )). This call knows the value Coeff [S(P )] and assigns a value to Coeff [P ]. So, if P is singular then Coeff [SW (P )] and Coeff [W (P )] are needed, as shown in Lemma 15. Hence, the procedure advances clockwise around P, in order to compute (recursively) Coeff [SW (P )] (with Coeff [S(P )] known) and Coeff [W (P )] (with Coeff [SW (P )] known). Fig. 8 shows COMPUTE, while Fig. 9 shows a run of COEFF for the function (x + y)ey(x+y) in Example 17. 4. Complexity It is easy to see that COEFF(i, j ) computes [x i y j ](x, y) if and only if every call COMPUTE(N k (E1c (P0 )), N k−1 (E1c (P0 ))) terminates and computes the family Coeff (N k (E1c (P0 ))). Hence, the problem is to analyse the families of coefficients computed by the recursive procedure COMPUTE. A call COMPUTE(Pout , Pin ) recursively calls itself if and only if Pout is singular. So, let Out0 = N k (E1c (P0 )) and In0 = N k−1 (E1c (P0 )) for a suitable integer k c2 , and consider the sequence of calls COMPUTE(Out0 , In0 ), . . . , COMPUTE(Outl , Inl ) contained in the stack associated with the call COMPUTE(Out0 ,In0 ) (at the bottom).
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
433
Fig. 9. Running COEFF(55,70) for the function (x+y)ey(x+y) (Example 17). Parallelograms that are not numbered belong to the set I of initial conditions or are computed by PRECOMPUTE.
For each 0 p < l, let Stepp = Pp1 , . . . , Pph be the 4-connected sequence of parallelograms 8-adjacent to Outp such that Ppi =
Inp if i = 1 nextOutp (Ppi−1 ) if i > 1
and h = min{j | nextOutp (Ppj ) = Inp+1 }.
and Seq, associated with the We consider three sequences of parallelograms, Seq, Seq stack and defined as follows: • Seq = Out0 , . . . , Outl is the 8-connected sequence of singular parallelograms such that Coeff (Outi ) is not known (0 i l);
= P0 , E(P0 ), . . . , E c1 (P0 ), N (E c1 (P0 )), . . . , N k−1 (E c1 (P0 )) is the 4-connected • Seq
ascending sequence of c1 + k parallelograms such that Coeff (P ) is known, P ∈ Seq; = Step0 , . . . , Stepl−1 , Inl is the 4-connected sequence such that for all P ∈ Seq, • Seq Coeff (P ) has been computed by recursive calls to COMPUTE. The families of coefficients computed by COMPUTE are identified by the following: Lemma 18. Let COMPUTE(N k (E c1 (P0 )), N k−1 (E c1 (P0 ))) be a call occurring in COEFF. Then, for all the calls COMPUTE(Pout , Pin ) that are pushed onto the stack we have N k (E c1 (P ))
Pout ∈ ClN k (E c1 (P0 )) . 0
434
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
and Seq be the sequences associated with Proof. Let Out0 = N k (E c1 (P0 )) and let Seq, Seq the stack having the call COMPUTE(Out0 , S(Out0 )) at the bottom. We show that for all Out0 Outi in Seq we have Outi ClOut , that is, Outi ∗Out0 Out0 . Hence, since Outi Outi+1 for 0 0 i < l, it is sufficient to prove that Outi ∈ PARZ (Out0 ).
(3)
= {Seq} ∩ {Seq}
= ∅ and note that we can univocally identify Observe that {Seq} ∩ {Seq} g sequences Seqi (1i g) such that Seq = Seq1 , Seq2 , . . . , Seqg , where • Seq1 is the maximal descending sequence appearing at the beginning of Seq; • Seq2i is the maximal ascending sequence after Seq1 , . . . , Seq2i−1 , 1 < 2i g; • Seq2i+1 is the maximal descending sequence after Seq1 , . . . , Seq2i , 1 < 2i + 1 g. We prove (3) by induction on the number g of ascending or descending sequences in the decomposition of Seq above considered. (Basis). Seq consists of one descending sequence Out0 , . . . , Outl where Outi = E wi (W vi u (S i (Out0 ))) and either Out1 = W (Out0 ) or Out1 = SW (Out0 ). We state that vi > wi for 1i l (and then Outi ∈ PARZ (Out0 )). In fact, let ˆ™ = min{i | vi < wi } (note that
= ∅). Then, we would have v™ˆ−1 > w™ˆ−1 and v™ˆ < w™ˆ , that is, v™ˆ = w™ˆ since {Seq} ∩ {Seq} Out™ˆ−1 / Out™ˆ . (Induction) Seq = Seq1 , . . . , Seqn−1 , Seqn . By induction we know that all parallelograms in Seq1 , . . . , Seqn−1 satisfy (3). Let Seqn = Outs , . . . , Outl and let Outs−1 be the last parallelogram of Seqn−1 . We distinguish two cases. (n is odd) Seqn is a descending sequence. By induction we have Outs−1 ∈ PARZ (Out0 ), that is, Outs−1 = W s−1 (S us−1 (Pˆ )) with s−1 , us−1 ∈ N, s−1 > 0. Since Outs = T (Outs−1 ), with T ∈ {SW, S, SE}, we have Outs = W s (S us (Out0 )) with s , us ∈ N,
= ∅. Now, the same analysis done for the basis s 0. Again, s = 0 since {Seq} ∩ {Seq} shows that parallelograms in Seqn satisfy (3). (n is even) Seqn is an ascending sequence, that is, Outs = T (Outs−1 ) with T ∈ {N W, N, NE}. We claim that Outs−1 = N E(Outs−1 ). In fact, each sequence Stepi of parallelograms examined by COMPUTE(Outi , Ini ) before calling COMPUTE(Outi+1 , Ini+1 ) is 4-connected. This means that Ins−1 Outs−1 . In particular, Ins−1 = N (Outs−1 ) since in the other three cases the call COMPUTE(Outs−1 , Ins−1 ) would compute Coeff (Outs−1 ) without any recursion. Therefore, COMPUTE(Outs−1 , Ins−1 ) recursively calls COMPUTE(N E(Outs−1 ), Ins ) with Ins = Ins−1 = N (Outs−1 ) ∈ Seq. obtained by joining Seq
to Seq, Now, consider the 4-connected sequence Seq = P0 , E(P0 ), . . . , E c1 (P0 ), N (E c1 (P0 )), . . . , N k−1 (E c1 (P0 )), Seq Step0 , . . . , Steps−1 , Ins . We have {Seq}∩{Seq n } = ∅. In fact, Coeff (P ) is known if P ∈ Seq and unknown otherwise (P ∈ Seqn ). Informally, this means that the parallelograms in the ascending sequence Seqn consisting of parallelograms that are restricted to lie in a closed area (delimited by Seq) satisfy (3).
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
435
An immediate consequence of the previous lemma is: Corollary 19. Let Pk = N k (E c1 (P0 )) be a singular parallelogram. If a call COMPUTE (Pk , S(Pk )) occurring in COEFF computes Coeff (P ), then P ∈ B(ClPPkk ) ∪ ClPPkk . Proof. By inspecting the code of COMPUTE, we note that if it computes Coeff (P ), either P is singular (and COMPUTE(P , Pin ) is a call generated by COMPUTE(Pk , S (Pk ))) or P is nonsingular and 8-adjacent to a singular parallelogram Ps such that there exists a recursive call COMPUTE(Ps , Q), generated by COMPUTE(Pk , S(Pk )), that computes Coeff (P ). In the first case Lemma 18 states that P ∈ ClPPkk while in the second we have P ∈ B(ClPPkk ).
Lemma 20. The stack associated with a call COMPUTE(P , S(P )) occurring in COEFF does not contain two identical calls. Proof (by contradiction). Let COMPUTE(Outh , Inh ) be the first repeated occurrence of a call, that is, h = min{0 i l | ∃ > 0, Outi = Outi− ∧ Ini = Ini− }. Without loss of generality, we suppose that Inh = W (Outh ). Consider the 8-connected subsequence of Seq given by S = Outh− , Outh−+1 , . . . , Outh , and the 4-connected subsequence of Seq, S = Steph− , Steph−+1 , . . . , Steph−1 , Inh . For each P ∈ S, the family Coeff (P ) is known. Moreover, we have that for each P ∈ S (P ∈ S) there exists Q ∈ S (Q ∈ S) such that P Q. Note that both sequences are “closed”, that is, their first and last parallelograms coincide. Moreover, we have {S} ∩ { S} = ∅. For each closed sequence S, denote by Inside(S) the set of all parallelograms in PAR(P ) that lie in the area surrounded by S. Then, it is immediate to observe that we have only two cases: S ⊆ Inside(S). This means that if P ∈ S it is impossible to find a 4-connected sequence TP = P0 , . . . , P such that {TP } ∩ {S} = ∅. On the other hand, we know that for every P ∈ S there exists a 4-connected sequence TP from P0 to P, consisting of parallelograms in PAR(P ), such that if Q ∈ TP the family Coeff (Q) has been computed (see the sequence in the proof of Lemma 18). Therefore, we have Seq S Inside(S). S ⊆ Inside( S). Let k1 , k2 ∈ N such that N k1 (E k2 (P0 )) ∈ S
and N h1 (E h2 (P0 )) ∈ S ⇒ k1 + k2 h1 + h2 .
Let Outh = N k1 (E k2 (P0 )). Since S ⊆ Inside( S), it is immediate to prove that S(Outh ) and S. More precisely, because S is 4-connected, it follows that W (Outh ) belong to S = Inh , . . . , S(Outh ), SW (Outh ), W (Outh ), . . . , Inh .
436
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Then, the call computing Coeff (SW (Outh )) is COMPUTE(Outh , Inh ). By observing the code, we note that if COMPUTE(Outh , Inh ) computes Coeff (SW (Outh )) then it has previously computed Coeff (S(Outh )) and it necessarily computes Coeff (W (Outh )). So, this call would terminate without recursion. The following lemma states that we can develop an efficient data structure for storing all the coefficients computed by the algorithm. Lemma 21. The data structure Coeff [] can be implemented in space O(i+j ) and accessed in time O(1). Proof. Coeff [] could be easily implemented as a matrix Mc1 +1×c2 +1 that requires O(i · j ) space and admits O(1) access time. We give here an outline of how to lower the space requirement to O(i + j ). Let us consider two integers Dmaxn = max{degn (ar (n, k)), degn (a0 (n, k)), degn (bs (n, k)), degn (b0 (n, k))}, Dmaxk = max{degk (ar (n, k)), degk (a0 (n, k)), degk (bs (n, k)), degk (b0 (n, k))}, univocally associated with an instance Bn , Bk , Sec, Un , Uk , I, i, j (see also Lemma 13). Consider now the subset L ⊂ {0, 1, . . . , c2 } such that, for c ∈ L, we have {N c (E h (P0 )) ∈ PARZ (P )} = (i + j ). It is easily shown that L 4Dmaxk , since for each c ∈ L there is necessarily a factor of type (k − k1 )1 in one of the polynomials a0 , ar , b0 , bs . Moreover, for c ∈ {0, 1, . . . , c2 } \ L we have {N c (E h (P0 )) ∈ PARZ (P )} < = 4Dmaxn (b + 1) = O(1). In other words, we have to develop an efficient implementation for a sparse matrix having O(c1 + c2 ) entries different from 0. So, we define an array of c2 + 1 links to tables of size 9 (for each singular parallelogram we have to consider at most eight 8-adjacent parallelograms). The ith element of the array allows us to access the families Coeff (N i (E h (P0 ))). As long as a table is not full it supports insertion operations in time O(9) = O(1). Suppose that the cth table is full and we want to insert a new element: this means that c belongs to L, so we dynamically replace the cth table with an array of size c1 = O(i + j ) in order to maintain O(1) access time. Note that the number of replacements is at most 3 · L. Therefore, Coeff [] can be implemented in space O(i + j ) and accessed in time O(1). Theorem 22. The total number of calls to COMPUTE during the execution of COEFF(i, j ) is O(i + j ). Proof. Recall that (i, j ) ∈ P = P (™, E) = N c2 (E c1 (P0 )), with c2 = O(j ) and c1 = O(i + j ). Let COMPUTE(P1 , S(P1 )), . . . , COMPUTE(Pt , S(Pt )) be the sequence of calls observed in COEFF(i, j ) (t = O(j )). Moreover, let TOT = COMPUTE(P1 , P2 ) | P1 ∈ PARZ (P ), P1 P2
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
437
and, for 1k t, let TOTk = {C ∈ TOT | C is a call originated by COMPUTE(Pk , S(Pk ))} . For 1k t, each call COMPUTE(Pk , S(Pk )) recursively generates calls of type COMPUTE(P , Q), with P ∈ ClPPkk , such that Coeff (P ) has not previously been computed by COMPUTE(Pl , S(Pl )) with 1 l < k. In other words, TOTl ∩ TOTm = ∅, for l = m. Lemma 20 guarantees that COMPUTE(Pk , S(Pk )) generates exactly TOTk recursive calls. Hence, recalling Lemma 13, the total number of calls is t t TOTk = TOTk TOT = 4 · PARZ (P ) = O(™ + E) k=1
k=1
= O(i + j ).
At last, we have: Theorem 23. COEFF(i, j ) runs in time O(i + j ) and in space O(i + j ). Proof. We have already noted that PRECOMPUTE(Sec, Bn , Bk , I, i, j ) can be easily implemented in time O(i + j ) and space O(i + j ). Then, by Theorem 22, we know that COMPUTE is called O(i + j ) times. By inspecting the code, we note that each call consists of a constant number of operations because the cost of accessing Coeff [] is O(1) (see Lemma 21). Moreover, the space requirement is bounded by the sum of the maximum stack size and the size of the data structure Coeff []. So, we conclude that COEFF(i, j ) runs in time O(i + j ) using O(i + j ) space. 5. Conclusions In this paper we have presented an algorithm that computes the coefficient [x i y j ](x, y) of a bivariate holonomic formal series (x, y) in time and space O(i +j ) (under the uniform cost criterion). We recall that this is an improvement with respect to the algorithm presented in [9] that runs in time O(i · j ) in the bivariate case. So, it would be interesting to study whether the technique we have presented can be modified in order to deal with more than two variables. More precisely, we would like to answer to the question: is there an algorithm that solves the coefficient problem for ∈ Q[[X]]h with X = {x1 , . . . , xn }, n > 2, in time O(i1 +· · ·+in )? In case of a positive answer, we would have a dramatic improvement of the O(i1 · . . . · in ) upper bound given by Lipshitz’s algorithm. Actually, it is quite natural to extend our method to holonomic power series in three variables but this leads to a quadratic algorithm (versus the cubic Lipshitz’s algorithm). Therefore, a deeper investigation is needed. Last but not least, we would like to develop a robust implementation of the algorithm for a computer algebra system. For testing purposes, we took advantage of the package ‘Mgfun’ (implemented by Chyzak in [3]) to compute the recurrences needed by the algorithm and to develop a prototypical implementation under Maple.
438
P. Massazza, R. Radicioni / Theoretical Computer Science 346 (2005) 418 – 438
Acknowledgements The authors wish to thank the anonymous referees for their accurate suggestions. References [1] I.N. Bernstein, Modules over a ring of differential operators, study of the fundamental solutions of equations with constant coefficients, Functional Anal. Appl. 5 (1971) 1–16 (Russian), pages 89–101 (English). [2] A. Bertoni, P. Massazza, R. Radicioni, Random generation of words in regular languages with fixed occurrences of symbols, in: Proc. of WORDS’03, Fourth Internat. Conf. on Combinatorics of Words, Turku, Finland, 2003, pp. 332–343. [3] F. Chyzak, An extension of Zeilberger’s fast algorithm to general holonomic functions, in: Proc. of FPSAC 1997, Universität Wien, 1997, pp. 172–183. [4] F. Chyzak, B. Salvy, Non-commutative elimination in ore algebras proves multivariate identities, J. Symbolic Comput. 26 (1998) 187–227. [5] A. Denise, Génération aléatoire uniforme de mots de langages rationnels, Theoret. Comput. Sci. 159 (1996) 43–63. [6] I. Dutour, J.M. Fédou, Object grammars and random generation, Discrete Math. and Theoret. Comput. Sci. 2 (1998) 47–61. [7] P. Flajolet, P. Zimmermann, B. Van Cutsem, A calculus for the random generation of labelled combinatorial structures, Theoret. Comput. Sci. 132 (1994) 1–35. [8] L. Lipshitz, The diagonal of a D-Finite power series is D-Finite, J. Algebra 113 (1988) 373–378. [9] L. Lipshitz, D-Finite power series, J. Algebra 122 (1989) 353–373. [10] P. Massazza, R. Radicioni, On computing the coefficients of rational formal series, in: Proc. of FPSAC’04, 16th Annu. Internat. Conf. on Formal Power Series and Algebraic Combinatorics, Vancouver, Canada, 2004, pp. 211–226, available at
. [11] R.P. Stanley, Differentiably Finite Power Series, European J. Combin. 1 (1980) 175–188. [12] D. Zeilberger, A holonomic systems approach to special functions identities, J. Comput. Appl. Math. 32 (1990) 321–368.
Theoretical Computer Science 346 (2005) 439 – 454 www.elsevier.com/locate/tcs
Reconstruction of convex polyominoes from orthogonal projections of their contours C. Picouleau Laboratoire CEDRIC-CNAM, 292 rue Saint Martin, 75003 Paris, France
Abstract The problem of reconstructing a convex polyominoes from its horizontal and vertical projections when the projections are defined as the number of cells of the polyomino in the different lines and columns was studied by Del Lungo and M. Nivat. In this paper, we study the reconstruction of any convex polyomino when the orthogonal projections are defined as the contour length of the object intercepted by the ray. We prove the NP-hardness of this problem for several classes of polyominoes: general, h-convex, v-convex. For hv-convex polyominoes we give a polynomial time algorithm for the reconstruction problem. © 2005 Elsevier B.V. All rights reserved. Keywords: Discrete tomography; Polyomino; NP-complete; Graph; 2-SAT problem
1. Introduction In discrete tomography one wants to reconstruct a discrete object from its projections. This study is motivated by some interesting applications in image processing, data bases, crystallography, statistics, data compressing, scheduling, graph theory, . . . Reconstruction of two dimensional objects from their two orthogonal projections have been studied by many authors. First, Ryser [15] showed how to reconstruct a binary matrix from its row and column sums. In [12] chapters deal with theoretical and practical aspects of discrete tomography (see [2–6,8,9,11,13] for other examples). In [7] Del Lungo and Nivat study the reconstruction of convex polyominoes from their horizontal and vertical projections when the projections are defined as the number of cells of the polyomino in the considered ranks. Here, we will E-mail address: [email protected]. 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.023
440
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
study the reconstruction of convex polyominoes when the orthogonal projections represent the length of their contour lines. This problem is justified by the measurement of a hollow body with fine walls using a X-rays electroscope. To our knowledge this problem was not studied in the literature. This article is organized as follows: the problem definition and some general properties are given in Section 2; Section 3 deals with the NP-hardness of reconstructing a polyomino, even in the cases of h-convexity or v-convexity; the main part of this paper is in Section 4 in which we design a polynomial time algorithm when the polyomino to reconstruct must be horizontally and vertically convex; we conclude and give some new perspectives in Section 5. 2. Preliminaries Let R be a discrete rectangle with m rows and n columns. We denote by C(i, j ) the cell of R lying on the row i and column j; the rows are indiced from top to bottom and the columns from left to right. The top edge of a cell C(i, j ) is denoted by T (i, j ), its right edge by R(i, j ), its bottom edge by B(i, j ), and its left edge by L(i, j ). We say that two cells are connected (or adjacent) if they share an edge. A polyomino (see Fig. 1) is a connected subset of cells of R. In the following we are interested in polyominoes without holes. Without loss of generality, we will consider polyominoes having at least one cell in every row and column. (R is therefore the smallest rectangle containing the considered polyomino.) Given a polyomino P ⊂ R, we can define (P ) its contour line in the following way: (P ) = {T (i, j ) : C(i, j ) ∈ P , C(i − 1, j ) ∈ / P } ∪ {R(i, j ) : C(i, j ) ∈ P , C(i, j + 1) ∈ / P } ∪ {B(i, j ) : C(i, j ) ∈ P , C(i + 1, j ) ∈ / P } ∪ {L(i, j ) : C(i, j ) ∈ P , C(i, j − 1) ∈ / P} (see Fig. 1). Since P is finite and without hole, (P ) is a closed curve. A polyomino is horizontally convex (in the following we write h-convex) (see Fig. 2) if for each row i, the cells C(i, j ) ∈ P form an interval, i.e. ∀i, ∃(l, r) ∈ n2 , l r, ∀k < l, C(i, k) ∈ / P , ∀l k r, C(i, k) ∈ P , ∀k > r, C(i, k) ∈ / P . Similarly a polyomino is vertically convex (v-convex) (see Fig. 2) if for each column j the cells C(i, j ) ∈ P form an interval, i.e. ∀j, ∃(t, b) ∈ m2 , t b, ∀k < t, C(k, j ) ∈ / P , ∀t k b, C(k, j ) ∈ P , ∀k > b, C(k, j ) ∈ / P . A polyomino is hv-convex iff it is h-convex and v-convex (see Fig. 2). The two orthogonal projections of (P ) are defined as following: H (P ) = (h0 , h1 , . . . , hm ), the horizontal projection, is a (m + 1)-dimensional vector of nonnegative integers where hi = |{T (i +1, j ) : T (i +1, j ) ∈ (P )}|+|{B(i, j ) : B(i, j ) ∈ (P )}|; V (P ) = (v0 , v1 , . . . , vn ), the vertical projection, is a (n + 1)-dimensional vector of nonnegative integers where vj = |{R(i, j ) : R(i, j ) ∈ (P )}|+|{L(i +1, j ) : L(i +1, j ) ∈ (P )}| (see Fig. 3). We will now prove two basic properties linking the orthogonal projections with horizontal and vertical convexity. Proposition 1. A polyomino P is h-convex if and only if
n
j =0 vj
= 2m.
Proof. If P is h-convex, then for each line i there is one edge L(i, j ) ∈ (P ) and one edge R(i, j ) ∈ (P ) and thus nj=0 vj = 2m. Reciprocally, let P be a polyomino: for each line
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
441
Fig. 1. A polyomino and its contour.
Fig. 2. h-convex, v-convex and hv-convex polyominoes.
2 3 5 4 5 5 2
1
2
1
2
3
2
1
Fig. 3. The projections H (P ) = (2, 3, 5, 4, 5, 5) and V (P ) = (2, 1, 2, 1, 2, 3, 2, 1).
i there is an edge L(i, j ) ∈ (P ) and an edge R(i, k) ∈ (P ) and L(i, j ) = R(i, k). If n j =0 vj = 2m then for each i there is one edge L(i, j ) ∈ (P ) and one edge R(i, j ) ∈ (P ) and P is h-convex. By symmetry we have the property hereafter. Proposition 2. A polyomino P is v-convex if and only if
m
i=0
hi = 2n.
Given two vectors H and V, our goal is to reconstruct a polyomino P (possibly P may satisfy some additional convexity constraints) such that (P ) has projections H and V. So our problem is formally defined as follows: INPUT : two nonnegative integer vectors H = (h0 , h1 , . . . , hm ) and V = (v0 , v1 , . . . , vn ).
442
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
1 2 2 2
1 2 2 2
2
2
2
2
2
2
2 1
2 1
1 2 2
2
2
2
2 2 1
1 2 2
2
2
2
2 2 1
Fig. 4. Two hv-convex polyominoes having the same projections H and V.
OUTPUT : a polyomino P such that H (P ) = H and V (P ) = V if such a P exists. Before proving complexity results and giving algorithms for various problems, we will make a preliminary remark about these polyominoes having the same contour projections. In Fig. 4 are shown two polyominoes (these polyominoes are both hv-convex) with the same contour projections. One can notice that the two polyominoes have not the same number of cells. Of course this fact is a major difference with the polyominoes reconstructing problems studied in [7].
3. Intractability results The central purpose of this section is to show that the existence problems for the classes of v-convex polyominoes, h-convex polyominoes, and general polyominoes are NP-complete. We first prove the NP-completeness for v-convex polyominoes. Therefore, the same result holds immediately for h-convex polyominoes. As corollary to the polynomial transformation used for Theorem 3 we will deduce the NP-completeness for polyominoes. Theorem 3. The existence problem for the class of v-convex polyominoes is NP-complete. Proof. The transformation is from the problem numerical matching with target sums (NMTS) which is NP-complete in the strong sense [10]. NMTS is defined below: Instance: {a1 , . . . , ap }, {b1 , . . . , bp }, {B1 , . . . , Bp } three sets of p positive integers. Question: Is there a perfect matching between ai ’s and bj ’s such that for each target Bk there is a pair (ai , bj ) of the matching such that Bk = ai + bj ? Let a = max{ai } and b = max{bi }. Without loss of generality, one can consider the instances of NMTS such that min{Bi } > max{a, b}. For each instance of NMTS, we construct an instance of the v-convex polyominoes existence problem in the following way (see Fig. 5 for an example): the rectangle R containing the polyomino has m rows and n columns and we set m = 1 + 2(a + b) and n = 2p + 1. Let i be the number of elements ak such that i = ak ; in the same way, we denote by i the number of elements bk such that i = bk .
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
443
The horizontal projections are as follows: h2i = a−i , h2i+1 = 0,
0 i a − 1,
h2a = h2a+1 = p + 1, h2(a+i)+1 = i ,
h2(a+i) = 0, 1 i b.
The vertical projections are: v0 = v2p+1 = 1, v2i−1 = v2i = 2Bi ,
1 i p.
We prove that if NMTS has a positive answer then there exists a v-convex polyomino P which satisfies the projections. The cells of P are the following (see Fig. 5): C(2a + 1, j ) ∈ P , 1j n; if for the i’st target we have Bi = aj +bk , then C(l, 2i) ∈ P , 2(a −aj ) l 2a and C(l, 2i) ∈ P , 2(a + 1)l 2(a + bk ) + 1 (on column 2i there are a peak of 2aj cells above the line 2a and a peak of 2bk cells below the line 2a + 1). Thus, P is v-convex and the projections are satisfied. Now we prove that if a v-convex polyomino P exists that satisfies the contour projections, there is a positive answer for NMTS. By the reduction we have h2a = h2a+1 = p + 1 and vi > 2 max{a, b}, i = 0, 2p+1, hence we cannot have T (2a, j ) ∈ (P ) and T (2a, j +1) ∈ (P ) or B(2a, j ) ∈ (P ) and B(2a, j +1) ∈ (P ). It follows that for every j, 1 j p+1, we have T (2a, 2j −1) ∈ (P ), T (2a, 2j ) ∈ / (P ) and B(2a, 2j −1) ∈ (P ), B(2a, 2j ) ∈ / (P ). Therefore C(2a + 1, 1) ∈ P and by the connectedness the cell C(2a + 1, 2) belongs to P; condition B1 > max{a, b} implies that there are cells of P up and down the (2a + 1)th row and, P being vertically convex, they form a bar; by the reduction and the fact that P satisfies the projections, there exists ak and bj such that ak + bj = B1 ; and so on for B2 , . . . , Bp . Thus we have a positive answer for NMTS. Using symmetry we have the following: Corollary 4. The existence problem for h-convex polyominoes is NP-complete. From the reduction used in the prove above we can deduce the following result: Corollary 5. The existence problem for general polyominoes is NP-complete. m=2(a+b)+1 hi = 2p + Proof. In the reduction above one can observe that 2a i=0 hi = i=2a+1 1 = n and so in every column there are exactly two unit top or bottom contour of the object. Thus a set of unit lines consistent with such a projection corresponds to a simple closed curve, i.e. the contour of a polyomino. 4. hv-convex polyominoes In this section, we present a polynomial time algorithm that reconstructs a hv-convex polyomino from H and V if such a polyomino exists. The skeleton of our algorithm is the
444
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
1 0 2 0 0 0 4 4 0 1 0 0 0 1 0 1
1
8
8
12 12 10 10 1
Fig. 5. a1 = 3, a2 = 2, a3 = 2, b1 = 4, b2 = 1, b3 = 3, B1 = 4, B2 = 6, B3 = 5.
same as the one of the algorithm of Del Lungo and Nivat [7] used for the reconstruction of hv-convex polyominoes when the projections are the number of cells in each row. We will focus our attention to the specific points of our algorithm. j We introduce some useful notations: Hi∗ = ik=0 hk , Vj∗ = k=0 vk . 4.1. Feet of a polyomino We define the top foot of an hv-convex polyomino P as the edges of (P ) lying on the top segment of R, that is the edges T (1, j ) ∈ (P ). Since P is h-convex, this foot contains h0 adjacent edges, where h0 = |{T (1, j ) : T (1, j ) ∈ (P )}|. In the same way, the bottom foot of P consists of hm adjacent edges B(m, j ) ∈ (P ); the left foot is the v0 adjacent edges L(i, 1) ∈ (P ); and the right foot is the vn adjacent edges R(i, n) ∈ (P ). In the following, we suppose that the left most edge of the top foot is located to the left of the left most edge of the bottom foot. The converse case is obtained by symmetry. Proposition 6. If the left most edge of the top foot is T (1, k), then Vj∗−1 equals the number of P cells in the jth column. Proof. Fig. 6 illustrates the proof. Since the bottom foot is on the right of the top foot, the edges T (tj −1 , j − 1) ∈ (P ), T (tj , j ) ∈ (P ), 1 j k are such that tj −1 tj and the edges B(bj −1 , j − 1) ∈ (P ), B(bj , j ) ∈ (P ), 1 j k are such that bj −1 bj and we
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
v0
vi
vk-1
445
vk
v*i
Fig. 6. The top foot.
v k-1
vl
vj
v k-1 vl
vk+h
v j-1
0
TOP FOOT v*k-1
v*k-1
v*k+h
v*j =m
0
vl vl BOTTOM FOOT Fig. 7. On the left: j k + h0 ; on the right j > k + h0 .
have vj −1 = (tj −1 − tj ) + (bj − bj −1 ). For the first column we have |{C(i, j ) : C(i, 1) ∈ P }| = v0 , so for a column j we obtain |{C(i, j ) : C(i, j ) ∈ P }| = |{C(i, j −1) : C(i, j −1) ∈ P }| + (tj −1 − tj ) + (bj − bj −1 ) = Vj∗−2 + vj −1 = Vj∗−1 . Proposition 7. If the left most edge of the top foot is T (1, k) and the left most edge of the ∗ , l) ∈ (P ), k l min{k + h , j }. bottom foot is B(m, j ), then B(Vl−1 0 Proof. Fig. 7 illustrates the proof. Since the left most edge of the top foot is T (1, k) then ∗ , k) ∈ (P ). Two T (1, l) ∈ (P ), k l k + h0 . From Property 6, we have that B(Vk−1 consecutive bottom edges B(i, l) ∈ (P ), B(i , l + 1) ∈ (P ), k l j − 1 must satisfy i − i = vl . So the property follows. Proposition 8. If the right most edge of the top foot is T (1, k) and the left most edge of the bottom foot is B(m, j ), k + 1 < j then for each column l such that k < l < j , we ∗ /2 , l) ∈ P and the two edges B(b, l) ∈ (P ) and T (t, l) ∈ (P ) satisfy the have C( Vl−1 ∗ . relation: b + t − 1 = Vl−1
446
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
TOP BASE
LEFT BASE
BOTTOM BASE
RIGHT BASE
Fig. 8. The four bases of P. ∗ derives from the fact that P is hv-convex and the Proof. The relation b + t − 1 = Vl−1 ∗ + 1/2 t, and thus column l is situated between the two feet. Since b t we have b Vl−1 ∗ ∗ ∗ Vl−1 + 1 Vl−1 + 1 Vl−1 b > = t 2 2 2 ∗ is even, and when Vl−1 ∗ Vl−1 V∗ +1 = t b l−1 2 2 ∗ is odd. when Vl−1
From the properties above, for a fixed position of the top foot and the bottom foot, we have the following information: by Property 6 we know the number of cells in each column on the left of the top foot; by Property 7 we can recognize the ‘bottom shape’ of the P intersecting the strip of the top foot (and therefore the number of cells in the columns); by Property 8 we get a cell of P in every column between the top and the bottom feet. We define as the top base of P the cells of P that are in the columns containing an edge of the top foot; we denote the top base by t = {C(i, j ) ∈ P , T (1, j ) ∈ (P )}, and we t denote ¯ = {C(i, j ) ∈ / P , T (1, j ) ∈ (P )}. In the same way, we define the bottom base b b = {C(i, j ) ∈ P , B(m, j ) ∈ (P )}, and ¯ = {C(i, j ) ∈ / P , B(m, j ) ∈ (P )}; the left l r l r ¯ ¯ base , the right base and and the sets , are defined in the same way (see Fig. 8). 2 1 We say that two bases 1 , 2 are compatible if 1 ∩ ¯ = ∅ and 2 ∩ ¯ = ∅ (in Fig. 8, b r and are not compatible). So we have that if P is a hv-convex polyomino, and 1 , 2 are two bases of P, then 1 and 2 are compatible. We say that a base 1 intersects a base 2 if 1 ∩ 2 = ∅ (in Fig. 8, b intersects r ). We have that if P is a hv-convex polyomino with the left most edge of its top foot on the left of the left most edge of its bottom foot, then l intersects t and b intersects r ; and by
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
CELL OUTSIDE P
447
CELL INSIDE P
Fig. 9. A row after excluding and filling operations.
symmetry, if P is a hv-convex polyomino with the left most edge of its bottom foot on the left of the left most edge of its top foot, then l intersects b and t intersects r . 4.2. Filling and excluding operations When the four bases are determined and their compatibility checked, our aim is to expand the set of cells that have to belong into P and the set of cells that have not to belong into P. Recall that from the previous steps, for each row, we know at least one cell C(i, j ) belonging to P. The two operations we present hereafter are the same as in [7] (this reference gives a detailed description of these operations named the connecting and coherence operations). These operations take advantage of the convexity constraints. These operations are described for a column j, but they can be easily adapted for a row i. We denote by C(t, j ) and C(b, j ) the top most and the bottom most cells of column j known to be inside P. The filling operation consists to add to the set of cells already inside P, every cell C(i, j ) such that t < i < b. The excluding operation is as follows: if it exists a cell C(i, j ) ∈ / P such that i < t, then for each cell C(k, j ) with 1 k < i, C(i, k) ∈ / P ; if there exists a cell C(i, j ) ∈ / P such that b < i, then for each cell C(k, j ), i < k m, C(k, j ) ∈ / P. Thus a filling-excluding algorithm can be designed as follows: perform filling or excluding operations for every line and column of R until no more cell can be filled in P or excluded of P or until there is a contradiction (a cell C(i, j ) with C(i, j ) ∈ P and C(i, j ) ∈ / P ). The complexity of this algorithm is O(mn). After the filling-excluding algorithm the situation is the following: for each row we have a nonempty interval of cells that belong to P and two intervals of cells that not belong to P (see Fig. 9). The other cells of the row form two intervals where the cells have an undetermined status (either inside P or outside P). Hereafter we establish how to add new cells into P and how to exclude new cells from P, depending upon the position of the row relatively to the feet. We describe these operations for the columns, so it is an easy task to adapt them to the lines. In the case of an external column, from Property 6 we know that |{C(i, k) : C(i, k) ∈ ∗ (without loss of generality, k is a column on the left of the top base), so we use P }| = Vk−1 ∗ be the number of cells inside P, these cells are the same operations as in [7]. Let l Vk−1 C(t +1, k), . . . , C(t +l, k); the interval of cells outside P are C(1, k), . . . , C(h, k), 1 ht ∗ and C(b, k), . . . , C(m, k), t + l < b m. We can remark that Property 6 implies l Vk−1 ∗ b − h + 1. The interval containing the l cells inside P must be extended by filling and Vk−1 ∗ − l cells. We consider two cases in order to make this extension (see Fig. 10): it with Vk−1 ∗ − l < t − h or t + V ∗ the first case is when Vk−1 k−1 < b − 1, the second case is when
448
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
CELL INSIDE P
CELL OUTSIDE P
UNDETERMINED STATUS
NEW CELL INSIDE P
NEW CELL OUTSIDE P
Fig. 10. An extension of two cells. ∗ − l > t − h or t + V ∗ > b − 1. For the case V ∗ − l < t − h (the case t + V ∗ < Vk−1 k−1 k−1 k−1 b − 1 is obtained by a symmetrical argument), since the interval of cells inside P must be ∗ − l cells, the cells C(i, k), i t − (V ∗ − l) (C(i, k), i > t + V ∗ in extended with Vk−1 k−1 k−1 ∗ the case t + Vk−1 < b − 1) are necessarily outside P. Thus the set of undetermined cells ∗ − l) + 1, k), . . . , C(t, k)} ∪ {C(t + l + 1, k), . . . , C(t + V ∗ , k)}. becomes {C((t − (Vk−1 k−1 ∗ ∗ Also we have Vk−1 − l = |{C((t − (Vk−1 − l) + 1, k), . . . , C(t, k)}| = |{C(t + l + ∗ , k)}|. For the case V ∗ − l > t − h (the case t + V ∗ 1, k), . . . , C(t + Vk−1 k−1 k−1 > b − 1 can be derived using symmetry), in the interval C(h + 1, k), . . . , C(t, k) at most t − h cells ∗ − l of the extension must be inside P; so the (V ∗ − l) − (t − h) cells among the Vk−1 k−1 ∗ − l + h, k) must be inside P. Then the set of undetermined cells C(t + l + 1, k), . . . , C(Vk−1 ∗ − l + h + 1, k), . . . , C(t + V ∗ , k)} and we becomes {C(h + 1, k), . . . , C(t, k)} ∪ {C(Vk−1 k−1 ∗ −l +h+1, k), . . . , C(t +V ∗ , k)}|. have t −h = |{C(h+1, k), . . . , C(t, k)}| = |{C(Vk−1 k−1
Now we consider the case of an internal column. Let k be a column situated on the right of ∗ ∗ the left base and on the left of the right base. We suppose that Vk−1 m (if Vk−1 > m, since vj = 2m, renumbering the columns from right to left leads to a similar situation). If l is the ∗ , l) ∈ (P ). We denote right most column of the left base, from Property 7 we have B(Vl−1 by p the number of cells belonging to P; these cells form the interval C(t + 1, k), . . . , C(t + p, k), and the cells outside P constitute the two intervals C(1, k), . . . , C(h , k), 1 h < t, and C(h +1, k), . . . , C(m, k), t +p h < m (see Fig. 11). If P is a hv-convex polyomino, there is one unique row i, i ∈ {h + 1, . . . , t + 1}, such that T (i, k) ∈ (P ) and one unique row j, j ∈ {t + p, . . . , h }, such that B(j, k) ∈ (P ): hence i and j satisfy the relation ∗ . Therefore we have {C(q, k) ∈ ∗ − h < q < V ∗ − h + 1}, / P : Vk−1 i + j − 1 = Vk−1 k−1 ∗ − t}, and {C(q, k) ∈ P : V ∗ − t − p + 1 q t + 1}. {C(q, k) ∈ P : t + p q Vk−1 k−1 Now, one can remark that after these filling and excluding operations, for any row, the two intervals of undetermined cells contain the same number of cells.
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
l
449
k
h'
CELL INSIDE P
CELL OUTSIDE P t NEW CELL OUTSIDE P t+p
h''
Fig. 11. A cell is excluded.
4.3. Relations between undetermined cells After the previous filling and excluding operations if it remains no undetermined cell, we have reconstruct P an hv-convex polyomino satisfying H and V. When there are undetermined cells, we show how to link two undetermined cells of a same row. We have two kinds of relations according as the row containing the two cells is internal or external. Again we present these relations in the case of a column j. First we treat the case where j is an external column: let C(i, j ) be an undetermined cell situated above the interval of cells set inside P. From Property 6 we know l, the number of cells of a hv-convex polyomino, on the column j. Then we have the following property. Proposition 9. C(i, j ) ∈ P if and only if C(i + l, j ) ∈ / P. Proof. Since P is hv-convex and satisfies H and V, C(i, j ) and C(i + l, j ) cannot be inside P together (otherwise the number of cells inside P would be at least l + 1). After the filling operations, since C(i, j ) is above the cells set inside P, the cell C(i + l, j ) is below this set; thus C(i, j ) and C(i + l, j ) cannot be outside P together (otherwise the number of cells inside P would be at most l − 1). Now we consider the case where j is an internal column: let C(i, j ) be an undetermined cell such that C(i, j ) is above the interval of cells already set into P; we suppose that Vj∗−1 m. Recall that from Property 8 we have i Vj∗−1 /2 . We establish the property below. Proposition 10. C(i, j ) ∈ P if and only if C(Vj∗−1 − i − 1, j ) ∈ P .
450
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
j
k-1
CELL OF P i k
CELL OUTSIDE P i
V*=l+k-1 j l
V*-i-1 j l V*-i-1 j Fig. 12. Relation in an internal column.
Proof. Fig. 12 illustrates the proof. If P is a hv-convex polyomino satisfying H and V, there exist k and l (k l), such that T (k, j ) ∈ (P ), B(l, j ) ∈ (P ) and (k − 1) + l = Vj∗−1 . If C(i, j ) ∈ P , we have i k which implies Vj∗−1 −i−1 Vj∗−1 −l and C(Vj∗−1 −i−1, j ) ∈ P ; if C(i, j ) ∈ / P , i < k and we obtain Vj∗−1 − i − 1 > Vj∗−1 − l, hence C(Vj∗−1 − i − 1, j ) ∈ / P. 4.3.1. Graph of undetermined cells Now we construct a graph capturing the relations defined above. This graph is G = (U, E) where the vertex set U corresponds to the undetermined cells and the edge set E is as follows: If C(i, j ) is on an external row and C(i, j ) is on the left of the interval of cells that are inside P then {C(i, j ), C(i, j + l)} ∈ E, where l is the number of cells of P in the row i, If C(i, j ) is on an external column and C(i, j ) is above the interval of cells that are inside P then {C(i, j ), C(i + l, j )} ∈ E, where l is the number of cells of P in the column j, If C(i, j ) is on an internal row and C(i, j ) is on the left of the interval of cells that are ∗ − j − 1)} ∈ E, inside P, then {C(i, j ), C(i, Hi−1 If C(i, j ) is on an internal column and C(i, j ) is above the interval of cells that are inside P then {C(i, j ), C(Vj∗−1 − i − 1, j )} ∈ E. Since for each row the two intervals of undetermined cells have the same size, each vertex of G has degree 2 and G is a collection of disjoint even cycles {C1 , . . . , Ck }. In a same manner as in [7] we associate a boolean variable xi with each vertex vi of G. If xi = 1 then the corresponding cell is inside P; if xi = 0 the cell is outside P. From Properties 9 and 10, we have that each cycle Ci corresponds to one unique variable: indeed for any edge {vk , vl } ∈ E, when the two corresponding cells are in an external row we have xk = x¯l (Property 9), and when they are in an internal row we have xk = xl (Property 10).
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
451
h x1
x2
x3
x4
x1
x2
x3
x4
Fig. 13. Boolean variables for an external row.
h1 x1
x2
x3
x4
x4
x3
x2
x1
h2 Fig. 14. Boolean variables for an internal row.
4.3.2. How to satisfy the hv-convexity As in [7] we show that finding P a hv-convex polyomino consistent with H and V, is equivalent to satisfy a boolean formula over the variables xi associated with the cycles Ci . We will express the formula associated with a row i (the formula associated with a column can be easily derived). We study two cases, depending whether the row is external or internal. When the row i is external we are in the same situation as in [7]: let h be the number of cells of P in row i; we denote by x1 , . . . , xk the variables associated with the undetermined cells situated on the left of the cells that are inside P (from left to right, see Fig. 13); thus the variables associated with the undetermined cells on the right are x¯1 , . . . , x¯k (from left to right, {C(i, j ), C(i, j + h)} ∈ E). We have the next property (see [7] for its proof). Proposition 11. The boolean formula Fi = (x¯1 ∨ x2 ) ∧ (x¯2 ∨ x3 ) ∧ · · · ∧ (x¯k−1 ∨ xk ) is satisfied if and only if there are exactly hi successive cells in row i of P. ∗ = h +h with 0 h h ; Now we consider the case where the row i is internal: let Hi−1 1 2 1 2 we denote by x1 , . . . , xk the variables associated with the undetermined cells situated on the left of the cells inside P (from left to right, see Fig. 14); thus the variables associated with the undetermined cells situated on the right are x1 , . . . , xk (from the right to the left); thus if xl corresponds to the cell C(i, h1 ), xl is also associated with the cell C(i, h2 ) (see Property 10). The property below establishes the equivalence between the satisfaction of a boolean formula and the h-convexity and the horizontal projection constraints for the row i.
Proposition 12. Fi = (x¯1 ∨ x2 ) ∧ (x¯2 ∨ x3 ) ∧ · · · ∧ (x¯k−1 ∨ xk ) is satisfied if and only if there is one unique interval of cells inside P in row i and the projection hi is satisfied. Proof. If the h-convexity and projection constraints are satisfied then Fi is true (using similar arguments used in the proof of Property 11).
452
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
If Fi is satisfied: let l be the smallest index such that xl = 1, then we have xp = 1 for l < p k. Let C(i, h1 ) and C(i, h2 ) be the two cells associated with xl , then cells C(i, h1 ), C(i, h1 +1), . . . , C(i, h2 ) are inside P and the h-convexity holds. Since h1 +h2 = ∗ , we also satisfy the projection constraint. Hi−1 Now, we are able to prove the main result. Theorem 13. For a fixed and coherent position of the four feet, P a hv-convex m polyomino n satisfying (H, V ) exists if and only if the boolean formula F = F i=1 i j =1 Fj is satisfied. Proof. If P is a hv-convex polyomino with projections (H, V ) the status of each cell is determined, and so the value of the variable associated with each cycle Ci of G. Thus the boolean formula Fi associated with each row i has value true and F is satisfied. If F is satisfied, each Fi is true. So from Properties 6, 11 and 12, P is a hv-convex polyomino with contour projections H and V. 4.4. Reconstruction algorithm Here, we give an algorithm that builds P an hv-convex polyomino that satisfies (H, V ) is such a P exists. The is as follows: algorithm i i 1. compute Hi∗ = h , 1 i m, and Vi∗ = j =0 j j =0 vj , 1 i n, and check that Hm∗ = 2n, Vn∗ = 2m (Properties 1 and 2) 2. repeat 2.1 choose a coherent position for the four feet; 2.2 compute the bases t , b , l , r and check their compatibility 2.3 perform filling and excluding operations and check their consistency 2.4 construct G and match a boolean variable xi with each cycle Ci of G 2.5 check whether the boolean formula F associated with G is satisfied until there exists P an hv-convex polyomino that satisfies (H, V ) or all the feet positions have been examined. Theorem 14. The reconstruction problem of an hv-convex polyomino P satisfying the projections H and V can be solved in polynomial time. Proof. From Theorem 13 one can check that our algorithm returns a hv-convex polyomino satisfying H and V if such a polyomino exists. The number of feet positions is O(m2 n2 ). The determination of the four bases can be performed in time O(m + n) from the partial sums Hi∗ and Vi∗ ; their compatibility can be checked in time O(mn). Filling and excluding operations can be performed in time O(m2 n2 ). The construction of G and the determination of its cycles can be done in time O(mn). Build the boolean formula F takes O(mn), and since F is a 2-SAT formula it can be solved in time O(mn) (see [1]). Thus the time complexity of the algorithm is O(m4 n4 ).
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
453
5. Conclusion We have studied problems arising in the reconstruction of convex polyominoes when the orthogonal projections are defined as the length of their contour lines. We have proved the NP-completeness of the related existence problems in the case of h-convex or v-convex polyominoes. For the class of hv-convex polyominoes we gave a polynomial time reconstruction algorithm. From a practical point of view, the problem of unicity of a solution is often a crucial aspect in discrete tomography (see [14]). This problem is not studied in this paper but should be the subject of a future work. Other future researches arise with the following optimization problems: Fig. 4 shows two hv-convex polyominoes with the same projections but with two different areas; let P be the set of hv-convex polyominoes consistent with the projections (H, V ), one can be interested in finding a thin polyomino that is p ∈ P such that |{C(i, j ) : C(i, j ) ∈ p}| = minp ∈P {|{C(i, j ) : C(i, j ) ∈ p }|} or, on the opposite, in finding a fat polyomino that is p ∈ P such that |{C(i, j ) : C(i, j ) ∈ p}| = maxp ∈P {|{C(i, j ) : C(i, j ) ∈ p }|}. A further work is trying to adapt our polynomial algorithm to these optimization problems.
6. Acknowledgments The author express its gratitude to an anonymous referee for helpful comments that substantially contributed to improve the presentation of the paper. References [1] B. Aspvall, M. Plass, R. Tarjan, A linear-time algorithm for testing the truth of certain quantified Boolean formulas, Inform. Process. Lett. 8 (1979) 121–123. [2] E. Barcucci, A. Del Lungo, M. Nivat, R. Pinzani, Reconstructing convex polyominoes from horizontal and vertical projections, Theoret. Comput. Sci. 155 (1996) 321–347. [3] E. Barcucci, A. Del Lungo, M. Nivat, R. Pinzani, Medians of polyominoes: a property for reconstruction, Internat. J. Imaging Systems Technol. 8 (1998) 121–123. [4] R.A. Brualdi, Matrices of zeros and ones with fixed row and column sum vectors, Linear Algebra Appl. 33 (1980) 159–231. [5] S.K. Chang, The reconstruction of binary patterns from their projections, Commun. ACM 14 (1971) 21–24. [6] A. Del Lungo, Polyominoes defined by two vectors, Theoret. Comput. Sci. 127 (1994) 187–198. [7] A. Del Lungo, M. Nivat, in: G. Herman, A. Kuba (Eds.), Reconstruction of Connected Sets from Two Projections, in Discrete Tomography, Birkhauser, Basel, 1999, pp. 163–188. [8] A. Del Lungo, M. Nivat, R. Pinzani, The number of convex polyominoes reconstructible from their orthogonal projections, Discrete Math. 157 (1996) 65–78. [9] R.J. Gardner, P. Gritzmann, Discrete tomography: determination of finite sets by X-rays, Trans. Amer. Math. Soc. 349 (1997) 2271–2295. [10] M.R. Garey, D.S. Johnson, Computers and Intractability, a Guide to the Theory of NP-Completeness, Freeman, New York, 1979. [11] P. Gritzmann, D. Prangenberg, S. de Vries, M. Wiegelmann, Success and failure of certain reconstruction and uniqueness algorithms in discrete tomography, Internat. J. Imaging Systems Technol. 9 (1998) 101–109. [12] G. Herman, A. Kuba, Discrete Tomography: Foundations, Algorithms and Applications, Birkhauser, Basel, 1999.
454
C. Picouleau / Theoretical Computer Science 346 (2005) 439 – 454
[13] A. Kuba, The reconstruction of two-directionally connected binary patterns from their two orthogonal projections, Comput. Vision, Graphics, Image Process. 27 (1984) 249–265. [14] A. Kuba, G.T. Herman, in: G. Herman, A. Kuba (Eds.), Discrete Tomography: A Historical Overview, in Discrete Tomography, Birkhauser, Basel, 1999, pp. 4–34. [15] H. Ryser, Combinatorial Mathematics, Mathematical Association of America, Quinn & Boden, Rahway, NJ, 1963.
Theoretical Computer Science 346 (2005) 455 – 468 www.elsevier.com/locate/tcs
Three dimensional Narayana and Schröder numbers Robert A. Sulanke Department of Mathematics, Boise State University, Boise, ID, USA
Dedicated to the memory of Alberto Del Lungo
Abstract Consider the 3-dimensional lattice paths running from (0, 0, 0) to (n, n, n), constrained to the region {(x, y, z) : 0 x y z}, and using various step sets. With C(3, n) denoting the set of constrained paths using the steps X := (1, 0, 0), Y := (0, 1, 0), and Z := (0, 0, 1), we consider the statistic counting descents on a path P = p1 p2 . . . p3n ∈ C(3, n), i.e., des(P ) := |{i : pi pi+1 ∈ {Y X, ZX, ZY }, 1 i 3n − 1}|. A combinatorial cancellation argument and a result of MacMahon yield a formula for the 3-Narayana number, N(3, n, k) := |{P ∈ C(3, n) : des(P ) = k + 2}|. We define other statistics distributed by the 3-Narayana number and show that 4 k 2k N (3, n, k) yields the nth large 3-Schröder number which counts the constrained paths using the seven positive steps of the form (1 , 2 , 3 ), i ∈ {0, 1}. © 2005 Elsevier B.V. All rights reserved. Keywords: Lattice paths; Narayana numbers; Schröder numbers.
1. Introduction We begin by reviewing the usual Narayana and Schröder numbers. Let C(2, n) denote the set of planar lattice paths using the unit steps E := (1, 0) and N := (0, 1), running from (0, 0) to (n, n), and lying in the wedge {(x, y) : 0 x y}. Common, and essentially equivalent, statistics on C(2, n) are the number of peaks and the number of valleys. These are defined as the number of NE pairs (EN pairs, respectively) on P, which we denote by
E-mail address: [email protected]. 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.014
456
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
Table 1 The statistical values for paths in C(3, 2) P ∈ C(3, 2)
des(P )
asc(P )
des(P ) − asc(P )
ZZYYXX ZZYXYX ZYZYXX ZYZXYX ZYXZYX
2 3 3 3 4
0 1 1 2 1
2 2 2 1 3
peaks(P ) (vals(P ), respectively). If we define the Narayana number N (n, k) := |{P ∈ C(2, n) : vals(P ) = k}| = |{P ∈ C(2, n) : peaks(P ) = k + 1}| for 0 k n − 1, it is well known that (See Section 6 and sequence A001263 in [12].) ⎡ ⎤ n n−1 n 1 n k+1 k+1 = det ⎣ ⎦ . (1) N (n, k) = n+1 n n k k+1 k+1
k+1
We define the Narayana polynomial so N2,n (t) :=
N (n, k)t k =
k
P ∈C (2,n)
t vals(P ) =
t peaks(P )−1 .
P ∈C (2,n)
Note that (|C(2, n)|)n 0 = (N2,n (1))n 0 is the sequence of Catalan numbers. When t = 2, consider counting the set of all copies of the paths of C(2, n) on which the peaks are independently colored blue or red. If on each copy we change each blue peak into a diagonal step of the form (1, 1) and discard the red color, then the copies are transformed into Schröder paths. Indeed (2N2,n (2))n 1 (with the term for n = 0 equaling 1) is the sequence of large Schröder numbers (sequence A006318 in [12]). For 3-dimensional results, let C(3, n) denote the set of paths using the steps X := (1, 0, 0), Y := (0, 1, 0), and Z := (0, 0, 1), running from (0, 0, 0) to (n, n, n), and lying in the chamber {(x, y, z) : 0 x y z}. On C(3, n) we define two statistics, the number of descents and the number of ascents (Table 1) so that for any path P := p1 p2 . . . p3n , des(P ) := |{i : pi pi+1 ∈ {Y X, ZX, ZY }, 1 i 3n − 1}|, asc(P ) := |{i : pi pi+1 ∈ {XY , XZ, YZ}, 1 i 3n − 1}|. For 0 k 2n − 2, we define the 3-Narayana numbers to be N (3, n, k) := |{P ∈ C(3, n) : asc(P ) = k}|, and the 3-Narayana polynomial to be N3,n (t) :=
k
N (3, n, k)t k .
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
457
We find that (see sequence A087647 in [12,17]) N3,1 (t) = 1, N3,2 (t) = 1 + 3t + t 2 , N3,3 (t) = 1 + 10t + 20t 2 + 10t 3 + t 4 , N3,4 (t) = 1 + 22t + 113t 2 + 190t 3 + 113t 4 + 22t 5 + t 6 , N3,5 (t) = 1 + 40t + 400t 2 + 1456t 3 + 2212t 4 + 1456t 5 + 400t 6 + 40t 7 + t 8 . When t = 1 and n0, as seen in Section 2.1, |C(3, n)| = N3,n (1) =
2(3n)! , n!(n + 1)!(n + 2)!
(2)
which are known as the 3-dimensional Catalan numbers ([7, p. 133], [18]. Sequence A005789 in [12]. We remark that the paths of C(3, n) can be represented as standard Young tableaux of rectangular shape 3 × n; hence, (2) follows immediately from the hook-length formula.) As we will see in Section 5 where we count paths with steps being the edges and diagonals of the unit cube, we should take the sequence (4N3,n (2))n 1 = (4, 44, 788, 18372, 505156, 15553372, 520065572, . . . ) to be the 3-dimensional analogue of the large Schröder numbers. (Sequences A088594 in [12].) In Section 2 we will use a combinatorial cancellation argument and a result of MacMahon to prove Proposition 1. If M(n, h, i, j ) denotes the matrix ⎡ n−1n−1−i n−2n−2−i ⎤ nn−i i
j
i
j
i
j
⎢ ⎥ ⎢ n+1 n+1+i n n+i n−1 n−1+i ⎥ ⎢ h−i−j i+j ⎥, h−i−j i+j h−i−j i+j ⎣ ⎦ n+2 n+1 n h−j
h−j
h−j
then, for 2 h 2n, |{P ∈ C(3, n) : des(P ) = h}| =
h h i=0 j =0
det(M(n, h, i, j )).
(3)
In Section 3 we will establish a bijection showing Proposition 2. The statistics asc(·) and des(·) − 2 are equi-distributed; i.e., for 0 k 2n − 2, |{P ∈ C(3, n) : asc(P ) = k}| = |{P ∈ C(3, n) : des(P ) = k + 2}|.
458
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
In Section 4 we will indicate how the following result can be routinely deduced from more general results of MacMahon [7]: Proposition 3. For 0 k 2n − 2, N (3, n, k) =
k j =0
(−1)k−j
2 3n + 1 n + i + j n + i −1 . k − j i=0 n n
(4)
Moreover, the 3-Narayana polynomial N3,n (t) is a reciprocal polynomial (i.e., the sequence of its coefficients is palindromic) of degree 2n − 2. This paper emphasizes the derivation of formula (3). Upon reviewing the methods used to derive (3) and (4), it does not appear that either method can be modified so that formula (3) can be derived directly with respect to the number of ascents or that formula (4) can be derived directly with respect to the number of descents. In [17] the author studies (4), showing it to be much more tractable than (3) for establishing the reciprocity of the 3-Narayana polynomials, for finding recurrence relations, and for generalizing results to higher dimensions.
2. Derivation of the determinantal formula (3) In Section 2.1 we will “twist” the combinatorial-cancellation scheme of the Gessel– Viennot method [3,5] to enumerate unconstrained paths with respect to the number of descents. We do so by first mapping the paths of C(3, n) to certain non-intersecting triples of planar lattice paths, which are a special case of “vicious walkers” introduced by Fisher [2] (See also [4,5].). We will then do our counting using these triples. In Section 2.2 we will complete the derivation of formula (3) by using a result of MacMahon regarding the equi-distribution of the number of descents and the number of exceedances to enumerate the unconstrained paths using the steps X, Y , and Z. The extension of the techniques of this section to higher dimensions does not appear to yield a neat general formula. 2.1. Combinatorial cancellation with a twist Let S3 denote the set of the permutations on {1, 2, 3}. Using the notation, = 1 2 3 , we designate the permutations as 1 = 11 22 33 , 2 = 21 12 33 , (1) (2) (3) 3 = 11 23 23 , 4 = 21 32 13 , 5 = 13 21 23 , and 6 = 13 22 31 . Observe that their signs satisfy sgn(1 ) = sgn(4 ) = sgn(5 ) = 1 while sgn(2 ) = sgn(3 ) = sgn(6 ) = −1. For ∈ S3 and n 1, let T (n, ) denote the set of all ordered triples of 2-dimensional lattice paths (R, R , R ) where , and R = r r . . . r • (i) the paths R = r1 r2 . . . r3n , R = r1 r2 . . . r3n 1 2 3n use the steps E = (1, 0) and N = (0, 1), • (ii) R runs from (−(1), (1)) to (2n − 1, n + 1), • (iii) R runs from (−(2), (2)) to (2n − 2, n + 2),
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
459
(2n–3,n+3) (2n–2,n+2) (2n–1,n+1)
(–3,3) (–2,2) (–1,1)
Fig. 1. The triple of paths (R, R , R ) belonging to N (4) ⊂ T (4, 1 ). This triple corresponds to the path ZYZYXZZYXYXX ∈ C(3, 4).
• (iv) R runs from (−(3), (3)) to (2n − 3, n + 3), • (v) for each i, 1 i 3n, exactly one of ri , ri , and r i is an N step. Figs. 1 and 3 illustrate triples belonging to T (4, 1 ), T (7, 1 ), and T (7, 2 ). Further, let T (n, , XY ) denote that subset of triples (R, R , R ) in T (n, ) where R and R have the most north-eastern point of intersection. Likewise, let T (n, , YZ) denote that subset of triples (R, R , R ) in T (n, ) where R and R have the most north-eastern point of intersection. Condition (v) guarantees that there is no triple where R and R have the most north-eastern point of intersection. Let N (n) denote that subset of T (n, 1 ) containing no intersecting paths. Let L(n1 , n2 , n3 ) denote the set of unconstrained lattice paths running from (0, 0, 0) to
(n1 , n2 , n3 ) using the unit steps X, Y , and Z. We define a bijection with domain ∈S3 T (n, ) so that, for each ∈ S3 , : T (n, ) → L(n + 1 − (1), n + 2 − (2), n + 3 − (3)) and, if ((R, R , R )) = p1 p2 . . . p3n , then, for 1 i 3n, (ri , ri , r i ) = (N, E, E) (ri , ri , r i ) = (E, N, E) (ri , ri , r i ) = (E, E, N)
if and only if pi = X, if and only if pi = Y, if and only if pi = Z.
We now define an involution on ∈S3 T (n, ), which is sign reversing with respect to the signs of the permutations, by the following three cases. Figs. 2 and 3 illustrate this involution. Case (i): For (R, R , R ) ∈ N (n), ((R, R , R )) = (R, R , R ). Case (ii): For (R, R , R ) ∈ T (n, , XY ), factor R as R = R 1 R 2 R 3 R 4 where R 1 = r 1 . . . r j , R 2 = r j +1 . . . r k , R 3 = r k+1 . . . r , R 4 = r +1 . . . r 3n , are the most north-eastern point of so that the initial points of the steps r+1 and r+1 intersection of R and R , and so that R 1 and R 3 are maximal subpaths (perhaps empty)
460
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
Fig. 2. The action of the involution on
∈S3
T (n, ).
consisting only of N steps. Using the j , k, and so determined, let R1 = r1 . . . rj , R2 = rj +1 . . . rk , R3 = rk+1 . . . r , R4 = r+1 . . . r3n , . R1 = r1 . . . rj , R2 = rj +1 . . . rk , R3 = rk+1 . . . r , R4 = r+1 . . . r3n For any path Q = q1 . . . qm , let Q denote qm . . . q1 ; this is the “twist” of Q. We then define ((R, R , R )) = (R1 R2 R3 R4 , R1 R2 R3 R4 , R 1 R 2 R 3 R 4 ). Case (iii): Similarly for (R, R , R ) ∈ T (n, , YZ), factor R as R = R1 R2 R3 R4 where R1 = r1 . . . rj , R2 = rj +1 . . . rk , R3 = rk+1 . . . r , R4 = r+1 . . . r3n , so that the initial points of the steps r+1 and r +1 are the most north-eastern point of intersection of R and R , and so that R1 and R3 are maximal subpaths (perhaps empty) consisting only of N steps. Using the j , k, and so determined, let , R1 = r1 . . . rj , R2 = rj +1 . . . rk , R3 = rk+1 . . . r , R4 = r+1 . . . r3n R 1 = r 1 . . . r j , R 2 = r j +1 . . . r k , R 3 = r k+1 . . . r , R 4 = r +1 . . . r 3n .
We then define ((R, R , R )) = (R1 R2 R3 R4 , R1 R 2 R3 R4 , R 1 R2 R 3 R 4 ). In essence, acts by cutting out a section (R2 , R2 , R 2 ), twisting (i.e., rotating) each subpath of this section 180◦ , and then re-attaching each subpath according to the relevant permutation. We observe that, except on N (n), is sign reversing with respect to the permutations defining the set of triples. Importantly, one can routinely check that the twisting scheme yields des(((R, R , R ))) = des((R, R , R )).
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
461
Fig. 3. The first triple belongs to T (7, 1 , XY ) and corresponds to the path ZZYXXXZXYZXYYZZYYZYXX ∈ L(7, 7, 7). The second triple is its image under . It belongs to T (7, 2 , XY ) and corresponds to the path ZZXXYZXYZYYYXZZYYZYXX ∈ L(6, 8, 7).
for all (R, R , R ) ∈ we have
∈S3
T (n, ). Hence, by the cancellation summarized in Fig. 2,
Lemma 1. For n 1,
(R,R ,R )∈N (n)
t des((R,R ,R
))
=
∈S3
sgn()
(R,R ,R )∈T
t des((R,R ,R (n,)
or equivalently, P ∈C (3,n)
t des(P ) =
∈S3
sgn()
P ∈L(n+1−(1),n+2−(2),n+3−(3))
t des(P ) .
))
462
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
In the case that t = 1, we immediately obtain the formula for the three dimensional Catalan numbers. Since the cardinality of L(n1 , n2 , n3 ) is (n1 + n2 + n3 )!/(n1 !n2 !n3 !), Lemma 1 implies the following, which simplifies to (2): ⎡ 1 ⎤ 1 1 ⎢ |C(3, n)| = (3n)! det ⎢ ⎣
n! 1 (n+1)! 1 (n+2)!
(n−1)! 1 n! 1 (n+1)!
(n−2)! 1 (n−1)! 1 n!
⎥ ⎥. ⎦
2.2. Two statistics for unconstrained paths We now seek a formula for P ∈L(n1 ,n2 ,n3 ) t des(P ) , where L(n1 , n2 , n3 ) was defined in Section 2. Order the steps so that X < Y < Z. We recall two statistics considered by MacMahon [7, Arts. 149–151]: the number of descents (called number of major contacts in [7]) and number of exceedances. For any path P = p1 p2 . . . pm in L(n1 , n2 , n3 ), define • des(P ) = |{i : pi > pi+1 }| = the number of ZY , ZX, or YX pairs on P . • exceed(P ) = |{i : pi > qi }| where q1 q2 . . . qm is that path in L(n1 , n2 , n3 ) for which qi qi+1 for 1i < m. Observe that exceed(P ) is the number of Z steps in first n1 + n2 positions of P plus the number of Y steps in first n1 positions of P . We will use a result of MacMahon [7,8] which is considered bijectively by Foata, as recorded in [6] and [8, pp. 455–456], and which in our case reduces to the following: Proposition 4. The statistics des and exceed are identically distributed on L(n1 , n2 , n3 ). Hence, using this proposition and counting the paths having i Z’s and j Y ’s in the first n1 positions and k Z’s and Y ’s in the next n2 positions, we have t des(P ) = |{P : des(P ) = h}|t h P ∈L(n1 ,n2 ,n3 )
h
=
|{P : exceed(P ) = h}|t h
h
=
g(n1 , n2 , n3 , i, j, k, )t i+j +k ,
i,j,k,
where g(n1 , n2 , n3 , i, j, k, ) denotes n1 ! n2 ! n3 ! . i!j !(n1 −i −j )! k!!(n2 −k−)! (n3 −i −k)!(n2 −j −)!(i +j +k+−n3 )! Consequently, upon applying the Chu–Vandermonde convolution, we find t des(P ) P ∈L(n1 ,n2 ,n3 )
=
n1 n 1 − i n 2 n2 + i n3 t i+j +k . i k i + k j i + j i j k
(5)
We remark that MacMahon [7, Art. 151] derives an equivalent formula. Finally, Lemma 1 and (5), with k = h − i − j , yield formula (3).
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468 Table 2 The candidate matrices 000 MD := 1 0 0 110
000
Ma := 0 1 1 011
110 010 000
000
010
000 011
011
MA := 0 0 1
101
001 101 000
Md := 0 1 0
Mb := 0 0 0
010 100
010 Mf := 1 1 0
100
V Ma := 0 0 0
000 Me := 1 1 0
V Mc := 1 0 1
001
101 Mc := 0 0 0 001
463
000
100 110 000 010 000 110
000 001 101 101 100 000 010 011 000 001 000 011 110 000 100
000
101 001 000 000 100 101 000 011 010 011 000 001 100 000 110
3. Other statistics having the 3-Narayana distribution Our main intention here is to obtain a bijective proof of Proposition 2. To do so, we will consider 24 statistics for C(3, n), each of which is encoded in terms of a 3 by 3 0-1 matrix M. With X1 := X, X2 := Y , X3 := Z, with P := p1 p2 . . . p3n ∈ C(3, n), and with (M)j denoting the entry in row j and column of M, we let M denote a statistic such that M (P ) :=
3 3 j =1 =1
(M)j |{i : pi pi+1 = Xj X , 1 i 3n − 1}|.
For example, the statistic asc corresponds to the matrix MA :=
0 1 1 001 000
, since
asc(P ) = |{i : pi pi+1 ∈ {X1 X2 , X1 X3 , X2 X3 }}|.
0 0 0 Similarly, the statistic des corresponds to the matrix MD := 1 0 0 . 110 For small values of n, a simple search over C(3, n) shows that, if a statistic has the prescribed form M and is distributed by N (3, n, k − c), for some c ∈ {0, 1, 2}, then it must correspond to one of the 24 matrices of Table 2. A series of lemmas will establish. Proposition 5. For n 1, each matrix M in the first two columns of Table 2 yields a statistic M − (M)21 − (M)32 having the 3-Narayana distribution. In particular, asc(·) and des(·) − 2 are equi-distributed. (The sum (M)21 + (M)32 adjusts the statistic so |{P ∈ C(3, n) : M (P ) − (M)21 − (M)32 = k}| = N (3, n, k).) Conjecture 1. For n 1, each matrix M in the last two columns of Table 2 yields a statistic M −(M)21 −(M)32 having the 3-Narayana distribution. Consequently, the statistic des(·) − asc(·) − n − 3 (which was suggested 1 1 1 in Table 1) has the 3-Narayana distribution in agreement with Mb + MA + Me = 1 1 1 . 111
464
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
Table 3 Statistical values P
MD (P )
MA (P )
Me (P )
Mf (P )
hdes(P )
ZZYYXX ZZYXYX ZYZYXX ZYZXYX ZYXZYX
2 3 3 3 4
0 1 1 2 1
1 1 1 0 2
1 2 0 1 1
2 1 1 1 0
If one considers any two statistics 1 and 2 on C(3, n) to be equivalent when either 1 +2 or 1 −2 is a constant statistic for each n, then Table 3 shows the non-equivalency of MD , MA , Me and Mf . The statistic hdes counting the high descents, considered at the end of this section, requires n = 3 to see that it is not equivalent to the others. Lemma 2, below, shows that each column of Table 2 corresponds to an equivalence class. For each matrix M being considered, we define the horizontal complement, HM, and the vertical complement, VM, to be matrices defined so 0 if j is a zero row of M, (H M)j := 1 − (M)j if otherwise. 0 if is a zero column of M, (V M)j := 1 − (M)j if otherwise. (For e.g., see Table 2, where Ma = H MD . See also Fig. 3.) Lemma 2. For any M in Table 3 and for any P ∈ C(3, n), 2n if the first row M is a zero row, M (P ) + H M (P ) = 2n − 1 if otherwise. 2n if the last column of M is a zero column, M (P ) + V M (P ) = 2n − 1 if otherwise. Proof. We note that each path begins with Z, ends with X, and has a total of 3n − 1 consecutive step pairs. If row 1 of M is a zero row, then the n − 1 non-final X steps, all of which immediately precede some other step on P, do not contribute to M (P ) + H M (P ). Hence, M (P ) + H M (P ) = (3n − 1) − (n − 1). If row 2 of M is a zero row, then only the n Y steps, which must immediately precede some other step on P, do not contribute to M (P ) + H M (P ) = (3n − 1) − n. Similarly, the other instances of the lemma are valid. Lemma 3. For any M in Table 2 and for any P ∈ C(3, n), M (P ) − (M)23 − (M)32 + H M (P ) − (H M)23 − (H M)32 = 2n − 2. M (P ) − (M)23 − (M)32 + V M (P ) − (V M)23 − (V M)32 = 2n − 2. Proof. This is an easily checked consequence of Lemma 2.
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468 H
V
H
T
V
H
465
V
MD −→ Ma −→ V Ma −→ Mb −→ Mc −→ V Mc −→ Md −→ MA Fig. 4. The schema for proving that des(·) − 2 and asc(·) are equi-distributed.
Lemma 4. Suppose that 1 is distributed by a reciprocal polynomial of degree 2n − 2 on C(3, n). If 1 (P ) + 2 (P ) = 2n − 2 for all P ∈ C(3, n), then 1 and 2 are equidistributed. Proof. P ∈C (3,n)
t 2 (P ) =
P ∈C (3,n)
t 2n−2−1 (P ) =
P ∈C (3,n)
t 1 (P ) .
Lemma 5. For Mb and Mc defined in Table 2 and for 1 k < 2n − 2, there is an explicit bijection : {P ∈ C(3, n) : Mb (P ) = k} → {P ∈ C(3, n) : Mc (P ) = k}, and hence Mb and Mc are equi-distributed (Fig. 4). Proof. For any P ∈ C(3, n), we split P into maximal blocks (i.e., maximal subpaths) which either contain only Y steps or contain no Y step. In each block of the second type, we exchange its initial maximal subblock (perhaps empty) of X steps with its final maximal subblock (perhaps empty) of X steps. (P ) is the resulting path. We note that (P ) ∈ C(3, n) since the condition 0 x y z for any point (x, y, z) on a path holds during the exchanges. The action of leaves the number of XX and ZZ pairs fixed and transforms the number of ZX pairs to the number of XZ pairs. Since Mc = T Mb , where T denotes the usual transpose operator, the proof is complete. Proof of Proposition 5. This is a consequence of Lemmas 3, 4, 5, and the reciprocity of the 3-Narayana polynomials, which is considered in Section 4. See Fig. 3 where T denotes the transpose operator. In particular by Lemma 2, for any P ∈ C(3, n), the following identities MD (P ) + Ma (P ) = 2n, V Ma (P ) + Mb (P ) = 2n − 1, V Mc ((P )) + Md ((P )) = 2n,
Ma (P ) + V Ma (P ) = 2n − 1, Mc ((P )) + V Mc ((P )) = 2n − 1, Md ((P )) + MA ((P )) = 2n − 1,
together with Mb (P ) = Mc ((P )), yield bijectively that MD (P ) − 2 = MA ((P )). High descents: On any planar path a high peak is any YX pair whose intermediate vertex (x, y) satisfies y − x > 1. Deutsch [1] introduced the statistic counting the high peaks on the path P, and showed that this statistic has the Narayana distribution on C(2, n). Now, for any path P = p1 p2 . . . p3n ∈ C(3, n), call any step pair pi pi+1 a high descent if pi pi+1 = Xj X for j > and its intermediate vertex (x1 , x2 , x3 ) satisfies xj − x > 1.
466
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
With hdes(P ) denoting the number of high descents on the path P, we show in [17] that |{P ∈ C(3, n) : hdes(P ) = k}| = N (3, n, h). 4. Proving MacMahon’s formula for the 3-Narayana numbers Here we briefly indicate how one can obtain Proposition 3 by specializing and, then translating into our notation, MacMahon’s [7, Arts. 436–498] q-results for plane partitions. Later, Stanley extended MacMahon’s work with his theory of P -partitions. Accordingly, for a different notational perspective, one can also obtain Proposition 3 as a corollary of Stanley’s work [13,14, Theorem 4.5.14]. In 1910 MacMahon [7,8] introduced the sub-lattice function, which is a q-analogue of a “d-dimensional Narayana number”. Instead of the steps X, Y , and Z, MacMahon uses the symbols , , and , respectively. He uses “lattice permutation” for “constrained path in C(3, n)”. Hence, for example, “the constrained path ZZYXYX with an ascent at XY ” corresponds to his “lattice permutation with a major contact at .” Specific to the 3-dimensional case (and in our notation), the “sub-lattice function of order k”, denoted by Lk (n, 3; ∞), is defined to satisfy Lk (n, 3; ∞)t k = t asc(P ) q (P ) , P ∈C (3,n)
k
where (in our notation) (P ) is the lesser index of P, i.e., (p1 p2 p3 . . . pi . . . p3n ) denotes the sum of the indices i where pi pi+1 is an ascent. Hence, when q → 1, Lk (n, 3; ∞) = N (3, n, k). In [7, Art. 429] MacMahon uses GF (n; d; j ) to denote the generating function, with respect to the sum of the parts with size marked by q, of the plane partitions having at most n columns, at most d rows, and part size bounded by j . In [7, Art. 443] he records the bottom formula of page 197, which reduces to
GF (n; 3; j )g j =
j
L0 (n, 3; ∞) + L1 (n, 3; ∞)g + · · · + L2n−2 (n, 3; ∞)g 2n−2 . (6) (1 − g)(1 − gq) · · · (1 − gq 3n )
In [7, Art. 495] he obtains a formula for GF (n; 3; j ) which becomes, for q → 1, 2 j + n + i n + i −1 GF (n; 3; j ) = . n n i=0 With q → 1, this and (6) yield
N (3, n, k)g k = (1 − g)3n+1
k
2 j i=0
j 3n+1
j +n+i n
n + i −1 j g . n
Since (1 − g)3n+1 = j (−g) , formula (4) follows by forming the convolution. j MacMahon gave a proof for the reciprocity of the polynomial N3,n (t) in [8, Art. 29]; his argument in [7, Art. 449] seems incomplete. The reciprocity can also be derived either from the results of [13, Section 18], [14, Section 4.5], or [17]. The degree of this polynomial is considered in [7, Art. 445], [14, Section 4.5], and [17].
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
467
5. Three-dimensional Schröder paths Now we count constrained paths using the seven steps corresponding to the edges and the diagonals of the unit cube. Let D(n) denote the set of paths running from (0, 0, 0) to (n, n, n), lying in {(x, y, z) : 0 x y z}, and using the non-zero steps of the form (1 , 2 , 3 ) where i ∈ {0, 1} for 1 i 3. One might call each path in D(n), a 3-Schröder path. Proposition 6. For n1, D(n) has cardinality equal to 4N3,n (2). Proof. Let C (3, n) denote the set of all possible paths formed by independently coloring blue or red the intermediate vertices of the YX, ZX, and ZY pairs on copies of the paths of C(3, n). Hence, C (3, n) has cardinality h 2h |{P ∈ C(3, n) : des(P ) = h}| = 4N3,n (2). Next we define a bijection
: C (3, n) −→ D(n), so that, for each P ∈ C (3, n), (P ) is obtained by first replacing sequentially each maximal factor of steps having consecutively blue, B, intermediate vertices as follows: YBX ZBX ZBY ZBYB
−→ −→ −→ −→
(1, 1, 0), (1, 0, 1), (0, 1, 1), (1, 1, 1).
On the resulting path keep the remaining non-diagonal unit steps and remove the color red. Hence the cardinalities of C (3, n) and D(n) agree. For example, the bijection acts by sending ZZBYRXZZBYBXYYZBXXZRYRXYBX ∈ C (3, 6) to Z(0, 1, 1)RXZZ(1, 1, 1)YY (1, 0, 1)XZRYRX(1, 1, 0), which then becomes Z(0, 1, 1)XZZ(1, 1, 1)YY (1, 0, 1)XZYX(1, 1, 0) ∈ D(6).
6. Notes In MacMahon’s text [7], one finds the formula for the Narayana numbers as a special case of the 5th formula of article 495. nIn 1955, using different terminology, Narayana [9,10], introduced the number (1/n) hn h−1 to count, in essence, pairs of non-intersecting paths using the steps E and N, where the lower path runs from (1, 0) to (h, n − h) and the upper path runs from (0, 1) to (h − 1, n − h + 1). His interest was the derivation of distributions related to statistical tests of the Kolmogorov–Smirnov type. Implicit in [10] (explicit in [16, Section 2]) is a bijection between these pairs of such non-intersecting paths and paths in C(2, n) having h peaks. The papers [15,16] study the Narayana polynomial.
468
R.A. Sulanke / Theoretical Computer Science 346 (2005) 455 – 468
Acknowledgements The author is appreciative of the references on counting paths in higher dimensions supplied by Heinrich Niederhausen, especially those listed in his paper [11], which studies enumerating constrained walks in terms of diffusion walks where particles from different sources with opposite charges cancel upon meeting. His cancellation scheme differs from reflection or that of this note. The author is also thankful to Christian Krattenthaler for refreshing his memory about bijection and the result of Proposition 4. The recent paper [4] includes a summary of the literature on the enumeration of general higher-dimensional walks in regions bounded by hyperplanes and the associated enumeration of n-tuples of non-intersecting walks in the plane. Finally, he is grateful to the referees for their positive suggestions. References [1] E. Deutsch, An involution on Dyck paths and its consequences, Discrete Math. 204 (1–3) (1999) 163–166. [2] M.E. Fisher, Walks, walls, wetting, and melting, J. Statist. Phys. 34 (5–6) (1984) 667–729. [3] I.M. Gessel, X.G. Viennot, Determinants, paths, and plane partitions, preprint, 1989. . [4] C. Krattenthaler, Asymptotics for random walks in alcoves of affine Weyl groups, preprint, 2002. . [5] C. Krattenthaler, A.J. Guttmann, X.G. Viennot, Vicious walkers, friendly walkers and Young tableaux II: with a wall, J. Phys. A 33 (2000) 8835–8866. [6] M. Lothaire, Combinatorics on Words, Addison-Wesley, Reading, MA, 1983 reprinted by Cambridge University Press, Cambridge, MA, 1997. [7] P.A. MacMahon, Combinatory Analysis, Cambridge University Press, Cambridge, MA, 1915–1916 reprinted by Chelsea, New York, 1955. [8] P.A. MacMahon, in: G.E. Andrews (Ed.), Collected Papers, Vol. 1, MIT Press, Cambridge, MA, 1978. [9] T.V. Narayana, Sur les treillis formés par les partitions d’un entier; leurs applications à la théorie des probabilités, Comp. Rend. Acad. Sci. Paris 240 (1955) 1188–1189. [10] T.V. Narayana, Lattice Path Combinatorics with Statistical Applications, University of Toronto Press, Toronto, 1979. [11] H. Niederhausen, Random walks in octants, and related structures, J. Statistical Planning and Inference 135 (2005) 165–196. [12] N.J.A. Sloane, On-line Encyclopedia of Integer Sequences. . [13] R. Stanley, Ordered structures and partitions, Memoirs of the American Mathematical Society, Vol. 119, American Mathematical Society, 1972. [14] R. Stanley, Enumerative Combinatorics, Vol. 1, Cambridge University Press, Cambridge, MA, 1997. [15] R.A. Sulanke, Counting lattice paths by Narayana polynomials, Electron. J. Combin. 7 (1) (paper 40) (2000) 9. [16] R.A. Sulanke, The Narayana distribution, Special issue on lattice path combinatorics and applications, Vienna, 1998, J. Statist. Plann. Inference 101 (1–2) (2002) 311–326. [17] R.A. Sulanke, Generalizing Narayana and Schröder numbers to higher dimensions, Electron. J. Combin. 11 (1) (2004) Art. R54. [18] D. Zeilberger, André’s reflection proof generalized to the many candidate ballot problem, Discrete Math. 44 (1983) 325–326.
Theoretical Computer Science 346 (2005) 469 – 489 www.elsevier.com/locate/tcs
Rauzy substitutions and multi-dimensional Sturmian words Robert Tijdeman Mathematical Institute, Leiden University, Postbus 9512, NL-2300 RA Leiden, The Netherlands To the respectful memory of Alberto Del Lungo
Abstract Recently, Berthé and the author developed a method to construct a multi-dimensional Sturmian word as a limit of a sequence of words on lattice domains. In the present paper, the reach of the approach is studied in the special case of Rauzy substitutions. © 2005 Elsevier B.V. All rights reserved. Keywords: Rauzy substitutions; Sturmian words; Multi-dimensional words; Towers of lattices
1. Introduction In 1982, Rauzy [11] introduced a substitution on words consisting of three letters, 0,1,2 say, given by 0 → 01, 1 → 02, 2 → 0. If this substitution is applied infinitely often starting with 0 an infinite limit word 01020100 . . . appears. Rauzy studied an induced twodimensional fractal. One of his results states that the shift on the symbolic dynamical system generated by the Rauzy substitution corresponds to an exchange of three subdomains. Later, the so-called Rauzy fractal was studied intensively, see e.g. [8,9,15,16]. The two letter substitution 0 → 01, 1 → 0 leads to the well-known Fibonacci word [7,10]. The four letter substitution 0 → 01, 1 → 02, 2 → 03, 3 → 0 occurs in Example 4 of [13]. In 1991, Arnoux and Rauzy [2] introduced three letter words which have been named Arnoux–Rauzy words since. In the notation of the present paper they use the substitutions Ri given by i → i and j → ji for j = i, i, j ∈ {0, 1, 2}. They noticed that the Rauzy substitution applied thrice is equal to the reverse result of the substitution R0 R1 R2 . Arnoux E-mail address: [email protected]. 0304-3975/$ - see front matter © 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.tcs.2005.08.013
470
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
and Ito [1] studied periodic sequences (Rhn )∞ n=1 with hn ∈ {0, 1, 2}. They called these substitutions “generalised Rauzy substitutions” and proved that if all the substitutions occur at least once, then the associated two-dimensional system is measurably isomorphic to a translation on the torus T2 . They also considered other substitutions such as the “modified Rauzy substitution” 0 → 10, 1 → 02, 2 → 0. For the closely related episturmian words and sequences, see e.g. Droubay et al. [6] and Richomme [12] and the references given therein. In this paper, we study a class of substitutions which covers all the substitutions mentioned above. Let k be a positive integer and i ∈ {0, 1, . . . , k}. We call a substitution Ri on k + 1 letters 0, 1, . . . , k a Rauzy substitution if i → i and j → ij or ji for j = i (j = 0, 1, . . . , k). In Section 2, we apply an arbitrary sequence of Rauzy substitutions (Rhn )∞ n=1 starting from the word 0 1 . . . k and study the limit distribution 0 , 1 , . . . , k of the fractions of the numbers of letters originating from 0, 1, . . . , k, respectively. Hence, kj =0 j = 1. In Theorem 2.1, it is stated that for any sequence (hn )∞ n=1 the numbers 0 , 1 , . . . , k are well defined. It appears from Theorem 2.3 that all numbers i are positive if and only if (hn )∞ n=1 is nonconstant. Theorem 2.4 says that the numbers 0 , 1 , . . . , k are linearly dependent over Z if and only if at most k − 1 elements from {0, 1, . . . , k} occur infinitely often in the sequence (hn )∞ n=1 . The proofs apply rather elementary arguments from real analysis. The effects of the insertions are studied in Section 3. Berthé and the author [3] have introduced a method involving lattices (N) ⊂ Zk to construct a k-dimensional “colouring function” (N) : Zk / → {0, 1, . . . , k} corresponding to the sequence (hn )N n=1 . Depending on the chosen insertions they defined “roundwalks” w(N) consisting of one representative of each coset of (N) such that w(N) ⊂ w(N+1) ⊂ w(N+2) ⊂ · · · and (N) ( x ) = (N+1) ( x) = (N+2) (N) (N) ( x ) = · · · provided that x ∈ w . Hence, := limN→∞ is a well-defined function on a subset of Zk . This process is described in Section 3.1 for canonical Rauzy substitutions Ri given by i → i and j → ji for j = i, and for anti-canonical substitutions Ri given by i → i and j → ij for j = i (cf. Fig. 2). These substitutions lead to fractals. In Sections 3.3 and 3.4 a mixture of both substitutions is studied which also occurs in [14], such that the resulting shapes are hexagonal in case k = 2 and “generalised hexagonal” for k > 2. The rule for the substitutions is stated in Proposition 3.5(iii) (cf. Figs. 3 and 5). In Theorem 3 of [3], it is shown that under a rather general but complicated condition the limit function exists and can be expressed in terms of 0 , 1 , . . . , k . The proof of this result is based on a classical result from ergodic theory by Furstenberg. In the case that (hn )∞ n=1 is periodic, it suffices that each of R0 , R1 , . . . , Rk occurs in the period and the limit values 0 , 1 , . . . , k are linearly independent over the rationals. In this case, the limit word turns out to be the k-dimensional Sturmian word given by ( x ) = ((x1 , . . . , xk )) = j ⇔ {x1 1 + . . . xk k } ∈ (j , j +1 ] (j = 0, 1, . . . , k), j −1 where {y} denotes the fractional part of the real number y and j := i=0 i for j = 0, 1, . . . , k + 1. Hence, 0 = 0 1 · · · k = 1. The word is called Sturmian, since 1 , . . . , k are linearly independent over Z. Such words were studied by Berthé and Vuillon [4,5]. They generalise the classical Sturmian words which are obtained by taking k = 1. For the classical Sturmian words I refer to Chapter 2 of [7]. In Theorem 4.1, we show that in the case of Rauzy substitutions it suffices that (hn )∞ n=1 is not ultimately constant to have
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
471
a limit word : Zk → {0, 1, . . . , k} as described above. Proposition 4.3 and Theorem 2.4 imply that the word is Sturmian if and only if at least k elements from 0, 1, . . . , k occur infinitely often in the sequence (hn )∞ n=1 . All the results in the paper are proved by elementary arguments. For my convenience, I have used a notation which is sometimes different from what is usual in the literature. The present paper can be read independently of [3], but the latter paper contains a general context not provided here. 2. Rauzy matrices We study properties of products of incidence matrices of Rauzy substitutions. 2.1. Existence of limits In this subsection, we show that if an infinite sequence of Rauzy substitutions is applied to starting letters 0, 1, . . . , k, then the lengths of the resulting words after n substitutions have a limit distribution as n → ∞. Let k be a positive integer. We define the (k + 1) × (k + 1) Rauzy matrix j as the matrix with 1’s both on the diagonal and in the jth column and 0’s elsewhere (j = 0, 1, . . . , k). Hence, j is the transpose of the incidence matrix of the Rauzy substitution Rj ; the entry (l, m) with l, m = 0, 1, . . . , k of the matrix j indicates how many letters l occur when the substitution Rj is applied to the letter m. Of course, the incidence matrix is independent of the choice in the substitution Rj . Let (hn )∞ n=1 be (n) = h1 h2 . . . hn for n = an infinite sequence of elements from {0, 1, . . . , k}. Put M 0, 1, . . . . Hence, M (0) is the identity matrix and for n 0 we obtain M (n+1) from M (n) by substituting the row sums of M (n) into the hn+1 th column and leaving all other columns unchanged. It follows by induction that the transpose of M (n) is the incidence matrix of the word obtained by applying the substitutions Rh1 , Rh2 , . . . , Rhn to the starting word 01. . . k. (n) (n) Denote by c(n) = (c0 , . . . , ck ) the row vector of column sums of M (n) and by (n) (n) r(n) = t (r0 , . . . , rk ) the column vector of row sums of M (n) where the left superscript t indicates transposition of vectors or matrices. Let E ∈ Zk+1 be the column vector with all entries equal to 1. Then c(n) =
t
E M (n)
and
r(n) = M (n) E.
Example 1. We consider k = 2 and apply successively Rauzy steps R0 , R1 , R2 , R1 , R1 , R2 , R0 . This yields a sequence of matrices (M (n) )7n=0 given by ⎛ ⎞ ⎛ ⎞ ⎛ ⎞ ⎛ ⎞ 10 0 10 0 1 1 0 1 1 2 ⎝0 1 0⎠ ⎝1 1 0⎠ ⎝1 2 0⎠ ⎝1 2 3⎠ 0 0 1 10 1 12 1 1 2 4 n=0 n=1 n=2 n=3 ⎛ ⎞ ⎛ ⎞ ⎛ ⎞⎛ ⎞ 1 4 2 1 72 1 7 10 18 7 10 ⎝ 1 6 3 ⎠ ⎝ 1 10 3 ⎠ ⎝ 1 10 14 ⎠ ⎝ 25 10 14 ⎠ 1 7 4 1 12 4 1 12 17 30 12 17 n=4 n=5 n=6 n=7
472
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
Starting with the word 012 and applying the Rauzy substitution Ri with always the canonical choice j → ji we obtain successively the so-called coding words 0|1|2, 0|10|20, 01|101|2101, 0212|120212|2120212, 0121121|1210121121|211210121121, . . . , where the symbol | is used to separate the respective word parts originating from the 0,1,2 of the starting word. The entry at place (l, m) of M (n) with l = 1, 2, 3; m = 0, 1, 2 denotes how many m’s occur in the lth part of the nth word. The row sums r(n) denote the lengths of the corresponding parts of the nth word, the column sums c(n) the frequencies of the corresponding letters in the nth word. (n) (n+1) Let fi be the ith column vector of M (n) for i = 0, 1, . . . , k. Then fhn+1 = r(n) and
r(n+1) = 2r (n) − fhn+1 (n)
for n = 0, 1, . . . .
Let D (n) denote the sum of all entries of M (n) , that is the sum of all the entries of c(n) as well as the sum of all the entries of r(n) . Example 5 in [3, Section 5] provides an instance of an infinite sequence of Rauzy matrices for which r(n) 2 1 , = , , lim n→∞ D (n) ( + 1)2 + 1 ( + 1)2 where is the real root of the polynomial x 3 − x 2 − x − 1. The following theorem shows that in the case of Rauzy matrices the limit limn→∞ r(n) /D (n) always exists. Theorem 2.1. Let hn ∈ {0, 1, . . . , k} for n = 1, 2, . . . . Define r(n) and D (n) as above. Then limn→∞ r(n) /D (n) exists. (n)
Proof. Obviously, it suffices to show that limn→∞ ri /D (n) exists for i = 0, 1, . . . , k. For (n) ri and D (n) we have the recurrence relations (n+1)
(n)
= 2ri
ri
(n)
− Mi,hn+1 ,
D (n+1) = 2D (n) −
k j =0
(n)
Mj,hn+1
n−1 (n−1) (n) (n) (n−1) for i = 0, 1, . . . , k and all n. Observe that Mi,hn = ri = , chn = j =0 Mi,j n−1 (n−1) (n−1) = j =0 cj for i = 0, 1, . . . , k and n = 0, 1, . . . . To prove Theorem 2.1 it, D (n)
therefore, suffices to prove the following lemma for a fixed i ∈ {0, 1, . . . , k} with aj (n) (n) Mi,j , bj
=
(n) cj , An (0)
=
(n) Mi,hn , Bn
(0)
=
(n) chn
=
for j ∈ {0, 1, . . . , k} and n = 0, 1, 2, . . . .
(0)
(0)
(0)
(0)
Lemma 2.2. Let a0 , a1 , . . . , ak be real numbers and let b0 , b1 , . . . , bk be positive real numbers. Let (hn )∞ n=1 be a sequence of numbers chosen from {0, 1, . . . , k}. For every positive integer n define (n)
(n)
(n)
(n)
(n)
(n)
a0 , a1 , . . . , ak , b0 , b1 , . . . , bk
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
473
k (n) (n−1) (n) (n−1) (n) (n−1) (n) (n−1) by putting ahn = kj =0 aj , bhn = and ai = ai , bi = bi for j =0 bj (n) (n) all i = hn . Put An = ahn , Bn = bhn . Then limn→∞ An /Bn exists. Proof. Put xn = An /Bn and yn =
k
(n) (n) (n) 2 j =0 bj (xn+1 −aj /bj ) for every n. The following k (n) (n) (n) Observe that j =0 bj (x − aj /bj )2 has a unique
argument shows that yn−1 − yn 0. minimum at x = xn+1 . Therefore, (n) 2 k aj (n) yn xn − (n) bj bj j =0 (n−1) 2 (n−1) 2 k aj ahn An 2 (n−1) (n−1) xn − (n−1) xn − (n−1) = bj + B n xn − − bhn Bn bj bhn j =0 2 (n−1) ahn (n−1) xn − (n−1) = yn−1 − bhn . bhn Hence, (n−1) yn−1 − yn bhn
(n−1) 2
xn −
ahn
0.
(n−1)
bhn
Since (yn )∞ n=1 is monotonically nonincreasing, we have that (n)
bounded, by C0 say. It implies that limn→∞ |xn+1 −
aj
(n) bj
k
(n) j =0 bj (xn+1
(n)
−
aj
(n) bj
)2 is
| → 0 for every j for which
(n)
→ ∞ as n → ∞, that is, for every j for which hn = j has infinitely many solutions n. Taking j = hn , we see in particular, using that Bn → ∞ as n → ∞, that |xn+1 − xn | → 0 as n → ∞. Now, suppose that lim inf n→∞ An /Bn =: < := lim supn→∞ An /Bn . Put := − . (n ) Choose n0 so large that bj 0 > 9C0 −2 for every j ∈ J , where J denotes the set of terms j occurring infinitely often in the sequence (hn )∞ / J occurs in the tail n=1 and that no j ∈ (hn )∞ . Hence, for such j and nn , 0 n=n0 bj
(n) 2
9−2 C0 xn+1 − so that
(n)
aj
xn+1 − (n)
bj
aj
(n)
bj
(n) bj
(n) 2
xn+1 −
aj
(n)
bj
C0
3 (n )
(n )
for n n0 , j ∈ J . Choose n1 > n0 such that xn1 +1 < + /6. Then aj 1 /bj 1 < + /2 for j ∈ J . Choose n2 as the minimal integer > n1 such that xn2 +1 > + /2. Since
474
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
(n)
(n)
(n−1)
= aj
aj /bj (n )
(n2 )
aj 2 /bj we have
(n−1)
/bj
(n)
(n)
can only happen if j = hn and xn = ahn /bhn , we have (n )
(n )
+ /2 for j ∈ J whence xn2 = ahn2 /bhn2 + /2 < xn2 +1 . For n > n2 2
xn+1 =
=
(n+1)
bhn+1
k
k
(n+1)
ahn+1
=
(n) j =0 aj k (n) j =0 bj
(n)
(n−1)
(n) 2bhn
(n−1) − bhn−1
2ahn − ahn−1
=
2
(n−1) j =0 aj k (n−1) j =0 bj
=
(n)
(n−1)
(n)
(n−1)
+ ahn − ahn−1 + bhn − bhn−1
2An − An−1 Bn−1 = xn + (xn − xn−1 ). 2Bn − Bn−1 2Bn − Bn−1
Since Bn > Bn−1 > 0, we obtain by induction on n that xn+1 > xn for n > n2 . Thus, +
< xn2 +1 < xn2 +2 < xn2 +3 < · · · . 2
This contradicts lim inf n→∞ xn = .
Remark. The numbers 0 , 1 , . . . , k are the relative sizes of the parts of a Rauzy fractal which are interchanged by a Rauzy substitution. 2.2. Positivity The next theorem shows that, in general, all the entries 0 , 1 , . . . , k of limn→∞ r(n) / are positive.
D (n)
(n)
(n)
Theorem 2.3. Let hn ∈ {0, 1, . . . , k} for n = 1, 2, . . . . Define r(n) = (r0 , . . . , rk ) and (n) D (n) as above. Put i = limn→∞ ri /D (n) for i = 0, 1, . . . , k. Then i = 0 for some i ∈ {0, 1, . . . , k} if and only if hn = i for every n. = 1 for all n. Since D (n) → ∞ as n → ∞, it Proof. If (hn )∞ n=1 is constant i, then ri −1 follows that i = 0. Furthermore, j = k for j = i. For the converse statement, suppose two distinct values, h and j say, have occurred (N) contain only positive entries. Put in (hn )N n=1 . Then the two columns fh and fj of M k (n) (n) (n) (n) (n) (n) bi,j = h=0,h=j Mi,h and bj = (b0,j , b1,j , . . . , bk,j ) for i, j = 0, 1, . . . , k. Then each (n) (n) (n) (n) (n−1) (n−1) + bj of b0 , b1 , . . . , bk has positive entries for nN . If hn = j , then bh = bh (n) (n−1) (n) (n) for h = j and bj = bj for h, j = 0, 1, . . . , k and all n. Put bj = ki=0 bi,j for j = (n)
(n)
(n)
(n)
0, 1, . . . , k, and i =minj bi,j /bj
(n)
(n)
(n)
(n)
(n)
i <1 for i, j ∈{0, 1, . . . , k} and n N . Since bi,j /bj (n)
(n)
bi,j /bj
(n−1)
i
(n−1)
= (bi,j
(n−1)
(n−1)
+ bi,hn )/(bj
(n)
(n)
(n)
(n)
and i =maxj bi,j /bj . Hence, 0<i bi,j /bj (n−1)
+ bhn
(n−1)
if hn = j and
/bj
(n−1)
), if hn = j , we have i (N)
for n > N. By induction we obtain 0 < i
{0, 1, . . . , k} and nN . Observe that r(n) =
(n−1)
= bi,j (n)
(n)
(N)
bi,j /bj i
(n−1) (n) r(n−1) + bhn , hence ri
(n)
(n)
i i
< 1 for i, j ∈ (n−1)
= ri
(n−1)
+ bi,hn
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
475
(n−1) (N) (n−1) k (n−1) i=0 bi,hn . Since i bi,hn / i=0 bi,hn (N) (n) (N) i for n > N and limn→∞ ri /D (n) exists by Theorem 2.1, we conclude that i (n) (N) (N) (N) limn→∞ ri /D (n) i for i = 0, 1, . . . , k. Hence, 0 < i i i < 1 for i =
for i = 0, 1, . . . , k and D (n) = D (n−1) +
0, 1, . . . , k.
k
2.3. Linear independence of the densities Theorem 2.3 provided a criterion for the positivity of the numbers i . Similarly, the following result gives a criterion for the linear dependence over Z of the numbers i . Theorem 2.4. Define 0 , 1 , . . . , k as in Theorem 2.3. The numbers 0 , 1 , . . . , k are linearly independent over Z if and only if at least k elements from 0, 1, . . . , k occur infinitely often in the sequence (hn )∞ n=1 . The proof of Theorem 2.4 will be given in Section 4.2.
3. Roundwalks In this section, we introduce k-dimensional words (presented as roundwalks) corresponding to the one-dimensional coding words from Section 2. In fact, for every n the Rauzy matrix M (n) determines a lattice (n) in Zk+1 and a mapping (n) : Zk+1 /(n) → {0, 1, . . . , k}. The chosen Rauzy substitution determines a lattice domain V (n) of (n) on which the nth word is defined as the restriction of (n) to V (n) . In Sections 3.1 and 3.3, we introduce the roundwalks. Sections 3.2 and 3.4 describe what happens if a Rauzy substitution is applied to go from level n to level n + 1. 3.1. Canonical and anti-canonical substitutions In this subsection, we consider the words corresponding to applying consistently canonical Rauzy substitutions i → ij for i = j or consistently anti-canonical Rauzy substitutions i → ji for i = j . Let k + 1 vectors v0 , v1 , . . . , vk in Zk be given such that d0 , d1 , . . . , dk defined by d0 := det( v1 , . . . , vk ),
di := det( v1 , v2 , . . . , vi−1 , − v0 , vi+1 , . . . , vk )
are coprime positive integers. Then v1 − v0 , . . . , vk − v0 are linearly independent vectors. Let be the lattice Z( v1 − v0 ) + · · · + Z( vk − v0 ). Then det() = d0 + d1 + · · · + dk =: D Furthermore, v0 , v1 , . . . , vk are all in the same coset and d0 v0 + d1 v1 + · · · + dk vk = 0. of . Since v1 , . . . , vk are linearly independent and d0 , d1 , . . . , dk are coprime, it follows from a0 v0 + · · · + ak vk = 0 for some a0 , . . . , ak ∈ Z that ai = tdi for some integer t and i = 0, 1, . . . , k. So, if b0 v0 ∈ for some b0 ∈ Z, then b0 v0 = a1 ( v1 − v0 ) + · · · + ak ( vk − v0 ) = (−a1 . . . − ak ) v0 + a1 v1 + · · · + ak vk
476
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
130 170 40 210 80 21 121 61
32 72 112 151 191 01
162 202 12 52 91
102 142 182 222
Fig. 1. Roundwalk with jumps from { v0 , v1 , v2 }.
for suitable a0 , a1 , . . . , ak ∈ Z. Hence, ai = tdi for i = 1, . . . , k and b0 + a1 + · · · + ak = −td0 for some t ∈ Z. It follows that b0 = t (−d0 −d1 . . .−dk )=−tD. Thus, i v0 (0 i< D) form a complete set of representatives of Zk /. 0, w 1, . . . , w D−1 , w D = w 0 of By a roundwalk w through Zk / we mean a sequence w elements from Zk such that w i+1 − w i ∈ { v0 , v1 , . . . , vk } for i = 0, 1, . . . , D − 1. Hence, w m − m v0 ∈ for m = 0, 1, . . . , D. Since w D = w 0 , for j ∈ {0, 1, . . . , k} there are i+1 − w i = vj . The corresponding exactly dj numbers i ∈ {0, 1, . . . , D − 1} such that w coding word w = w0 . . . wD−1 of the roundwalk is defined by wi = j if w i+1 − w i = vj for 0 i D − 1. Given the vectors v0 , v1 , . . . , vk and the vector w 0 , the roundwalk w is determined by its coding word w. In the sequel, we shall use the notation w both for the sequence of vectors (wi )D i )D−1 i=0 . i=0 and for the set of vectors (w Example 2. We take k = 2, v0 = (3, 1), v1 = (1, 4), v2 = (−2, −3). Hence, d0 = 5, d1 = 7, d2 = 11, D = 23, = Z(−2, 3) + Z(−5, −4). We make a roundwalk w 0, w 1, . . . , w 23 = w 0 through Z2 / where ⎧ ⎨ v0 for i = 4, 8, 13, 17, 21, w i+1 − w i = v1 for i = 0, 2, 6, 9, 12, 15, 19, ⎩ v2 for i = 1, 3, 5, 7, 10, 11, 14, 16, 18, 20, 22. The corresponding coding word w of the roundwalk is given by w = 1 2 1 2 0 2 1 2 0 1 2 2 1 0 2 1 2 0 2 1 2 0 2, where j means that the next jump is vj . Note that there are d0 numbers 0, d1 numbers 1, d2 numbers 2 in the coding word indeed. The corresponding roundwalk is presented in Fig. 1, i from where the next jump is vj , where 0 indicates the origin and ij indicates the vector w that means w i+1 − w i = vj . 3.2. Rauzy extensions We shall now extend the roundwalk by a Rauzy step Rj for some j ∈ {0, 1, . . . , k}. We indicate the values after the Rauzy step by a superscript R. Put viR = vi − vj for i = 0, 1, . . . , k with i = j and vjR := vj . Then diR = di for i = j , and djR = d0 +· · ·+dk = D. v1R − v0R ) + · · · + Z( vkR − v0R ). Then v0R , v1R , . . . , vkR Hence, D R = 2D − dj . Put R = Z( R 0, w 1, . . . , w D = w 0 in Zk to are all in the same coset of . We extend the roundwalk w
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
477
R = w a roundwalk w 0R , w 1R , . . . , w D 0R in Zk by inserting for every pair h, i with w h+1 − R R R w h = vi and i = j either w h + vi or w h + vj in between w h and w h+1 . Doing so, we R R R R obtain a roundwalk where w 0 , w 1 , . . . , w D R −1 represent the D cosets of R and w iR is
h + viR is inserted, we say that the insertion is done in in the same coset of R as i v0R . If w the canonical way, in case w h + vjR is inserted, we speak of the anti-canonical way. The R corresponding coding word w R = w0R w1R . . . wD R −1 of the new roundwalk is defined by the substitution i → ij for i = j in case of canonical insertion and by i → ji for i = j in case of anti-canonical insertion. Note that the only jumps which are not replaced with a pair of jumps when applying Rj are jumps vj . Hence, these jumping places are places x, where x + vj already belongs to the roundwalk. After applying anti-canonical insertion throughout, all the jumping places x in the old roundwalk are followed by x + vj in the new roundwalk, since all images of letters begin with j. After applying canonical insertion throughout, all the jumping places x in the old roundwalk are preceded by x − vj in the new roundwalk, since all images of letters end with j. Thus, if all the substitutions in the coding word are canonical, then the range of the new roundwalk is the union of the range of the old roundwalk and the range of the old roundwalk translated by − vj . If all the substitutions are anti-canonical, then the corresponding property with − vj replaced with vj holds. Example 2 (Continued). We apply the canonical Rauzy substitution R1 to the coding word in Example 2: wR1 = 1 21 1 21 01 21 1 21 01 1 21 21 1 01 21 1 21 01 21 1 21 01 21. We obtain v0R = (2, −3), v1R = (1, 4), v2R = (−3, −7), d0R = 5, d1R = 23, d2R =11, D R = 39. There are d0 + d2 = 16 new points. The new roundwalk is given in Fig. 2. The new roundwalk is obtained from the old roundwalk in Fig. 1 by replacing jumps v0 = (3, 1) by two successive jumps v0R = (2, −3), v1R = (1, 4) and jumps v2 = (−2, −3) by two successive jumps v2R = (−3, −7), v1R = (1, 4). We indicate the intermediate new place by a hat. So the new roundwalk is given by ˆ 5, 6, ˆ 6, 7, 8, ˆ 2, 3, 4, ˆ 4, 5, ˆ 8, 9, ˆ 9, 10, 11, ˆ 11, 12, ˆ 12, 13, 14, ˆ 14, . . . , 0, ˆ 0, 0, 1, 2, where a new place is inserted after a subscript 0 or 2, but not after a subscript 1. Observe that Fig. 2 can also be obtained from Fig. 1 by translating Fig. 1 over the vector − v1R = (−1, −4), replacing the numbers j at new places by jˆ with subscripts 1 and taking the union with Fig. 1.
3.3. Generalised hexagonal domains In the rest of the paper, we describe a mixed strategy of Rauzy substitutions leading to more compact lattice domains which have the shape of a generalised hexagon. Such domains were introduced by Simpson and Tijdeman [14]. First, we investigate the structure of the domains themselves. The notation we use here is different from that used in [14], but
478
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
40 80 121 ˆ1 17 ˆ1 4ˆ 1 21 8ˆ 1 2ˆ 1 ˆ 1 6ˆ 1 12
130 170 210 21 61 ˆ1 11 ˆ1 15 ˆ1 19 0ˆ 1
32 72 112 151 191 01 5ˆ 1 9ˆ 1
162 202 12 52 91 220 ˆ1 18 ˆ 221
102 142 182 222
Fig. 2. Canonical Rauzy extension.
the arguments are similar. The proofs are shorter, since we have no case distinction between 0 and 1, 2, . . . , k anymore and since we assume that v0 , . . . , vk generate Zk . Let v0 , v1 , . . . , vk be defined as in the previous section. Define the set W by W = { 0 v0 + · · · + k vk : 0 i 1, i ∈ R for i = 0, . . . , k}. Observe that, because of the unique relation d0 v0 + · · · + dk vk = 0 with minimal positive coefficients, every element a of W has a unique expression of the above type with at least one coefficient equal to 0 and all other minimal. We call this the minimal representation of a . We write W int for the interior of W, and, for j = 0, 1, . . . , k, Wj := { 0 v0 + · · · + k vk : 0 i < 1 for 0 i < j ; j = 0; 0 < i 1 for j < i k}.
Lemma 3.1. W0 , W1 , . . . , Wk are disjoint and W int ⊆
k
j =0
Wj ⊆ W .
Proof. Suppose x ∈ W int . Write x = 0 v0 + · · · + k vk
with 0 i 1 for i = 0, . . . , k
(1)
and at least one i equal to 0. Let h be the largest index i with i = 0. We claim that x ∈ Wh . By the definition of h we have j > 0 for j > h. Suppose i = 1 for some i < h. Then we see from i = 1, h = 0 that representation (1) is unique and that x is a boundary point of W contradicting the hypothesis that x belongs to the interior of W. Thus, 0 i < 1 for 0 < i < h, whence x ∈ Wh . Obviously, Wi ⊂ W for i = 0, . . . , k. It remains to show that W0 , . . . , Wk are disjoint. Suppose x ∈ Wh ∩ Wj for some h, j with 0 h < j k. Then x = 0 v0 + · · · + k vk = 0 v0 + · · · + k vk ,
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
479
Fig. 3. The sets V0 (closed circles), V1 (open circles) and V2 (+ signs) formed using v0 = (6, 4), v1 = (−5, −1)
−1 6
−1
= 19 is the number of closed circles, |V = 20 is and v2 = (−1, −4). Note that |V0 | = −5 | =
1 −4 4
−1 4
6 −1
the number of open circles, |V2 | = 4 −4 = 14 is the number of +signs. In the roundwalk w points in Vi are followed by a jump vi for i = 0, 1, 2. Performing all jumps yields a bijection which induces an “exchange of the v0 + v1 + v2 )/2 and has sides pieces” V0 , V1 , V2 . Note that the surrounding hexagon is point-symmetric around ( parallel to v0 , v1 , v2 .
with 0 i < 1 for 0 i < h; h = 0; 0 < i 1 for h < i k and 0 i < 1 for 0 i < j ; j = 0; 0 < i 1 for j < i k. Obviously both representations are minimal, but h = 0 and h > 0. This yields a contradiction. We set Vi = Wi ∩ Zk for i = 0, 1, . . . , k and V = ki=0 Vi . The case k = 2 is illustrated in Fig. 3. We define a function : V → V by ( v ) = v + vh if v ∈ Vh for h ∈ {0, 1, . . . , k}. Lemma 3.2. : V → V is a bijection. Proof. Let h ∈ {0, 1, . . . , k}. For v ∈ Vh we have ( v ) = 0 v0 +· · ·+ k vk with 0 i < 1 v ) as 0 v0 +· · ·+ k vk with 0 i 1 for 0 i < h; h = 1; 0 < i 1 for i > h. Rewrite ( for i = 0, . . . , k and 0 minimal. Then there is a largest j with j = 0. Note that if h = 1, v ) ∈ Vj and (V ) ⊆ V . then h = h + 1, whence j = j and therefore j < h. Thus, ( Next, we check that is injective. Suppose w = ( u) = ( v ) for some u, v ∈ V , u = v. Assume u ∈ Vh , v ∈ Vj with 0 h j k. Then h = j . Furthermore, w = 0 v0 + · · · + k vk = 0 v0 + · · · + k vk , with 0 i < 1 for 0 i < h; h = 1; 0 < i 1 for h < i k and 0 i < 1 for 0 i < j ; j = 1; 0 < i 1 for j < i k. By h = 1, h < 1 we have 0 > 0 . From j 1, j = 1 we obtain 0 0 . This contradiction shows that is injective.
480
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
Since V is finite and is injective, is also surjective.
We call u and v -adjacent if u = ( v ) or v = ( u). Lemma 3.3. If u, v ∈ V and v = u + vj for some j with 0 j k, then u and v are
-adjacent. Proof. Write u as 0 v0 + · · · + k vk with 0 i 1 for i = 0, . . . , k and minimal coefficients. Since v = 0 v0 + · · · + j −1 vj −1 + ( j + 1) vj + j +1 vj +1 + · · · + k vk ∈ V ⊂ W, we have j = 0. It follows from u ∈ V that i < 1 for i < j and from v ∈ V that i > 0 for i > j . Thus, u ∈ Vj and v = ( u). The next result shows that the elements of V form a cycle under iteration of of length D = d0 + · · · + dk . Since in case k = 2 the roundwalk fills a hexagon, we call this the generalised hexagonal roundwalk through V. Proposition 3.4. (i) If u, v ∈ V , then v = m ( u) for some m with 0 m < D. (ii) If 0 ∈ V , then every v ∈ V can be represented by v = a0 v0 + a1 v1 + · · · + ak vk
with ai ∈ Z, 0 ai di for i = 0, . . . , k.
Proof. By Lemma 3.2 and the finiteness of V, for every v ∈ V there exists a minimal positive integer n such that n ( v ) = v. Hence, by the definition of , v = n ( v ) = v + b0 v0 + b1 v1 + · · · + bk vk , with b0 , . . . , bk ∈ Z 0 and b0 + b1 + · · · + bk = n. Since the vectors v0 , v1 , . . . , vk with any one among them omitted are linearly independent over Z, we have b0 , . . . , bk > 0. From b0 v0 + · · · + bk vk = 0 we obtain that (b0 , . . . , bk ) = t (d0 , . . . , dk ) for some positive integer t. On the other hand, |V | = D whence b0 + · · · + bk D. Thus, t = 1 and bi = di for i = 0, . . . , k. This implies (ii). It follows that V = { v , ( v ), . . . , D−1 ( v )} and (D)
( v ) = v. This implies (i). 3.4. Rauzy extensions of hexagonal domains We investigate the hexagonal roundwalks when applying a suitable Rauzy substitution. Note that the domain W is point-symmetric around the centre point vc := 21 kh=0 vh , which k we assume vc , Bi = Wi − vc , Ai = Bi ∩Zk for i = 0, . . . , k and k to be in Z . We put B = W − A = i=0 Ai . Obviously, all the results derived in Section 3.3 for V , V0 , . . . , Vk have their analogues for A, A0 , . . . , Ak . In particular, : A → A given by ( a ) = a + vh whenever (0), . . . , D−1 (0)} and D (0) = 0. a ∈ Ah , is a bijection on A such that A = {0,
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
481
Fig. 4. Situation after canonical substitution R = R2 is applied to the situation in Fig. 3. The sets V0R (closed v2 = (7, 8), v1R := v1 − v2 = (−4, 3) and circles), V1R (open circles) and V2R (+ signs) are formed using v0R := v0 −
−4 −1
−1 7
R R v2 := v2 = (−1, −4). Note that |V0 | = 3 4 = 19 is the number of closed circles, |V1R | = −4
= 20 8
7 −4
R is the number of open circles, |V2 | = 8 3 = 19+20+14 = 53 is the number of +signs. Performing all jumps in the roundwalk wR yields a bijection of the points which induces an “exchange of the pieces” V0R , V1R , V2R . Note that the surrounding hexagon is still point-symmetric, but that no longer it has sides parallel to v0R , v1R , v2R . Anti-canonical substitutions lead to the same figure, but translated by v2R .
= 2. Let j ∈ {0, 1, 2}. We apply a Rauzy step R = Rj to { v0 , v1 , v2 } and 5). Put again viR = vi − vj for i = 0, 1, 2 with i = j and = 21 2h=0 vhR . Following Section 3.3 with viR instead of vi we obR → AR given by ( a ) = a + vhR for a ∈ AR h is a bijection on A R −1 R D D R (0), ..., and (0) = 0. We show that the roundwalk such that A = {0, (0)} 0, (0), . . . , D R (0) through AR is an extension of the roundwalk 0, (0), . . . , D (0) (i) (i+1) (0) of the roundwalk through A through A such that between any two places (0),
at most one new place in the roundwalk through AR is inserted. From now on k (compare Figs. 4 vjR = vj . Set vcR tain that : AR
Proposition 3.5. Let k = 2. Suppose AR arises from A by a Rauzy step R = Rj . Then (i) A ⊂ AR . ∈ A and (b) ∈ A. (ii) If b ∈ AR \ A, then −1 (b) a ) = a + vjR (iii) If a ∈ Ai with minimal representation 0 v0 + 1 v1 + 2 v2 − vc , then ( R whenever 0 + 1 + 2 1 and ( a ) = a + vi whenever 0 + 1 + 2 > 1. (iv) Let a ∈ Ai . If i = j , then ( a ) = ( a ). If i = j , then 2 ( a ) = a + viR + vjR = ( a ). Proof. (i) Let a ∈ A. Then a ∈ Aj for some j ∈ {0, 1, 2}. Hence, a ∈ Z2 and a = 0 v0 + 1 v1 + 2 v2 − vc with 0 i < 1 for 0 i < j ; j = 0; 0 < i 1 for j < i 2.
482
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
Fig. 5. Situation after hexagonal substitution R = R2 is applied to the situation in Fig. 3. The sets V0R (closed circles), V1R (open circles) and V2R (+ signs) have the properties as described below Fig. 4. Performing all jumps in the roundwalk wR yields a bijection of the points which induces an “exchange of the pieces” V0R , V1R , V2R . Note that the surrounding hexagon is point-symmetric, and that it has sides parallel to v0R , v1R , v2R .
It follows that a = 0 v0R + · · · + j −1 vjR−1 + ( 0 + 1 + 2 ) vjR + j +1 vjR+1 + · · · + 2 v2R − vc = 0 v0R + · · · + j −1 vjR−1 + ( 0 + 1 + 2 − 1) vjR + j +1 vjR+1 + · · · + 2 v2R − vcR . Let 0 v0 + · · · + 2 v2 − vc be the minimal representation of a . Then i − i = udi for i = j and ( 0 + 1 + 2 − 1) − j = u(d0 + d1 + d2 ) = uD for some real number u. Note that 0 0 + 1 + 2 2. If 0 + 1 + 2 < 1, then j = 0, u = ( 0 + 1 + 2 − 1) × D −1 < 0 and, by di < D, i = i − udi = i +
(1 − 0 − 1 − 2 )di di i + (1 − i ) 1, D D
and even < 1 if i = 1. If 0 + 1 + 2 1, then u 0 and 0 i 1 for i = 1, with i = 1 if and only if u = 0 and i = 1. Furthermore, 0 j 1 with j = 1 if and only if u = 0 and 0 + 1 + 2 = 2. Note that 0 + 1 + 2 = 2 implies u > 0 hence i < 1. We conclude that i = 1 if and only if i = 1 and u 0. If i = 1 and u0, then i > j and h > 0 for j < h 2. Let g be the maximal index with g = 0. Then i = 1 implies g j < i, whence a ∈ AR ∈ AR . g . Thus, a
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
483
(ii) Let b ∈ AR \ A. Choose j ∈ {0, 1, 2} such that b ∈ AR 0R + 1 v1R + j . Write b = 0 v R R 2 v2 − vc with 0 i < 1 for 0 i < j ; j = 0; 0 < i 1 for j < i 2. Hence, b = 0 v0 + · · · + j −1 vj −1 + (1 − ( 0 + 1 + 2 )) vj + j +1 vj +1 + · · · + 2 v2 − vc . If 0 0 + 1 + 2 1, then b ∈ A which is excluded. Therefore, 0 + 1 + 2 > 1. It follows from 0 2 − ( 0 + 1 + 2 ) < 1 that b + vjR = b + vj ∈ Ai for some i ∈ {0, 1, 2}. and therefore (b) ∈ A. We know that Since Ai ⊂ A ⊆ AR , it follows that b + vR = (b) j
∈ AR . If −1 (b) ∈ AR \ A, then b = (−1 (b)) ∈ A. This contradiction shows −1 (b) −1 that (b) ∈ A. (iii) Let a ∈ Ai . If i = j , then a ∈ Aj whence a + vj ∈ Aj . In this case, the assertion is obvious. Let a ∈ Ai for some i ∈ {0, 1, 2} with i = j . Then the minimal representation of a reads 0 v0 + 1 v1 + 2 v2 − vc with i = 0 and 0 h < 1 for 0 h < i; 0 < h 1 for i < h 2. Hence, a = 0 v0R + · · · + j −1 vjR−1 + ( 0 + 1 + 2 − 1) vjR + j +1 vjR+1 + · · · + 2 v2R − vcR . If 0 + 1 + 2 1 then a + vj ∈ AR and therefore ( a ) = a + vj . If 0 + 1 + 2 > 1 R. then a ∈ AR whence ( a ) = a + v i i (iv) If i = j , then viR = vi and therefore ( a ) = ( a ). If i = j , then ( a ) = a + viR R R R or ( a ) = a + vj by (iii). Recall that vi = vi + vj and, by (i), a + vi ∈ AR . Hence, a + viR + vjR ∈ AR . Since every coset in R has only one representative in AR , we have 2 ( a ) = a + vi = ( a ).
Corollary. When applying a Rauzy step Rj to a hexagonal roundwalk through A, the extended roundwalk is the hexagonal roundwalk through AR . In the extended roundwalk a ∈ Ai is followed by a + vi if i = j and by either a + viR or a + vjR and subsequently by a + viR + vjR if i = j . Whether the successor of a is a + viR or a + vjR is determined by Proposition 3.5(iii). It follows that in order to obtain the coding sequence of the extended roundwalk every letter i in the original coding sequence should be replaced by ji if 0 + 1 + 2 1 and by ij otherwise.
4. Limit words In this section, we study the limit words : V → {0, 1, . . . , k} which arise by applying an infinite number of Rauzy extensions. The limit words are restrictions to V of functions defined on Zk . We characterise in terms of 0 , 1 , . . . , k and give a necessary and sufficient condition for 0 , 1 , . . . , k to be linearly independent over Z. It is an open question under which conditions V = Zk , but some insight is gained by our results.
484
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
4.1. Characterisation of limit words We show that a characterisation of limit words given in [3] in case of Rauzy substitutions holds under much more general conditions than provided in the Corollary to Theorem 3 of [3]. We use the notation introduced above, some with superscripts (n) with n a nonnegative (0) (0) (0) number. Let v0 = e1 , vj = ej +1 − ej for j = 1, . . . , k − 1 and vk = −ek , where (0) (0) (0) (0) (0) e1 , . . . , ek are the unit vectors. Then v + · · · + v = 0 and d = d = · · · = d = 0
k
(0)
(0)
0
1 (0)
k
(0)
0 , w 1 , . . . , w k+1 = w 0 given by 1, D (0) = k +1. We start with the roundwalk w(0) = w Note that by definition w 0, e1 , e2 , . . . , ek , 0. i+1 − w i ∈ { v0 , . . . , vk } for i = 0, . . . , k. Let (hn )∞ be a sequence with elements from {0, . . . , k}. For any positive integer n let M (n) n=1 be the corresponding product of Rauzy matrices h1 h2 . . . hn . Furthermore, depending on the way of insertion, by applying successively Rauzy steps Rh1 , Rh2 , . . . , Rhn to the (n) (n) (n) 0 , w 1 , . . . , w D (n) starting from and roundwalk w(0) we obtain a roundwalk w(n) = w By construction, we have w(0) ⊂ w(1) ⊂ w(2) . . . . Put w = ∞ w(n) . The ending at 0. n=1 vectors e1 , . . . , ek occur in every roundwalk w(n) . We shall express the index j for which (n) (n) (n) (n) (n) (n) w j = ei in terms of r0 , . . . , rk . Put sj = r0 + · · · + rj −1 for j = 0, 1, . . . , k + 1. (n) (n) (n) = w (n) = ej Hence, s = 0, s = D (n) . By induction the reader can check that sj (0) 0
k+1
sj
for j = 1, . . . , k. We introduce the colouring number (n) : w(n) → {0, 1, . . . , k} by (n) ( v ) = j if v = (n) (n) s (n) (n)
(0) with sj s < sj +1 . In particular, (0) = 0 and (ej ) = j for j = 1, . . . , k and all n. In fact, ej is the first place in the roundwalk w(n) with (n) -value j. By the extension rules (n) ( v ) = (n+1) ( v ) for every n for which v ∈ w(n) . Thus, ( v ) := limn→∞ (n) ( v) is defined for every v ∈ w. In this way, we obtain a function : w → {0, 1, . . . , k}. The following theorem shows that is the restriction to w of a homogeneous linear mapping modulo 1 defined on Zk . Again {y} denotes the fractional part of y. Theorem 4.1. Suppose (hn )∞ = (x1 , . . . , xk ) ∈ w. Put n=1 is not ultimately constant. Let x (n) (n) j = limn→∞ sj /D for j = 1, . . . , k and n = 1, 2, . . . . Then, for j = 0, 1, . . . , k, ( x ) = j ⇐⇒ {x1 1 + · · · + xk k } ∈ [j −1 , j ). The proof of Theorem 4.1 depends on the following result the proof of which resembles the proof of Theorem 2.3. Proposition 4.2. If (hn )∞ n=1 is not ultimately constant and for some n the representative of the (n) -coset of x ∈ Zk occurs before the representative of the (n) -coset of y ∈ Zk in the (n) (n) (n) (n) (n) 1 , . . . , w D (n) −1 obtained by removing the jump from w D (n) −1 to w D (n) sequence w 0 , w from w(n) , then {x1 1 + · · · + xk k } < {y1 1 + · · · + yk k }. Proof. Let x, y ∈ Zk . Let tn and un be integers with 0 tn D (n) and 0 un D (n) tn and y ∈ Zk is in the same coset such that x ∈ Zk is in the same coset of (n) as w
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489 (n)
(n)
485
(n)
of (n) as w un , where w(n) = w 0 w 1 . . . w D (n) . Suppose that T is a positive integer (n)
=hT +1 hT +2 . . . hn for nT . Choose N > T so large that the k (n) (n) (n) = sequence hT +1 , hT +2 , . . . , hN is nonconstant. Put Bi,j = h=0,h =j M i,h and Bj (n) (n) (n) (n) (n) (n) (B , B , . . . , B ) for i, j = 0, 1, . . . , k. Then each of B , B , . . . , B has posiwith tT
0,j
1,j
0
k,j
1
k
(n) (n−1) (n−1) (n) (n−1) + Bj for h = j and Bj = Bj tive entries for nN . If hn = j , then Bh = Bh (n) (n) (n) for h, j = 0, 1, . . . , k and all n. Let Bj = ki=0 Bi,j for j = 0, 1, . . . , k. Put i = (n)
(n)
minj Bi,j /Bj
(n)
and i
(n)
(n)
(n)
(n)
(n)
(n)
= maxj Bi,j /Bj . Hence, 0 < i Bi,j /Bj i
< 1 for
(n) (n) (n−1) (n−1) (n) (n) if hn = j and Bi,j /Bj = i = 0, 1, . . . , k and nN. Since Bi,j /Bj = Bi,j /Bj (n) (n−1) (n−1) (n−1) (n−1) (n−1) (n−1) (n) + Bhn ) if hn = j , we have i i i i for (Bi,j + Bi,hn )/(Bj (N) (N) (n) (n) n > N. By induction, we obtain 0 < i Bi,j /Bj i < 1 for i, j ∈ {0, 1, . . . , k} (T ) (T ) (T ) uT starting from x = w tT foland n N. Let vi be a jump which is made to reach y = w (T ) (T ) lowing the roundwalk w(T ) . For example, take w tT +1 − w tT . Then we obtain by induction (n) (n−1) on n that (un −tn )−(un−1 −tn−1 ) Bi,hn for n > T . Furthermore, M (n) = M (T ) M for (n) (n) (n) n T . Hence, D (n) D (T ) D , where D is the sum of all the entries of M . We have (N) (n) (n−1) (n−1) (N) (n) (n) D −D = Bhn . Since 0 < i Bi,j /Bj i < 1 for nN , we obtain (n−1)
1 un − t n 1 (un−1 − tn−1 ) + Bi,hn un − tn (n−1) (n−1) D (n) D (T ) D (n) D (T ) D + Bhn for n > N. Therefore, (n−1)
Bi,hn un − t n 1 1 (N) lim inf > 0. lim inf n→∞ D (n) D (T ) n→∞ B (n−1) D (T ) i hn Thus, by Theorem 2.1, lim
n→∞
un tn − lim (n) > 0. (n) n→∞ D D
By applying the above argument with un = D (n) for all n, we see that limn→∞ tn /D (n) < 1 if x ∈ / (T ) for some T. Since limn→∞ tn /D (n) = 0 if x ∈ (n) for all n, we may assume that limn→∞ un /D (n) < 1 for all y ∈ Zk . The number tn is in fact the number g (n) ( x ) defined in [3, Section 4.1] as the number (n) g ∈ {0, 1, . . . , D (n) − 1} such that x and g v0 are in the same coset of (n) . By the linearity of g (n) we have tn = g (n) ( x) =
k j =1
xj g (n) (ej ) =
k j =1
(n)
xj sj (mod D (n) ).
486
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
k
(n) (n) j =1 yj sj (mod D ). Hence, (n) k k sj un tn lim (n) − lim (n) = lim yj (n) − lim yj n→∞ D n→∞ D n→∞ j =1 n→∞ j =1 D
Similarly, un = g (n) ( y) =
(n)
sj
D (n) = {y1 1 + · · · + yk k } − {x1 1 + · · · + xk k }.
We conclude that {y1 1 + · · · + yk k } − {x1 1 + · · · + xk k } > 0.
Proof of Theorem 4.1. By Theorem 2.1 the numbers i , hence the numbers i , are well = 0 and (ej ) = j for j = 1, . . . , k. By defined for i = 0, 1, . . . , k. Furthermore, (0) Proposition 1 of [3] we have k (n) (n) (n) si+1 si h=1 xh sh (n) < x ) = i ⇐⇒ (i = 0, 1, . . . , k). ( D (n) D (n) D (n) Let x ∈ w(T ) and (T ) ( x ) = i. We have (n) ( x ) = (T ) ( x ) for every n T . Hence, for every nT , k (n) (n) (n) si+1 si h=1 xh sh < . D (n) D (n) D (n) Thus, by letting n → ∞, i {x1 1 + · · · + xk k } i+1 .
(n) Suppose {x1 1 + · · · +xk k }=i+1 . We know that there exists an N such that { kh=1 xh (sh / (n) D (n) )} < si+1 /D (n) for nN . Hence, x and ei+1 are in different cosets of (N) , and the coset of x occurs before the coset of ei+1 in w(N) . By Proposition 4.2 we have {x1 1 + · · · + xk k } < i+1 . 4.2. Linear independence of the densities We prove Theorem 2.4 which states that the relative frequencies of the letters of a Rauzy word are linearly independent over Z if and only if each Rauzy substitution Rj occurs infinitely often. Suppose x, y belong to the same coset of (n) for every n. Then x − y ∈ (n) for all n. The following result provides a criterion for this phenomenon to happen. Proposition 4.3. There exists a c ∈ Zk , c = 0 such that c ∈ (n) for n = 1, 2, . . . if and only if at most k − 1 values from {0, 1, . . . , k} occur infinitely often in (hn )∞ n=1 . Proof. Suppose c ∈ (n) for all n and that at least k values from {0, 1, . . . , k} occur infinitely often in (hn )∞ n=1 . Without loss of generality, we may assume that the terms 1, 2, . . . , k occur infinitely often in (hn )∞ n=1 , and even, by the box principle, that there exist infinitely many intervals (ni , pi ] (i = 1, 2, . . .) such that hni +1 = 1, the next hn with a different value is 2, the next hn with a value different from 1 and 2 is 3, . . ., the last new value is k and 0 does not occur as a term in this finite sequence.
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
Suppose c ∈ (n) for n = 1, 2, . . . . Write c = section, g (n) ( c) =
k j =1
k
j . j =1 cj e
487
Then, as in the previous
(n)
cj sj (mod D (n) ).
Since c and 0 are assumed to be in the same coset of (n) , we obtain 0 ≡
k j =1
(n)
cj
sj
D (n)
k
≡
j =1
cj
i=0
By Theorem 2.1 this implies q := for nN, k j =1
(n)
cj
sj
D (n)
=
k j =1
cj
j −1 i=0
j −1
(n)
ri (mod 1) D (n)
k
j =1 cj
j −1 i=0
for n = 1, 2, . . . .
i ∈ Z. Then there exists an N such that,
(n)
ri = q. D (n)
Hence, for nN , (n+1) (n) k sj sj cj − (n) = 0. D (n+1) D j =1 (n+1)
(n)
(n+1)
This implies that for n N the vector (s1 /D (n+1) − s1 /D (n) , . . . , sk /D (n+1) − k (n) (n) sk /D ) is in the hyperplane j =1 cj xj = 0 in the real (x1 , . . . , xk )-space. We claim, (n+1)
(n)
(n+1)
(n)
/D (n+1) −s1 /D (n) , . . . , sk /D (n+1) −sk /D (n) ) genhowever, that the vectors (s1 erate a subspace of dimension k, i.e. Rk itself. This contradiction will prove the proposition. Without loss of generality, we may assume that the above found integer N is a term of (n) the sequence (ni )∞ i=1 . Let (N, P ) = (ni , pi ) for some i. Consider the integer matrices M (0) (n) introduced in Section 2.1. Since det(M ) = 1, we find by induction on n that det(M ) = 1 for all n. Denote by f0 , f1 , . . . , fk the column vectors of M (N) . Put F = kj =0 fj . Then be the sum of the entries F , f1 , . . . , fk are linearly independent over R. Let Fi = (fi , E) k (N) of fi for i = 0, 1, . . . , k. Then D = i=0 Fi . Write (n) (n) r(n) = t (n) F − t1 f1 . . . − tk fk
for n = N, N + 1, . . . .
(N)
Hence, t (N) = 1, ti = 0 for i = 1, . . . , k. Recall that for every n > 0 there exists an m such that r(n+1) = 2r (n) − r(m) , where m is the largest integer < n with hm+1 = hn+1 . By construction fi = r(m) , where m is the largest integer < n such that hm+1 = i. Hence, we (n) find by induction on n for n > N that tj = 0 if j is not among the terms hN+1 , . . . , hn . (n+1)
However, if n > N is the smallest integer such that hn+1 = j , then tj
= 1.
(n) (n) Write s(n) =(s1 , . . . , sk ). We want to show that the rank of the vectors (s (n+1) /D (n+1) (n) (n) (n) P −1 − s(n) /D (n) )n=N equals k. Since sj +1 − sj = rj for j = 0, 1, . . . , k and n = 1, 2, . . . ,
488
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
it is equivalent to show that the vectors (n+1) (n+1) (n) (n) rk−1 rk−1 r0 r0 − (n) , . . . , (n+1) − (n) D (n+1) D D D
(n = N, . . . , P − 1)
(n) generate Rk . Since kj =0 rj = D (n) , we can show as well that the vectors (r (n+1) /D (n+1) − r(n) /D (n) ) for n = N, . . . , P −1 generate the subspace of dimension k consisting of vectors = 0. It therefore suffices to show that the vectors r(n) /D (n) (n = x , E) x ∈ Rk+1 with ( N, . . . , P ) generate Rk+1 . Of course, we can omit the constant D (n) in this statement. We prove by induction that the vectors r(n) (n = N, . . . , P ) generate Rk+1 . For n = N , we have r(N) = F . By our assumption we have hN+1 = 1, hence r(N+1) = 2r (N) − f1 = 2F − f1 . Since F and f1 are R-linearly independent, r(N) and r(N+1) generate a subspace of dimension 2. Let i ∈ {1, 2, . . . , k} and let ni be the smallest integer N such that hni +1 = i. Then we state as induction hypothesis that r(N) , r(N+1) , . . . , r(ni +1) generate the (i + 1)-dimensional subspace RF + Rf1 + · · · + Rfi . This is true for i = 1. Suppose it is true for i with i < k. Since rn+1 = 2r (n) − r(m) for ni n < ni+1 , where r(m) ∈ {r (N) , r(N+1) , . . . , r(n−1) }, we deduce from the induction hypothesis that r(N) , r(N+1) , . . . , r(n+1) generate the (i + 1)-dimensional subspace RF + Rf1 + · · · + Rfi . However, r(ni+1 +1) = 2r (ni+1 ) − fi+1 is not contained in this subspace, since F , f0 , f1 , . . . , fi , fi+1 are linearly independent over R. Thus, r(N) , r(N+1) , . . . , r(ni+1 +1) generate the (i + 2)-dimensional subspace RF + Rf1 + · · · + Rfi+1 and the induction step is made. We conclude that the vectors r(n) (n = N, . . . , P ) generate Rk+1 . Thus, the k vectors (s (n+1) /D (n+1) − s(n) /D (n) )∞ n=N generate R and (n+1) (n) k sj sj cj − (n) = 0 (n N ) D (n+1) D j =1 implies that c1 = · · · = ck = 0. Apparently, the assumption that k terms from {0, 1, . . . , k} occur infinitely often in (hn )∞ n=1 is wrong. Suppose at most k − 1 elements from {0, 1, . . . , k} occur infinitely often in the sequence ∞ (hn )∞ n=1 . It is no restriction to suppose that 0 and 1 do not occur in the tail (hn )n=N . (n) (n) (N) (N) Then v1 − v0 = v1 − v0 ∈ (N) for n N . Since t x ∈ (n) if D (n) |t, we have (N) (N) D (1) D (2) . . . D (N) ( v1 − v0 ) ∈ (n) for n = 1, 2, . . . . Proof of Theorem 2.4. Suppose at most k − 1 elements from {0, 1, . . . , k} occur infinitely often in the sequence (hn )∞ a c = (c1 , . . . , ck ) ∈ Zk n=1 . Then, by Proposition 4.3, there exists such that c ∈ (n) for n = 1, 2, . . . . Hence, by Proposition 4.2, kj =1 cj j = q for some c ∈ Z. Then 1, 1 , . . . , k and, by 0 + 1 + · · · + k = 1, also 0 , 1 , . . . , k are linearly dependent over Z. Suppose the densities 0 , 1 , . . . , k are linearly independent over Z. Then 1, 1 , . . . , k are c1 , . . . , ck , c such that k linearly independent over Z and there exist nontrivial integers ∞ is ultimately constant c = c. It follows from Proposition 4.2 that either (h ) j n j j =1 n=1 or the representative of (c1 , . . . , ck ) is in the same coset of (n) as 0 for n = 1, 2, . . . . In the former case, only one element from {0, 1, . . . , k} occurs infinitely often in (hn )∞ n=1 . In the
R. Tijdeman / Theoretical Computer Science 346 (2005) 469 – 489
489
latter case, it follows from Proposition 4.3 that at most k − 1 elements from {0, 1, . . . , k} occur infinitely often in (hn )∞ n=1 . Remarks. If (w(n) )∞ ∈ Zk there exists an n such n=1 is space-filling, that is for every x k (n) that x occurs in w , hence V = Z , then by Proposition 4.3 at least k values from {0, 1, . . . , k} occur infinitely often. Hence, by Theorem 2.4, the numbers 0 , 1 , . . . , k are linearly independent over Z. By Theorem 4.1, the limit word depends only on 1 , . . . , k and is independent of the way of insertion. We wonder which insertions lead to space-filling roundwalks. It is possible to apply the techniques from this paper to other substitutions than Rauzy substitutions. Berthé and the author plan to publish such results in another paper. Acknowledgement I am grateful to Valerie Berthé for discussions and remarks on earlier versions of the paper. References [1] P. Arnoux, S. Ito, Pisot substitutions and Rauzy fractals, Bull. Belg. Math. Soc. Simon Stevin 8 (2001) 181–207. [2] P. Arnoux, G. Rauzy, Représentation géométrique de suites de complexité 2n + 1, Bull. Soc. Math. France 119 (1991) 199–215. [3] V. Berthé, R. Tijdeman, Lattices and multi-dimensional words, Theoret. Comput. Sci. 319 (2004) 177–202. [4] V. Berthé, L. Vuillon, Tilings and rotations on the torus: a two-dimensional generalization of Sturmian sequences, Discrete Math. 223 (2000) 27–53. [5] V. Berthé, L. Vuillon, Suites doubles de basse complexité, J. Th. Nombr. Bordeaux 12 (2000) 179–208. [6] X. Droubay, J. Justin, G. Pirillo, Episturmian words and some constructions of De Luca and Rauzy, Theoret. Comput. Sci. 255 (2001) 539–553. [7] M. Lothaire, Algebraic Combinatorics on Words, Encyclopedia of Mathematics and its Applications, Vol. 90, Cambridge University Press, Cambridge, 2002. [8] A. Messaoudi, Propriétés arithmétiques et dynamiques de fractal de Rauzy, J. Th. Nombr. Bordeaux 10 (1998) 135–162. [9] A. Messaoudi, Frontière du fractal de Rauzy et système de numèration complexe, Acta Arith. 95 (2000) 195–224. [10] N. Pytheas Fogg, in: V. Berthé, S. Ferenczi, C. Mauduit, A. Siegel (Eds.), Substitutions in Dynamics, Arithmetics and Combinatorics, Lecture Notes in Mathematics Series, Vol. 1794, Springer, Berlin, 2002. [11] G. Rauzy, Nombres algébriques et substitutions, Bull. Math. Soc. France 110 (1982) 147–178. [12] G. Richomme, Conjugacy and episturmian morphisms, Theoret. Comput. Sci. 302 (2003) 1–34. [13] Y. Sano, P. Arnoux, S. Ito, Higher dimensional extensions of substitutions and their dual maps, J. Anal. Math. 83 (2001) 183–206. [14] R.J. Simpson, R. Tijdeman, Multi-dimensional versions of a theorem of Fine and Wilf and a formula of Sylvester, Proc. Amer. Math. Soc. 131 (2003) 1661–1667. [15] V.F. Sirvent, On some dynamical subsets of the Rauzy fractal, Theoret. Comput. Sci. 180 (1997) 363–370. [16] V.F. Sirvent, Y. Wang, Self-affine tiling via substitution dynamical systems and Rauzy fractals, Pacific J. Math. 206 (2002) 465–485.
Theoretical Computer Science 346 (2005) 490–491
Author index volume 346 (2005) The issue number is given in front of the page numbers.
Alpuente, M., M. del Mar Gallardo, E. Pimentel and A. Villanueva, A semantic framework for the abstract model checking of tccp programs Baril, J.-L. and V. Vajnovszki, Minimal change list for Lucas strings and some graph theoretic consequences Bravetti, M., R. Gorrieri, R. Lucchi and G. Zavattaro, Quantitative information in the tuple space coordination model Brlek, S., G. Labelle and A. Lacasse, The discrete Green Theorem and some applications in discrete geometry Cerone, A. and A. Di Pierro, Preface Chavanon, F., M. Latapy, M. Morvan, E. Re´mila and L. Vuillon, Graph encoding of 2D-gon tilings de Mier, A. and M. Noy, A solution to the tennis ball problem del Mar Gallardo, M., see M. Alpuente Di Pierro, A., see A. Cerone Epifanio, C. and F. Mignosi, A multidimensional critical factorization theorem Fidge, C.J., see K. Lermer Gardun˜o, E. and G.T. Herman, Implicit surface visualization of reconstructed biological molecules Gerard, Y., Reduction from three-dimensional discrete tomography to multicommodity flow problem Gorrieri, R., see M. Bravetti Gouyou-Beauchamps, D. and P. Leroux, Enumeration of symmetry classes of convex polyominoes on the honeycomb lattice Harrison, P.G. and T.T. Lee, Separable equilibrium state probabilities via time reversal in Markovian process algebra Hayes, I.J., see K. Lermer Herman, G.T., see E. Gardun˜o Hurd, J., A. McIver and C. Morgan, Probabilistic guarded commands mechanized in HOL Huth, M., On finite-state approximants for probabilistic computation tree logic Kuba, A. and M. Nivat, A sufficient condition for non-uniqueness in binary tomography with absorption Labelle, G., see S. Brlek Lacasse, A., see S. Brlek Latapy, M., see F. Chavanon Lee, T.T., see P.G. Harrison Lermer, K., C.J. Fidge and I.J. Hayes, A theory for execution-time derivation in realtime programs Leroux, P., see D. Gouyou-Beauchamps Lluch-Lafuente, A. and U. Montanari, Quantitative -calculus and CTL defined over constraint semirings Louchard, G., Monotone runs of uniformly distributed integer random variables: A probabilistic analysis Lucchi, R., see M. Bravetti
(1) 58– 95 (2–3) 189–199 (1) 28– 57 (2–3) 200–225 (1) 1– 2 (2–3) (2–3) (1) (1) (2–3) (1)
226–253 254–264 58– 95 1– 2 265–280 3– 27
(2–3) 281–299 (2–3) 300–306 (1) 28– 57 (2–3) 307–334 (1) 161–182 (1) 3– 27 (2–3) 281–299 (1) 96–112 (1) 113–134 (2–3) (2–3) (2–3) (2–3) (1)
335–357 200–225 200–225 226–253 161–182
(1) 3– 27 (2–3) 307–334 (1) 135–160 (2–3) 358–387 (1) 28– 57
Author index volume 346 / Theoretical Computer Science 346 (2005) 490–491 Martı´ nez, C. and X. Molinero, Efficient iteration in admissible combinatorial classes Massazza, P. and R. Radicioni, On computing the coefficients of bivariate holonomic formal series McIver, A., see J. Hurd Mignosi, F., see C. Epifanio Molinero, X., see C. Martı´ nez Montanari, U., see A. Lluch-Lafuente Morgan, C., see J. Hurd Morvan, M., see F. Chavanon Nivat, M., see A. Kuba Noy, M., see A. de Mier Pergola, E. and S. Rinaldi, Preface Pergola, E. and S. Rinaldi, In memoriam: Alberto Del Lungo (1965–2003) Picouleau, C., Reconstruction of convex polyominoes from orthogonal projections of their contours Pimentel, E., see M. Alpuente Radicioni, R., see P. Massazza Re´mila, E., see F. Chavanon Rinaldi, S., see E. Pergola Rinaldi, S., see E. Pergola Sulanke, R.A., Three dimensional Narayana and Schro¨der numbers Tijdeman, R., Rauzy substitutions and multi-dimensional Sturmian words Vajnovszki, V., see J.-L. Baril Villanueva, A., see M. Alpuente Vuillon, L., see F. Chavanon Zavattaro, G., see M. Bravetti
491
(2–3) 388–417 (2–3) (1) (2–3) (2–3) (1) (1) (2–3) (2–3) (2–3) (2–3) (2–3)
418–438 96–112 265–280 388–417 135–160 96–112 226–253 335–357 254–264 183–183 184–188
(2–3) (1) (2–3) (2–3) (2–3) (2–3) (2–3) (2–3) (2–3) (1) (2–3) (1)
439–454 58– 95 418–438 226–253 183–183 184–188 455–468 469–489 189–199 58– 95 226–253 28– 57