Enumerative graph theory · formal theorem

Cayley’s Formula for Labeled Trees

For every n ≥ 1, the number of labeled unrooted trees on the vertex set Fin n is exactly n^(n − 2).

Lean proofpassed
Unfinished proof stepsNone
Formal resultAccepted
Cayley formula statement mapLabeled trees on n vertices correspond to Prüfer codes of length n minus two, giving exactly n to that power.
Exact scope: For every natural number n with 1 ≤ n, the number of labeled unrooted trees on Fin n is n^(n − 2).

Line counts exclude blank lines; comments and documentation count. The total is the commit-pinned first-party Lean import closure; Mathlib and other third-party dependencies are excluded.

The theorem at a glance

Cayley’s Formula at a glance

Editorial theorem poster stating Cayley’s formula, the Prüfer encoder and decoder, and the exact labeled-tree scope.
Cayley’s formula counts labeled trees through an equivalence with length-n−2 Prüfer codes.

Accessible transcript

Nat.card (LabeledTree n) = n ^ (n − 2)

For every n at least one, the number of finite simple trees on the labeled vertex type Fin n is n raised to n minus two. The proof builds an encoder, decoder, and both inverse laws.

Read the complete poster transcript

COMBINATORICS · LABELED TREES

CAYLEY’S FORMULA

HOW MANY TREES ON n LABELED VERTICES?

FOR EVERY n ≥ 1

|LabeledTree(n)| = n^(n − 2)

PRÜFER CODES

A tree on n ≥ 2 vertices corresponds to a sequence of length n − 2 with entries in Fin n.

LEAF → NEIGHBOR

Remove the least leaf and record its unique neighbor.

CODE → TREE

Reconnect the least missing remaining label, then join the final two labels.

WHY THE COUNT IS n^(n − 2)

n choices for each of n − 2 positions.

HOW THE PROOF MOVES

1 · CHOOSE THE LEAST LEAF

2 · ENCODE ITS NEIGHBOR

3 · REBUILD FROM THE CODE

4 · PROVE BOTH INVERSE LAWS

5 · TRANSFER CARDINALITY

EXACT SCOPE

Finite simple trees on the labeled vertex type Fin n. Counts labeled trees, not unlabeled tree shapes.

Theorem schematic

Prüfer encoding and decoding

An eight-symbol labeled tree is pruned into an ordered code ribbon and reconstructed through the inverse route.
Canonical leaf deletion turns a labeled tree into a Prüfer code, and the decoder reconstructs the same tree.

Labeled trees on n vertices ↔ Prüfer codes of length n − 2

The least current leaf is removed while its unique neighbor is recorded. Repetition produces an ordered code, and reversing the state changes reconstructs the labeled tree.

Proof architecture

Why Prüfer codes count labeled trees

6 curated stages

The checked proof turns labeled trees into Prüfer codes by repeatedly deleting one canonical leaf, builds an exact decoder with a final-pair step, proves both state machines are inverse, and transfers the code-space cardinality back to trees.

These source-anchored stages explain the retained proof route. They are not an extracted Lean proof-term dependency graph.

  1. One eight-symbol labeled tree faces six code positions, each with the same eight available choices.
    For n ≥ 2, counting trees reduces to counting length-n−2 codes over the same labels.
    01

    The tree count becomes a code count

    LabeledTree (n + 2) ≃ PruferCode (n + 2)

    The proof separates the one-vertex boundary case and reduces the main count to an equivalence between trees and functions from n−2 positions into the labels.

    Lean lemmas for this step
    • PruferCode
    • pruferCode_natCard
    • labeledTree_one_natCard
    • pruferEquiv
  2. The star leaf disappears while its triangle neighbor enters the first of six code slots.
    The least current leaf is deleted, and its unique neighbor—not the leaf—is emitted as the next code symbol.
    02

    The encoder chooses one canonical leaf

    chosenStep emits the neighbor label and erases the chosen leaf

    The chosen step removes the least degree-one label, records its neighbor in original-label coordinates, and preserves a smaller tree.

    Lean lemmas for this step
    • chosenLeaf
    • PruferState.chosenStep
    • PruferState.chosenStep_labelFinset_eq_erase_chosenLeaf
  3. Three shrinking trees retain seven, six, and five nodes while the code prefix grows to triangle, diamond, and ring.
    Three canonical deletions shrink the remaining-label set and fill the Prüfer code in a fixed order.
    03

    Repeated pruning produces the ordered code

    pruferEncodeState records an ordered head and recursive tail

    Successive encoder states erase STAR, SQUARE, and DIAMOND. Their neighbors become the ordered code prefix while original labels persist.

    Lean lemmas for this step
    • PruferState.labelFinset
    • PruferState.liftedGraph
    • pruferEncodeState_succ_zero
    • pruferEncodeState_succ_tail
  4. Six code tokens align with six exact edge cards; a final dot–bar card completes the eight-node tree.
    Each code token determines one decoder edge, and the last two labels supply the seventh edge.
    04

    The decoder rebuilds every edge

    pruferDecodeTree : PruferCode (n + 2) → LabeledTree (n + 2)

    The decoder joins the least remaining label absent from the tail to the current head. Six recursive edges and the final pair produce a tree.

    Lean lemmas for this step
    • decodeLeaf
    • PruferDecodeState.step
    • PruferDecodeState.finish
    • pruferDecodeGraph_isTree
    • pruferDecodeTree
  5. A complete eight-symbol tree maps to a six-token code and back, while the same code maps through the tree back to itself.
    Decode after encode recovers the tree, and encode after decode recovers the code.
    05

    Encoder and decoder close both inverse loops

    decode (encode T) = T and encode (decode c) = c

    State invariants align the chosen leaf with the least missing label at every step, proving both inverse laws.

    Lean lemmas for this step
    • PruferState.decodeLeaf_encode_eq_chosenLeaf_label
    • pruferDecodeState_encode_graph_sup_final_liftedGraph_eq
    • pruferEncode_decodeTree_succ
    • pruferEquiv
  6. Six code positions each carry exactly the same eight symbol choices.
    With n choices at each of n−2 positions, the code space has n^(n−2) elements.
    06

    The code space gives Cayley’s count

    Nat.card (LabeledTree n) = n ^ (n − 2)

    The equivalence transfers the code-space cardinality to labeled trees; the one- and two-vertex cases are handled separately in the source.

    Lean lemmas for this step
    • pruferCode_natCard
    • pruferEquiv
    • labeledTree_one_natCard
    • cayleyTreeFormula

Exact formal proposition

Hypotheses and conclusion

theorem cayleyTreeFormula : CayleyTreeFormulaStatement

Result boundary

What this page does—and does not—establish

For every natural number n with 1 ≤ n, the number of labeled unrooted trees on Fin n is n^(n − 2).

About these visual explanations

These AI-generated visuals explain the theorem and proof route; they are not proof evidence. Their publication review was completed separately from review of the formal result. The exact Lean proposition and checked source remain authoritative.

Continue the mathematics

Start from the complete checked source

The pinned theorem and its complete local import closure let internal and external agents inspect the proof, compare an alternate route, isolate reusable lemmas, or formulate a stronger exact statement. Lean checks every proposed extension against its exact formal statement.

The ZIP contains the checked first-party Lean import closure, exact statements and boundaries, license, notice, evidence, source-footprint manifest, and an agent continuation file. Mathlib and other third-party dependencies are not bundled.

Formal-result publication and review details

Independent publication review

The formal theorem's publication gates are accepted

Lean checks the proof. Independent AI review separately accepted evidence completeness, statement alignment, result boundary, and the retained theorem wording. Those gates apply to the formal result; generated media is reviewed and promoted separately. Neither review replaces Lean's proof check or broadens the theorem.

01

Formal evidence

Independent review accepted the recorded build, exact declarations, unfinished-step scan, and axiom evidence.

02

Statement alignment

The formal declaration was accepted against the named theorem and its exact variant.

03

Result boundary

The accepted boundary keeps nearby stronger or commonly confused claims out of scope.

04

Public wording

Independent review accepted the retained theorem explanation and source presentation. Generated media follows a separate review and promotion gate.

05

Canonical source

The first-party source link is pinned to the checked package commit and exact Lean file.

06

Accepted result

A validated accepted-result record binds the four reviews to the checked formalization.

Expanded visual

Open original image in a new tab