applications in enumerative combinatorics of infinite ... · applications in enumerative...

35
Scientific Annals of Computer Science vol. 24 (1), 2014, pp. 137–171 doi: 10.7561/SACS.2014.1.137 Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs Rodrigo De Castro 1 , Andr´ es Ram´ ırez 1 , Jos´ e L. Ram´ ırez 1, 2 . Abstract In this paper, we present a general methodology to solve a wide vari- ety of classical lattice path counting problems in a uniform way. These counting problems are related to Dyck paths, Motzkin paths and some generalizations. The methodology uses weighted automata, equations of ordinary generating functions and continued fractions. This new methodology is called Counting Automata Methodology. It is a varia- tion of the technique proposed by Rutten, which is called Coinductive Counting. Keywords: infinite weighted automata, enumerative combinatorics, continued fractions, generating functions, lattice paths 1 Introduction Formal languages, finite automata and grammars are basic mathematical objects in Theoretical Computer Science with remarkable applications in various fields such as Algebra, Number Theory and Combinatorics, [5, 7, 10]. In particular, by using finite automata and grammars, some combinatorial results are related to enumeration of discrete objects and their generating functions [6, 8, 10, 15, 18, 21, 22, 23]. Combinatorics is an important branch of Mathematics which is focused on study of discrete objects. These kind of objects often arise in Theoretical 1 Departamento de Matem´ aticas, Universidad Nacional de Colombia, Bo- got´a, Colombia, Email: [email protected], [email protected], [email protected] 2 Instituto de Matem´ aticas y sus Aplicaciones, Universidad Sergio Arboleda, Bogot´ a, Colombia, Email: [email protected]

Upload: others

Post on 01-Jun-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Scientific Annals of Computer Science vol. 24 (1), 2014, pp. 137–171

doi: 10.7561/SACS.2014.1.137

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs

Rodrigo De Castro1, Andres Ramırez1, Jose L. Ramırez1,2.

Abstract

In this paper, we present a general methodology to solve a wide vari-ety of classical lattice path counting problems in a uniform way. Thesecounting problems are related to Dyck paths, Motzkin paths and somegeneralizations. The methodology uses weighted automata, equationsof ordinary generating functions and continued fractions. This newmethodology is called Counting Automata Methodology. It is a varia-tion of the technique proposed by Rutten, which is called CoinductiveCounting.

Keywords: infinite weighted automata, enumerative combinatorics,continued fractions, generating functions, lattice paths

1 Introduction

Formal languages, finite automata and grammars are basic mathematicalobjects in Theoretical Computer Science with remarkable applications invarious fields such as Algebra, Number Theory and Combinatorics, [5, 7, 10].In particular, by using finite automata and grammars, some combinatorialresults are related to enumeration of discrete objects and their generatingfunctions [6, 8, 10, 15, 18, 21, 22, 23].

Combinatorics is an important branch of Mathematics which is focusedon study of discrete objects. These kind of objects often arise in Theoretical

1Departamento de Matematicas, Universidad Nacional de Colombia, Bo-gota, Colombia, Email: [email protected], [email protected],

[email protected] de Matematicas y sus Aplicaciones, Universidad Sergio Arboleda, Bogota,

Colombia, Email: [email protected]

Page 2: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

138 R. De Castro, A. Ramırez, J.L. Ramırez

Computer Science. Enumerate Combinatorics is one of the main subfieldof Combinatorics and it addresses the problem how to count the number ofelements of a finite set in an exact or approximate way. The finite set isgiven by some combinatorial conditions. Some examples of combinatorialobjects are lattice paths, trees, polyominoes, words and planar maps, etc.

Several different methods exist to study combinatorial objects. Forexample, the symbolic enumeration method [15] is a unified algebraic the-ory which develops systematic symbolic relations between combinatorialconstructions and operations on generating functions. The transfer-matrixmethod [16] uses the adjacency matrices of graphs to solve enumeration prob-lems; it is a variation of modeling by deterministic automata and modelingby paths in standard graphs. The Schutzenberger methodology, also calledDelest-Viennot-Schutzenberger methodology [6], is a method of enumera-tion which uses algebraic languages. The coinductive counting [25] is amethodology which makes use of coinductive calculus of streams, infiniteweighted automata and stream bisimulation.

An infinite weighted automaton is a generalization of a nondeterminis-tic weighted finite automaton. Its transitions carry weights. These weightsmay model, e.g., the cost involved when executing a transition, or the proba-bility or reliability of its successful execution [13]. Some restricted relationsbetween infinite weighted automata and combinatorics have been developedin [20, 25, 32, 31]; however, there are few studies in this direction.

In this paper, we present a variation of the methodology developed byRutten in [25], without the use of coinduction. We use only infinite weightedautomata, weighted graphs and continued fractions. The weights in theseautomata can be generating functions instead of just numbers; this is ageneralization suggested by Rutten in [25]. We call this new methodologyCounting Automata Methodology.

The general idea in this methodology is to associate a system of ordi-nary generating functions to an infinite weighted graph which is obtainedfrom an infinite weighted automaton. Then, we develop a set of propertiesallowing us to find the associated ordinary generating function by solvingsystems of equations. Specifically, we study two families of automata, thelinear and bilinear infinite counting automata, in which each edge is labelledwith a general generating function. We find the generating function associ-ated with these automata, and some combinatorial relations. Additionally,we introduce an operator on linear and bilinear automata which transformsthem into similar automata with a new set of accepting states. From this,

Page 3: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 139

we find new combinatorial constructions related to the ones already studied.

From this new perspective, it is possible to derive existing and newcounting results. Moreover, with this methodology many different com-binatorial constructions can be enumerated in a uniform and simple way.Specifically, we apply this methodology to problems of lattice paths, suchas Dyck paths, Riordan paths, Motzkin paths, colored Motzkin paths andgeneralized Motzkin paths, among others.

The outline of this paper is as follows. In Section 2 we recall the notionsof weighted automata and its ordinary generating functions. In Section 3 wedevelop a set of properties to decide when an automaton is convergent, whichare necessary to find the ordinary generating function associated with theautomaton. Then in Section 4 we describe the proposed Counting AutomataMethodology. In Section 5 we find the generating function of a family ofinfinite weighted automata and we work out some examples of lattice paths.Finally, in Section 6 we introduce a general operator on linear and bilinearcounting automata.

2 Weighted Automata and Generating Functions

The terminology and notations are mainly those of Sakarovitch [26] andShallit [28]. Let Σ be a finite alphabet, whose elements are called symbols.A word over Σ is a finite sequence of symbols from Σ. The set of all wordsover Σ, i.e., the free monoid generated by Σ, is denoted by Σ∗. The identityelement ǫ of Σ∗ is called the empty word. For any word w ∈ Σ∗, ∣w∣ denotesits length, i.e., the number of symbols occurring in w. The length of ǫ istaken to be equal to 0. If a ∈ Σ and w ∈ Σ∗, then ∣w∣a denotes the numberof occurrences of a in w. Let Σ be a finite alphabet. Then each subset ofΣ∗ is called a formal language over Σ. The number of words of length n ina language L is denoted by L(n).

An automaton M is a 5-tuple M = (Σ,Q, q0, F,E), where Σ is anonempty input alphabet, Q is a nonempty set of states of M, q0 ∈ Q

is the initial state of M, ∅ ≠ F ⊆ Q is the set of final states of M andE ⊆ Q × Σ ×Q is the set of transitions of M. The language recognized byan automatonM is denoted by L(M). If Q,Σ and E are finite sets, we saythatM is a finite automaton [1, 19, 26].

We often describe an automatonM by providing a transition diagramor a labelled graph. This is a directed graph where states are represented

Page 4: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

140 R. De Castro, A. Ramırez, J.L. Ramırez

by circles, final states by double circles, the initial state is labelled by aheadless arrow entering a state, and transitions are represented by directedarrows, labelled with a symbol. Automata in this paper do not have uselessstates.

Example 1. Consider the finite automatonM= (Σ,Q, q0, F,E) where Σ ={a, b}, Q = {q0, q1}, F = {q0} and E = {(q0, a, q1), (q0, b, q0), (q1, a, q0)}. Thetransition diagram of M is as shown in Figure 1. It is easy to verify thatL(M) = (b ∪ aa)∗.

q0 q1

b

a

a

Figure 1: Transition diagram ofM, Example 1.

Example 2. Consider the infinite automatonMD = (Σ,Q, q0, F,E), whereΣ = {a, b}, Q = {q0, q1, . . .}, F = {q0} and E = {(qi, a, qi+1), (qi+1, b, qi) ∶ i ∈ N}.The transition diagram ofMD is as shown in Figure 2.

q0 q1 q2 q3

a

b

a

b

a

b

Figure 2: Transition Diagram ofMD, Example 2.

The language accepted byMD is:

L(MD) = {w ∈ Σ∗ ∶ ∣w∣a = ∣w∣b and for all prefix v of w, ∣v∣b ≤ ∣v∣a} .

This automaton is known as the Dyck Automaton [4].

2.1 Generating Function of Languages

An ordinary generating function F = ∑∞n=0 fnzn corresponds to a formallanguage L if fn = ∣{w ∈ L ∶ ∣w∣ = n}∣, i.e., if the n-th coefficient fn gives thenumber of words in L with length n.How to find the ordinary generating function (GF) corresponding to context-free language is known as the Schutzenberger methodology, (see, e.g., [6,10, 15]). If L ⊆ Σ∗ is an unambiguous context-free language, then theGF corresponding to L is algebraic over Q(x); moreover, if L is a regular

Page 5: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 141

language then the GF corresponding to L is a rational series (see, e.g.,[13, 15, 26]).

Let G = (V,Σ, P, S) be an unambiguous context-free grammar of thelanguage LG, where V is a finite set of nonterminal symbols, Σ is a finite setof terminal symbols with Σ ∩ V = ∅, S ∈ V is a special symbol in V , calledthe starting symbol and P is a finite set of rules which, P ⊆ V × (V ∪Σ)∗.The morphism Θ is defined by

Θ(ǫ) = 1,

Θ(a) = z, ∀a ∈ Σ,

Θ(A) = A(z), ∀A ∈ V.

Any production rule A → e1∣e2∣⋯∣ek ∈ P yields an algebraic equation in theA(z),B(z), . . .

Θ(A) =∞∑i=1

Θ(ei).

We obtain a system of equations over the unknown A(z),B(z), . . .. Thissystem has to be solved for S(z) and gives the generating function corre-sponding to LG.

Example 3. Consider the finite automaton from Example 1. Then weobtain the following system of equations

⎧⎪⎪⎨⎪⎪⎩

L0 = {b} × L0 + {a} × L1 + 1

L1 = {a} × L0

This gives rise to a set of equations for the associated GFs

⎧⎪⎪⎨⎪⎪⎩

L0(z) = zL0(z) + zL1(z) + 1

L1(z) = zL0(z)

Solving the system, we have the GF corresponding to L(M). It is L0(z)since the initial state of the automaton is q0, and

L0(z) =1

1 − z − z2=∞∑n=0

Fnzn,

where Fn is the n-th Fibonacci number, see sequence A000045 3.

3Many integer sequences and their properties are to be found electronically on theOn-Line Encyclopedia of Sequences [30].

Page 6: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

142 R. De Castro, A. Ramırez, J.L. Ramırez

2.2 Formal Power Series and Weighted Automata

Given an alphabet Σ and a semiring K. A formal power series or formalseries S is a function S ∶ Σ∗ → K. The image of a word w under S is calledthe coefficient of w in S and is denoted by sw. The series S is written asa formal sum S = ∑w∈Σ∗ sww. The set of formal power series over Σ withcoefficients in K is denoted by K ⟨⟨Σ∗⟩⟩.

An automaton over Σ∗ with weight in K, or K-automaton over Σ∗ isa graph labelled with elements of K ⟨⟨Σ∗⟩⟩, associated with two maps fromthe set of vertices to K ⟨⟨Σ∗⟩⟩. Specifically, a weighted automaton M overΣ∗ with weights in K is 4-tupleM= (Q, I,E,F ) where

Q is a nonempty set of states ofM.

An element E of K ⟨⟨Σ∗⟩⟩Q×Q called transition matrix.

I is an element of K ⟨⟨Σ∗⟩⟩Q, i.e., I is a function from Q to K ⟨⟨Σ∗⟩⟩.I is the initial function ofM and can also be seen as a row vector ofdimension Q, called initial vector ofM.

F is an element of K ⟨⟨Σ∗⟩⟩Q, i.e., F is a function from Q to K ⟨⟨Σ∗⟩⟩.F is the final function ofM and can also be seen as a column vectorof dimension Q, called final vector ofM.

For more details see [13, 26].

We say thatM is a counting automaton if K = Z and Σ∗ = {z}∗. Witheach automaton, we can associate a counting automaton. It can be obtainedfrom a given automaton replacing every transition labelled with a symbola, a ∈ Σ, by a transition labelled with z. This transition is called a countingtransition and the graph is called a counting automaton ofM.

p qa p qz

Figure 3: Counting transition.

Each transition from p to q yields an equation:

L(p)(z) = zL(q)(z) + [p ∈ F ] +⋯.We use Lp to denote L(p)(z). We also use Iverson’s notation, [P ] = 1 if theproposition P is true and [P ] = 0 if P is false.

Page 7: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 143

3 Convergent Automata and Convergent Theorems

We denote by L(n)(M) the number of words of length n recognized by theautomatonM, including repetitions.

Definition 1. We say that an automatonM is convergent if for all integern ⩾ 0, L(n)(M) is finite.

It is clear that every finite automaton is convergent, however, there arenon convergent infinite automata.

Example 4. Let M = (Σ,Q, q0, F,E) be an infinite automaton, where Σ ={a}, Q = {q0, q1, . . .} = F and E = {(qi, a, qi+1) ∶ i ∈ N}, see Figure 4. It isclear that L(M) = {an ∶ n ≥ 0}, then L(n)(M) = 1 for all n ⩾ 1, henceM isconvergent.

q0 q1 q2 q3a a a ⋯

Figure 4: Transition diagram ofM, Example 4.

Example 5. Let M = (Σ,Q, q0, F,E) be an infinite automaton, where Σ ={a0, a1, . . .}, Q = {q0, q}, F = {q} and E = {(q0, ai, q) ∶ i ∈ N}, see Figure 5.It is clear that L(M) = Σ, which is an infinite set, thenM is not convergent.

q0 q

a0a1a2⋮

Figure 5: Transition diagram ofM, Example 5.

Example 6. Let M = (Σ,Q, q0, F,E) be an infinite automaton, where Σ ={a}, Q = {q0, q1, q2,⋯}, F = {q1, q2,⋯} and E = {(q0, a, qi) ∶ i ∈ Z+}, seeFigure 6. It is clear that L(M) = {a}, however, L(1)(M) is infinite.

q0

q1

q2

aa⋮

Figure 6: Transition diagram ofM, Example 6.

Page 8: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

144 R. De Castro, A. Ramırez, J.L. Ramırez

3.1 Criterions for Convergence

Definition 2. LetM= (Σ,Q, q0, F,E) be an automaton. We defined the setof states of M reachable from state q ∈ Q in n transitions, Qq

n, recursivelyas follows:

Qqn =⎧⎪⎪⎨⎪⎪⎩{q} , if n = 0;

⋃{p′ ∶ (p, a, p′) ∈ E,p ∈ Qqn−1} , if n ⩾ 1.

Theorem 1 (First Convergence Theorem). Let M be an automaton,such that each vertex (state) of the counting automaton of M has finitedegree. ThenM is convergent.

Proof. Any path of length n in the transition diagram of M can be con-sidered as a sequence of n + 1 states, where each state is taken exclusivelyof the sets Qq0

0,Q

q01,Q

q02, . . . ,Q

q0n . Since ⋃n

k=0Qq0k

is a finite set, L(n)(M) isfinite, because any word of length n is obtained after n choices, each with afinite number of options.

Example 7. The counting automaton of the automatonMD in Example 2is convergent. This automaton was studied in [23].

The following definition plays an important role in the development ofapplications because it allows to simplify counting automata whose transi-tions are formal series.

LetM be an automaton, and let f(z) = ∑∞n=1 fnzn be a formal powerseries with fn ∈ N for all n ⩾ 1. In a counting automaton of M the set ofcounting transitions from state p to state q, without intermediate final states,see Figure 7(left), is represented by a graph with a single edge labelled byf(z), see Figure 7(right).

This kind of transition is called a transition in parallel. The states p

and q are called visible states and the intermediate states are called hiddenstates.

Example 8. In Figure 8(left) we display a counting automatonM1 withouttransitions in parallel, i.e., every transition is label by z. The transitions

from state q1 to q2 correspond to the series 1−√1−4z2

= z + z2 + 2z3 + 5z4 +14z5+⋯. However, this automaton can also be represented using transitionsin parallel. Figure 8(right) displays two examples.

This example shows that a counting automaton can have differentequivalent representations.

Page 9: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 145

p qp q

f(z)

f1

times

f2

times

f3

times

fn

times

´¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¸¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¶n − 1 states, n transitions⋮

Figure 7: Transitions from the state p to q and transition in parallel.

Definition 3. Two counting automataM1 andM2 are equivalent if for allinteger n ⩾ 0, L(n)(M1) = L(n)(M2). This is denoted byM1 ≅M2.

Definition 4. Let f(z) = ∑∞t=0 ftzt be a power series (or a polynomial). Wedefine nf(z) as the polynomial nf(z) = ∑n

t=0 ftzt.

Theorem 2 (Second Convergence Theorem). LetM be an automaton,and let f q

1(z), f q

2(z), . . . , be the transitions in parallel from state q ∈ Q in a

counting automaton ofM. ThenM is convergent if the series

F q(z) = ∞∑k=1

fqk(z)

is a convergent series for each visible state q ∈ Q of the counting automaton.

Proof. Any word of length n is accepted by M if there is a path from q0to some final state. Since the hidden states in a transition in parallel arenot final states, then the paths from a visible state to another visible state,corresponding to the terms fn+1zn+1, fn+2zn+2, . . . of a transition in parallelf(z) in a counting automaton of M, are not accepting paths. Let M′ bean automaton obtained by replacing all transitions in parallel f(z) in acounting automaton ofM by the transition nf(z), then clearly L(n)(M) =L(n)(M′) for all n ⩾ 0. On the other hand, the number of transitions of

Page 10: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

146 R. De Castro, A. Ramırez, J.L. Ramırez

q0

q1

q2

q0

q1

q2

q0

q1

q2

q3

2z + z2

1 −√1 − 4z2

2z

2z

2z

z z − z√1 − 4z2

M1

M2:

M3:

Figure 8: Counting automata with transitions in parallel, Example 8.

each visible state q ∈ Q′ inM′ is finite because

∞∑k=1

nfqk(1) = nF

q(1) < ∞,

and from each of the hidden state starts a single transition. Hence, byTheorem 1, M′ is convergent. Hence L(n)(M) = L(n)(M′) is finite for alln ⩾ 0, thereforeM is convergent.

Proposition 1. If f(z) is a polynomial transition in parallel from state p

to q in a finite counting automaton M, then this gives rise to an equationin the system of GFs equations ofM:

Lp = f(z)Lq + [p ∈ F ] +⋯Proof. Let f(z) = f1z+f2z2+⋯+fnzn be a polynomial transition in parallel,then the set of transitions in parallel corresponding to the term fkz

k, 1 ≤k ≤ n, can be represented with a graph as in Figure 9.

Therefore the GF equation is

Lp(z) = zLq11(z) + zLq21(z) +⋯+ zLqfk1(z) + [p ∈ F ] .

Since Lqi1(z) = zk−1Lq(z), thenLp(z) =

fk−times³¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹·¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹¹µzkLq(z) + zkLq(z) +⋯+ zkLq(z)+ [p ∈ F ]= fkz

kLq(z) + [p ∈ F ] .

Page 11: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 147

p q

q11 q12 q1k−1

q21 q22 q2k−1

qfk1 qfk2 qfkk−1

z

z

z

z z z

z

z

z

⋮ ⋮ ⋮

Figure 9: Transition in parallel corresponding to the term fkzk.

Considering each of the terms fk, (1 ≤ k ≤ n), then

Lp(z) = f1zLq(z) + f2z2Lq(z) +⋯+ fnznLq(z) + [p ∈ F ]= f(z)Lq(z) + [p ∈ F ] .

Proposition 2. Let M be a convergent automaton such that a countingautomaton ofM has a finite number of visible states q0, q1, . . . , qr, in whichthe number of transitions in parallel starting from each state is finite. Letfqt1(z), f qt

2(z), . . . , f qt

s(t)(z) be the transitions in parallel from the state qt ∈ Q.

Then the GF for the language L(M) is Lq0(z). It is obtained by solving thesystem of r + 1 GFs equations

L(qt)(z)= f qt

1(z)L(qt1)(z) + f qt

2(z)L(qt2)(z) +⋯+ f qt

s(t)(z)L(qts(t))(z) + [qt ∈ F ],with 0 ≤ t ≤ r, where qtk is the visible state joined with qt through thetransition in parallel f qt

k, and L(qtk) is the GF for the language accepted by

M if qtk is the initial state.

Proof. Let n ⩾ 0 be an integer, and let M′ be the automaton obtained byreplacing the s(t) transitions in parallel (f qt

1(z), f qt

2(z), . . . , f qt

s(t)(z)) leavingthe state qt ∈ Q by the transitions nf

qt1(z), nf

qt2(z), . . . , nf

qts(t)(z), with

0 ≤ t ≤ r. Hence M′ is a finite automaton and from Proposition 1 the GFofM′ is obtained by solving the following system for L′(q0)L′(qt)(z) = nf

qt1(z)L′(qt1)(z) + nf

qt2(z)L′(qt2)(z) +⋯+ nf

qts(t)(z)L′(qts(t))(z) + [qt ∈ F ],

Page 12: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

148 R. De Castro, A. Ramırez, J.L. Ramırez

where 0 ≤ t ≤ r. Therefore L′(q0)(z) is a rational function R evaluatedat variables nf

qtk(z), with 0 ≤ t ≤ r,1 ≤ k ≤ s(t). We denoted this by

L′(q0)(z) = R(nf qtk(z)). It is clear that nL

′(q0)(z) = nL(q0)(z). Finallywe consider the series R(f qt

k(z)), as the calculation of a rational expression

involves only a finite number of sums, differences, products and reciprocals,and after applying one of these operations the n-th term of the power seriesdepends only on the first n terms of the series involved in the operation.Hence, R(nf qt

k(z)) = nR(f qt

k(z)) for all n ≥ 0. Therefore the GF of M is

R(f qtk(z)) = L(q0).

Example 9. The system of GFs equations associated withM2, see Example8, is

⎧⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎩

L0 = (2z + z2)L1 + 1

L1 =1 −√1 − 4z2

L2

L2 = 2zL0.

Solving the system for L0, we find the GF for the languageM2 and thereforeofM1 andM3.

L0 =1

1 − (2z2 + z3)(1 −√1 − 4z) = 1 + 4z3 + 6z4 + 10z5 + 40z6 + 114z7 +⋯.4 Counting Automata Methodology (CAM)

A counting automaton associated with an automaton M can be used tomodel combinatorial objects if there is a bijection between all words recog-nized by the automaton M and the combinatorial objects. Such method,along with the previous theorems and propositions constitute theCountingAutomata Methodology (CAM).

We distinguish three phases in the CAM:

1. Given a problem of enumerative combinatorics, we have to find aconvergent automaton M (see Theorems 1 and 2) whose GF is thesolution of the problem.

2. In Propositions 1 and 2 we describe how to find the generating functionassociated with a counting automatonM. To find the GF ofM we usean auxiliary automaton M′, which is obtained from M by removing

Page 13: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 149

a set of states or edges as explained in the proof of Proposition 2.Sometimes we find a relation of iterative type, such as a continuedfraction. Moreover, it is practical to use equivalent automata (seeDefinition 3).

3. Find the GF f(z) to which the GFs associated with eachM′ converge,which is guaranteed by the convergence theorems.

4.1 Examples of the Counting Automata Methodology

Example 10. A Motzkin path of length n is a lattice path of Z ×Z runningfrom (0,0) to (n,0) that never passes below the x-axis and whose permittedsteps are the up diagonal step U = (1,1), the down diagonal step D = (1,−1)and the horizontal step H = (1,0), called rise, fall and level step, respec-tively. The number of Motzkin paths of length n is the n-th Motzkin numbermn, sequence A001006. Many other examples of bijections between Motzkinnumbers and others combinatorial objects can be found in [3].

The number of words of length n recognized by the convergent automa-tonMMot, see Figure 10, is the n-th Motzkin number and its GF is

M (z) = ∞∑i=0

mizi =

1 − z −√1 − 2z − 3z2

2z2(1)

=1

1 − z −z2

1 − z −z2

1 − z −z2

. (2)

q0 q1 q2 q3

z

z

z

z

z

z

z z z z

MMot ∶

Figure 10: Convergent Automaton associated with Motzkin Paths.

In this case the edge from state qi to state qi+1 represents a rise, theedge from the state qi+1 to qi represents a fall and the loops represent thelevel steps, see Table 1.

Moreover, it is clear that a word is recognized byMMot if and only if thenumber of steps to the right and to the left coincide, which ensures that thepath is well formed. Then mn = ∣{w ∈ L(MMot) ∶ ∣w∣ = n}∣ = L(n)(MMot).

Page 14: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

150 R. De Castro, A. Ramırez, J.L. Ramırez

(qi, z, qi+1) ∈ E⇔ (qi+1, z, qi) ∈ E⇔ (qi, z, qi) ∈ E⇔Table 1: Bijection betweenMMot and Motzkin paths.

Let MMots, s ≥ 1 be the automaton obtained from MMot, by deletingthe states qs+1, qs+2, . . . . Therefore the system of GFs equations of MMots

is

⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩L0 = zL0 + zL1 + 1,

Li = zLi−1 + zLi + zLi+1, 1 ≤ i ≤ s − 1,

Ls = zLs−1 + zLs.

Substituting repeatedly into each equation Li, we have

L0 =H

1 −F 2

1 −F 2

1 − F 2

⎫⎪⎪⎪⎪⎪⎪⎪⎪⎬⎪⎪⎪⎪⎪⎪⎪⎪⎭s times

where F = z1−z and H = 1

1−z . Since MMot is convergent, then as s →∞ weobtain a convergent continued fraction M of the GF ofMMot. Moreover,

M =H

1 − F 2 (MH).

Hence z2M2 − (1 − z)M + 1 = 0 and

M(z) = 1 − z ±√1 − 2z − 3z2

2z2.

Since ǫ ∈ L(MMot), M → 0 as z → 0. Hence we take the negative sign forthe radical in M(z).Example 11. The number of Motzkin paths of length n without level stepson the x-axis (Riordan paths) is the n-th Riordan number rn, sequenceA005043. The number of words of length n recognized by the convergent

Page 15: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 151

automatonMR, see Figure 11(left), is the n-th Riordan number and its GFis

R(z) = ∞∑i=0

rizi =

1 + z −√1 − 2z − 3z2

2z(1 + z) (3)

=1

1 −z2

1 − z −z2

1 − z −z2

. (4)

In the automaton MR, the initial loop was removed to avoid the levelsteps on the x-axis, then it is clear that rn = ∣{w ∈ L(MR) ∶ ∣w∣ = n}∣ =L(n)(MR). Moreover, we can use equivalent automata because the automa-ton MMot is a subautomaton of MR. Hence, there is an automaton M′

R

with only two visible states, such thatM′R ≅MR, see Figure 11(right).

q0 q1 q2 q3

z

z

z

z

z

z

z z z

q0 q1

z

zM(z)⋯ ≅≅

MR: M′R:

Figure 11: Equivalent AutomataM′R ≅MR, Example 11.

Then we have the following system of GFs equations

{R(z) = 1 + zL1

L1 = zM(z)R(z),where M(z) is the GF for Motzkin numbers. Whence

R(z) = 1 + z2M(z)R(z), (5)

then

R(z) = 1

1 − z2M(z) = 2

1 + z +√1 − 2z − 3z2

=1 + z −

√1 − 2z − 3z2

2z(1 + z)Moreover, from Equation (5)

rn =n−2∑j=0

mjrn−j−2, n ≥ 2.

We also have R(z) = 1+zM(z)1+z then (1+z)R(z) = 1+zM(z). Hence rn+1+rn =

mn, n ≥ 0, this equation is derived in [3] using a combinatorial argument.

Page 16: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

152 R. De Castro, A. Ramırez, J.L. Ramırez

5 Linear Infinite Counting Automaton

In this section we study a family of counting automata and their GFs.

Definition 5. A linear graph G is a 4-tuple G = (V,A,n,F ) whereV ⊆ Z is a nonempty set of the labelled vertices of G. If m ∈ V , thevertex is labelled by m.

A = (A−,A↷,A↶) is the set of edges of G, where

– A− = {i ∈ V ∶ there exists a loop at vertex i}.– A↷ = {i ∈ V ∶ there exists an edge from vertex i to vertex i + 1 }.– A↶ = {i ∈ V ∶ there exists an edge from vertex i + 1 to vertex i}.

n ∈ V is the initial vertex.

F ⊆ V is the set of final vertices.

In particular, if V = N, A = (N,N,N), n = 0, F = {0}, we say that G isa complete linear graph and is denoted by GL. If V = Z, A = (Z,Z,Z), n =0, F = {0}, we say that G is a complete bilinear graph and is denoted byGBT .

Example 12. Consider the linear graph V = N, A = (2N,N,N), n = 0, F ={0}. It is displayed in Figure 12.

0 1 2 3 ⋯

Figure 12: Linear graph, Example 12.

Definition 6. A linear counting automaton associated with the linear graphG is a weighted automatonMc determined by the pairMc = (G,E), whereE is the set of weighted transitions defined by the triple E = (E−,E↷,E↶)where

E− = {hi(z) ∶ i ∈ A−}.E↷ = {fi(z) ∶ i ∈ A↷}.E↶ = {gi(z) ∶ i ∈ A↶}.

Page 17: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 153

and for all integer i, fi(z), gi(z) and hi(z) are transitions in parallel.

The set of all counting automata is denoted byM∗c .

Example 13. Consider the linear counting automatonMc = (G,E = (∅,{z},{z})),where G = (N, (∅,N,N),0,{0}). It is displayed in Figure 13.

0 1 2 3

z

z

z

z

z

z

Figure 13: Linear counting automaton, Example 13.

The linear infinite counting automaton associated with the completelinear graph GL is denoted by MLin, see Figure 14(left). Similarly, thelinear infinite counting automaton associated with the complete bilineargraph GBL is denoted byMBLin, see Figure 14(right).

0 1 2 3

f0

g0

f1

g1

f2

g2

h0 h1 h2 h3

0 1 2−1−2

f0

g0

f1

g1g′0

g′1

f ′1

f ′0

⋯ ⋯

MBLin ∶ h0 h1 h2h′1

h′2

MLin ∶

Figure 14: Infinite counting automataMLin andMBLin.

5.1 Generating Function of MLin and MBLin

Theorem 3. The generating function ofMLin, see Figure 14 (left), is

E(z) = 1

1 − h0 (z) − f0 (z) g0 (z)1 − h1 (z) − f1 (z) g1 (z)

,

where fi(z), gi(z) and hi(z) are transitions in parallel for all integer i ⩾ 0.

Proof. We denoted byMLin−s the automaton obtained fromMLin deletingthe vertices s, s+1, s+2, . . . . The system of GFs equations ofMLin−s, s ≥ 1,is ⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩

L0 = h0L0 + f0L1 + 1

Li = gi−1Li−1 + hiLi + fiLi+1, 1 ≤ i ≤ s − 1

Ls = gs−1Ls−1 + hsLs.

Page 18: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

154 R. De Castro, A. Ramırez, J.L. Ramırez

Substituting repeatedly into each equation Li, we have

L0 =1

1 − h0 −f0g0

1 − h1 −f1g1

1 − hs−1 −fs−1gs−11 − hs

.

Since MLin is convergent, then when s → ∞ we obtain the convergentcontinued fraction E(z) of the GF ofMLin.

The last theorem coincides with Theorem 1 in [14] and Theorem 9.1in [25]. However, this presentation extends their applications, taking intoaccount that fi(z), gi(z) and hi(z) are GFs, which can be GFs of severalvariables.

Corollary 1. If for all integer i ≥ 0, fi(z) = f(z), gi(z) = g(z) and hi(z) =h(z) inMLin, then the GF is

B(z) = 1 − h(z) −√(1 − h(z))2 − 4f(z)g(z)2f(z)g(z) (6)

=∞∑n=0

∞∑m=0

Cn(m + 2nm)(f (z) g (z))n (h(z))m (7)

=1

1 − h (z) − f (z) g (z)1 − h (z) − f (z) g (z)

1 − h (z) − f (z) g (z)⋱

, (8)

where f(z), g(z) and h(z) are transitions in parallel and Cn is the n-thCatalan number, sequence A000108.

Proof. From Theorem 3 the GF is

B(z) = 1

1 − h (z) − f (z) g (z)1 − h (z) − f (z) g (z)

1 − h (z) − f (z) g (z)⋱

.

Page 19: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 155

Since the counting automaton is convergent, then

B(z) = 1

1 − h(z) − f(z)g(z)B(z) .Hence

B(z) = 1 − h(z) −√(1 − h(z))2 − 4f(z)g(z)2f(z)g(z) .

Equation (7) is obtained from observing that

B(z) = 1 − h(z) −√(1 − h(z))2 − 4f(z)g(z)2f(z)g(z)

=1

1 − h(z)1 −√

1 − 4 f(z)g(z)(1−h(z))2

2f(z)g(z)(1−h(z))2

=1

1 − h(z)C(u),where u = f(z)g(z)

(1−h(z))2 and C(z) = 1−√1−4z2z

is the GF for Catalan numbers.

Therefore

B(z) = 1

1 − h(z)C(u) = 1

1 − h(z)∞∑n=0

Cnun

=∞∑n=0

Cn(f(z)g(z))n(1 − h(z))2n+1

=∞∑n=0

∞∑m=0

Cn(m + 2nm)(f(z)g(z))n (h(z))m .

Example 14. If h(z) = f(z) = g(z) = z in Corollary 1, we obtain the GFfor Motzkin paths M(z), see Example 10. Moreover,

ms =⌊ s2⌋

∑n=0

Cn( s2n).

Indeed, using the Equation (7) it follows that

M(z) = ∞∑n=0

∞∑m=0

Cn(m + 2nm)z2n+m,

Page 20: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

156 R. De Castro, A. Ramırez, J.L. Ramırez

taking t = 2n +m

M(z) = ∞∑n=0

∞∑t=2n

Cn( t

t − 2n)zt,

hence

ms =⌊ s2⌋

∑n=0

Cn( s

s − 2n) = ⌊

s2⌋

∑n=0

Cn( s2n).

5.2 Applications of CAM to k-colored Motzkin Paths andGeneralized Motzkin Paths

Example 15. A k-colored Motzkin path of length n is a Motzkin path suchthat the level steps are labelled by k colors. The number of k-colored Motzinpaths of length n is the n-th k-colored Motzkin number, mn,k.

If f(z) = z = g(z) and h(z) = kz in Corollary 1, we obtain the GF fork-colored Motzkin paths

Mk(z) = ∞∑i=0

mi,kzi =

1 − kz −√(1 − kz)2 − 4z2

2z2,

and

mn,k =⌊ s2⌋

∑n=0

Cn( s2n)ks−2n. (9)

Equation (9) coincides with Equation (8) of [27]. In particular, if k = 2

M2(z) = ∞∑i=0

mi,2zi =

1 − 2z −√1 − 4z

2z

= z + 2z2 + 5z3 + 14z4 + 42z5 + 132z6 + 429z7 + 1430z8 +⋯.

Then zM2(z) = C(z) − 1 so the n-th 2-colored Motzkin number is equal toCn+1. In [12] and [33] there are some bijections between the numbers mn,2

and other combinatorial objects. If k = 3

M3(z) = ∞∑i=0

mi,3zi =

1 − 3z −√1 − 6z + 5z2

2z

= z + 3z2 + 10z3 + 36z4 + 137z5 + 543z6 + 2219z7 + 9285z8 +⋯,

Page 21: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 157

then the sequence A002212 is obtained, some properties about these numbersare established in [11, 29]. If k = 4 the sequence A005572 which starts 1, 4,17, 76, 354, 1704, 8421, 42508 is obtained.

Example 16. A generalized Motzkin path of length n is a Motzkin pathsuch that the level step is H = (k,1) where k is a fixed positive integer.The number of generalized Motzkin paths of length n is the n-th generalizedMotzkin number mk

n. If f(z) = z = g(z) and h(z) = zk in Corollary 1, weobtain the GF for generalized Motzkin path.

M (k)(z) = ∞∑i=0

mki z

i =1 − zk −

√(1 − zk)2 − 4z22z2

.

The last equation coincides with the Equation (1) of [2]. If k = 2, we obtainthe GF for Schroder paths, sequence A006318.

M (2)(z) = ∞∑i=0

m2

i zi =

1 − z2 −√1 − 6z2 + z4

2z2

= 1 + 2z2 + 6z4 + 22z6 + 90z8 + 394z10 + 1806z12 +⋯.

There is a relation well known between the numbers m2

i and Narayana num-bers N(n, k) = 1

n(nk)( n

k−1) with 1 ⩽ k ⩽ n which enumerate a large varietyof combinatorial objects, see sequence A001263. In particular, there is thefollowing identity, [9]

m2

n =n

∑k=0

N(n, k)2k.Example 17. If f(z) = z = g(z) and h(z) = kz

1−z in Corollary 1, we obtainthe GF Fk(z) for the lattice path which never goes below the x-axis, from(0,0) to (n,0) consisting of up steps U = (1,1), down steps D = (1,−1) andhorizontal steps H(k) = (k,0) for every positive integer k and can be labelledby k colors

Fk(z) = 1 − (1 + k)z −√1 − (2 + 2k)z + (−3 + 2k + k2)z2 + 8z3 − 4z42z2(1 − z) ,

and

f (k)s =s

∑n=0

s−2n∑m=0

Cn(m + 2nm)( s − 2n − 1

s −m − 2n)km,

Page 22: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

158 R. De Castro, A. Ramırez, J.L. Ramırez

where f(k)s = [zs]Fk(z). From Corollary 1 we have the first equation, besides

Fk(z) = ∞∑n=0

∞∑m=0

Cn(m + 2nm)z2n ( kz

1 − z)m

=∞∑n=0

∞∑m=0

∞∑i=0

Cn(m + 2nm)(i +m − 1

i)kmz2n+m+i,

taking t = 2n +m + i

∞∑n=0

∞∑m=0

∞∑

t=2n+mCn(m + 2n

m)( t − 2n − 1

t −m − 2n)kmzt,

hence

f (k)s =s

∑n=0

s−2n∑m=0

Cn(m + 2nm)( s − 2n − 1

s −m − 2n)km.

If k = 1 the sequence A135052 is obtained.

The last example shows the variety of results that can be obtainedwith the CAM, simply by changing the different transitions in parallel, i.e.,changing the GFs fi(z), gi(z) and hi(z).Definition 7. For all integer i ≥ 0 we define the continued fraction Ei(z)by:

Ei(z) = 1

1 − hi (z) − fi (z) gi (z)1 − hi+1 (z) − fi+1 (z) gi+1 (z)

1 − hi+2 (z) − fi+2 (z) gi+2 (z)⋱

,

where fi(z), gi(z), hi(z) are transitions in parallel for all integers positive i.

Theorem 4. The generating function ofMBLin, see Figure 14(right), is

Eb(z) = 1

1 − h0(z) − f0(z)g0(z)E1(z) − f ′0(z)g′0(z)E′1(z),where fi(z), f ′i(z), gi(z), g′i(z), hi(z) and h′i(z) are transitions in parallel forall i ∈ Z.

Page 23: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 159

0 1−1

f0

g0E1g′0

f ′0E′

1

h0

Figure 15: Equivalent automaton toMBLin.

Proof. It is clear that the automatonMBLin is equivalent to the automatonin Figure 15.

Therefore, we have the following system of GFs equations

⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩L0 = h0L0 + f0L1 + g′0L

′1 + 1

L1 = g0E1L0

L′1 = f0E′1L0,

where L′1= L−1. Solving the system for L0 we obtain the GF ofMBLin.

Corollary 2. If for all integer i, fi(z) = f(z) = f ′i(z), gi(z) = g(z) = g′i(z)and hi(z) = h(z) = h′i(z) inMBLin, then we have the GF

Bb(z) = 1√(1 − h(z))2 − 4f(z)g(z) (10)

=1

1 − h(z) − 2f(z)g(z)1 − h(z) − f(z)g(z)

1 − h(z) − f(z)g(z)⋱

, (11)

where f(z), g(z) and h(z) are transitions in parallel.

Proof. It is clear from Equation (10)

Bb(z) = 1

1 − h(z) − 2f(z)g(z)B(z) ,where B(z) is the GF in Corollary 1. The continued fraction is obtainedfrom the same corollary.

Page 24: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

160 R. De Castro, A. Ramırez, J.L. Ramırez

Corollary 3. If f(z) = g(z) in Corollary 2, then we have the GF

Bb(z) = 1

1 − h(z) +∞∑n=1

∞∑k=0

∞∑l=0

2nn

n + 2k(n + 2k

k)(l + 2n + 2k

l)f(z)2n+2kh(z)l,

(12)

where f(z), g(z) and h(z) are transitions in parallel.

Proof. From Theorem 4 we have

Bb(z) = 1

1 − h(z) − 2f2(z)B(z) ,where B(z) is the GF in Corollary 1 with g(z) = f(z), i.e.,

B(z) = 1 − h(z) −√(1 − h(z))2 − 4f2(z)2f2(z) =

1

1 − h(z)C(u),where u = f2(z)

(1−h(z))2 and C(u) is the GF for Catalan numbers. The powers

of the GF for Catalan numbers (see Eq. 5.70 of [17]), satisfy that

Cn(u) = ∞∑k=0

n

n + 2k(n + 2k

k)uk, n ⩾ 1.

Then

Bb(z) = 1

1 − h(z) − 2f2(z) C(u)1−h(z)

=1

1 − h(z) 1

1 − 2uC(u)=

1

1 − h(z)∞∑n=0(2uC(u))n = 1

1 − h(z) +∞∑n=1(2uC(u))n

=1

1 − h(z) +∞∑n=1

∞∑k=0

2nn

n + 2k(n + 2k

k) f2n(z)(1 − h(z))2nuk

=1

1 − h(z) +∞∑n=1

∞∑k=0

2nn

n + 2k(n + 2k

k) f2n+2k(z)(1 − h(z))2n+2k

=1

1 − h(z) +∞∑n=1

∞∑k=0

∞∑l=0

2nn

n + 2k(n + 2k

k)(l + 2n + 2k

l)f2n+2k(z)hl(z).

Page 25: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 161

Example 18. A Grand Motzkin path of length n is a Motzkin path withoutthe condition that never passes below the x-axis. The number of GrandMotzkin paths of length n is the n-th Grand Motzkin number mb

n, sequenceA002426.

The number of words of length n recognized by the convergent automa-ton MBLin, see Figure 14(right), with fi(z) = z = gi(z) = hi(z) = f ′i(z) =g′i(z) = h′i(z) for all integer i, is the n-th Grand Motzkin number and its GFis

M b (z) = ∞∑i=0

mbiz

i 1√1 − 2z − 3z2

(13)

=1

1 − z −2z2

1 − z −z2

1 − z −z2

(14)

=1

1 − z+∞∑n=1

∞∑k=0

∞∑l=0

2nn

n + 2k(n + 2k

k)(l + 2n + 2k

l)z2n+2k+l. (15)

These equations are easily obtained from Corollary 2 and 3.

In this case the edge from the state i and i+1 and vice versa, representa rise or a fall above the x-axis and the edge from the state −i and −(i + 1)and vice versa, represent a rise or a fall below the x-axis, and the loopsrepresent the level steps. Moreover, it is clear that a word is recognized byMBLin if and only if it has an equal number of steps to the right and to theleft, then

mbn = ∣{w ∈ L(MBLin) ∶ ∣w∣ = n}∣ = L(n)(MBLin).

On the other hand, taking t = 2n + 2k + l in Equation (15), we have

∞∑i=0

mbiz

i =1

1 − z+∞∑n=1

∞∑k=0

∞∑

t=2n+2k2n

n

n + 2k(n + 2k

k)( t

t − 2n − 2k)zt,

then

mbs = 1 +

s

∑n=0

⌊ s−2n2⌋

∑k=0

2nn

n + 2k(n + 2k

k)( s

2n + 2k).

Page 26: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

162 R. De Castro, A. Ramırez, J.L. Ramırez

The Grand Motzkin paths are related to the central trinomial coeffi-cients. Let Tn denote the n-th central trinomial coefficient, defined as thecoefficient of xn in the expression of (1 + x + x2)n or it can also be definedas the coefficient of the form xnynzk in the expression of (x + y + z)n. Forexample if n = 2 then (x+y+z)2 = x2+y2+z2+2xy+2xz+2yz, hence T2 = 3.It is clear that the Grand Dyck paths are enumerated by the central binomialcoefficients, i.e., Tn = mb

n. For integers a, b, c we call the coefficient of xn

in the expression (a+bx+cx2)n the generalized central trinomial coefficient,T ∗n or it can also be defined as the coefficients of the form xnynzk in theexpression (a + bx + cx2)n. Taking f(z) = az = f ′(z), g(z) = cz = g′(z) andh(z) = bz = h′(z) in the counting automaton MBLin, we obtain the GF forthe numbers T ∗n .

∞∑i=0

T ∗i zi =

1√(1 − bz)2 − 4acz2 =1√

1 − 2bz + (b2 − 4ac)z2=

1

1 − bz −2acz2

1 − bz −acz2

1 − bz −acz2

.

The last GF coincides with Equation (3) of [24]. By using the BinomialTheorem twice and the identity (n

k)( n−k

n−2k) = (2kk )( n2k), we have

T ∗n =⌊n/2⌋

∑k=0(2kk)( n

2k)bn−2k(ac)k.

Since mbn = Tn, then

⌊s/2⌋

∑k=0(2kk)( s

2k) = 1 + s

∑n=0

⌊ s−2n2⌋

∑k=0

2nn

n + 2k(n + 2k

k)( s

2n + 2k).

Example 19. In this example we consider lattice paths according to a givenstatistic. A k-colored Motzkin path of length n can be coded as a wordw ∈ M∗, where M = {U,D,H1, . . . ,Hk}, with U = (1,1),D = (1,−1),Hi =(1,0) (i = 1, . . . , k). Each step Hi represents a color, ∣w∣U = ∣w∣D and∣w∣D ≤ ∣w∣U . We denote by Mk the set of all k-colored Motzkin words, and

Page 27: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 163

by Mxk the set of all k-colored Motzkin words without level steps on the x-

axis. Let r(w) be the number of D’s in a k-colored Motzkin word. With theCAM we can find the following GFs:

Fk(x, y) = ∑w∈Mk

x∣w∣yr(w), Gk(x, y) = ∑w∈Mx

k

x∣w∣yr(w).

In fact, if f(x, y) = xy, g(x, y) = x and h(x, y) = kx in Corollary 1, wehave

Fk(x, y) = ∑w∈Mk

x∣w∣yr(w) =1 − kx −

√(1 − kx)2 − 4x2y2x2y

(16)

=∞∑n=0

∞∑t=2n

Cn( t

2n)kt−2nxtyn. (17)

Moreover,

Fk(x, y) = ∞∑n=0

∞∑m=0

Cn(m + 2nm)kmx2n+myn,

and letting t = 2n +m, we obtain

Fk(x, y) = ∞∑n=0

∞∑t=2n

Cn( t

t − 2n)kt−2nxtyn.

Therefore,

[xsyr]Fk(x, y) = Cr( s

s − 2r)ks−2r

=1

1 + r(2rr)( s

s − 2r)ks−2r

=1

1 + rs!

r!r!(s − 2r)!ks−2r=

1

1 + r( s

r, r, s − 2r),

with r ≤ ⌊ s2⌋.

The GF Gk(x, y) is obtained from the automaton in Figure 16.

Page 28: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

164 R. De Castro, A. Ramırez, J.L. Ramırez

0 1 2 3

xy

x

xy

x

xy

x

kx kx kx

Figure 16: Counting automaton associated withMxk.

Following the same idea of Example 11, we have

Gk(x, y) = ∑w∈Mx

k

x∣w∣yr(w) =1

1 − x2yFk(x, y)=∞∑n=0

∞∑r=n

∞∑t=2r

n

2r − n(2r − n

r)(t − n − 1

t − 2r)kt−2rxtyr,

[xsyl]Gk(x, y) = l

∑n=0

n

2l − n(2l − n

l)(s − n − 1

s − 2l), l ≤ ⌊s

2⌋ .

The above results coincide with [27].

6 Other Counting Automata

In this section, we introduce a general operator on linear and bilinear count-ing automata. Then, we obtain a new family of automata with an arbitraryset of accepting states.

Definition 8. Let Mc = (M,E) be a counting automaton, where G =(V,A,n,F ). We define the operator FinH ∶ M∗c Ð→M

∗c , by FinH(Mc) =

M′c, whereM

′c = (G′,E) with G′ = (V,A,n,H).

In other words, this operator redefines the set of final states of a givencounting automaton.

Example 20. Consider the counting automaton FinN(MLin). It is dis-played in Figure 17.

0 1 2 3

f0

g0

f1

g1

f2

g2

h0 h1 h2 h3

FinN(MLin) ∶

Figure 17: Linear infinite counting automaton FinN(MLin).

Page 29: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 165

Theorem 5. The GF of FinN(MLin), see Figure 17, is

G(z) = E(z) + ∞∑j=1

⎛⎝j−1∏i=0(fi(z)Ei(z))Ej(z)⎞⎠ , (18)

where E(z) is the GF in Theorem 3, and Ei(z) is as in Definition 7.

Proof. The system of GFs equations of FinN(MLin−s), s ≥ 1, is⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩L0 = h0L0 + f0L1 + 1

Li = gi−1Li−1 + hiLi + fiLi+1 + 1, 1 ≤ i ≤ s − 1

Ls = gs−1Ls−1 + hsLs + 1.

It is equivalent to

⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩L0 = F0L1 +H0

Li = Gi−1Li−1 + FiLi+1 +Hi, 1 ≤ i ≤ s − 1

Ls = Gs−1Ls−1,

where Fi =fi(z)

1−hi(z),Gi =

gi(z)1−hi+1(z)

and Hi = 1

1−hi(z), for all integer i ≥ 0.

Substituting repeatedly into each equation Li, we have

Li =Gi−1

Trunc(Ei)Li−1 +∏s−2

j=i Fj(Hs +Hs−1)∏s−1j=i Trunc(Ej) +

s−2∑j=i

∏j−1k=i FkHj

∏j

l=iTrunc(El)where

Trunc(Ei) = 1 − FiGi

1 −Fi+1Gi+1⋮

1 − Fs−1Gs−1

,

for all 1 ⩽ i ⩽ s − 1. Hence

L0 =H0

Trunc(E0) +∏s−2

j=0 Fj(Hs +Hs−1)∏s−1j=0 Trunc(Ej) +

s−2∑j=1

∏j−1k=0FkHj

∏j

l=0Trunc(El)Since FinN(MLin) is convergent, then when s→∞ we have the GF

L0 = E(z) + ∞∑j=1

∏j−1k=0 FkHj

∏jl=0Trunc∞(El) = E(z) +

∞∑j=1

⎛⎝j−1∏i=0(fi(z)Ei(z))Ej(z)⎞⎠ ,

Page 30: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

166 R. De Castro, A. Ramırez, J.L. Ramırez

where

Trunc∞(Ei) = 1 − FiGi

1 −Fi+1Gi+1

1 −Fi+2Gi+2⋱

Proposition 3. The GF of the automaton Fin2N(MLin), with fi(z) =f(z), gi(z) = g(z) and hi(z) = h(z) for all integer i ⩾ 0, see Figure 18, is

D2N(z) = (1 − h(z))2 − f2(z) −√((1 − h(z))2 − f2(z))2 − 4f(z)g(z)(1 − h(z))22f(z)g(z)(1 − h(z)) .

(19)

0 1 2 3

f

g

f

g

f

g

h h h h

Fin2N(MLin) ∶

Figure 18: Linear Infinite Counting Automaton Fin2N(MLin).Proof. It is clear that the automaton Fin2N(MLin) is equivalent to the au-tomaton in Figure 19. Hence, we have the following system of GFs equations

0 1 2

f

g

f

gD2N(z)

h h

D2N(z)

Figure 19: Equivalent Automaton to Fin2N(MLin).⎧⎪⎪⎪⎪⎨⎪⎪⎪⎪⎩D2N(z) = hD2N(z) + fL1 + 1

L1 = gD2N(z) + hL1 + fL2

L2 = gD2N(z)L1 +D2N(z).Solving the system for D2N(z) we obtain the GF.

Page 31: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 167

Proposition 4. The GF of the automaton Fin2N+1(MLin), with fi(z) =f(z), gi(z) = g(z) and hi(z) = h(z) for all integer i ⩾ 0, see Figure 20, is

D2N+1(z) = f(z)D2N(z)1 − h(z) − f(z)g(z)D2N(z) , (20)

where D2N(z) is the GF in Proposition 3.

0 1 2 3

f

g

f

g

f

g

h h h h

Fin2N+1(MLin) ∶

Figure 20: Linear Infinite Counting Automaton Fin2N+1(MLin).Example 21. If f(z) = z = g(z) = h(z) in the GF D2N(z), we have the GFfor Motzkin paths ending at even heights.

D2N(z) = 1 − 2z −√1 − 4z + 8z3 − 4z4

2z2(1 − z)= 1 + z + 3z2 + 7z3 + 19z4 + 51z5 + 143z6 + 407z7 + 1183z8 +⋯.

It is the sequence A135052, however, this interpretation is not displayedin [30]. Something interesting is that the last GF is the same in Example17 with k = 1, i.e., the number of Motzkin paths ending in even heights isequal to the number of paths consisting of steps U = (1,1),D = (1,−1) andH(i) = (i,0) for i ⩾ 1. Hence

[zs]D2N(z) = f (1)s =s∑

n=0

s−2n∑m=0

Cn(m + 2nm)(s − 2n − 1

m − 1).

Moreover, we have the equivalency between counting automata shown in theFigure 21. It would be interesting to have a bijection proof of this.

If f(z) = z = g(z) = h(z) in the GF D2N+1(z), we have the GF forlattice path ending in odd heights.

D2N+1(z) = zD2N(z)1 − z − z2D2N(z)= z + 2z2 + 6z3 + 16z4 + 46z5 + 132z6 + 388z7 + 1152z8 +⋯.

Page 32: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

168 R. De Castro, A. Ramırez, J.L. Ramırez

0 1 2 3

z

z

z

z

z

z

z z z z

0 1 2 3

z

z

z

z

z

z

z1−z

z1−z

z1−z

z1−z

⋯ ⋯≅

Figure 21: Equivalence between counting automata, Example 21.

7 Conclusions and Future Research

In this paper, we have introduced a new counting methodology, the so calledCounting Automata Methodology (CAM), based on infinite weighted au-tomata, weighted graphs, continued fractions and generating functions. Byusing this methodology we have derived both existing and new combinato-rial identities.

We now suggest some topics for further research. (1) Find new applica-tions in other combinatorial constructions, for example in trees, polyominoesor numerical arrays such as Catalan triangle. (2) Generalize the CAM toobtain generating functions in two or more variables; Example 19 would bea particular case. (3) Following the ideas in Section 6, find new generaloperators on linear and bilinear automata.

Acknowledgements

The authors thank the anonymous referees for their careful reading of themanuscript and his fruitful comments and suggestions. The third authorwas partially supported by Universidad Sergio Arboleda.

References

[1] A. V. Aho, R. Sethi, and J. D. Ullman. Compilers: Principles, Tech-niques and Tools. Addison-Wesley, Reading, MA, 1986.

[2] E. Barcucci, E. Pergola, R. Pinzani, and S. Rinaldi. ECO method andhill-free generalized Motzkin paths. Seminaire Lotharingien de Combi-natoire, 46:1–14, 2001.

Page 33: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 169

[3] F. Bernhart. Catalan, Motzkin, and Riordan num-bers. Discrete Mathematics, 204(1-3):73–112, 1999.doi:10.1016/S0012-365X(99)00054-0

[4] J. Berstel, L. Boasson, O. Carton, and I. Fagnot. Stur-mian trees. Theory of Computing Systems, 46(3):443–478, 2010.doi:10.1007/s00224-009-9228-0

[5] V. Berthe and M. Rigo. Combinatorics, Automata and Number Theory.Encyclopedia of Mathematics and its Applications, Cambridge, 2010.

[6] M. Bousquet-Melou. Algebraic generating functions in enumera-tive combinatorics and context-free languages. In: V. Diekert andB. Durand, editors, STACS 2005, volume 3404 of Lecture Notesin Computer Science, pages 18–35, Springer, Heidelberg, 2005.doi:10.1007/978-3-540-31856-9_2

[7] P. Branden and T. Mansour. Finite automata and pattern avoidancein words. Journal of Combinatorial Theory, Series A, 110(1):127–145,2005. doi:10.1016/j.jcta.2004.10.007

[8] W. Chen. Context-free grammars, differential operators and formalpower series. Theoretical Computer Sciences, 117(1-2):113–129, 1993.doi:10.1016/0304-3975(93)90307-F

[9] W. Chen, S. Yan, and L. Yang. Identities from weighted Motzkinpaths. Advances in Applied Mathematics, 41(3):329–334, 2008.doi:10.1016/j.aam.2004.11.007

[10] M. Delest. Algebraic languages: a bridge between combinatorics andcomputer science. DIMACS Series in Discrete Mathematics and Theo-retical Computer Science, 24:71–88, 1996.

[11] E. Deutsch, E. Munarini, and S. Rinaldi. Skew Dyck paths. Jour-nal of Statistical Planning and Inference, 140(8):2191–2203, 2010.doi:10.1016/j.jspi.2010.01.015

[12] E. Deutsch and L. Shapiro. A bijection between ordered trees and2-Motzkin paths and its many consequences. Discrete Mathematics,256(3):655–670, 2002. doi:10.1016/S0012-365X(02)00341-2

Page 34: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

170 R. De Castro, A. Ramırez, J.L. Ramırez

[13] M. Droste, W. Kuich, and H. Vogler. Handbook of Weighted Automata,first edition, Springer, Monographs in Theoretical Computer Science,2009.

[14] P. Flajolet. Combinatorial aspects of continued frac-tions. Discrete Mathematics, 32(2):125–161, 1980.doi:10.1016/0012-365X(80)90050-3

[15] P. Flajolet and R. Sedgewick. Analytic Combinatorics, Cambridge,2009.

[16] R. Graham, M. Grotschel, and L. Lovasz. Handbook of Combinatorics,volume 2, MIT Press, Cambridge, 1995.

[17] R. Graham, D. Knuth, and O. Patashnik. Concrete Mathematics, sec-ond ediction, Addison-Wesley, 1994.

[18] T. Mansour. Combinatorics of Set Partitions. Discrete Mathematicsand its Applications, CRC Press, 2012.

[19] J. E. Hopcroft, R. Motwani, and J. D. Ullman. Introduction to Au-tomata Theory, Languages, and Computation. Addison-Wesley, Read-ing, MA, 2001.

[20] A. Lascoux. Symmetric Functions and Combinatorial Operators onPolynomials. CBMS Regional Conference Series in Mathematics, Amer-ican Mathematical Society, 2003.

[21] S. Heubach and T. Mansour. Combinatorics of Compositions andWords. Discrete Mathematics and its Applications, CRC Press, 2010.

[22] T. Mansour and A. O. Munagi. Enumeration of gap-bounded set par-titions. Journal of Automata, Languages and Combinatorics, 14(3-4):237–245, 2009.

[23] T. Mansour and A. Vainshtein. Restricted permutations and Cheby-shev polynomials. Seminaire Lotharingien de Combinatoire, 47 ArticleB47c:(2002).

[24] T. Noe. On the Divisibility of Generalized Central Trinomial Coeffi-cients. Journal of Integer Sequences, 9(2):1–12, 2006.

Page 35: Applications in Enumerative Combinatorics of Infinite ... · Applications in Enumerative Combinatorics of Infinite Weighted Automata and Graphs 141 language then the GF corresponding

Applications in Enumerative Combinatorics ofInfinite Weighted Automata and Graphs 171

[25] J. M. Rutten. Coinductive counting with weighted automata. Journalof Automata, Languages and Combinatorics, 8(2):319–352, 2003.

[26] J. Sakarovitch. Elements of Automata Theory, Cambridge, 2009.

[27] A. Sapounakis and P. Tsikouras. On k-colored Motzkin words. Journalof Integer Sequences, 7(2):1–13, 2004.

[28] J. Shallit. A Second Course in Formal Languages and Automata Theory.Cambridge, 2009.

[29] L. Shapiro and C. Wang. A Bijection Between 3-Motzkin Paths andSchroder Paths With No Peak at Odd Height. Journal of Integer Se-quences, 12(3):1–9, 2009.

[30] N. J. A. Sloane. The On-Line Encyclopedia of Integer Sequences.https://oeis.org/.

[31] K. Uchimura. Properties of structure generating functions of automataand their applications for linear systems. Theoretical Computer Science,18(2):207–220, 1982. doi:10.1016/0304-3975(82)90022-6

[32] K. Uchimura. Truncations of infinite matrices and algebraic serieswith some CF grammars. Theoretical Computer Science, 31(3):227–261,1984. doi:10.1016/0304-3975(84)90035-5

[33] W. Woan. Animals and 2-Motzkin Paths. Journal of Integer Sequences,8(5):1–12, 2005.

c Scientific Annals of Computer Science 2014