"""Reconstruct the exceptional affine column from the finite root flows.""" from __future__ import annotations from typing import NamedTuple def require(condition, message): if not condition: raise ValueError(message) def finite_roots(cartan): """Enumerate the Weyl orbits of the simple roots in simple-root coordinates.""" rank = len(cartan) queue = [tuple(int(i == j) for i in range(rank)) for j in range(rank)] roots = set(queue) for root in queue: for i, row in enumerate(cartan): image = list(root) image[i] -= sum(x * y for x, y in zip(row, root)) image = tuple(image) if image not in roots: roots.add(image) queue.append(image) return roots def lowering_string(roots, rank, leaf): """Maximal finite lowering strings from the leaf root to minus theta.""" root = tuple(int(i == leaf) for i in range(rank)) lowest = min(roots, key=sum) zero = (0,) * rank chain = [] while root != lowest: for i in range(rank): candidate = list(root) power = 0 while True: candidate[i] -= 1 if tuple(candidate) != zero and tuple(candidate) not in roots: break power += 1 if power: candidate[i] += 1 root = tuple(candidate) chain.append((i, power)) break else: raise ValueError("Adjoint lowering stopped before the lowest root") return chain class Exchange(NamedTuple): pivot: int positive: list negative: list def exchange_row(matrix, k): row = matrix[k] return Exchange(k, [(j, value) for j, value in enumerate(row) if value > 0], [(j, -value) for j, value in enumerate(row) if value < 0]) def mutate(matrix, pivot): """Ordinary matrix mutation on mutable rows and all columns.""" result = [row[:] for row in matrix] exchange = exchange_row(matrix, pivot) for i, row in enumerate(result): if i == pivot: result[i] = [-x for x in row] continue incidence = row[pivot] terms = exchange.positive if incidence > 0 else exchange.negative if incidence: for j, power in terms: row[j] += incidence * power row[pivot] = -incidence return result def mutation_path(initial, word): """Save the exchange monomials. Each binomial can be used in reverse.""" matrix = initial path = [] for position in word: require(type(position) is int and 1 <= position <= len(initial), "Invalid mutable position in mutation word") pivot = position - 1 path.append(exchange_row(matrix, pivot)) matrix = mutate(matrix, pivot) return path, matrix def coefficient_monomial(endpoint, symmetrizers, boundary, length, sign): """Mutable powers in a finite adapted chart from its calculated column.""" monomial = [] for i, (row, delta) in enumerate(zip(endpoint, symmetrizers)): exponent, remainder = divmod(sign * delta * row[boundary], length) require(exponent >= 0 and remainder == 0, "Invalid adapted finite column") if exponent: monomial.append((i, exponent)) require(monomial, "Empty finite-current coefficient") return monomial def leaf_coordinate(matrix, labels, leaf, size, incoming, edge_power): """Verify the triangular negative Hankel shifts giving the leaf current.""" if size == 1: return [], incoming, edge_power path = [] for layer in range(1, size): upper, lower = ("s", "z") if layer % 2 else ("z", "s") for h in range(1, size - layer + 1): pivot = labels.index((upper, leaf + 1, h)) expected = [0] * len(labels) expected[labels.index((lower, leaf + 1, h))] = 2 if h > 1: expected[labels.index((lower, leaf + 1, h - 1))] = -1 if h + 1 < size: expected[labels.index((lower, leaf + 1, h + 1))] = -1 else: expected[incoming] = -edge_power require(matrix[pivot] == expected or matrix[pivot] == [-x for x in expected], "Leaf exchange disagrees with Hankel condensation") path.append(exchange_row(matrix, pivot)) matrix = mutate(matrix, pivot) return path, path[-1].pivot, 1 def monomial_weight(weights, terms): total = [0] * len(weights[0]) for j, exponent in terms: for i, value in enumerate(weights[j]): total[i] += exponent * value return tuple(total) def transport(weights, path): for pivot, positive, negative in path: numerator = max(monomial_weight(weights, positive), monomial_weight(weights, negative)) weights[pivot] = tuple(x - y for x, y in zip(numerator, weights[pivot])) def affine_extrema(matrix, labels, symmetrizers, lengths, sizes, parent, roots, framing, words): """Coordinatewise Newton extrema of E_0(c) at c=1 in the proposed chart.""" leaf = len(lengths) - 1 if framing == 0 else 0 source = parent[leaf] edge = labels.index(("edge", source + 1, leaf + 1)) edge_power = max(1, lengths[source] // lengths[leaf]) leaf_path, leaf_index, leaf_power = leaf_coordinate( matrix, labels, leaf, sizes[leaf], edge, edge_power) chain = lowering_string(roots, len(lengths), leaf) finite = {} for color in sorted({i for i, _ in chain}): path, endpoint = mutation_path(matrix, words[f"F{color + 1}"]) boundary = labels.index(("principal", color + 1)) monomial = coefficient_monomial(endpoint, symmetrizers, boundary, lengths[color], -1) finite[color] = (path, boundary, monomial) affine_path, endpoint = mutation_path(matrix, words["E0"]) powers = tuple(power for _, power in chain) # A tuple encodes (tau_1-weight, ..., tau_q-weight, coordinate weight). # Lexicographic maximum first extracts the successive maximal divided powers. bounds = [] for j in range(len(labels)): lower_upper = [] for sign in (-1, 1): weights = [(0,) * len(chain) + (sign * int(j == k),) for k in range(len(labels))] transport(weights, reversed(affine_path)) # Pullback of the leaf function composes the point actions in reverse. for stage in reversed(range(len(chain))): color, _ = chain[stage] path, boundary, monomial = finite[color] transport(weights, path) translated = list(monomial_weight(weights, monomial)) translated[stage] += 1 weights[boundary] = max(weights[boundary], tuple(translated)) transport(weights, reversed(path)) transport(weights, leaf_path) weight = tuple(leaf_power * value for value in weights[leaf_index]) require(weight[:-1] == powers, "Geometric current disagrees with the maximal root strings") lower_upper.append(sign * weight[-1]) bounds.append(tuple(lower_upper)) return bounds, endpoint def recover_matrix(raw_matrix, labels, symmetrizers, lengths, sizes, parent, roots, framing, words): """Recover the actual homogeneous matrix from its c-free part and the chart words.""" c = len(raw_matrix) reduced = [row[:c] + row[c+1:] for row in raw_matrix] reduced_labels = [tuple(label) for label in labels[:c] + labels[c+1:]] bounds, endpoint = affine_extrema(reduced, reduced_labels, symmetrizers, lengths, sizes, parent, roots, framing, words) require(all(low == high for low, high in bounds), "Positive affine coefficient has more than one Laurent exponent") exponents = [low for low, _ in bounds] require(exponents.count(1) == 1 and exponents.count(0) == len(labels) - 2 and exponents.index(1) < c, "Expected a single mutable affine coefficient") # Corollary 7.2 gives u_j = delta_j B_jc at the positive endpoint. full_endpoint = [] for row, exponent, delta in zip(endpoint, exponents, symmetrizers): entry, remainder = divmod(exponent, delta) require(remainder == 0, "Nonintegral endpoint c-column") full_endpoint.append(row[:c] + [entry] + row[c:]) _, recovered = mutation_path(full_endpoint, reversed(words["E0"])) require(all(row[:c] + row[c+1:] == old for row, old in zip(recovered, reduced)), "Backward mutation changed the projected initial matrix") return recovered, exponents.index(1) + 1 def grading_equations(matrix, symmetrizers, lengths, framing, words): """Linear equations for the geometric grading in initial coordinates.""" num_mutable = len(matrix) num_variables = len(matrix[0]) c_row = [int(j == num_mutable) for j in range(num_variables)] equations = list(matrix) + [c_row] targets = [0] * num_mutable + [lengths[framing]] for i, length in enumerate(lengths, start=1): path, endpoint = mutation_path(matrix, words[f"E{i}"]) boundary = num_mutable + i terms = coefficient_monomial(endpoint, symmetrizers, boundary, length, 1) # Degree(E_i b_i) - degree(b_i) = 0 at the finite adapted endpoint. constraint = [0] * num_variables for j, exponent in terms: constraint[j] = exponent constraint[boundary] = -1 # Pull the linear form back using deg x'_k = -deg x_k + deg M_+. for pivot, positive, _ in reversed(path): coefficient = constraint[pivot] constraint[pivot] = -coefficient for j, exponent in positive: constraint[j] += coefficient * exponent equations.append(constraint) targets.append(0) require(len(equations) == num_variables, "Grading system is not square") return equations, targets