def affine_subspace(V, a, m, ref=False): n = V.degree() diff = n - m.degree() - 1 base = [x**i * m for i in range(diff + 1)] if ref: base = [p(b) for b in base] W = V.subspace([ V(list(base[i]) + [0] * (n - base[i].degree() - 1)) for i in range(diff + 1) ]) if ref: a = p(a) return AffineSubspace(V(a.list() + [0] * (n - a.degree() - 1)), W)
def _affine_subspace(self): """ Return the hyperplane as affine subspace. OUTPUT: The hyperplane as a :class:`~sage.geometry.hyperplane_arrangement.affine_subspace.AffineSubspace`. EXAMPLES:: sage: H.<x,y> = HyperplaneArrangements(QQ) sage: h = -1/3*x + 1/2*y - 1; h Hyperplane -1/3*x + 1/2*y - 1 sage: h._affine_subspace() Affine space p + W where: p = (-12/13, 18/13) W = Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 2/3] """ from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace return AffineSubspace(self.point(), self.linear_part())
def _para_intersection_poset(A): from sage.geometry.hyperplane_arrangement.affine_subspace import AffineSubspace from sage.all import exists, flatten, Set, QQ, VectorSpace, Poset from .Globals import __SANITY N = _N K = A.base_ring() whole_space = AffineSubspace(0, VectorSpace(K, A.dimension())) # L is the ranked list of affine subspaces in L(A). L = [[whole_space], list(map(lambda H: H._affine_subspace(), A))] # hyp_cont is the ranked list describing which hyperplanes contain the # corresponding intersection. hyp_cont = [[Set([])], [Set([k]) for k in range(len(A))]] c = A.is_central() * (-1) for r in range(2, A.rank() + c + 1): print("{1}Working on elements of rank {0}".format(r, _time())) m = len(L[r - 1]) pmax = lambda k: (k + 1) * (m // N) + (k == N - 1) * (m % N) pmin = lambda k: k * (m // N) all_input = lambda k: tuple([ A, range(pmin(k), pmax(k)), hyp_cont[r - 1][pmin(k):pmax(k)], L[r - 1] [pmin(k):pmax(k)] ]) data = list( build_next([all_input(k) for k in range(N) if pmin(k) != pmax(k)])) data = _reduce(lambda x, y: x + y[1], data, []) new_lev, new_hyp = list(zip(*data)) new_lev = list(new_lev) new_hyp = list(new_hyp) i = 0 # Merge the lists down print("{0}Merging the lists from the {1} workers".format(_time(), N)) # First we check the affine spaces while i < len(new_lev): U = new_lev[i] B1 = U.linear_part().basis_matrix() p1 = U.point() j = i + 1 while j < len(new_lev): V = new_lev[j] B2 = V.linear_part().basis_matrix() p2 = V.point() if B1 == B2 and p1 == p2: new_lev = new_lev[:j] + new_lev[j + 1:] new_hyp[i] = new_hyp[i].union(new_hyp[j]) new_hyp = new_hyp[:j] + new_hyp[j + 1:] else: j += 1 i += 1 # Second we check the labels of intersection (don't want duplicates) i = 0 while i < len(new_lev): j = i + 1 while j < len(new_lev): if new_hyp[i] == new_hyp[j]: new_lev = new_lev[:j] + new_lev[j + 1:] new_hyp = new_hyp[:j] + new_hyp[j + 1:] else: j += 1 i += 1 L.append(new_lev) hyp_cont.append(new_hyp) # A silly optimization for centrals. if A.is_central() and len(A) > 1: inter = lambda X, Y: X.intersection(Y._affine_subspace()) L.append([_reduce(inter, A[1:], A[0]._affine_subspace())]) hyp_cont.append([Set(list(range(len(A))))]) L_flat = list(_reduce(lambda x, y: x + y, L, [])) hc_flat = list(_reduce(lambda x, y: x + y, hyp_cont, [])) # Sanity checks if __SANITY: print("{0}Running sanity check".format(_time())) assert len(L_flat) == len(hc_flat) for i in range(len(hc_flat)): for j in range(i + 1, len(hc_flat)): assert hc_flat[i] != hc_flat[j], "{0} vs {1}".format(i, j) for i in range(len(L_flat)): I = list(map(lambda x: A[x], hc_flat[i])) U = _reduce(lambda x, y: x.intersection(y._affine_subspace()), I, whole_space) assert U == L_flat[i], "{0} vs {1}".format(U, L_flat[i]) print("{0}Constructing lattice of flats".format(_time())) t = {} for i in range(len(hc_flat)): t[i] = Set(list(map(lambda x: x + 1, hc_flat[i]))) cmp_fn = lambda p, q: t[p].issubset(t[q]) label_dict = {i: t[i] for i in range(len(hc_flat))} get_hyp = lambda i: A[label_dict[i].an_element() - 1] hyp_dict = {i + 1: get_hyp(i + 1) for i in range(len(A))} return [Poset((t, cmp_fn)), label_dict, hyp_dict]