Skip to content

hall_basis

from tensorsig.algebra.hall import hall_basis

Return Hall basis elements up to depth over an alphabet of size width.

The Hall basis is a particular basis for the free Lie algebra. Elements are ordered first by depth, then lexicographically by the recursive Hall ordering. Degree-1 elements are labeled 1..width and higher degrees are nested tuples representing Lie brackets.

Parameters:

Name Type Description Default
width int

Size of the alphabet (path dimension). Must be >= 1.

required
depth int

Maximum depth to generate basis elements. Must be >= 1.

required

Returns:

Type Description
List[HallBasisElement]

Hall basis elements, where each element is either an integer (degree 1) or a nested tuple representing a Lie bracket (higher degrees).

Raises:

Type Description
ValueError

If width < 1 or depth < 1.

Source code in src/tensorsig/algebra/hall_projection.py
def hall_basis(width: int, depth: int) -> List[HallBasisElement]:
    """Return Hall basis elements up to ``depth`` over an alphabet of size ``width``.

    The Hall basis is a particular basis for the free Lie algebra. Elements are
    ordered first by depth, then lexicographically by the recursive Hall ordering.
    Degree-1 elements are labeled 1..width and higher degrees are nested tuples
    representing Lie brackets.

    Parameters
    ----------
    width : int
        Size of the alphabet (path dimension). Must be >= 1.
    depth : int
        Maximum depth to generate basis elements. Must be >= 1.

    Returns
    -------
    List[HallBasisElement]
        Hall basis elements, where each element is either an integer (degree 1)
        or a nested tuple representing a Lie bracket (higher degrees).

    Raises
    ------
    ValueError
        If ``width < 1`` or ``depth < 1``.
    """
    if width < 1:
        raise ValueError("width must be >= 1")
    if depth < 1:
        raise ValueError("depth must be >= 1")

    depth_groups: Dict[int, List[HallBasisElement]] = {}
    letters = list(range(1, width + 1))
    depth_groups[1] = letters
    basis: List[HallBasisElement] = list(letters)

    for current_depth in range(2, depth + 1):
        candidates: List[HallBasisElement] = []
        for left_depth in range(1, current_depth):
            right_depth = current_depth - left_depth
            for left in depth_groups[left_depth]:
                for right in depth_groups[right_depth]:
                    if _hall_is_valid_pair(left, right):
                        candidates.append((left, right))
        candidates.sort(key=_hall_basis_key)
        depth_groups[current_depth] = candidates
        basis.extend(candidates)

    return basis