A Python script that computes the Kac matrix (Gram matrix) of the
Verma module for the Virasoro algebra at a given level. The entries are
symbolic polynomials in the central charge c and the highest weight h.
The Virasoro algebra is the infinite‑dimensional Lie algebra
generated by L_n (n ∈ ℤ) with commutation relations
A highest‑weight representation is built on a state |h⟩ satisfying
L_0|h⟩ = h|h⟩ and L_n|h⟩ = 0 for n > 0. The states of the Verma module
at integer level N are spanned by λ = (λ₁, λ₂, …) is a partition of N into positive integers,
usually written in non‑increasing order.
The Kac matrix (or Gram matrix) M(N) records the inner products
between these basis states. Its determinant, the Kac determinant,
gives the condition for the existence of singular (null) vectors. The
matrix elements are computed recursively using the algebra commutation
relations.
- Generates all integer partitions of the given level
N. - For every pair of partitions, builds the appropriate product of
Virasoro generators and evaluates the vacuum expectation value
⟨h| … |h⟩symbolically. - Returns the symmetric matrix of inner products as SymPy expressions.
- Caches intermediate results (
functools.lru_cache) for speed. - Prints the matrix in both SymPy pretty‑print and a plain‑text format
(with
^for exponentiation and no*for multiplication).
- Python ≥ 3.8
- SymPy (install with
pip install sympy)
The script uses only the standard library and SymPy; NumPy is not required.
Run from the command line:
python kac.py [level]If no level is given, the default is 4.
python3 Kac.py 3
Kac matrix for level 3:
⎡24⋅h⋅(h + 1)⋅(2⋅h + 1) 12⋅h⋅(3⋅h + 1) 24⋅h ⎤
⎢ ⎥
⎢ 12⋅h⋅(3⋅h + 1) h⋅(c + 8⋅h + 8) 10⋅h ⎥
⎢ ⎥
⎣ 24⋅h 10⋅h 2⋅c + 6⋅h⎦
String matrix (with '^' and no '*'):
['24h(h + 1)(2h + 1)', '12h(3h + 1)', '24h']
['12h(3h + 1)', 'h(c + 8h + 8)', '10h']
['24h', '10h', '2c + 6h']The number of partitions grows rapidly (≈ $p(N) ~ e^{π√(2N/3)} / 4N√3$), so computation becomes expensive for N > 8–9. Memoization greatly reduces the number of recursive calls, but the exponential complexity remains. For higher levels you may need to add more optimisations or use a dedicated determinant formula.
This project is released under the MIT License. Feel free to use, modify, and distribute it.