"""Exact homogeneous linear algebra for the order-14 slice over F_211.""" import numpy as np import sympy as sp from mixed_jets import independent_minor, inverse, monomials def kernel(matrix, p): """Right kernel by block elimination. The BLAS products are exact integers.""" rows, columns = matrix.shape assert max(rows, columns) * (p - 1)**2 + p < 2**53 reduced = np.array(matrix, dtype=np.float64, order="C") % p blocks = [] pivot_columns = [] for start in range(0, columns, 96): stop = min(start + 96, columns) rank = len(pivot_columns) if rank == rows: break chosen, local = independent_minor(reduced[rank:, start:stop].astype(np.int64), p) if not local: continue chosen = rank + chosen top = np.arange(rank, rank + len(local)) gained = np.setdiff1d(chosen, top) lost = np.setdiff1d(top, chosen) reduced[np.r_[top, gained], start:] = reduced[np.r_[chosen, lost], start:].copy() pivots = start + np.asarray(local) block_inverse = inverse(reduced[np.ix_(top, pivots)].astype(np.int64), p) normalized = block_inverse.astype(float) @ reduced[top, start:] % p for i in range(rank + len(local), rows, 400): part = slice(i, min(i + 400, rows)) reduced[part, stop:] = (reduced[part, stop:] - reduced[part, pivots] @ normalized[:, stop-start:]) % p blocks.append((start, pivots, normalized)) pivot_columns.extend(pivots) free = np.setdiff1d(np.arange(columns), pivot_columns) basis = np.zeros((columns, len(free))) basis[free] = np.eye(len(free)) for start, pivots, normalized in reversed(blocks): basis[pivots] = (-normalized @ basis[start:]) % p assert not np.any((matrix.astype(float) @ basis) % p) return basis.astype(np.int64) def degree_eleven(forms): """Rows are all degree-6 monomial multiples of the independent quintics.""" target = {a: i for i, a in enumerate(monomials(11, 6))} source = monomials(5, 6) multiples = monomials(6, 6) matrix = np.zeros((len(multiples) * len(forms), len(target)), dtype=np.uint16) for i, b in enumerate(multiples): indices = [target[tuple(x+y for x, y in zip(a, b))] for a in source] matrix[i*len(forms):(i+1)*len(forms), indices] = forms return matrix def prolong(basis, degree, p): """The six degree-e restrictions of a degree-(e+1) functional must agree.""" old = {a: i for i, a in enumerate(monomials(degree, 6))} new = monomials(degree+1, 6) width = basis.shape[1] constraints, first = [], [] for b in new: restrictions = [] for i, count in enumerate(b): if count: a = list(b) a[i] -= 1 restrictions.append((i, old[tuple(a)])) i, j = restrictions[0] first.append((i, j)) for k, h in restrictions[1:]: row = np.zeros((6, width), dtype=np.int16) row[i], row[k] = basis[j], -basis[h] constraints.append(row.ravel()) compatible = kernel(np.array(constraints), p) result = np.zeros((len(new), compatible.shape[1]), dtype=np.int64) for k in range(6): rows, source = zip(*[(i, j) for i, (key, j) in enumerate(first) if key == k]) result[list(rows)] = basis[list(source)] @ compatible[k*width:(k+1)*width] % p return result def directions(forms, p): chosen, _ = independent_minor(forms, p) assert len(chosen) == 12 basis = kernel(degree_eleven(forms[chosen]), p) assert basis.shape[1] == 90 for degree, expected in [(11, 38), (12, 20)]: basis = prolong(basis, degree, p) assert basis.shape[1] == expected next_basis = prolong(basis, 13, p) assert next_basis.shape[1] == 20 rows, _ = independent_minor(basis, p) target = {a: i for i, a in enumerate(monomials(14, 6))} source = monomials(13, 6) blocks = [] for j in range(6): shifted = [] for i in rows: a = list(source[i]) a[j] += 1 shifted.append(target[tuple(a)]) blocks.append(next_basis[shifted]) chart_inverse = inverse(blocks[0], p) matrices = [block @ chart_inverse % p for block in blocks] assert all(np.array_equal(a@b % p, b@a % p) for a in matrices for b in matrices) separating = sum(j * m for j, m in enumerate(matrices)) % p variable = sp.Symbol("T") poly = sp.Poly.from_list([int(c) % p for c in sp.Matrix(separating).charpoly().all_coeffs()], variable, modulus=p) factors = poly.factor_list()[1] assert sorted((f.degree(), m) for f, m in factors) == [(1, 1)]*9 + [(2, 1)] + [(3, 1)]*3 powers = [np.eye(20, dtype=np.int64)] for _ in range(19): powers.append(powers[-1] @ separating % p) flat = np.array(powers).reshape(20, -1).T values = np.array(matrices).reshape(6, -1).T rows, cols = independent_minor(flat, p) assert len(cols) == 20 coefficients = inverse(flat[rows], p) @ values[rows] % p assert np.array_equal(flat @ coefficients % p, values) return coefficients, [np.array([int(c) % p for c in f.all_coeffs()[::-1]]) for f, _ in factors]