def verify(self, inequalities, equations): """ Compare result to PPL if the base ring is QQ. This method is for debugging purposes and compares the computation with another backend if available. INPUT: - ``inequalities``, ``equations`` -- see :class:`Hrep2Vrep`. EXAMPLES:: sage: from sage.geometry.polyhedron.double_description_inhomogeneous import Hrep2Vrep sage: H = Hrep2Vrep(QQ, 1, [(1,2)], []) sage: H.verify([(1,2)], []) """ from sage.rings.all import QQ from sage.geometry.polyhedron.constructor import Polyhedron if self.base_ring is not QQ: return P = Polyhedron(vertices=self.vertices, rays=self.rays, lines=self.lines, base_ring=QQ, ambient_dim=self.dim, backend='ppl') Q = Polyhedron(ieqs=inequalities, eqns=equations, base_ring=QQ, ambient_dim=self.dim, backend='ppl') if (P != Q) or \ (len(self.vertices) != P.n_vertices()) or \ (len(self.rays) != P.n_rays()) or \ (len(self.lines) != P.n_lines()): print 'incorrect!', print Q.Vrepresentation() print P.Hrepresentation()
def verify(self, vertices, rays, lines): """ Compare result to PPL if the base ring is QQ. This method is for debugging purposes and compares the computation with another backend if available. INPUT: - ``vertices``, ``rays``, ``lines`` -- see :class:`Vrep2Hrep`. EXAMPLES:: sage: from sage.geometry.polyhedron.double_description_inhomogeneous import Vrep2Hrep sage: vertices = [(-1/2,0)] sage: rays = [(-1/2,2/3), (1/2,-1/3)] sage: lines = [] sage: V2H = Vrep2Hrep(QQ, 2, vertices, rays, lines) sage: V2H.verify(vertices, rays, lines) """ from sage.rings.all import QQ from sage.geometry.polyhedron.constructor import Polyhedron if self.base_ring is not QQ: return P = Polyhedron(vertices=vertices, rays=rays, lines=lines, base_ring=QQ, ambient_dim=self.dim) trivial = [self.base_ring.one()] + [self.base_ring.zero()] * self.dim # always true equation Q = Polyhedron(ieqs=self.inequalities + [trivial], eqns=self.equations, base_ring=QQ, ambient_dim=self.dim) if not P == Q: print 'incorrect!', P, Q print Q.Vrepresentation() print P.Hrepresentation()
def cone_triangulate(C, hyperplane=None): r""" Triangulation of rational cone contained in the positive quadrant. EXAMPLES:: sage: from surface_dynamics.misc.linalg import cone_triangulate sage: P = Polyhedron(rays=[(1,0,0),(0,1,0),(1,0,1),(0,1,1)]) sage: list(cone_triangulate(P)) # random [[(0, 1, 1), (0, 1, 0), (1, 0, 0)], [(0, 1, 1), (1, 0, 1), (1, 0, 0)]] sage: len(_) 2 sage: rays = [(0, 1, 0, -1, 0, 0), ....: (1, 0, -1, 0, 0, -1), ....: (0, 1, -1, 0, 0, -1), ....: (0, 0, 1, 0, 0, 0), ....: (0, 0, 0, 1, 0, -1), ....: (1, -1, 0, 0, 1, -1), ....: (0, 0, 0, 0, 1, -1), ....: (0, 0, 1, -1, 1, 0), ....: (0, 0, 1, -1, 0, 0), ....: (0, 0, 1, 0, -1, 0), ....: (0, 0, 0, 1, -1, -1), ....: (1, -1, 0, 0, 0, -1), ....: (0, 0, 0, 0, 0, -1)] sage: P = Polyhedron(rays=rays) sage: list(cone_triangulate(P, hyperplane=(1, 2, 3, -1, 0, -5))) # random [[(0, 0, 0, 0, 0, -1), (0, 0, 0, 0, 1, -1), (0, 0, 0, 1, -1, -1), (0, 0, 1, 0, 0, 0), (0, 1, -1, 0, 0, -1), (1, -1, 0, 0, 1, -1)], ... (0, 0, 1, 0, 0, 0), (0, 1, -1, 0, 0, -1), (0, 1, 0, -1, 0, 0), (1, -1, 0, 0, 1, -1), (1, 0, -1, 0, 0, -1)]] sage: len(_) 16 """ rays = [r.vector() for r in C.rays()] dim = len(rays[0]) if hyperplane is None: hyperplane = [1] * dim scalings = [sum(x * h for x, h in zip(r, hyperplane)) for r in rays] assert all(s > 0 for s in scalings) normalized_rays = [r / s for r, s in zip(rays, scalings)] P = Polyhedron(vertices=normalized_rays) for t in P.triangulate(): simplex = [P.Vrepresentation(i).vector() for i in t] yield [(r / gcd(r)).change_ring(ZZ) for r in simplex]
def experiment(): rank = 5 level = 4 num_points = 11 client = cbc.CBClient() liealg = cbd.TypeALieAlgebra(rank, store_fusion=True, exact=True) rays = [] wts = [] ranks = [] for wt in liealg.get_weights(level): if wt == tuple([0 for x in range(0, rank)]): continue cbb = cbd.SymmetricConformalBlocksBundle(client, liealg, wt, num_points, level) if cbb.get_rank() == 0: continue divisor = cbb.get_symmetrized_divisor() if divisor == [ sage.Rational(0) for x in range(0, num_points // 2 - 1) ]: continue rays = rays + [divisor] wts = wts + [wt] ranks = ranks + [cbb.get_rank()] #print(wt, cbb.get_rank(), divisor) p = Polyhedron(rays=rays, base_ring=RationalField(), backend="cdd") extremal_rays = [list(v.vector()) for v in p.Vrepresentation()] c = Cone(p) print("Extremal rays:") for i in range(0, len(rays)): ray = rays[i] wt = wts[i] rk = ranks[i] if ray in extremal_rays: print(rk, wt, ray)