import tensorflow as tf

      loop_vars=[n, result, two])
  return result


def factorial(n: TensorLike) -> TensorLike:
  n = tf.convert_to_tensor(value=n)

  return tf.exp(tf.math.lgamma(n + 1))


def generate_l_m_permutations(
    max_band: int,
    name: str = "spherical_harmonics_generate_l_m_permutations") -> Tuple[TensorLike, TensorLike]:
  with tf.name_scope(name):
