COUNTINGLIB · AN INTERACTIVE INTRODUCTION

The mathematics of counting possibilities.

Finding one answer is only the beginning. CountingLib explores how hard it is to count them all—and brings the proofs into Lean.

A small explorer faces a vast landscape of branching stone bridges. One golden route crosses the network toward a distant illuminated arch.
ONE PATH. A WORLD OF POSSIBILITIES.How many ways through?
A simple question. An entire field of mathematics.
FIGURE 1 · SIX POINTS, MANY POSSIBILITIESInteractive

Each point can be on or off. Connected points cannot both be on.

One configuration

✓ This one works

All 2⁶ = 64 configurations
AllowedRuled outSelect any pattern
18possibilities
remain
18 / 64
Change the rules
A local rule changes the whole space of solutions. Try the three rule sets: the answers are 64, 48, and 18.
01 / THE QUESTION

Finding one. Counting them all.

Imagine a timetable with no clashes. Finding one answers the question “Is this possible?” Counting asks something more: how many different timetables satisfy the rules?

The same distinction appears in coloring maps, matching workers to tasks, and describing configurations of a physical system. Checking a proposed answer can be easy. Counting every answer may demand a very different idea.

Our six-point example is small enough to list every configuration. With 100 points, there are already 2100 on/off patterns. Counting complexity asks: when does the structure let us avoid examining them one by one?

A huge number of possibilities does not by itself make counting hard. With no connections, the answer for n points is simply 2n. The structure of the rules is what matters.

02 / A COMMON LANGUAGE

When possibilities carry weight.

Ordinary counting gives every valid answer a contribution of 1. In many models, different answers carry different weights. Adding those contributions gives a partition function.

Return to the six-point cycle. Give each point that is on a weight λ. A configuration with k points on then contributes λk. Move the slider to turn a count into a weighted sum.

FIGURE 2 · THE SAME CYCLE, DIFFERENT WEIGHTSInteractive
Z(λ) = 1 + 6λ + 9λ² + 2λ³=18
02
At λ = 1, every valid configuration counts equally. The sum is 18 again.

Local rules supply contributions; the whole problem sums over assignments. This shared pattern connects questions about constraints, graphs, and networks—and gives their proofs common ground.

03 / THE RESEARCH LANDSCAPE

Which structures make counting tractable?

An algorithm solves a class of problems. A classification theorem asks a broader question: across a whole family, which cases admit efficient algorithms, and which are #P-hard? CountingLib connects these results and their reusable mathematics across the following directions.

BOOLEAN HOLANT

Local functions. A global sum.

Place a function at each junction of a network, then sum over assignments to its wires. Boolean Holant dichotomies classify the function families that permit efficient evaluation and those that lead to #P-hardness.

COMPLEX-WEIGHTED CSP

Recognizing what the rules allow.

Variables interact through weighted local constraints. The research addresses both the classification of evaluation problems and effective recognition of which case a given collection of rules belongs to.

PLANAR GRAPH HOMOMORPHISMS

How many ways can one graph fit another?

Assign a type to each vertex while respecting which types may be neighbors. Graph coloring is a familiar example. The library includes planar homomorphism dichotomies for nonnegative algebraic weights.

MATCHGATE WIDTH

How compact can an exact representation be?

A complicated counting object may admit a smaller exact representation. Matchgate-width results explore the power and limits of this compression, including qutrit trichotomy and exact compression.

These are introductions to the ideas. The diagrams are schematic; the linked papers and formal sources give the precise assumptions, reductions, and conclusions.

04 / FROM RESEARCH TO A LIBRARY

Proofs that other proofs can build on.

A paper explains why a result is true. Lean is a proof assistant: it checks the logical steps of a formal proof against precise definitions and assumptions. Those proofs can then become parts of new results.

CountingLib connects research into a reusable system. Shared definitions describe the objects being counted. Algorithms specify what they compute. Bridge theorems connect models. Classification results retain their precise scope.

01

Shared foundations

Counts · partitions · encodings · machines

02

Algorithms & bridges

Variable elimination · interpolation · Pfaffians · reductions

03

Classification & recognition

Holant · ComplexCSP · PlanarHom · Matchgate Width

Models, computation, and research results have distinct roles, connected through explicit interfaces and proofs.

Computing the right value and proving a running-time bound are different guarantees. CountingLib states them separately, so the next piece of research can see exactly what it uses and what it assumes.

Further reading

Papers & formalizationsFollow the mathematical statements to their sources. Documentation & APIInstallation, imports, and using the library in your own work. Counting Problems for BabiesAn illustrated introduction, with notes for grown-ups. 38-page PDF.PDF ↗

The interactive figures use small browser computations to illustrate the mathematics; they are not Lean-verified executables. The documentation identifies its source snapshot; the repository tracks further development.