First Post

This was my first ever on-line posting, to sci.math in 1988. The world wide web wasn't invented until 1989 so we didn't have links---I added them in 2004 when I posted this to my blog.

Kristian Damm Jensen wrote:

Consider a string of matching parentheses, i.e. a string of parentheses where each prefix contains more left-parentheses than right-parentheses.

Now, given n left- and right parentheses, in how many ways can you order them and still get a string of matching parentheses?

"The Invisible Man" replied:

Here's as far as I got. Possibly far enough, perhaps too far. It looks like someone better at this sort of thing can get a result in closed form.

Let f(n) be the number of valid paren strings of n pairs of parens. (and define f(0) to be 1). We can get a recurrence relationship as follows:

Any string of n paren pairs can be derived uniquely from 2 smaller paren pair strings by considering it to be 1 leading string (possibly null) contained in parens followed by a trailing string: the rest. For example, (())(()())() is a combination of (()) and (()())(). We can thus say that f(n) = sum j=0 to n-1 of f(j)*f(n-1-j)

If this isn't far enough yet, consider g(x) = sum j=0 to infinity of f(j)*(x^j) This is the generating function for f() (see Knuth Vol 1) Using the above recurrence, note that

g^2 = (g - 1)/x

which solved for g gives:

g = (1 - sqrt(1-4x))/(2x)

This can also (i.e. if it does any good) be written as:

g = 2/(1+sqrt(1-4*x))

What we want now is an expression for the nth coefficient for the expansion of g as a power series in x. So, what's the next step?

OK, we want the series for sqrt(1-4x). The binomial thereom gives

sqrt(1-4x)= (1-4x)^(1/2)
          = sum i=0 to infty of C(1/2,i)(-4)^ix^i

where C(n,r)=n!/(r!(n-r)!) is the binomial coefficient. If you're worried about calculating (1/2)! just trust me.

C(n,r)= product i from 1 to r of (n-(i-1))/i
C(1/2,i)(-4)^i = (1/2)(1/2-1)(1/2-2)....(1/2-(i-1))
                 -----------------------------------(-4)^i
                    1   2      3    ....  i
              (-1)(1)(3)...(2i-3)
            = -------------------2^i
                      i!

            = (-1)(1)(3)...(2i-3)(2)(4)(6)...(2i)
              -----------------------------------
                      i! i!
            = -C(2i,i)/(2i-1)

So sqrt(1-4x)= sum i=0 to infty of (-C(2i,i)/(2i-1))x^i.
= -1 - sum i=1 to infty of (C(2i,i)/(2i-1))x^i
let j = i-1
= -1 - sum j=0 to infty of (C(2j+2,j+1)/(2j+1))x^(j+1)
hence g(x) = (1-sqrt(1-4x))/2x
= (sum j=0 to infty of (C(2j+2,j+1)/(2j+1))x^(j+1))/2x
= sum j=0 to infty of (C(2j+2,j+1)/(4j+2))x^j
So f(n) = C(2n+2,n+1)/(4n+2) = C(2n,n)(2n+2)(2n+1) = C(2n,n)/(n+1).
-------------------
(n+1)(n+1)(4n+2)

This is called the Catalan number. It is also the number of different ways of triangulating a convex polygon with n+2 sides, the number of different binary trees with n nodes and the number of different ways of folding a strip of n stamps.

Tags

More like this

Todays bit of programming insanity is a bit of a novelty: it's an object-oriented programming language called Glass, with an interpreter available here. So far in all of my Friday Pathological Programming columns, I haven't written about a single object-oriented language. But Glass is something…
Consider this not-so-difficult sum: It consists of just a string of fractions up to whichever N you happen to choose. Add them up, and you certainly and unambiguously have a number. If you chose to stop at N = 10, you'd find that f(10) = 1627/2520, which is about 0.645635. If you chose to stop…
Last week we did the sinc function. Let's do it again! The function, to refresh our collective memory, is this: Now I was thinking about jumping right into some contour integration, but on actually doing it again I see that it's a little hardcore for one post so eventually when we do it we'll…
It is time to continue our quest to prove that the sum of the reciprocals of the primes diverges. We have one more ingredient to put into place. I am referring to the notion of a Taylor series. The idea is this: Some functions, like those from trigonometry, are difficult to evaluate precisely.…