Chapter 3
Algebraic Generating Functions for Languages Avoiding Riordan Patterns
This chapter is an extended version of our paper D. Merlini and M. Nocentini. Algebraic Generating Functions for Languages Avoiding Riordan Patterns. Journal of Integer Sequences, 21(18.1.3), 2018. URL https://cs.uwaterloo.ca/journals/JIS/VOL21/Merlini/merlini5.html that studies languages of binary words avoiding a given pattern such that for any where and correspond to the number of -bits and -bits in the word , respectively. In particular, we concentrate on patterns related to the concept of Riordan arrays. These languages are not regular and can be enumerated by algebraic generating functions corresponding to many integer sequences which are unknown in the OEIS. We give explicit formulas for these generating functions expressed in terms of the autocorrelation polynomial of and also give explicit formulas for the coefficients of some particular patterns, algebraically and combinatorially.
3.1Introduction#
The notion of a pattern can be formalized in several ways and in this paper we consider factor patterns, that is, patterns whose letters must appear in an exact order and contiguously in the sequence under observation. The set of binary words avoiding a pattern, without the restriction is defined by a regular language and can be enumerated in terms of the number of -bits and -bits by using classical results (see, e.g., L. J. Guibas and A. M. Odlyzko. Long repetitive patterns in random sequences. Zeitschrift für Wahrscheinlichkeitstheorie und Verwandte Gebiete, 53(3):241–262, January 1980. ISSN 1432-2064. doi: 10.1007/BF00531434. URL https://doi.org/10.1007/BF00531434L. J. Guibas and A. M. Odlyzko. String overlaps, pattern matching, and nontransitive games. Journal of Combinatorial Theory, Series A, 30(2):183–208, 1981. ISSN 0097-3165. doi: 10.1016/0097-3165(81)90005-4. URL http://www.sciencedirect.com/science/article/pii/0097316581900054R. Sedgewick and P. Flajolet. An Introduction to the Analysis of Algorithms. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1996. ISBN 0-201-40009-X). However, when we consider the additional restriction that the words have no more -bits than -bits, the language is no longer regular and enumerating it is a harder problem.
In this paper we are interested in Riordan patterns, a concept which has been defined in D. Merlini and R. Sprugnoli. Algebraic aspects of some Riordan arrays related to binary words avoiding a pattern. Theoretical Computer Science, 412(27):2988–3001, 2011. ISSN 0304-3975. doi: 10.1016/j.tcs.2010.07.019. URL http://www.sciencedirect.com/science/article/pii/S0304397510004056. Combinatorics on Words (WORDS 2009) in terms of the autocorrelation polynomial of pattern . The coefficients of this polynomial are given by the autocorrelation vector associated to , that is, the vector of bits defined in terms of Iverson’s bracket notation (for a predicate , the expression has value if is true and otherwise) as follows:
in words, the bit is determined by shifting to the right by positions, setting if and only if the remaining letters match the original.
| 1 | 0 | 1 | 0 | 1 | Tails | |||||
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 0 | 1 | 1 | |||||
| 1 | 0 | 1 | 0 | 1 | 0 | |||||
| 1 | 0 | 1 | 0 | 1 | 1 | |||||
| 1 | 0 | 1 | 0 | 1 | 0 | |||||
| 1 | 0 | 1 | 0 | 1 | 1 |
For example, when the autocorrelation vector is , as illustrated in Table 3.1, and , namely we add a term for each tail of the pattern with -bits and -bits, where . For each pattern we can compute the complement pattern by changing every to and every to ; for example, if then , therefore .
Addition of constraints to the nature of a pattern yields the following
Definition 3.1 (Riordan pattern). We say that is a Riordan pattern if and only if
with where and correspond to the number of -bits and -bits in the pattern, respectively.
For example, Table 3.1 corresponds to a Riordan pattern and is another Riordan pattern having and Moreover, in Table 3.2 we give all the Riordan patterns of length with first bit equal to and their correlation polynomials, the corresponding complement patterns can be easily determined.
| 1010100, 1011000, 1011100, 1100010, 1100100, 1101000, 1101010, 1101100, 1110000, 1110010, 1110100, 1111000 | |
| 1001100, 1100110 | |
| 1000111, 1001011, 1001101, 1010011, 1011001, 1100101, 1101001, 1110001 | |
| 1010101 |
The name Riordan in the above definition is due to the connection with the well-known concept of Riordan arrays, introduced in Chapter 1. Consider the languages of binary words avoiding a pattern and let be the number of words avoiding and having -bits and -bits; additionally, let the enclosing matrix. The following theorem, which is proved in D. Merlini and R. Sprugnoli. Algebraic aspects of some Riordan arrays related to binary words avoiding a pattern. Theoretical Computer Science, 412(27):2988–3001, 2011. ISSN 0304-3975. doi: 10.1016/j.tcs.2010.07.019. URL http://www.sciencedirect.com/science/article/pii/S0304397510004056. Combinatorics on Words (WORDS 2009), shows the importance of Riordan patterns:
Theorem 3.2. Matrices and are Riordan arrays if and only if is a Riordan pattern.
By previous theorem, matrices and can be defined as
for the appropriate given a Riordan pattern ; moreover, they represent the lower and upper part of the array , where denotes the number of words avoiding pattern and having -bits and -bits.
Remark 3.3. Riordan patterns are not the only patterns related to Riordan arrays; for example, given the pattern corresponding to , matrix is still a Riordan array but is not, as illustrated in Example 5.4 of D. Baccherini, D. Merlini, and R. Sprugnoli. Binary words excluding a pattern and proper Riordan arrays. Discrete Mathematics, 307:1021–1037, 2007. However, in these situations it is not easy to find functions and while for Riordan patterns it is always possible, as shown in Theorem 3.2 and Theorem 3.5.
As already observed, the enumeration of the set of binary words avoiding a pattern, without the restriction about the number of -bits and -bits can be done by using classical results and gives the following rational bivariate generating function for the sequence
where and correspond to the number of -bits and -bits, respectively, and is the autocorrelation polynomial, all relative to pattern . Consequently, and count the words avoiding according to the number of -bits and to length of each word, respectively.
Using the theory of Riordan arrays and the results in D. Merlini and R. Sprugnoli. Algebraic aspects of some Riordan arrays related to binary words avoiding a pattern. Theoretical Computer Science, 412(27):2988–3001, 2011. ISSN 0304-3975. doi: 10.1016/j.tcs.2010.07.019. URL http://www.sciencedirect.com/science/article/pii/S0304397510004056. Combinatorics on Words (WORDS 2009), we give explicit algebraic generating functions enumerating the set of binary words avoiding a Riordan pattern with the restriction according to various parameters, in particular to the number of -bits and to the words length. Most of the corresponding sequences are new in the On-Line Encyclopedia of Integer Sequences (OEIS for short) N. J. A. Sloane. The Encyclopedia of Integer Sequences. URL http://oeis.org/, which uses the convention to identify each sequence with a label of the form , where ; moreover, we also give explicit formulas for the coefficients of some particular patterns by providing algebraic and combinatorial proofs.
Finally, our results can be interpreted in the theory of paths and codes in light of the bijection among binary words and paths, which maps a -bit to a south-east step and a -bit to a north-east step . From this point of view, a coefficient counts the number of paths containing steps of kind and steps of kind, avoiding the subpath corresponding to pattern , allowed to cross the axis but required to end at coordinate such that . In particular, is the generating function of paths which avoid and end on the axis.
Example 3.4. The Riordan pattern entails the matrices shown in Table 3.3.
| Matrix | Entries ( leading minor) |
|---|---|
3.2Riordan arrays for Riordan patterns#
We start with a result which is a direct consequence of Theorems 2.3 and 3.3 in D. Merlini and R. Sprugnoli. Algebraic aspects of some Riordan arrays related to binary words avoiding a pattern. Theoretical Computer Science, 412(27):2988–3001, 2011. ISSN 0304-3975. doi: 10.1016/j.tcs.2010.07.019. URL http://www.sciencedirect.com/science/article/pii/S0304397510004056. Combinatorics on Words (WORDS 2009):
Theorem 3.5. Let be the number of binary words with -bits and -bits, avoiding a Riordan pattern Then the triangle is a Riordan array In particular, if and correspond to the number of -bits and -bits in the pattern, is the autocorrelation polynomial of and then:
if we have:
if we have:
if we have:
If denotes the bivariate generating function of the Riordan array as already mentioned in Section 3.1, we have:
and Theorem 3.5 allows us to state the following results.
Theorem 3.6. Let be a Riordan pattern and the generating function enumerating the set of binary words avoiding a Riordan pattern according to the number of -bits. Then we have:
if
where
if
where
if
where
Proof. For the proof we can observe that or, equivalently, that and apply the fundamental rule (1.2) with The statement of the theorem can be found after some algebraic simplification. □
Theorem 3.7. Let be a Riordan pattern and the generating function enumerating the set of binary words avoiding a Riordan pattern according to the length. Then we have:
if
where
if
where
if
where
Proof. For the proof we can observe that the application of generating function as
entails that which is the number of binary words with -bits and -bits. To enumerate according to the length let , therefore . The statement of the theorem can be found after some algebraic simplification. □
Theorem 3.6 and Theorem 3.7 allows us to find the generating functions and in terms of the autocorrelation polynomial for any Riordan pattern In what follows, we study some special classes of patterns characterized by an autocorrelation polynomial which can be easily computed, as in the case For such particular patterns, Theorem 3.5 simplifies as follows.
Corollary 3.8. Let be the Riordan array corresponding to the number of binary words with -bits and -bits which avoid the Riordan pattern Then we have the following particular cases:
for we have the Riordan array:
we have the Riordan array:
and we have the Riordan array:
we have the Riordan array:
we have the Riordan array:
As a peculiar instance, observe that when we instantiate a pattern from family with we get a Riordan array such that
so the number of words containing -bits and -bits, avoiding pattern , is for . If we consider the combinatorial interpretation of as lattice paths as illustrated in the last paragraph of Section 3.1, this corresponds to the fact that there is exactly one valley-shaped path having steps of both kinds and , avoiding and terminating at coordinate for each , formally the path .
By applying Theorem 3.6 to the same patterns as before we state the
Corollary 3.9. Let the generating function enumerating the set of binary words avoiding a Riordan pattern according to the number of -bits. We have the following particular cases:
for we have:
for we have:
for and we have:
for we have:
for we have:
where .
We observe that the case in Corollary 3.9 corresponds to the sequence studied in S. Bilotta, E. Pergola, and E. Grazzini. Counting Binary Words Avoiding Alternating Patterns. Journal of Integer Sequences, 16, 2013; moreover, in Table 3.4, Table 3.5, Table 3.6, Table 3.7 and Table 3.8 we report some series developments related to functions just defined, respectively.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 3 | 7 | 15 | 31 | 63 | 127 | 255 | 511 | 1023 | 2047 | 4095 |
| 2 | 1 | 3 | 10 | 32 | 106 | 357 | 1222 | 4230 | 14770 | 51918 | 183472 | 651191 |
| 3 | 1 | 3 | 10 | 35 | 123 | 442 | 1611 | 5931 | 22010 | 82187 | 308427 | 1162218 |
| 4 | 1 | 3 | 10 | 35 | 126 | 459 | 1696 | 6330 | 23806 | 90068 | 342430 | 1307138 |
| 5 | 1 | 3 | 10 | 35 | 126 | 462 | 1713 | 6415 | 24205 | 91874 | 350406 | 1341782 |
| 6 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6432 | 24290 | 92273 | 352212 | 1349768 |
| 7 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24307 | 92358 | 352611 | 1351574 |
| 8 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24310 | 92375 | 352696 | 1351973 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 3 | 8 | 20 | 48 | 112 | 256 | 576 | 1280 | 2816 | 6144 | 13312 |
| 2 | 1 | 3 | 10 | 33 | 111 | 378 | 1302 | 4525 | 15841 | 55783 | 197389 | 701286 |
| 3 | 1 | 3 | 10 | 35 | 124 | 447 | 1632 | 6015 | 22336 | 83439 | 313216 | 1180511 |
| 4 | 1 | 3 | 10 | 35 | 126 | 460 | 1701 | 6351 | 23890 | 90398 | 343713 | 1312108 |
| 5 | 1 | 3 | 10 | 35 | 126 | 462 | 1714 | 6420 | 24226 | 91958 | 350736 | 1343069 |
| 6 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6433 | 24295 | 92294 | 352296 | 1350098 |
| 7 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24308 | 92363 | 352632 | 1351658 |
| 8 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24310 | 92376 | 352701 | 1351994 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24310 | 92378 | 352716 | 1352078 |
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 2 | 1 | 3 | 9 | 27 | 82 | 253 | 791 | 2499 | 7960 | 25520 | 82248 | 266221 |
| 3 | 1 | 3 | 10 | 34 | 118 | 417 | 1493 | 5400 | 19684 | 72196 | 266122 | 985003 |
| 4 | 1 | 3 | 10 | 35 | 125 | 454 | 1671 | 6211 | 23261 | 87641 | 331821 | 1261398 |
| 5 | 1 | 3 | 10 | 35 | 126 | 461 | 1708 | 6390 | 24086 | 91328 | 347965 | 1331072 |
| 6 | 1 | 3 | 10 | 35 | 126 | 462 | 1715 | 6427 | 24265 | 92154 | 351666 | 1347326 |
| 7 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6434 | 24302 | 92333 | 352492 | 1351028 |
| 8 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24309 | 92370 | 352671 | 1351854 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 3 | 7 | 18 | 48 | 131 | 363 | 1017 | 2873 | 8169 | 23349 | 67024 |
| 2 | 1 | 3 | 10 | 32 | 109 | 377 | 1324 | 4697 | 16795 | 60425 | 218485 | 793259 |
| 3 | 1 | 3 | 10 | 35 | 123 | 445 | 1631 | 6036 | 22511 | 84460 | 318438 | 1205457 |
| 4 | 1 | 3 | 10 | 35 | 126 | 459 | 1699 | 6350 | 23911 | 90572 | 344737 | 1317397 |
| 5 | 1 | 3 | 10 | 35 | 126 | 462 | 1713 | 6418 | 24225 | 91979 | 350910 | 1344092 |
| 6 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6432 | 24293 | 92293 | 352317 | 1350272 |
| 7 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24307 | 92361 | 352631 | 1351679 |
| 8 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24310 | 92375 | 352699 | 1351993 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 3 | 8 | 22 | 61 | 171 | 483 | 1373 | 3923 | 11257 | 32418 | 93644 |
| 2 | 1 | 3 | 10 | 33 | 113 | 393 | 1384 | 4920 | 17618 | 63456 | 229642 | 834342 |
| 3 | 1 | 3 | 10 | 35 | 124 | 449 | 1647 | 6099 | 22754 | 85394 | 322022 | 1219205 |
| 4 | 1 | 3 | 10 | 35 | 126 | 460 | 1703 | 6366 | 23974 | 90818 | 345691 | 1321092 |
| 5 | 1 | 3 | 10 | 35 | 126 | 462 | 1714 | 6422 | 24241 | 92042 | 351156 | 1345049 |
| 6 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6433 | 24297 | 92309 | 352380 | 1350518 |
| 7 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24308 | 92365 | 352647 | 1351742 |
| 8 | 1 | 3 | 10 | 35 | 126 | 462 | 1716 | 6435 | 24310 | 92376 | 352703 | 1352009 |
| Coefficient | Words |
|---|---|
| 111, 0111, 1011, 00111, 01011, 10011, 10101, 000111, 001011, 010011, 010101, 100011, 100101, 101001, 101010 | |
| 111, 0111, 1011, 1101, 1110, 01011, 01101, 01110, 10101, 10110, 11010, 11100, 010101, 010110, 011010, 011100, 101010, 101100, 110100, 111000 | |
| 11111111, 111111110, 1111111100, 11111111000, 111111110000, 1111111100000, 11111111000000, 111111110000000, 1111111100000000 | |
| 111, 0111, 1110, 00111, 01110, 10011, 11001, 11100, 000111, 001110, 010011, 011001, 011100, 100011, 100110, 110001, 110010, 111000 | |
| 111, 0111, 1011, 1101, 1110, 00111, 01101, 01110, 10011, 10110, 11001, 11100, 000111, 001101, 001110, 011001, 011100, 100011, 100110, 101100, 110001, 111000 |
Finally, by applying Theorem 3.7 to the pattern families already examined, we find the following result.
Corollary 3.10. Let the generating function enumerating the set of binary words avoiding a Riordan pattern according to the length. We have the following particular cases:
for we have:
for we have:
for and we have:
for we have:
for we have:
where .
In Table 3.10, Table 3.11, Table 3.12, Table 3.13 and Table 3.14 we report some series developments related to functions just defined, respectively.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 3 | 3 | 7 | 7 | 15 | 15 | 31 | 31 | 63 | 63 | 127 | 127 | 255 |
| 2 | 1 | 1 | 3 | 4 | 11 | 15 | 38 | 55 | 135 | 201 | 483 | 736 | 1742 | 2699 | 6313 |
| 3 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 63 | 159 | 247 | 610 | 969 | 2354 | 3802 | 9117 |
| 4 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 255 | 634 | 1015 | 2482 | 4041 | 9752 |
| 5 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1023 | 2506 | 4087 | 9880 |
| 6 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4095 | 9904 |
| 7 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4096 | 9908 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 3 | 4 | 9 | 13 | 26 | 39 | 73 | 112 | 201 | 313 | 546 | 859 | 1469 |
| 2 | 1 | 1 | 3 | 4 | 11 | 16 | 40 | 61 | 147 | 231 | 542 | 870 | 2004 | 3269 | 7423 |
| 3 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 161 | 253 | 622 | 999 | 2414 | 3942 | 9396 |
| 4 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 636 | 1021 | 2494 | 4071 | 9812 |
| 5 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2508 | 4093 | 9892 |
| 6 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4096 | 9906 |
| 7 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4096 | 9908 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4096 | 9908 |
| 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 | 5 | 5 | 6 | 6 | 7 | 7 | 8 |
| 2 | 1 | 1 | 3 | 4 | 10 | 14 | 33 | 48 | 109 | 163 | 362 | 552 | 1207 | 1868 | 4036 |
| 3 | 1 | 1 | 3 | 4 | 11 | 16 | 41 | 62 | 154 | 240 | 583 | 928 | 2217 | 3587 | 8459 |
| 4 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 162 | 254 | 629 | 1008 | 2455 | 4000 | 9614 |
| 5 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 637 | 1022 | 2501 | 4080 | 9853 |
| 6 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2509 | 4094 | 9899 |
| 7 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4096 | 9907 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 3 | 3 | 7 | 8 | 19 | 23 | 53 | 66 | 150 | 191 | 429 | 555 | 1235 |
| 2 | 1 | 1 | 3 | 4 | 11 | 15 | 38 | 56 | 139 | 210 | 511 | 790 | 1892 | 2973 | 7034 |
| 3 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 63 | 159 | 248 | 614 | 978 | 2382 | 3857 | 9273 |
| 4 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 255 | 634 | 1016 | 2486 | 4050 | 9780 |
| 5 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1023 | 2506 | 4088 | 9884 |
| 6 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4095 | 9904 |
| 7 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4096 | 9908 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 3 | 4 | 9 | 13 | 28 | 42 | 87 | 134 | 271 | 425 | 844 | 1342 | 2628 |
| 2 | 1 | 1 | 3 | 4 | 11 | 16 | 40 | 61 | 149 | 234 | 558 | 895 | 2098 | 3420 | 7909 |
| 3 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 161 | 253 | 624 | 1002 | 2430 | 3967 | 9492 |
| 4 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 636 | 1021 | 2496 | 4074 | 9828 |
| 5 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2508 | 4093 | 9894 |
| 6 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4096 | 9906 |
| 7 | 1 | 1 | 3 | 4 | 11 | 16 | 42 | 64 | 163 | 256 | 638 | 1024 | 2510 | 4096 | 9908 |
3.3Code for enumeration and construction of Riordan arrays#
>>> w_1, w_0 = 3, 2
>>> binary_words = words(avoiding=[1,1,0],
... ones=[1]*w_1,
... zeros=[0]*w_0)
>>> sorted(binary_words)
[[0, 0, 1, 1, 1], [0, 1, 0, 1, 1],
[1, 0, 0, 1, 1], [1, 0, 1, 0, 1]]
>>> words_as_strings(binary_words)
['00111', '01011', '10011', '10101']
>>> {w_0: sorted(words(avoiding=[1,1,0],
... ones=[1]*w_1,
... zeros=[0]*w_0))
... for w_0 in range(w_1+1)}
{0: [[1, 1, 1]],
1: [[0, 1, 1, 1], [1, 0, 1, 1]],
2: [[0, 0, 1, 1, 1], [0, 1, 0, 1, 1],
[1, 0, 0, 1, 1], [1, 0, 1, 0, 1]],
3: [[0, 0, 0, 1, 1, 1], [0, 0, 1, 0, 1, 1],
[0, 1, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1],
[1, 0, 0, 0, 1, 1], [1, 0, 0, 1, 0, 1],
[1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 1, 0]]}After the initial imports
from collections import namedtuple
from functools import wraps
import sympy
J_index = namedtuple('J_index', ['j'])
W_index = namedtuple('W_index', ['w_1', 'w_0'])we introduce the definition words to be a simple implementation of a word generator, in the sense of Python generator, inspired by a tableau schema. If exausted, words yields all binary words that don’t contain pattern avoiding, using the given occurrences of ones and zeros, respectively.
def words(avoiding, ones, zeros):
a = len(avoiding)
def W(word, ones, zeros):
if ones:
one = ones[0]
new_word = word + [one]
if new_word[-a:] != avoiding:
yield from W(new_word, ones[1:], zeros)
if zeros:
zero = zeros[0]
new_word = word + [zero]
if new_word[-a:] != avoiding:
yield from W(new_word, ones, zeros[1:])
if not ones and not zeros: yield word
return W([], ones, zeros)A decorator is a function returning another function, usually applied as a function transformation using the @wrapper syntax.
The decorator syntax is merely syntactic sugar, the following two function definitions are semantically equivalent with respect to the staticmethod decorator:
>>> def f(*args):
... pass
>>> f = staticmethod(f)
>>> @staticmethod
... def f(*args):
... passDecorators provides metaprogramming capabilities and modularity; for example, a memoized version of Fibonacci numbers recursion can be coded using the lru_cache decorator:
from functools import lru_cache
@lru_cache(maxsize=None)
def fibonacci(n):
'''
Fibonacci's numbers, memoized.
>>> fibonacci(100)
354224848179261915075
>>> list(map(fibonacci, range(20)))
... # doctest: +NORMALIZE_WHITESPACE
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
144, 233, 377, 610, 987, 1597, 2584, 4181]
'''
if n < 2:
return n
return fibonacci(n-1) + fibonacci(n-2)Together with the decorator avoiding
class avoiding:
def __init__(self, pattern, G):
self.pattern = pattern
self.G = G # `G` stands for *generator*
def __call__(self, post):
@wraps(post)
def A(n_domain, j_domain, *args, **kwds):
T = {J_index(j):
{W_index(w_1, w_0): sorted(words)
for w_1 in n_domain
for w_0 in range(w_1+1)
for words in [self.G(pattern,
ones=[1]*w_1,
zeros=[0]*w_0)]}
for j in j_domain
for pattern in [self.pattern(j)]} # implicit `let`
res = post(T, *args, **kwds)
return res if res else T
return Awith the two helper definitions words_as_strings and rows_sums
def words_as_strings(bws):
J = lambda w: ''.join(map(str, w))
return sorted(map(J, bws), key=len)
def rows_sums(M):
return list(M * sympy.ones(M.rows, 1))it allows us to enumerate words in our families with
@avoiding(pattern=lambda j: [1]*(j+1) + [0]*j, G=words)
def ones_then_zeros_words(table): pass
@avoiding(pattern=lambda j: [0]*(j+1) + [1]*j, G=words)
def zeros_then_ones_words(table): pass
@avoiding(pattern=lambda j: [0]*j + [1]*j, G=words)
def zeros_equals_ones_words(table): pass
@avoiding(pattern=lambda j: [1,0]*j + [1], G=words)
def one_zero_star_one_words(table): pass
@avoiding(pattern=lambda j: [0,1]*j + [0], G=words)
def zero_one_star_zero_words(table): passover the domains for the number of -bits, the length and params
>>> n_domain, l_domain, j_domain = (list(range(11)),
list(range(13)),
list(range(3)))respectively. Counting words grouped by the number of -bits and by their length by definitions
def group_by_ones(n_domain, words):
Z = sympy.zeros(len(n_domain), len(n_domain))
for o in n_domain:
for z in range(o+1):
Z[o, o-z] += len(words[W_index(o, z)])
return Z
def group_by_length(n_domain, words):
rows = len(n_domain)
Z = sympy.zeros(2 * rows, 2 * rows)
for o in n_domain:
for z in range(o+1):
Z[o+z,o-z] += len(words[W_index(o, z)])
return Z[:rows,:rows]respectively, we justify the content of previous tables with the following computationsProves the set of words already enumerated in the first row of Table 3.9.
>>> binary_words = ones_then_zeros_words(n_domain, j_domain)
>>> words_as_strings([w for w_1 in [3]
... for w_0 in range(w_1+1)
... for J,W in [(J_index(1),W_index(w_1, w_0))]
... for w in binary_words[J][W]])
['111', '0111', '1011', '00111', '01011', '10011', '10101',
'000111', '001011', '010011', '010101', '100011', '100101',
'101001', '101010']
>>> M = group_by_ones(n_domain, binary_words[J_index(1)])
>>> rows_sums(M)
[1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047]
>>> MProves the series development in row of Table 3.4 as row summation M.
>>> binary_words = ones_then_zeros_words(l_domain, j_domain)
>>> M = group_by_length(l_domain, binary_words[J_index(1)])
>>> rows_sums(M)
[1, 1, 3, 3, 7, 7, 15, 15, 31, 31, 63, 63, 127]
>>> MProves the series development in row of Table 3.10 as row summation M.
>>> M = group_by_length(l_domain, binary_words[J_index(2)])
>>> rows_sums(M)
[1, 1, 3, 4, 11, 15, 38, 55, 135, 201, 483, 736, 1742]
>>> MProves the series development in row of Table 3.10 as row summation M.
3.4Some combinatorial interpretations#
In the previous section we proved results about the enumeration of words avoiding patterns from an algebraic point of view. The aim of this section is to analyze in more details some particular cases of the various pattern families. We approach these problems either combinatorially by providing an interpretation, or algebraically by computing the coefficients of the involved generating functions explicitly.
3.4.1Enumeration with respect to the number of -bits#
Corollary 3.11. Consider pattern , there is only one word in for ; on the other hand, there are words for .
Proof. When the pattern to avoid is , therefore only words in are suitable choices; however, the constraint makes the only one.
When the pattern to avoid is and we observe that the generic binomial can be interpreted as the number of binary words with -bits containing occurrences of the substring , which we call an inversion with respect to pattern . In order to build a word in the language we start from the substring for and select -bits, transforming each one using the mapping , while preventing the transformation of the -bit in the just introduced. This maneuver introduces inversions and the selection can be done in ways; finally, we pad on the right with a strip , because it is mandatory for a word to have -bits, hence there is one padding for each set of inversions and there is no other way to avoid . Therefore
as can be verified algebraically by extracting the coefficient of the generating function , as required. □
The same argument can be rewritten in term of sets which allows us give a constructive approach. Let be the set of binary words containing and occurrences of -bits and -bits, respectively, with inversions, namely an occurrence of the subsequence . By union respect to and we get sets and , formally:
For the sake of clarity, we enumerate all binary words avoiding containing -bits, formally we partition as follows
where
the same set of words shown in Table 3.4.
Corollary 3.12. Consider pattern , there is one word for each in when ; on the other hand, there are words for .
Proof. When the pattern to avoid is , therefore only words are suitable, hence there is one of them for each .
When the pattern to avoid is , therefore we extract the -th coefficient after instantiation of the corresponding generating function , as required.
We also provide a combinatorial interpretation of the theorem; first of all, we observe that sequence is the binomial transform of the sequence of the positive integers , formally
where the generic summand can be interpreted as the number of binary words with -bits containing occurrences of the substring , which we call an inversion respect to pattern . We construct the set of words avoiding to show the bijection with the previous assert as follows: if in a word there are occurrences of the substring then contains bits in total, of both kind. Since it is mandatory that the number of is , we add -bits to it, resulting in a new word of length which can be augmented with at most additional -bits, according to the constraint . In order to build a word with the structure of , we start from the substring and select -bits, transforming each one using the mapping , simultaneously to prevent transforming -bit in just introduced. This maneuver introduces inversions and the selection can be done in ways; moreover, we are free to pad on the right with strips, for hence there are paddings for each set of inversions. Therefore, since there can be up to inversions,
concludes the proof by symmetry of binomial coefficients. □
Corollary 3.13. Consider pattern (or, equivalently, ), there are
words in for ; on the other hand, there are words for .
Proof. When there is no pattern to avoid and this situation corresponds to the enumeration of binary words . After instantiating the generating function , we extract the -th coefficient
obtaining which simplifies by the identity as desired. It is possible to state the following combinatorial interpretation: since the maximum number of -bits is , we reserve boxes for them. To the left of each box reserve one more box and, finally, another one to the right of the very last box. In this way we have reserved boxes where we can put -bits in ways, as required.
When the pattern to avoid is (or, equivalently, ), therefore only words are suitable, which are , one for each value that can take. □
Last two patterns and are harder to study: for there are and words, respectively. On the other hand, when we report only the instantiated generating functions
As pointed out by an anonymous referee, previous functions can be rewritten as
respectively, where is the Motzkin numbers’ generating function. Such rewriting shows a relation among Motzkin numbers and powers of ; however, a combinatorial argument is not easy to state to the best of our knowledge.
3.4.2Enumeration with respect to the length#
Corollary 3.14. Consider pattern , there is one word in for ; on the other hand, there are words, where , for .
Proof. When the pattern to avoid is , therefore instantiating the generating function we have , as required.
When the pattern to avoid is , therefore we instantiate and extract the -th coefficient
and proceed by cases on the parity of . If then the second term in the rhs disappears, otherwise if the first term disappears; in both cases it is required to perform where , as required.
It is possible to state a combinatorial interpretation using an argument similar to the one given in the proof of Corollary 3.11. Let , therefore a word needs to have -bits, where ; conversely, needs to have -bits. Fixing in the given range, from the substring we select -bits to introduce inversions, namely occurrences of , applying the mapping simultaneously. This maneuver keeps the original -bits and introduces at most -bits, so we pad with -bits on the right in order to have the required -bits in the entire word; finally, selections can be done in
ways, because padding can be done in only one way, completing the case for even.
Let , therefore a word needs to have -bits, where ; conversely, needs to have -bits. Fixing in the given range, from the substring we select -bits to introduce inversions as done in the even case, introducing at most -bits, and padding as necessary to have -bits, the total number of selections equals the one given for the even case, completing the case for odd. □
Corollary 3.15. Consider pattern , there is one word for each in when ; on the other hand, there are words if else words if , for , where is the -th Fibonacci number.
Proof. When the pattern to avoid is , therefore suitable words of length are of the form , hence for each .
When the pattern to avoid is , therefore we instantiate and extract the -th coefficient
in order to have , where and .
It is possible to state a combinatorial interpretation using an argument similar to the one given in the proof of Corollary 3.12. Let , therefore a word needs to have -bits, where ; conversely, needs to have -bits. Fixing in the given range, from the substring we select -bits to introduce inversions, namely occurrences of , applying the mapping simultaneously. This maneuver keeps the original -bits and introduces at most -bits; finally, selections can be done in ways. In order to find a closed form for the double summation, we inspect the region of the Pascal triangle taken into account; marking with the involved binomials
and using identity for rearranging the summation and identities and to collect terms, we obtain
which equals , closing the case for even.
Let , therefore a word needs to have -bits, where ; conversely, needs to have -bits. Fixing in the given range, from the substring select -bits to introduce inversions as done for the even case; in parallel, selections can be done in ways. The involved region in the Pascal triangle has the same shape as the one shown for the even case translated one row to the bottom, so binomials lying on row are excluded and binomials are included, for . Therefore we rewrite
which equals , closing the case for odd. □
Corollary 3.16. Consider pattern (or, equivalently, ), there are words in if is odd else where , for ; on the other hand, there are words, where , for .
Proof. When the pattern to avoid is , namely the empty word, therefore instantiating the generating function we have
we extract the coefficient , where and , as required. We observe that these values correspond to the summation for where the binomial coefficient computes the number of ways to choose -bits among bits, and this gives the combinatorial interpretation.
When the pattern to avoid is (or, equivalently, ), therefore after instantiation
we extract the -th coefficient , so either or entails , as required.
A combinatorial interpretation can be given as follows. If then suitable words have structure for , and there are of them. On the contrary, if holds then suitable words have structure for , they are in number again, as required. □
As before, last two patterns and are harder to study and we avoid to report formulas about functions because we have not a meaningful combinatorial interpretation: we only point out that these functions can be expressed in terms of , where is the generating function of Motzkin numbers, similarly to the corresponding functions.
Conclusions#
As a final remark, we observe a structural properties of matrices against the studied families of patterns. Recall that the Pascal triangle and its inverse correspond to the Riordan arrays
respectively; therefore, for any Riordan array we can compute which is equivalent to say that is the binomial transform of or .
For the sake of clarity, consider the pattern family , so for we have the minor
which corresponds to
defined by functions and .
On the other hand, the Riordan array , that is in the family, is the binomial transform of
defined by functions
in particular, the latter expands to
Riordan arrays can be completely defined by using the results of Theorem 3.5 and the product rule of the Riordan group. Doing so, for each pattern family studied in this work with , the Riordan array appears to be the binomial transform of another Riordan array with non-negative integer coefficients, although it is not easy to spot this property looking at the corresponding functions because their series expansions might contain negative coefficients, as shown for matrices and . This fact could be further investigated from an algebraic and combinatorial point of view and possibly yield interesting combinatorial interpretations also in the case