Prerequisite – Combinatorics Basics, Generalized PnC Set 1, Set 2
Definition : Generating functions are used to represent sequences efficiently by coding the terms of a sequence as coefficients of powers of a variable (say)
in a formal power series.
Now with the formal definition done, we can take a minute to discuss why should we learn this concept.
This concept can be applied to solve many problems in mathematics. There is a huge chunk of mathematics dealing with just generating functions.
- It can be used to solve various kinds of Counting problems easily.
- It can be used to solve recurrence relations by translating the relation in terms of sequence to a problem about functions.
- It can be used to prove combinatorial identities.
In simple words generating functions can be used to translate problems about sequences to problems about functions which are comparatively easy to solve using maneuvers.
Some basic prerequisites…
Before we start let’s go through some basic Combinatorics formula.
![Rendered by QuickLaTeX.com %\documentclass{article} %\usepackage{amsmath} \newcommand*{\Perm}[2]{{}^{#1}\!P_{#2}}% \newcommand*{\Comb}[2]{{}^{#1}C_{#2}}% \begin{document} \Huge $\Perm{n}{k}=\frac{n!}{(n-k)!}$ $\binom nk=\Comb{n}{k}=\frac{n!}{k!(n-k)!}$ \end{document}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-43b59a62e364946eaed86ef6ca7406fb_l3.png)
A generating function is a “formal” power series in the sense that we usually regard x as a placeholder rather than a number. Only in rare cases will we actually evaluate a generating function by letting x take a real number value, so we generally ignore the issue of convergence.
of real numbers is the infinite series:

![Rendered by QuickLaTeX.com [g_{0},g_{1},g_{2},g_{3}...]\leftrightarrow g_{0} + g_{1}x+g_{2}x^{2}+g_{3}x^{3}....](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-b83583b415883cdd58cec829f19435d7_l3.png)
Note: we’ll indicate the correspondence between a sequence and its generating function with a double-sided arrow.
Some Important sequences and their results…

If you want to know more about the derivation of the given sequences you may refer here
![Rendered by QuickLaTeX.com %\documentclass{article} %\usepackage{amsmath} \begin{document} \Large \(\frac{1} {(1-x)}\) = 1 + x + x^2 + x^3.... \longleftrightarrow [1, 1, 1, 1...\normalsize\infty] \end{document}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-7ebb02892e72a87c2902d359bcbf90ab_l3.png)
![Rendered by QuickLaTeX.com %\documentclass{article} %\usepackage{amsmath} \begin{document} \Large \(\frac{1} {(1+x)}\)=1-x+x^2-x^3.... \longleftrightarrow [1, -1, 1, -1....\normalsize\infty] \end{document}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-3390167959af857e4662266d6d8389fd_l3.png)
![Rendered by QuickLaTeX.com %\documentclass{article} %\usepackage{amsmath} \begin{document} \Large \(\frac{1} {(1-ax)}\) = 1 + ax + {a^2}x^2 + {a^3}x^3.... \longleftrightarrow [1, a, a^2, a^3....\normalsize\infty] \end{document}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-6cb9f9fdc1e46df9c1ab153ecfe54c38_l3.png)
![Rendered by QuickLaTeX.com %\documentclass{article} %\usepackage{amsmath} \begin{document} \Large %\(\frac{1} {(1-ax)}\) = 1 - ax + {a^2}x^2 - {a^3}x^3.... \longleftrightarrow [1, a, a^2, a^...\infty] \(\frac{1} {(1-x^{2})}\) = 1 + x^2 + x^4.... \longleftrightarrow [1, 0, 1, 0...\normalsize\infty] \end{document}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-5ca35f531305cf1699d20bd861c1d6d4_l3.png)
Note that all the above series is infinite. There is one peculiar result of finite series which will be very handy so it’s recommended to remember these results to solve problems quickly.
An important result:
![Rendered by QuickLaTeX.com %\documentclass{article} %\usepackage{amsmath} \begin{document} \LARGE %\(\frac{1} {(1-ax)}\) = 1 - ax + {a^2}x^2 - {a^3}x^3.... \longleftrightarrow [1, a, a^2, a^.....] 1+x+x^2+x^3+....+x^n = \(\frac{1 + x^{n+1}} {(1-x)}\) \end{document}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-dad29ed170e0927705724ae18cefebdb_l3.png)
We can use these operations to get new sequences from known sequences, and new generating functions from known generating functions.
Scaling:
Multiplying a generating function by a constant scales every term in the associated sequence by the same constant.
![Rendered by QuickLaTeX.com \textup{Scaling Rule} \newline[f_{0},f_{1},f_{2},f_{3}...]\leftrightarrow F(x) \newline [cf_{0},cf_{1},cf_{2},cf_{3}...]\leftrightarrow cF(x) \\](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-e68056a936f5cedb41cc717b97a7dd73_l3.png)
![Rendered by QuickLaTeX.com \textup{Example:} \newline [1,0,1,0,1,0...]\hspace{0.25cm}\leftrightarrow \hspace{0.25cm}1+x^{2}+x^{4}+x^{6}....\hspace{0.25cm}=\frac{1}{1-x^{2}} \\ \\ \textup{Multiplying the generating function by 2 gives}\\ \\ \frac{2}{1-x^{2}}=\hspace{0.15cm}2+2x^{2}+2x^{4}+2x^{6}..](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-688d8939cd5f0fff5c800ed632484136_l3.png)
Addition:
Adding generating functions corresponds to adding the two sequences term by term.
![Rendered by QuickLaTeX.com \newline[f_{0},f_{1},f_{2},f_{3},f_{4}..]\leftrightarrow F(x) \newline [g_{0},g_{1},g_{2},g_{3},g_{4}..]\leftrightarrow G(x)\newline \textup{Then}\newline [f_{0}+g_{0},f_{1}+g_{1},f_{2}+g_{2},f_{3}+g_{3},...]\leftrightarrow F(x)+G(x)](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-786a4cb6e82fbdef65e5110c4842d334_l3.png)
![Rendered by QuickLaTeX.com \textup{Example:} \newline [1,1,1,1,1,1,1,1....]\leftrightarrow \frac{1}{1-x} \hspace{1cm} \newline [1,-1,1,-1,1,-1....]\leftrightarrow \frac{1}{1+x} \newline \textup{Adding both equation we will get}\newline [2,0,2,0,2,0...]\leftrightarrow \frac{1}{1-x}+\frac{1}{1+x} \newline =\frac{2}{1-x^{2}}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-8d6eef5926f3482adefae9ad65f951a1_l3.png)
Right Shifting:
![Rendered by QuickLaTeX.com \textup{Right Shifting Rule} \newline \textup{if}\hspace{0.25cm} [f_{0},f_{1},f_{2},f_{3}...]\leftrightarrow F(x) \newline \textup{then}\hspace{0.25cm} [\overbrace{\overset{\textup{k times}}{0,0,0,0,0,0} },f_{0},f_{1},f_{1}...]\leftrightarrow x^{k}F(x)](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-2aab9d54a4e0d7a5a235617d5c5676d1_l3.png)
![Rendered by QuickLaTeX.com \newline \textup{Example:} \newline \newline [\overbrace{\overset{\textup{k times}}{0,0,0,0,0,0} },1,1,1,1,1,1,1...]\leftrightarrow x^{k}+x^{k+1}+x^{k+2}+x^{k+3}..... \newline \hspace{20cm} =x^{k}(1+x+x^{2}+x^{3}...) \newline \hspace{20cm}=\frac{x^{k}}{x-1}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-31cfc68670fd3632168a51f78c6d6341_l3.png)
Differentiation:
In general, differentiating a generating function has two effects on the corresponding sequence: each term is multiplied by its index and the entire sequence is shifted left one place.
![Rendered by QuickLaTeX.com \textup{Derivative Rule:} \newline [f_{0},f_{1},f_{2},f_{3}...] \leftrightarrow F(x) \newline [f_{1},2f_{2},3f_{3},4f_{4}...] \leftrightarrow F{}'(x)](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-3ce073a02dd40773f0491394e34efe4a_l3.png)
![Rendered by QuickLaTeX.com \newline \textup{Example:} \newline 1+x+x^{2}+x^{3}+x^{4}+x^{5}... = \frac{1}{1-x} \newline \frac{\mathrm{d} }{\mathrm{d} x}(1+x+x^{2}+x^{3}+x^{4}...)=\frac{\mathrm{d} }{\mathrm{d} x}(\frac{1}{1-x}) \newline 1+2x+3x^{2}+4x^{3}....=\frac{1}{(1-x)^{^{2}}} \newline [1,2,3,4...]=\frac{1}{(1-x)^{2}}](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-47ae215cf92301d313fa1bc11833cab0_l3.png)
Example:
What sequence is represented by the following series :

SolutionBy now you must have got this, the coefficient of a0 = 1, a1 = 0, a2 = 4, a3 = 0, a4 = 1, a5 = 1/999, a6 = 100.
So sequence is:
![Rendered by QuickLaTeX.com \Large $ [1, 0, 4, 0, 1, \(\frac{1} {999}\), 100, ....] $](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-4bc5a78aec0a7c128be28bd683626361_l3.png)
From the perspective of GATE CS examination, problems from this topic are asked almost every year and the problems can easily be solved just by knowing the basics.
So, with this done, from the next post, we may start with some interesting Counting Problems and solve them with this approach. We will also see some previous GATE problems.
Next, we’ll see some problems based on counting and some problems based on coefficient extraction.
REFERENCES:
Kenneth H Rosen: Discrete Mathematics and Its Applications 6th [Chapter 2.4, 6.4]