226 Combinatorics of Compositions and Words
We now give the third proof for Theorem 6.25, actually using τ = 123
instead of τ = 132. For the scanning-element algorithm, either pattern is
equally easy. Note that we derive the generating function of the 123-avoiding
words according to their first letter, that is, we are obtaining a refined result
as a by-product of the proof.
Proof (of Theorem 6.25 using scanning-element algorithm) Define
P (n, k)=AW
[k]
n
(123)
and let w = w
1
w
2
···w
n
∈AW
[k]
n
(123). If w starts with k or k − 1, then w
1
cannot be part of any pattern 123, so the set P (n −1,k) is a reduction of the
sets P (n, k; k)andP (n, k; k −1). If w
1
= j ≤ k −2thenj ∈ I(n, k). Now we
look at the first two letters of w.Ifw
1
w
2
= ij with i ≥ j then w avoids 123 if
and only if jw
3
···w
n
∈AW
[k]
n−1
(123), so the set P(n − 1,k; j) is a reduction
of the set P (n, k; i, j) for all i ≥ j.Ifi<jthen the only letters that can
follow are from the alphabet [j], so we can map ijw
3
···w
n
∈AW
[k]
n
(123) to
iw
3
···w
n
∈AW
[j]
n−1
(123). Thus the set P (n − 1,j; i) is a reduction of the
set P (n, k; i, j) for all i<j. Putting these all together, (6.19) leads to the
following equations:
p(n, k; k)=p(n, k; k −1) = p(n − 1,k) (6.24)
p(n, k; i)=
i
j=1
p(n, k; i, j)+
k
j=i+1
p(n, k; i, j)
=
i
j=1
p(n − 1,k; j)+
k
j=i+1
p(n − 1,j; i), (6.25)
for all 1 ≤ i ≤ k − 2. Multiplying (6.25) by v
i−1
and summing over all
1 ≤ i ≤ k −1, we obtain a recurrence in terms of p(n, k; v):
p(n, k; v) − p(n, k; k)v
k−1
=
k−1
j=1
v
j−1
− v
k−1
1 − v
p(n − 1,k; j)+
k
j=2
(p(n − 1,j; v) −p(n − 1,j; j)v
j−1
).
Therefore
p(n, k; v) − p(n − 1,k;1)v
k−1
=
k−1
j=1
v
j−1
− v
k−1
1 − v
p(n − 1,k; j)+
k
j=2
(p(n − 1,j; v) −p(n − 1,j;1)v
j−1
)
=
1
1 − v
p(n − 1,k; v) − v
k−1
p(n − 1,k;1)
+
k
j=2
p(n − 1,j; v) −p(n − 2,j;1)v
j−1
,
© 2010 by Taylor and Francis Group, LLC