第5篇
\section{Multivariate Generating Functions and other Tidbits}%5
\markboth{Articles}{Multivariate Generating Functions and other Tidbits}
\vspace{4.2cm}
\subsection{Introduction}
This article is devoted to some of the methods and applications of generating
functions as used in Olympiad problem solving.
Their basic properties are well known to many problem solvers;
this article is intended to explore some more advanced applications and ideas,
the most prominent of which is the use
of multivariate generating functions.
\subsection{What is a Generating Function?}
In the words of Herbert Wilf, "A generating function is a clothesline on which
we hang up a sequence of numbers for display."\footnote{This is the opening line
in Herbert Wilf's book {\it Generating Functionology}, a marvelous
and well-written textbook.}
This placeholder or `clothesline' role is what makes them so valuable.
Generating functions allow us to
exploit the algebra of polynomials to model many otherwise unrelated situations.
Our first example shows how generating functions can easily store
important information and illustrates the importance of exploiting properties
of polynomials.
{\bf Problem 1.} (Zeitz).
{\it A standard die is labeled (one integer per face).
When you roll two standard dice, it is easy to compute the probability of
the various sums.
For example, the probability of rolling two dice and getting
a sum of is just , while the probability of getting a sum of is .
Is it possible to construct a pair of "nonstandard" [six-sided] dice (possibly
different from one another) with positive integer labels that nevertheless are
indistinguishable from a pair of standard dice if the sum of the dice is all that
matters?
For example, one of these nonstandard dice may have the label on
one of its faces, and two 's.
But the probability of rolling the two and getting
a sum of is still , and the probability of getting a sum of is still .
}
{\bf Solution.}
We can encode the contents of a standard die as a generating
function by letting the coefficient of be the number of faces that contain
the number .
Thus, we define
Here is why this encoding is useful: consider the product
To get a clear idea of what the expanded polynomial looks like, consider for
example the coefficient of .
The possible ways to get an term in the
product are
, , , and ,
so the coefficient of is 5.
Looking more closely, each of these terms in the expansion
represents one of the 5 ways to roll a sum of 6 with two dice:
, , , , and .
In essence, the polynomial multiplication does all
dice combinations for us and stores the results in the coefficients.
So by this reasoning,
where the coefficient of represents the number of ways to roll a sum of with
two dice.
We apply the same method to the nonstandard dice.
Let and
be the numbers on the two dice, and define the generating functions
to describe these dice.
By the same reasoning as above, the product
represents the generating function for the possible outcomes of the sum of the numbers on
the two dice.
Since these are supposed to be the same outcomes as those of
two standard dice, we have
.
So we factor:
It now remains to distribute these factors between and .
Let
and
where and
are nonnegative integers with
for .
Since ,
each polynomial is divisible by , i.e.,
.
Also, it is clear from their original definitions that
,
which means
,
i.e.,
.
If we also let then
,
which means both dice are standard.
The only other option is to let and (or the other way around):
Now we can easily read the contents of the dice directly from the generating
functions: 1, 3, 4, 5, 6, 8 and 1, 2, 2, 3, 3, 4.
Since this factorization was forced,
it also follows that this is the only pair of nonstandard dice that works.
\subsection{An Essential Tool}
The use of polynomials allows access to all the information stored in its
coeffcients through the manipulation of a single object.
There are many ways to utilize this relationship between the polynomial and
its coefficients, and the next problem gives another example of this.
{\bf Problem 2.}
(Romanian MO '03).
{\it How many -digit numbers, whose digits are in the set , are divisible by ?
}
{\bf Solution.}
Since a number is divisible by 3 if and only if the sum of its digits is
divisible by 3, we'll find how many of those numbers have a digital sum divisible
by 3.
So let's try to make a generating function
where is the number of -digit numbers with digits in and
a digital sum of .
Then the answer we want is
.
Each digit will add either 2, 3, 7, or 9 to the total digit sum, and so the
generating function for each digit is
.
Thus, the generating function we're looking for is simply
But how do we extract every third coefficient of the polynomial?
The ingenious answer comes from complex numbers.
Define
as one of the cube roots of unity, i.e., one of the solutions to
.
This number has the simple property that
.
This property allows us to single out every third coefficient of quite easily.
We have
and adding these equations gives
With this we can easily calculate the answer to the problem
The method used here is certainly not specific to 3, and it leads to an extremely
important tool.
{\bf Theorem 1.}
(Root of Unity Filter).
{\it Define
for a positive integer .
For any polynomial
(where is taken to be zero when
), the sum
is given by
}
{\bf Proof.}
The proof is based on a property of the sum
.
If , then and so
.
Otherwise, and
.
So
and the proof is complete after division by .
\subsection{Multiple Variables}
Now that we're familiar with (or reminded of) some of the basics, we can get
to the main focus of this article: multivariable generating functions.
As we've mentioned before, the importance of generating functions is their
spectacular ability to store large amounts of information.
If you come across
a problem that requires a lot of information storage and that poor little
can't do it all, give it a buddy!
Add other variables to help organize the information.
We have chosen two difficult examples to illustrate the enormous
power of these multivariate generating functions.
{\bf Problem 3.}
(IMO '95/6).
{\it Let be an odd prime number.
Find the number of subsets of the set such that
(i) has exactly elements, and
(ii) the sum of all elements in is divisible by .
}
{\bf Solution.}
Of course, we'll use a generating function to store information
about the subsets.
But what information might we want to keep track of?
The problem talks about the {\it size} and the {\it sum} of the subsets, so we probably want
to have information on both of these.
To this end, we'll design a generating function
such that is the number of -element subsets of with a sum
of .
The answer to the problem is therefore
The construction of the generating function is very straightforward.
We ask ourselves, how could the number affect a subset?
If it is not in the subset,
then it affects neither the sum nor the size.
But if it is in the subset, then it
increases the sum by m and the size by 1.
So for each we should have the term
in .
Therefore,
is the generating function we're looking for.
To get to our answer , we need to extract coefficients from two types of terms of
: and powers of .
Since we already have a tool to do the latter (the root of unity filter), we
choose to do this step first.
Define .
The filter tells us that
so we need to calculate
for .
When , .
For ,
since , the numbers
form a complete list of residues modulo (verify!), so
Putting these values back into equation (1) produces
Now that we have successfully extracted the coefficients of the powers of ,
our second task of finding the coefficient of is easy:
this coefficient (and the answer to our problem) is
Our discussion of this next problem is written to offer motivation and
insight into the solution, and as a result it is rather lengthy.
For this reason we have broken it into two parts in order to highlight the two main ideas used
in the solution.
Let's get started.
{\bf Problem 4.}
(USAMO '86/7).
{\it By a partition of an integer , we mean
here a representation of as a sum of one or more positive integers where
the summands must be put in nondecreasing order.
(E.g., if , then the partitions are
, , , and ).
For any partition , define to be the number of 1's which appear in ,
and define to be the number of distinct integers which appear in .
(E.g., if and is the partition
, then and ).
Prove that, for any fixed , the sum of over all partitions of is
equal to the sum of over all partitions of .
}
{\bf Solution.}
The idea is to create two different generating functions
where
is the sum of over all partitions of and
is (you guessed it!) the sum of over all partitions of .
If we succeed in finding and ,
we can hopefully show that ,
which would show that for all , which would solve the problem.
(The wonderful tactic of wishful thinking is hard at work.)
So, let's create .
We need information on two things: the sum of the partitions and the number
of 1's in the partitions.
So we make a generating function that gives us both
pieces of that information:
We've used the variable to keep track of the sum of each partition and the
variable to denote the number of 1's in that partition:
the coefficient is,
by design, the number of partitions of that have ones.
We may rewrite the geometric series to obtain the relatively simple
(For those readers who are writhing in pain because of the informal treatment
of infinite products and sums, a peek at section {\it A More Rigorous Treatment}
should calm you down.)
Okay, so how do we pull out of that generating function?
The coefficient is the total number of 1's in all partitions of .
This is equal to the number of partitions of with a single 1, plus twice the
number of partitions of with two 1's, plus 3 times the number of partitions
of with three 1's, etc.
Hence,
Multiplying this by and summing over gives
Our goal now is to mold into this sum.
The key to transforming into the generating function above is differentiation.
If we take the partial derivative of with respect to , we get
Then, setting produces the sum in equation (2)
Now all that's left to do is to calculate.
We find that
and by putting in we get
Good!
We're half done.
Now we'll try to create .
We will proceed in a similar manner.
We first create a generating function to keep track of the sum
of the partitions (with the variable ) and the number of distinct parts in the
partitions (with ):
The coefficient is the number of partitions of with distinct parts.
Luckily, and have a familiar relationship.
The number of distinct parts in
all partitions of is the number of partitions of with only one distinct part,
plus twice the number of partitions of with two distinct parts, etc., which
shows that
So once again we have
,
and by the same reasoning as above,
All that we need to do now is differentiate
with respect to and plug in !
Well, not quite.
Unfortunately, it isn't so easy to differentiate an infinite product of functions.
The closest we can get is differentiating finite products.
For example, if we define a function
then by repeated use of the product rule we obtain
This easily generalizes to the following.
{\bf Theorem 2.}
(Generalized Product Rule).
The derivative of the function
where each is a differentiable function of , is given by
The proof is an easy induction on , which we have omitted.
For the moment, to make sure we're on the right track, let's pretend that the generalized product
rule holds for an infinite product of functions.
Define
,
so that
We have
and
and so by the dubious extension of the product rule,
which is exactly what we want!
Now that we're confident of our method, we have to figure out a way to make it rigorous.
\subsection{More Rigorous Treatment}
It is natural to feel somewhat skeptical about the validity of some of the
manipulations we have been doing.
And that skepticism is for good reason!
Consider the generating function for the Fibonacci numbers
(Can you prove this?)
We can substitute into this identity to prove
which was a problem from the Round Four Individual Mandelbrot contest in
February 2002.
But on the same note, we can substitute into the same
identity to 'prove' that the sum of all the Fibonacci numbers is
which is absurd!
What went wrong?
What makes this different from the Mandelbrot question?
It seems that we need a more rigorous treatment of generating functions
and a clear idea of what is and isn't legal.
So here goes.
We begin by discussing the {\it formal} theory of generating functions.
This theory deals with a generating function as a purely algebraic object, whose
sole purpose is one of storage.
For a sequence , called the sequence of coefficients,
we define its {\it Ordinary Power Series Generating Function} by
Ordinary generating functions are algebraic objects that form a ring whose
laws of addition and multiplication are defined naturally:
(This multiplication rule is what makes ordinary generating functions applicable
to so many combinatorial situations.)
Other operations can also be defined in an intuitive way.
For example, differentiation is defined by
But keep in mind that a formal generating function is nothing more than an
algebraic object, and is nothing more than a placeholder.
It is {\it not} a variable, and the generating function
is not a function of .
Therefore functional operations such as evaluating
make absolutely no sense in the realm of formal generating functions.
However, it is often desirable to use generating functions for more than
their place-holding capabilities.
In that case, we turn to {\it analytic} generating functions.
Basically, if a generating function actually converges to an
analytic function on some nontrivial domain, then we may also treat
as an analytic function of when is in that domain.
The power series
still has all the properties of formal generating functions, but it has the added
bonus of being an analytic function, which makes it very useful.
For example, with the Mandelbrot question, it is easy to determine that
the radius of convergence of the power series
is (
is golden ratio), and thus when is inside that bound, saying that
is a valid assertion.
Since meets this condition, our calculation of
makes sense.
But lies outside this domain, and so the expression
is meaningless.
In the solution to Problem 3, we substituted values for without checking
that it was legal.
But the function in that problem is merely a polynomial
in and , and polynomials are certainly analytic functions.
So we're okay there.
With Problem 4 we were already having difficulties when we tried to differentiate
the infinite product of functions.
Well, now we have even more troubles: we need to be sure that
and are analytic functions of
and before we can start using them as such.
And with the functions we have, it's very difficult to verify this,
if it is even true!
So we need a way to get around the challenges that infinity poses.
\subsection{Finitization}
The easiest way to sidestep the difficulties of infinity is to eliminate infinity
from the problem and instead make everything finite.
We illustrate this idea of {\it finitization}
in the following completion of our solution to Problem 4.
{\bf Solution.}
(Cont.)
Previously we defined a generating function and
said that the generating function that we were looking for is equal to
with replaced by 1.
But we don't know how to take the derivative of
the infinite function, and we don't know if we can substitute legally.
Finitization will help us to get around that.
Fix a positive integer , and define
We have simply removed terms from to make , but we have not changed
any of the terms containing or lower.
So for the same reasons as before,
must be the coefficient of in .
(We indicate this with the notation
).
The only difference is that is a finite polynomial,
and so we can calculate this derivative and substitute without any problems.
Define
so that
.
We calculate
and so the generalized product rule (Theorem 2) indicates that
Remember that is the coefficient of in the analytic generating function above.
But now we no longer care that this generating function is analytic;
the only thing we care about it is that it has as the coefficient of .
So we may instead treat this polynomial as a formal generating function.
This updated interpretation of the polynomial allows us to do two things.
First, we may modify it as much as we want as long as the coefficient of is not changed.
And second, we don't have to feel guilty about using infinite expressions that
may or may not converge, because we don't care if they converge.
So, now we will mold it {\it without changing the term or any lower terms} in order to get
a better view of .
First, the only term in
that we care to preserve is ; we may do away with the rest.
The other alterations made to the polynomial in the next few steps also do not modify
the terms we care about:
(Go through these steps carefully and convince yourself that none of the important
terms has been changed.)
Since our was arbitrary, we have rigorously proved that
is the generating function for the sequence .
The construction of that was given previously still contains the
flaw of treating as an analytic function without knowing if the infinite product
converges.
But a similar application of finitization will sidestep this with ease.
We went to an extreme in the finitization of for the sake of instruction,
but other options are available that also work with less painful algebra.
Here's an example of an easier finitization used to make our construction of
rigorous.
Define
When and ,
each of the geometric series in converges, and
since is a finite product of these,
converges in that region.
Furthermore, the coefficient of in is the same as that in .
So we have
So we have now rigorously verified the identity of .
(Notice we were careful to ensure that lies in the domain we chose.
And did you catch the subtle change from analytic to formal generating functions in those last
steps?)
We have rigorously shown that and are identical, from which it
follows that for all , so the problem is finally solved.
\bigskip
\hfill
{\Large Zachary R. Abel, Massachusetts, USA}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix