Advanced maths

Chromatic polynomial calculator from a graph edge list

Compute a bounded graph’s exact chromatic polynomial and evaluate its number of proper colorings with a chosen number of labeled colors.

Your numbers

At most 24 edge rows with one-based labels. Duplicate undirected edges collapse. A self-loop makes every proper coloring impossible; blank means no edges.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A proper coloring assigns a color to every vertex with different colors at the two ends of each edge. The chromatic polynomial counts these assignments as a function of the number k of labeled colors. This calculator applies exact deletion–contraction with memoization, returns every integer coefficient and evaluates the polynomial at the selected k. A self-loop gives the zero polynomial, while repeated copies of the same undirected inequality do not create new coloring restrictions.

THE FORMULAP_G(k)=P_(G−e)(k)−P_(G/e)(k) for a nonloop edge; an edgeless n-vertex graph has P(k)=k^n.

A worked example

For a triangle, vertex one has k choices, vertex two has k−1 and vertex three must avoid both earlier colors, leaving k−2. Thus P(k)=k(k−1)(k−2)=k³−3k²+2k. At k=3 there are six proper colorings, and at k=2 there are none. The six assignments distinguish the color labels; they are not collapsed into one pattern by permuting the three colors.

Good to know

Supports 1–9 vertices and at most 24 edge rows, with an evaluation color count from zero through 10⁶. Integer coefficients and evaluations are exact. The exponential deletion–contraction procedure has a 100,000-call budget and can reject difficult inputs. Duplicate undirected edges are merged, loops force zero and isolated vertices remain declared. The output is not a count modulo graph symmetries, an automatic drawing-color assignment or an unbounded large-graph solver.

Deletion and contraction separate whether two endpoints share a color

Deleting an edge allows all proper colorings of the remaining graph, including assignments where the formerly adjacent endpoints have equal colors. Contracting those endpoints counts exactly that equal-color subset. Subtracting the contracted count from the deleted count restores the inequality required by the original edge. This reasoning explains the sign in the recurrence instead of treating subtraction as an arbitrary symbolic rule.

For a path on three vertices, the first color has k choices and each next vertex has k−1 choices, giving k(k−1)². At k=3 the value is twelve, different from the triangle’s six because the path endpoints are allowed to share a color. Adding an isolate multiplies the polynomial by k, since its color is unrestricted by the other vertices. The declared vertex count is therefore part of the calculation even if an isolate has no edge row.

A triangle requires a different labeled color at each of its three vertices123P(k)=k(k−1)(k−2)k³ − 3k² + 2kP(3) = 6
The first vertex has k choices, the second k−1 and the third k−2, giving k(k−1)(k−2). At k=3 this is six assignments. Color labels are distinguished, rather than identified by swapping colors.

The Graphical degree sequence calculator with Havel–Hakimi steps can construct one simple edge set from degrees; a chromatic polynomial instead depends on the actual edge constraints.

Labeled colors and symmetry classes count different objects

Swapping red and blue on all vertices generally produces another assignment under this convention. Likewise, permuting vertices through a graph symmetry does not identify two results. A count up to color or vertex symmetry would require a separate group-action analysis. The polynomial here is the standard count of assignments to the given labeled vertices from k labeled colors, and no implicit division by a factorial is performed.

A self-loop requires a vertex to differ from itself, so every coloring is impossible and the polynomial is zero. Parallel copies of an ordinary edge only repeat the same condition and are collapsed. A zero value at a particular k does not make every coefficient zero: the triangle polynomial is nonzero even though evaluating it at two gives zero. Exact coefficient output and the selected evaluation are kept separate so a small-k obstruction is not confused with the loop convention or a failed recursive computation.

A few questions, answered

Can coefficients be negative when coloring counts cannot?

Yes. The polynomial expansion can have alternating coefficients while its evaluation at every nonnegative integer color count is nonnegative. The triangle’s −3k² term is a normal example.

Does the page return the chromatic number?

Its main output is the polynomial and the selected evaluation. The chromatic number would be the smallest positive k with a positive count for a loop-free graph, but it is not silently substituted for the requested count.

Find your calculator

Start typing to explore the library.