def pascal_transport(plan, shift=-1):
"""Return rows T(e_i) without building an ambient Hall or tensor basis.
Hall trees are evaluated in the quotient. For trace basis representatives,
the degree-normalized left Dynkin map reconstructs the primitive before
substituting generators. This is valid modulo the homogeneous Hopf ideal.
The caller must establish invariance of that ideal under Pascal translation.
"""
width = plan.alphabet.code_dim
table = {}
for (i, j, k), coefficient in zip(
plan.bracket_indices.cpu().tolist(), plan.bracket_coefficients, strict=True
):
table.setdefault((i, j), []).append((k, coefficient))
def add(target, source, scale=Fraction(1)):
for k, value in source.items():
target[k] = target.get(k, Fraction()) + scale * value
if not target[k]:
del target[k]
def bracket(left, right):
result = {}
for i, a in left.items():
for j, b in right.items():
for k, coefficient in table.get((i, j), ()):
add(result, {k: coefficient}, a * b)
return result
generators = [
{i: Fraction(float(v)) for i, v in enumerate(row) if v}
for row in plan.generator_map.cpu().tolist()
]
shifted = []
for letter in range(plan.alphabet.width):
channel, degree = divmod(letter, width)
result = {}
for p in range(degree, width):
k = p - degree
coefficient = (
comb(shift, k) if shift >= 0 else (-1) ** k * comb(k - shift - 1, k)
)
add(result, generators[channel * width + p], Fraction(coefficient))
shifted.append(result)
@lru_cache(None)
def hall(element):
if isinstance(element, int):
return shifted[element - 1]
return bracket(hall(element[0]), hall(element[1]))
@lru_cache(None)
def dynkin(word):
if len(word) == 1:
return shifted[word[0]]
return bracket(dynkin(word[:-1]), shifted[word[-1]])
rows = []
for element in plan.basis:
if isinstance(element, TraceBasisElement):
row = {}
for word, coefficient in element.terms:
add(row, dynkin(word), coefficient / element.depth)
rows.append(row)
else:
rows.append(hall(element))
return rows