Generating Function

Generating Function

Wiki: Generating function utilizes a power series to contain information about a certain sequence. Mathematical manupulation on the generating function can provide information of the sequence.

Refer to excellent video on Youtube.

Video1 Video2

Let's first consider about the below generating function which stores the information of the power series \(\{a_1,a_2,\cdots,a_n\}\):

\[G(x)=\sum_{k=0}^na_kx^k=a_0+a_1x+\cdots+a_nx^k \]

We can retrieve the value of \(a_m\) by performing:

\[G^{(1)}(x)=\sum_{k=1}^nka_kx^{k-1}\\ G^{(2)}(x)=\sum_{k=2}^nk(k-1)a_kx^{k-2}\\ \vdots\\ G^{(m)}(x)=\sum_{k=m}^nk(k-1)\cdots(k-(m-1))a_kx^{k-m}\\ \vdots\\ \therefore G^{(m)}(0)=m!a_m+(m+1)\cdots2a_{m+1}x|_{x=0}+ \cdots=m!a_m\\ a_m=\frac{1}{m!}G^{(m)}(0) \]

We can obtain all the possible combination of sequence for a given power by multiplying two generating function:

\[G^2(x)= (a_0+a_1x+a_2x^2+\cdots)(a_0+a_1x+a_2x^2+\cdots)\\ = a_0^2+(a_0a_1+a_1a_0)x+(a_0a_2+a_1a_1+a_2a_0)x^2+\cdots \]

We can see that the sumation of the subscript is equilavent to the power of x.

Take the dice for example, we store the probability \(p_i\) of getting \(i\) in the generating function:

\[G(x)=p_1x+p_2x^2+p_3x^3+p_4x^4+p_5x^5+p_6x^6 \]

And so the multiplication of two generating function leads to:

\[G^2(x)=(p_1x+p_2x^2+\cdots)(p_1x+p_2x^2+\cdots)\\ =p_1p_1x^2+(p_1p_2+p_2p_1)x^3+\cdots \]

And we are lucky to find that the coefficient of this function gives us the all the possible cases at a given summation of two indices.

Another example to search all the possible combination of candies:

image-20220321220417811

To solve this, just multiply the above polynomials and we can deduce the combination from the coefficients.

For more intepretation, refer to video1 and its sequel. And also refer to wiki for example apart from the generating function.

More example:

The normal generating function stores the sequence \(\{1,1,1,\cdots,1\}\):

\[\frac{1}{1-x}=\sum_{n=0}^{\infty}x^n=1+x+x^2+\cdots+x^n \]

The more general generating function stores the sequence \(\{1,a,a^2,\cdots\}\):

\[\frac{1}{1-ax}=\sum_{n=0}^{\infty}a^nx^n=1+ax+a^2x^2+\cdots+a^nx^n \]

When \(a=1\), the above becomes the following which stores the sequence \(\{1,-1,1,-1,\cdots\}\)

\[\frac{1}{1+x}=\sum_{n=0}^{\infty}(-1)^nx^n=1-x+x^2-x^3+\cdots \]

The derivative of normal generating function \(\frac{1}{1-x}\) stores the sequence of \(\{1,2,3,4,\cdots\}\):

\[\frac{1}{(1-x)^2}=\frac{d}{dx}(\frac{1}{1-x})=\frac{d}{dx}(1+x+x^2+x^3+\cdots)\\ =1+2x+3x^2+4x^3+\cdots \]

The mulplication of \(x^3\) with the normal generating function stores the sequence \(\{0,0,0,1,1,\cdots,1\}\):

\[\frac{x^3}{1-x}=x^3(1+x+x^2+\cdots)=x^3+x^4+x^5+\cdots \]

posted @ 2022-03-21 22:58  miccoui  阅读(45)  评论(0编辑  收藏  举报