# The general genus-mass routine uses the full isometry group.
from sage.quadratic_forms.genera.genus import Genus, genera
def unimodular_mass(parity, n):
n = ZZ(n)
if parity == "I" and n >= 1:
return Genus(identity_matrix(ZZ, n)).mass()
if parity == "II" and n >= 0 and n % 8 == 0:
return QQ(1) if n == 0 else genera((n, 0), 1, even=True)[0].mass()
raise ValueError("No such unimodular genus")
unimodular_mass("I", 8) # 1/10321920
unimodular_mass("II", 8) # 1/696729600The generator evaluates the Bernoulli and Euler product formulas in rational arithmetic. It computes Bernoulli and signed Euler numbers by their defining recurrences, without floating-point division. The dimension-zero even mass and dimension-one odd mass are obtained directly from their trivial and order-two isometry groups, respectively.
Every one of the 37 values agrees exactly with SageMath's independent general genus-mass routine [4], after controls in dimensions 1, 2 and 8. The 36 values outside the rank-one exception agree with the separately transcribed exact fractions in Tables 2 and 4 of [1]. Class-sum checks cover odd dimensions 1 through 11 and even dimensions 0, 8, 16 and 24; the last sum uses all 24 stored Niemeier orders. The odd/even mass relation is checked at every positive dimension divisible by 8 in the table. Doubling the E8 mass and omitting the Leech class are rejected by the controls. These comparisons are repeated on the values read back from the draft. The attached generator and checks reproduce the calculations.