Open-source software · v1.0
colour
SU(N) colour factors of Feynman diagrams, symbolic in N
A header-only C++17 library. It takes a product of generators Taij, structure constants fabc, dabc and Kronecker deltas and returns a Laurent polynomial in N with exact rational coefficients for each structure of the trace basis in the external indices. Written with Claude Code.
fabc Tb Tc → (i/2) CA Ta · TbTaTb → (CF − CA/2) Ta
What's in the box
Four engines with the same interface and the same output keys; exact rationals throughout.
Reference engine
colour.hpp: f and d as traces, Fierz on internal adjoint labels, memoisation.
The simplest correct algorithm, and the one to read first.
Birdtrack rules
colour_fast.hpp: gluon bubble, triangle, vertex correction and tadpole removed
before any expansion; canonical relabelling so isomorphic states share a cache entry.
Hybrid engine
colour_v2.hpp: flat terms processed level by level with sort-and-merge, the
commutator rule, and connected components cached across all diagrams of an amplitude.
Independent oracle
colour_numeric.hpp: colour-flow tensor network contracted at integer N, exact
Newton interpolation in N. No Fierz, no f-expansion, no shared code.
Diagram front end
diagram.hpp: vertices with ordered leg lists (ggg, ghg, qqg). The colour and
kinematic codes read the same ordering, so signs of f cannot drift apart.
No dependencies
Headers only, C++17. Factors of i from f are counted, not carried, so all coefficients stay real; TF = 1/2 by default, configurable.
Quick start
Build the tests, then compute the one-loop vertex colour factor.
1 · build & self-check
# any C++17 compiler make test # → all agree, failures = 0 ./gen5 # all 2280 two-loop five-gluon graphs
2 · fabc Tb Tc
#include "colour.hpp" using namespace colour; Expression e; int i = e.fundamental("i"), j = e.fundamental("j"); int a = e.adjoint("a"); int b = e.adjoint_internal(), c = e.adjoint_internal(); int k = e.fundamental_internal(); e.f(a, b, c); e.T(i, k, b); e.T(k, j, c); std::cout << e.evaluate().str(); // (-i)^1 * [ (-1/2*N) (a )_{i,j} ] = (i/2) C_A T^a_ij
Download & cite
If colour is useful in your work, please cite it as
Validation & timing
Every engine is checked against the others and against explicit Gell-Mann matrices at N = 2, 3, 4.
| Case | Against | Result |
|---|---|---|
| Casimirs, vertex corrections, gluon box, two-loop quark linetest suites of all four engines | explicit SU(N) matrices; tensor-network oracle | all agree |
| all 2280 two-loop five-gluon cubic graphsone shared engine, 23 810 cache hits | birdtrack engine (every 10th graph) | 0 of 228 differ · 0.06 ms per graph |
| two-loop six-gluon ring, open indices103 trace structures | a FORM implementation (SUn.prc) | equal · 1.8 ms vs 14 ms |
| same ring, fully contracted | a FORM implementation (SUn.prc) | equal · 0.19 ms vs 2 ms |