Source code for ffsim.states.dimensions
# (C) Copyright IBM 2025.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""Convenience functions for computing the dimensions of the FCI space."""
from __future__ import annotations
import math
[docs]
def dims(norb: int, nelec: tuple[int, int]) -> tuple[int, int]:
"""Get the dimensions of the FCI space.
Args:
norb: The number of spatial orbitals.
nelec: The number of alpha and beta electrons.
Returns:
A pair of integers (dim_a, dim_b) representing the dimensions of the
alpha- and beta- FCI space.
"""
n_alpha, n_beta = nelec
dim_a = math.comb(norb, n_alpha)
dim_b = math.comb(norb, n_beta)
return dim_a, dim_b
[docs]
def dim(norb: int, nelec: int | tuple[int, int]) -> int:
"""Get the dimension of the FCI space.
Args:
norb: The number of spatial orbitals.
nelec: Either a single integer representing the number of fermions for a
spinless system, or a pair of integers storing the numbers of spin alpha
and spin beta fermions.
Returns:
The dimension of the FCI space.
"""
if isinstance(nelec, int):
return math.comb(norb, nelec)
n_alpha, n_beta = nelec
return math.comb(norb, n_alpha) * math.comb(norb, n_beta)