Generating function calculator

A generating function packs an entire sequence of numbers into a single power series, where the coefficient of x to the n is the nth term of the sequence. This compact encoding turns hard counting and recurrence problems into algebra, which is why generating functions are a cornerstone of combinatorics. This calculator works with the simplest and most important example, the ordinary generating function a divided by one minus r x. Expanded as a power series, this equals a plus a r x plus a r squared x squared and so on, so the coefficient of x to the n is a times r to the n, the familiar geometric sequence. You enter the leading term a, the ratio r and the index n, and the calculator returns that coefficient directly. From this single closed form you can read off geometric sequences and build more elaborate generating functions by combining and differentiating. Enter your own a, r and n to extract a coefficient, study a recurrence or check an exercise. Every figure here is computed deterministically from the geometric series expansion, shown in full below with a worked example that reconciles exactly to the calculator.

The ordinary generating function a / (1 minus r x) expands so that the coefficient of x to the n is a r to the power n. With a = 1, r = 2 and n = 5, the coefficient is 32.

Source: US National Institute of Standards and Technology (NIST). As at 25 June 2026.

Generating functiona / (1 - r x)
r to the power n--
Coefficient of x^n--

Ordinary generating function

G(x) = a / ( 1 - r x )
= a + a r x + a r^2 x^2 + a r^3 x^3 + ...
coefficient of x^n = a r^n
valid as a formal power series; converges for |r x| < 1
a = leading term, r = ratio, n = index (0, 1, 2, ...)

The fraction a over one minus r x is the closed form of the geometric power series. Reading off the term with x to the n gives the coefficient a times r to the n, which is exactly the nth term of a geometric sequence with first term a and common ratio r.

Worked example

Find the coefficient of x to the 5 in the generating function 1 / (1 - 2 x), so a = 1, r = 2, n = 5.

  1. The series is 1 + 2 x + 4 x^2 + 8 x^3 + 16 x^4 + 32 x^5 + ...
  2. The coefficient of x^n is a r^n
  3. r^n = 2^5 = 32
  4. Coefficient = a r^n = 1 x 32 = 32
  5. This matches the x^5 term in the expansion above

The coefficient of x to the 5 is 32. These are the calculator's default inputs, so the result above matches the widget exactly.

First coefficients of 1 / (1 - 2x)

nCoefficient (2 to the n)
01
12
24
38
416
532

Each coefficient is the previous one times the ratio r.

Generating function calculator: frequently asked questions

What is a generating function?

A generating function is a formal power series whose coefficients are the terms of a sequence. The coefficient of x to the n is the nth term. By treating a whole sequence as one algebraic object, generating functions let you solve recurrences, count structures and find closed forms using ordinary algebra.

Why is a / (1 - r x) the geometric generating function?

Expanding the fraction a over one minus r x as a power series gives a plus a r x plus a r squared x squared and so on, so the coefficient of x to the n is a times r to the n. That is precisely a geometric sequence, which is why this fraction is the generating function for it.

What is the coefficient of x to the n?

For the generating function a over one minus r x, the coefficient of x to the n is a times r to the power n. It is the nth term of the geometric sequence with first term a and common ratio r. This calculator returns that coefficient for the a, r and n you enter.

Does the series have to converge?

As a formal power series, the coefficient relationship holds regardless of convergence; the algebra is purely symbolic. If you want the series to sum to a finite number, you need the magnitude of r times x to be less than one. The coefficient itself, a times r to the n, is always defined.

Can I build more complex generating functions from this?

Yes. Sums, products, shifts and derivatives of simple generating functions build the generating functions for more complicated sequences, including those defined by recurrences. The geometric form here is the basic building block. The coefficient computation is deterministic and reconciles exactly to the worked example.

Official sources

Reviewed by the CalculatorHub team, edited by James Graham, 25 June 2026. See our methodology. This is general information, not financial, tax, legal or investment advice.