Skip to content

eulerian_permutations

from tensorsig.algebra.eulerian import eulerian_permutations

Return permutations and exact first-Eulerian-idempotent coefficients.

length is a non-negative integer. Degree zero has an empty schedule, since the first Eulerian idempotent annihilates the scalar unit.

Source code in src/tensorsig/algebra/eulerian.py
@lru_cache(maxsize=None)
def eulerian_permutations(
    length: int,
) -> tuple[tuple[tuple[int, ...], Fraction], ...]:
    """Return permutations and exact first-Eulerian-idempotent coefficients.

    ``length`` is a non-negative integer. Degree zero has an empty schedule,
    since the first Eulerian idempotent annihilates the scalar unit.
    """
    if not isinstance(length, int) or isinstance(length, bool) or length < 0:
        raise ValueError("length must be a non-negative integer.")
    if length == 0:
        return ()
    schedule = []
    for permutation in permutations(range(length)):
        descents = sum(
            left > right for left, right in zip(permutation, permutation[1:])
        )
        schedule.append(
            (
                permutation,
                Fraction((-1) ** descents, length * comb(length - 1, descents)),
            )
        )
    return tuple(schedule)