def num_spectral_coeffs_up_to_order(b):
    """
    The SO(3) spectrum consists of matrices of size (2l+1, 2l+1) for l=0, ..., b - 1.
    This function computes the number of elements in a spectrum up to (but excluding) b - 1.
    
    The number of elements up to and including order L is
    N_L = sum_{l=0}^L (2l+1)^2 = 1/3 (2 L + 1) (2 L + 3) (L + 1)
    
    :param b: bandwidth 
    :return: the number of spectral coefficients
    """
    L_max = b - 1
    assert L_max >= 0
    return ((2 * L_max + 1) * (2 * L_max + 3) * (L_max + 1)) // 3