Video failed to load

Lagrange Inversion: Count Recursive Objects Without Expanding the Recursion

461 words
2 minutes
Lagrange Inversion: Count Recursive Objects Without Expanding the Recursion

Some generating functions are defined by themselves. An ordered rooted tree consists of a root followed by an allowed sequence of subtrees, so its series naturally satisfies an implicit equation. Expanding that equation coefficient by coefficient can be expensive. Lagrange inversion often turns one desired coefficient into an ordinary polynomial-power coefficient.

The equation and its hypotheses#

Suppose T(x)=xϕ(T(x))T(x)=x\phi(T(x)), where ϕ(0)≠0\phi(0)\ne0 and T(0)=0T(0)=0. Over characteristic zero, the Lagrange-Burmann formula says that for n>0n>0,

[xn]H(T(x))=1n[un−1]H′(u)ϕ(u)n.[x^n]H(T(x))=\frac1n[u^{n-1}]H'(u)\phi(u)^n.

For H(u)=ukH(u)=u^k, this becomes

[xn]T(x)k=kn[un−k]ϕ(u)n,[x^n]T(x)^k=\frac{k}{n}[u^{n-k}]\phi(u)^n,

with zero when n<kn<k. In a prime field, the displayed divisions require the relevant integers to be invertible; a safe contest setting is precision below the characteristic.

A formal derivation instead of a memorized formula#

Use Res⁡\operatorname{Res} to mean the coefficient of x−1x^{-1}. Coefficient extraction gives [xn]H(T)=Res⁡H(T)x−n−1dx[x^n]H(T)=\operatorname{Res}H(T)x^{-n-1}dx. Substitute x=u/ϕ(u)x=u/\phi(u), valid because its linear coefficient is nonzero.

The derivative is dx=(ϕ−uϕ′)/ϕ2 dudx=(\phi-u\phi')/\phi^2\,du, so the residue becomes

Res⁡H(u)(ϕ(u)nun+1−ϕ(u)n−1ϕ′(u)un)du.\operatorname{Res}H(u)\left( \frac{\phi(u)^n}{u^{n+1}}- \frac{\phi(u)^{n-1}\phi'(u)}{u^n} \right)du.

The residue of a formal derivative is zero. Apply this to H(u)ϕ(u)nu−nH(u)\phi(u)^nu^{-n}, rearrange, and the two terms above collapse to

1nRes⁡H′(u)ϕ(u)nu−ndu.\frac1n\operatorname{Res}H'(u)\phi(u)^nu^{-n}du.

That is exactly the stated coefficient formula. The derivation identifies the required inverse of nn and explains why the factor k/nk/n appears in the power case.

application: unary-binary ordered trees#

Allow every node to have zero, one, or two ordered children, with one node contributing one factor of xx. Then

T=x(1+T+T2).T=x(1+T+T^2).

Lagrange inversion yields

[xn]T=1n[un−1](1+u+u2)n.[x^n]T=\frac1n[u^{n-1}](1+u+u^2)^n.

For n=4n=4, find coefficient u3u^3 in (1+u+u2)4(1+u+u^2)^4. Either three factors contribute uu, giving four choices, or one contributes u2u^2 and another contributes uu, giving twelve choices. Divide the total sixteen by four to obtain four trees.

The four structures can also be understood directly: one chain of four nodes; a unary root above a binary node with two leaves; and a binary root with one unary child on either the left or the right. An independent check is to expand the recurrence: T=x+x2+2x3+4x4+⋯T=x+x^2+2x^3+4x^4+\cdots.

One root

Allowed number of children

Zero children: 1

One ordered subtree: T

Two ordered subtrees: T squared

T equals x times one plus T plus T squared

One root

Allowed number of children

Zero children: 1

One ordered subtree: T

Two ordered subtrees: T squared

T equals x times one plus T plus T squared

Turn the formula into an algorithm#

To compute one coefficient for a dense ϕ\phi, truncate ϕn\phi^n at degree n−k+1n-k+1. Binary polynomial exponentiation is a simple baseline costing O(M(n)log⁡n)O(M(n)\log n) with truncation. When ϕ(0)=1\phi(0)=1, use

ϕn=exp⁡(nlog⁡ϕ)\phi^n=\exp(n\log\phi)

to obtain the needed prefix in O(M(n))O(M(n)) using FPS log and exp. A nonunit constant can be factored out if it is invertible. Sparse ϕ\phi may admit a simpler direct sum, as in the small example above.

The formula does not make all implicit equations disappear. If your equation is T=xϕ(T)+x2ψ(T)T=x\phi(T)+x^2\psi(T), it is not immediately in this form. Introducing another variable or applying a different inversion theorem needs a separate argument.

Exercise. Allow only zero or three ordered children. Prove that a nonzero count requires n≡1(mod3)n\equiv1\pmod3, then derive the closed binomial expression. Check the smallest three feasible sizes directly from the recursive construction.

Support & Share

If this article helped you, please share or support!

Sponsor
Lagrange Inversion: Count Recursive Objects Without Expanding the Recursion
https://blog.wsh.moe/posts/lagrange-inversion/
Author
Wsh
Published at
2026-10-24

Comments

LEAVE A NOTE

Join the conversation

Markdown supported

Be kind. Good conversations start with you.

Conversation

Loading conversation…

Comments powered by Waline

Profile Image of the Author
Wsh
Nice to meet you! Hello, I'm Wsh.
Announcement
Any news or updates will be shared here, so check back anytime! Thanks for stopping by, meow >.<
Categories
Tags
Site Statistics
Posts
27
Categories
7
Tags
69
Total Words
124,615
Running Days
0 days
Last Activity
0 days ago
Site Info
Build Platform
Vercel
Blog Version
Firefly v6.16.8
License
CC BY-NC-SA 4.0
Table of Contents