({{, (RefLink[GeneratingFunction, paclet:ref/GeneratingFunction])[expr,n,x] 
gives the generating function in x for the sequence whose n(^th) series coefficient is given by the expression expr.}, {, (RefLink[GeneratingFunction, paclet:ref/GeneratingFunction])[expr,{(Subscript[n, 1]),(Subscript[n, 2]),…},{(Subscript[x, 1]),(Subscript[x, 2]),…}]
gives the multidimensional generating function in (Subscript[x, 1]), (Subscript[x, 2]), … whose (Subscript[n, 1]), (Subscript[n, 2]), … coefficient is given by expr.}})

OpenersNotesSection(Spacer1)Details and Options

The generating function for a sequence whose n(^th) term is (Subscript[a, n]) is given by (∑_(n=0)^∞)(Subscript[a, n]) (x^n).

The multidimensional generating function is given by (∑_((Subscript[n, 1])=0)^∞)(∑_((Subscript[n, 2])=0)^∞)⋯ (Subscript[a, (Subscript[n, 1])(Subscript[n, 2])])⋯ (Subscript[x, 1]^(Subscript[n, 1])) (Subscript[x, 2]^(Subscript[n, 2])) ⋯.

The following options can be given:

In (RefLink[TraditionalForm, paclet:ref/TraditionalForm]), (RefLink[GeneratingFunction, paclet:ref/GeneratingFunction]) is output using 𝒢.

OpenersPrimaryExamplesSection(Spacer1)Examples  (40)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

The generating function for the sequence whose n(^th) term is 1:

GeneratingFunction[1,n,x]

All coefficients in the series are 1:

Series[%,{x,0,10}]

Univariate generating function:

GeneratingFunction[(1/((n!)^2)),n,x]

Multivariate:

GeneratingFunction[(1/((n+1)! m!)),{n,m},{x,y}]

The generating function for a shifted sequence:

GeneratingFunction[f[n+1],n,x]

OpenersExampleSection1(Spacer1)Scope  (23)

OpenersExampleSubsection0(Spacer1)Basic Uses  (7)

Generating function of a univariate function:

GeneratingFunction[a^n,n,z]

Generating function of a multivariate function:

GeneratingFunction[1/(m!n!),{m,n},{x,y}]

Compute a typical generating function:

F=GeneratingFunction[n (n+1)(-1/2)^n,n,z]

Plot the magnitude using (RefLink[Plot3D, paclet:ref/Plot3D]), (RefLink[ContourPlot, paclet:ref/ContourPlot]) or (RefLink[DensityPlot, paclet:ref/DensityPlot]):

Block[{z=u+I v},Table[plot[Abs[F],{u,-2,2},{v,-2,2}],{plot,{Plot3D,ContourPlot,DensityPlot}}]]

Plot the complex phase:

Block[{z=u+I v},Table[plot[Arg[F],{u,-2,2},{v,-2,2}],{plot,{Plot3D,ContourPlot,DensityPlot}}]]

Generate conditions for the region of convergence:

GeneratingFunction[a^n,n,z,GenerateConditions->True]

Plot the region for a==(1/2):

With[{z=u+I v},RegionPlot[Abs[z]<1/Abs[1/2],{u,-4,4},{v,-4,4}]]

Evaluate the generating function at a point:

F=GeneratingFunction[Sin[n 2Pi/3](2/3)^n,n,Exp[I ω]]

Plot the spectrum:

LogPlot[Abs[F]^2,{ω,0,2π},Ticks->{{0,π,2π},Automatic}]

The phase:

Plot[Arg[F],{ω,0,2π},Ticks->{{0,π,2π},Automatic}]

Plot both the spectrum and the plot phase using color:

LogPlot[Abs[F]^2,{ω,0,2π},Ticks->{{0,π,2π},Automatic},ColorFunction->Function[ω,Evaluate@Hue[Arg[F]/(2Pi)+1/2]],ColorFunctionScaling->False,Filling->Axis]

Plot the spectrum in the complex plane using (RefLink[ParametricPlot3D, paclet:ref/ParametricPlot3D]):

ParametricPlot3D[{Cos[ω],Sin[ω],Log[10,Abs[F]^2]},{ω,0,2π},BoxRatios->{1,1,1}]

(RefLink[GeneratingFunction, paclet:ref/GeneratingFunction]) will use several properties including linearity:

GeneratingFunction[a f[n]+b g[n],n,z]

Shifts:

{GeneratingFunction[f[n+1],n,z],GeneratingFunction[f[n-1],n,z]}

Multiplication by exponentials:

{GeneratingFunction[a^n f[n],n,z],GeneratingFunction[b^(-n)f[n],n,z]}

GeneratingFunction[Exp[I ω n]f[n],n,z]

Multiplication by polynomials:

{GeneratingFunction[ n f[n],n,z],GeneratingFunction[n(n+1) f[n],n,z]}

Conjugate:

GeneratingFunction[Conjugate[f[n]],n,z]

(RefLink[GeneratingFunction, paclet:ref/GeneratingFunction]) automatically threads over lists:

GeneratingFunction[{a^n,b^n},n,z]

GeneratingFunction[{{a^n,b^n},{n,n^2}},n,z]

Equations:

GeneratingFunction[a^n==f[n],n,z]

Rules:

GeneratingFunction[f[n]->a^n,n,z]

(RefLink[TraditionalForm, paclet:ref/TraditionalForm]) typesetting:

GeneratingFunction[f[n],n,z]//TraditionalForm

OpenersExampleSubsection1(Spacer1)Special Sequences  (12)

Discrete impulses:

{GeneratingFunction[DiscreteDelta[n],n,z],GeneratingFunction[DiscreteDelta[n-5],n,z]}

Table[DiscretePlot[f,{n,-10,10},PlotStyle->PointSize[Medium]],{f,{DiscreteDelta[n],DiscreteDelta[n-5]}}]

Discrete unit steps:

{GeneratingFunction[UnitStep[n],n,z],GeneratingFunction[UnitStep[n-3],n,z]}

Table[DiscretePlot[f,{n,-10,10}],{f,{UnitStep[n],UnitStep[n-3]}}]

Discrete ramps:

{GeneratingFunction[n UnitStep[n],n,z],GeneratingFunction[(n-3)UnitStep[n-3],n,z]}

Table[DiscretePlot[f,{n,-10,10}],{f,{n UnitStep[n],(n-3)UnitStep[n-3]}}]

Polynomials result in rational generating functions:

{GeneratingFunction[n,n,z],GeneratingFunction[n^2,n,z]}

Factorial polynomials:

GeneratingFunction[Pochhammer[n,Range[0,3]],n,z]

GeneratingFunction[FactorialPower[n,Range[0,3]],n,z]

Exponential functions:

GeneratingFunction[a^n,n,z]

Exponential polynomials:

{GeneratingFunction[n a^n,n,z],GeneratingFunction[n^2 a^n,n,z]}

Table[DiscretePlot[f,{n,0,40}],{f,{n (10/12)^n,n^2 (10/12)^n}}]

Factorial exponential polynomials:

GeneratingFunction[Pochhammer[n,Range[0,3]] a^n,n,z]

GeneratingFunction[FactorialPower[n,Range[0,3]] a^n,n,z]

Trigonometric functions:

{GeneratingFunction[Sin[ω n+ϕ],n,z],GeneratingFunction[Cos[ω n+ϕ],n,z]}

Table[DiscretePlot[f,{n,-20,20}],{f,{Sin[2π/10 n],Cos[2π/10 n]}}]

Trigonometric, exponential and polynomial:

{GeneratingFunction[(5/6)^n Sin[ω n],n,z],GeneratingFunction[n (5/6)^n Sin[ω n],n,z]}

Table[DiscretePlot[f,{n,0,20}],{f,{(5/6)^n Sin[2π/10 n],n (5/6)^n Sin[2π/10 n]}}]

Combinations of the previous input will also generate rational generating functions:

GeneratingFunction[n^2 a^n+b^n Sin[ω n] UnitStep[n+20],n,z]

DiscretePlot[n^2 (5/6)^n +(11/12)^n 20Sin[2Pi/10 n]UnitStep[n-20],{n,0,50}]

Different ways of expressing piecewise-defined signals:

GeneratingFunction[n (UnitStep[n]-UnitStep[n-6])+a^n UnitStep[n-6],n,z]

GeneratingFunction[Piecewise[{{n,n≤5},{a^n,True}}],n,z]

Simplify[%%-%]

Rational functions:

GeneratingFunction[1/(n+1),n,z]

GeneratingFunction[((n^2)+n+1)/(n+1)^2,n,z]

GeneratingFunction[FactorialPower[n,-2],n,z]

Rational exponential functions:

GeneratingFunction[a^n/(n+1)^2,n,z]

GeneratingFunction[a^n FactorialPower[n,-2],n,z]

Hypergeometric term sequences:

GeneratingFunction[1/n!,n,z]

The (RefLink[DiscreteRatio, paclet:ref/DiscreteRatio]) is rational for all hypergeometric term sequences:

DiscreteRatio[1/n!,n]

Many functions give hypergeometric terms:

hl={a^n,n!,Gamma[n],Pochhammer[a,n],FactorialPower[a,n],Binomial[n,a],Binomial[b,n],CatalanNumber[n]};

DiscreteRatio[hl,n]

Any products are hypergeometric terms:

DiscreteRatio[Times@@RandomChoice[hl,3],n]

Generating functions of hypergeometric terms:

GeneratingFunction[((2^(-2+n))/(Gamma[(1/2)+n])),n,z]

GeneratingFunction[n/Binomial[2n,n],n,z]

GeneratingFunction[CatalanNumber[n]/Binomial[2n,n],n,z]

GeneratingFunction[((FactorialPower[a1,n])/(FactorialPower[b1,n]FactorialPower[b2,n])),n,z]

Holonomic sequences:

GeneratingFunction[LegendreP[n,a],n,z]

A holonomic sequence is defined by a linear difference equation:

DifferenceRootReduce[LegendreP[n,a],n]

Many special function are holonomic sequences in their index:

GeneratingFunction[ChebyshevT[n,x],n,z]

GeneratingFunction[ChebyshevU[2n,x]^2,n,z]

Special sequences:

GeneratingFunction[BernoulliB[n]/n!,n,z]

GeneratingFunction[EulerE[n]/n!,n,z]

GeneratingFunction[DifferenceRoot[Function[{y,m},{y[m+2]==y[m+1]+y[m],y[0]==0,y[1]==1}]][n],n,z]

Periodic sequences:

GeneratingFunction[Mod[n,3],n,z]

GeneratingFunction[Exp[n 2π I/9],n,z]

Multivariate generating functions:

GeneratingFunction[(a^(n+m)),{n,m},{u,v}]

GeneratingFunction[n^2 m^3,{n,m},{u,v}]

GeneratingFunction[Sin[n+m]a^n,{n,m},{u,v}]

GeneratingFunction[m/(n+1),{n,m},{u,v}]

GeneratingFunction[Mod[n+m,3],{n,m},{u,v}]

OpenersExampleSubsection2(Spacer1)Special Operators  (4)

Linearity:

GeneratingFunction[a*f[n]+b*f[n],n,z]

Differences and shifts:

GeneratingFunction[DifferenceDelta[f[n],n],n,z]

GeneratingFunction[DiscreteShift[f[n],n],n,z]

Sums:

GeneratingFunction[Sum[f[m],{m,0,n}],n,z]

GeneratingFunction[Sum[f[m],{m,a,n}],n,z,Assumptions->a>0&&a∈Integers]

Integrals:

GeneratingFunction[Integrate[f[x,n],{x,a,b}],n,z]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

Compute the generating function at a point:

GeneratingFunction[1/n!,n,0.5]

GeneratingFunction[1/n!,n,1/z]

OpenersExampleSection3(Spacer1)Options  (6)

OpenersExampleSubsection3(Spacer1)Assumptions  (1)

In general, this generating function cannot be given:

GeneratingFunction[f[n+a],n,x]

By providing additional (RefLink[Assumptions, paclet:ref/Assumptions]), a closed form can be given:

GeneratingFunction[f[n+a],n,x,Assumptions->a∈Integers&&a>0]

OpenersExampleSubsection4(Spacer1)GenerateConditions  (1)

By default, no conditions are given for where a generating function is convergent:

GeneratingFunction[a^n,n,x]

Use (RefLink[GenerateConditions, paclet:ref/GenerateConditions]) to generate conditions of validity:

GeneratingFunction[a^n,n,x,GenerateConditions->True]

OpenersExampleSubsection5(Spacer1)Method  (1)

Different methods may produce different results:

GeneratingFunction[n,n,z]

GeneratingFunction[n,n,z,Method-> "Holonomic"]

OpenersExampleSubsection6(Spacer1)VerifyConvergence  (3)

Setting (RefLink[VerifyConvergence, paclet:ref/VerifyConvergence]) to (RefLink[False, paclet:ref/False]) will treat generating functions as formal objects:

GeneratingFunction[2^n,n,x,VerifyConvergence->False]

Setting (RefLink[VerifyConvergence, paclet:ref/VerifyConvergence]) to (RefLink[True, paclet:ref/True]) will verify that the radius of convergence is nonzero:

GeneratingFunction[2^n,n,x,VerifyConvergence->True]

In addition, setting (RefLink[GenerateConditions, paclet:ref/GenerateConditions]) to (RefLink[True, paclet:ref/True]) will display the conditions for convergence:

GeneratingFunction[2^n,n,x,VerifyConvergence->True,GenerateConditions->True]

OpenersExampleSection4(Spacer1)Properties & Relations  (5)

Use (RefLink[SeriesCoefficient, paclet:ref/SeriesCoefficient]) to get the sequence from its generating function:

GeneratingFunction[SeriesCoefficient[F[z],{z,0,n}],n,z]

GeneratingFunction[a^n Sin[n],n,z]

SeriesCoefficient[%,{z,0,n}]

(RefLink[GeneratingFunction, paclet:ref/GeneratingFunction]) effectively computes an infinite sum:

GeneratingFunction[n^2,n,z]

Sum[n^2 z^n,{n,0,Infinity}]

(RefLink[GeneratingFunction, paclet:ref/GeneratingFunction]) and (RefLink[ZTransform, paclet:ref/ZTransform]) can be expressed in terms of each other:

{ZTransform[n^2,n,z],GeneratingFunction[n^2,n,1/z]}//Simplify

{ZTransform[n^2,n,1/z],GeneratingFunction[n^2,n,z]}//Simplify

Linearity:

GeneratingFunction[a f[n]+b g[n],n,z]

Shifting:

GeneratingFunction[f[n+2],n,z]

Convolution:

GeneratingFunction[Sum[f[k]g[k-n],{k,0,n}],n,z]

Derivative:

GeneratingFunction[n f[n],n,z]

(RefLink[GeneratingFunction, paclet:ref/GeneratingFunction]) is closely related to (RefLink[ExponentialGeneratingFunction, paclet:ref/ExponentialGeneratingFunction]):

{GeneratingFunction[n/n!,n,z],ExponentialGeneratingFunction[n,n,z]}

(RefLink[ZTransform, paclet:ref/ZTransform]):

{GeneratingFunction[n,n,z], ZTransform[n,n,1/z]}//Simplify

(RefLink[FourierSequenceTransform, paclet:ref/FourierSequenceTransform]):

{GeneratingFunction[n,n,Exp[I*ω]],FourierSequenceTransform[n UnitStep[n],n,ω]}

OpenersExampleSection5(Spacer1)Possible Issues  (1)

A (RefLink[GeneratingFunction, paclet:ref/GeneratingFunction]) may not converge for all values of parameters:

{Sum[2^n 1^n,{n,0,∞}],GeneratingFunction[2^n,n,1]}

GeneratingFunction[a^n,n,x]

Use (RefLink[GenerateConditions, paclet:ref/GenerateConditions]) to get the region of convergence:

GeneratingFunction[a^n,n,x,GenerateConditions->True]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

Create a gallery of generating functions:

flist = {{UnitStep[n+1/2],n,z},{n^2+2,n,z},{1/(2n+1),n,z},{Sin[a n],n,z},{ChebyshevU[n,a],n,z},{BernoulliB[n]/n!,n,z},{a^n Sin[n],n,z},{Mod[n,7],n,z},{Binomial[m,n],{m,n},{u,v}},{m/(n + 1),{m,n},{u,v}}};

Grid[Join[{{f,Text["Generating Function"]}},Transpose[{flist[[;;,1]],Map[GeneratingFunction@@#&,flist]}]],Background->{None,{{None,GrayLevel[.9]}},{{1,1}->Hue[.6,.4,1],{1,2}->Hue[.6,.4,1]}},BaseStyle->{FontFamily->Times,FontSize->12},Dividers->All,FrameStyle->Hue[.6,.4,.8],Spacings->{2,1}]//TraditionalForm

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Series, paclet:ref/Series])  ▪  (RefLink[SeriesCoefficient, paclet:ref/SeriesCoefficient])  ▪  (RefLink[Sum, paclet:ref/Sum])  ▪  (RefLink[ZTransform, paclet:ref/ZTransform])  ▪  (RefLink[DiscreteConvolve, paclet:ref/DiscreteConvolve])  ▪  (RefLink[RSolve, paclet:ref/RSolve])  ▪  (RefLink[ExponentialGeneratingFunction, paclet:ref/ExponentialGeneratingFunction])  ▪  (RefLink[FindGeneratingFunction, paclet:ref/FindGeneratingFunction])  ▪  (RefLink[AsymptoticSum, paclet:ref/AsymptoticSum])  ▪  (RefLink[AsymptoticRSolveValue, paclet:ref/AsymptoticRSolveValue])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Integer Sequences, paclet:guide/IntegerSequences])}, {▪(RefLinkPlain[Discrete Mathematics, paclet:guide/DiscreteMathematics])}, {▪(RefLinkPlain[Discrete Calculus, paclet:guide/DiscreteCalculus])}, {▪(RefLinkPlain[Summation Transforms, paclet:guide/SummationTransforms])}, {▪(RefLinkPlain[Integral Transforms, paclet:guide/IntegralTransforms])}, {▪(RefLinkPlain[Recurrence and Sum Functions, paclet:guide/RecurrenceAndSumFunctions])}})}})