Skip to content

GeneratingFunction ​

The ordinary generating function ∑nexpr(n) xn\sum_n \mathrm{expr}(n)\,x^n of a sequence, in closed form, when one exists.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageGeneratingFunction!
GeneratingFunction(expr, n, x)the ordinary generating function of expr(n) in x
Typed signatures
TypePackageApplies
(any, symbol, symbol) -> anycombinatoricsalways

Domain: Combinatorics

Details
  • C-finite sequences (satisfying a constant-coefficient linear recurrence -- Fibonacci-like sequences, fixed-kk binomials, polynomials in nn, geometric terms, and any combination of those) get a rational generating function, found from the recurrence by Berlekamp--Massey -- there is no family-specific code.
  • A handful of named, non-C-finite sequences are recognised directly by value, not by name: the Catalan numbers have the algebraic generating function (1−1−4x)/(2x)(1-\sqrt{1-4x})/(2x).
  • Count(Family(n)) is not special-cased either: it is sampled numerically like any other sequence, so a family whose cardinality happens to be Catalan (or any C-finite sequence) gets the matching closed form automatically.
  • Falls back to staying symbolic when no closed form is found (e.g. n!n! has none), the same as Wolfram.

Examples

Basic #

x/(1−x−x2)x/(1-x-x^2)

live ↗
InGeneratingFunction(Fibonacci(n),n,x)\mathrm{GeneratingFunction}(\mathrm{Fibonacci}(n), n, x)Outx−x2−x+1\frac{x}{-x^2-x+1}

(1−1−4x)/(2x)(1-\sqrt{1-4x})/(2x) -- algebraic, not rational: Catalan numbers are not C-finite

live ↗
InGeneratingFunction(CatalanNumber(n),n,x)\mathrm{GeneratingFunction}(\mathrm{CatalanNumber}(n), n, x)Out1−1−4x2x\frac{1-\sqrt{1-4x}}{2x}

the same Catalan generating function, reached through a collection's cardinality rather than CatalanNumber directly

live ↗
InGeneratingFunction(Count(DyckPaths(n)),n,x)\mathrm{GeneratingFunction}(\mathrm{Count}(\mathrm{DyckPaths}(n)), n, x)Out1−1−4x2x\frac{1-\sqrt{1-4x}}{2x}

x3/(1−x)4x^3/(1-x)^4

live ↗
InGeneratingFunction((n3),n,x)\mathrm{GeneratingFunction}(\binom{n}{3}, n, x)Outx3x4−4x3+6x2−4x+1\frac{x^3}{x^4-4x^3+6x^2-4x+1}

1/(1−2x)1/(1-2x)

live ↗
InGeneratingFunction(2n,n,x)\mathrm{GeneratingFunction}(2^{n}, n, x)Out11−2x\frac{1}{1-2x}

The constant sequence 11 sums to the geometric series 1/(1−x)1/(1-x)

live ↗
InGeneratingFunction(1,n,x)\mathrm{GeneratingFunction}(1, n, x)Out11−x\frac{1}{1-x}
Scope #

n!n! has no elementary ordinary generating function -- stays unevaluated, as Wolfram does too

live ↗
InGeneratingFunction(n!,n,x)\mathrm{GeneratingFunction}(n!, n, x)OutGeneratingFunction(n!,n,x)\mathrm{GeneratingFunction}(n!, n, x)
live ↗
In[GeneratingFunction(n,n,z),GeneratingFunction(n2,n,z)]\bigl\lbrack\mathrm{GeneratingFunction}(n, n, z), \mathrm{GeneratingFunction}(n^2, n, z)\bigr\rbrackOut[zz2−2z+1,z2+z−z3+3z2−3z+1]\bigl\lbrack\frac{z}{z^2-2z+1}, \frac{z^2+z}{-z^3+3z^2-3z+1}\bigr\rbrack
live ↗
In[GeneratingFunction(UnitStep(n),n,z),GeneratingFunction(UnitStep(n−3),n,z)]\bigl\lbrack\mathrm{GeneratingFunction}(\mathrm{UnitStep}(n), n, z), \mathrm{GeneratingFunction}(\mathrm{UnitStep}(n-3), n, z)\bigr\rbrackOut[11−z,z31−z]\bigl\lbrack\frac{1}{1-z}, \frac{z^3}{1-z}\bigr\rbrack
live ↗
In[GeneratingFunction(nUnitStep(n),n,z),GeneratingFunction((n−3)UnitStep(n−3),n,z)]\bigl\lbrack\mathrm{GeneratingFunction}(n\mathrm{UnitStep}(n), n, z), \mathrm{GeneratingFunction}((n-3)\mathrm{UnitStep}(n-3), n, z)\bigr\rbrackOut[zz2−2z+1,z4z2−2z+1]\bigl\lbrack\frac{z}{z^2-2z+1}, \frac{z^4}{z^2-2z+1}\bigr\rbrack

The sequence nn gives z/(1−z)2z/(1-z)^2

live ↗
InGeneratingFunction(n,n,z)\mathrm{GeneratingFunction}(n, n, z)Outzz2−2z+1\frac{z}{z^2-2z+1}
Properties #

The squares give z(1+z)/(1−z)3z(1+z)/(1-z)^3, one more pole order than nn

live ↗
InGeneratingFunction(n2,n,z)\mathrm{GeneratingFunction}(n^2, n, z)Outz2+z−z3+3z2−3z+1\frac{z^2+z}{-z^3+3z^2-3z+1}
live ↗
In[GeneratingFunction(nn!,n,z),ExponentialGeneratingFunction(n,n,z)]\bigl\lbrack\mathrm{GeneratingFunction}(\frac{n}{n!}, n, z), \mathrm{ExponentialGeneratingFunction}(n, n, z)\bigr\rbrackOut[GeneratingFunction(nn!,n,z),zez]\bigl\lbrack\mathrm{GeneratingFunction}(\frac{n}{n!}, n, z), ze^{z}\bigr\rbrack
Possible issues #
live ↗
In[∑n=0∞2n,GeneratingFunction(2n,n,1)]\bigl\lbrack\sum_{n=0}^{∞}2^{n}, \mathrm{GeneratingFunction}(2^{n}, n, 1)\bigr\rbrackOut[∞,−1]\bigl\lbrack∞, -1\bigr\rbrack
About
Examples14
Checked againstWolfram Language 11 agree2 differ
CrosswalkWolfram Language

See also: ExponentialGeneratingFunction, FindSequenceFunction, DiscreteRatio