def _init_from_Hrepresentation(self, ieqs, eqns, minimize=True, verbose=False): r""" Construct polyhedron from H-representation data. INPUT: - ``ieqs`` -- list of inequalities; each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements - ``eqns`` -- list of equalities; each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements - ``minimize`` -- boolean (default: ``True``); ignored - ``verbose`` -- boolean (default: ``False``); whether to print verbose output for debugging purposes EXAMPLES:: sage: p = Polyhedron(backend='normaliz') # optional - pynormaliz sage: from sage.geometry.polyhedron.backend_normaliz import Polyhedron_normaliz # optional - pynormaliz sage: Polyhedron_normaliz._init_from_Hrepresentation(p, [], []) # optional - pynormaliz """ import PyNormaliz if ieqs is None: ieqs = [] nmz_ieqs = [] for ieq in ieqs: d = LCM_list([denominator(ieq_i) for ieq_i in ieq]) dieq = [ZZ(d * ieq_i) for ieq_i in ieq] b = dieq[0] A = dieq[1:] nmz_ieqs.append(A + [b]) if not nmz_ieqs: # If normaliz gets an empty list of inequalities, it adds # nonnegativities. So let's add a tautological inequality to work # around this. nmz_ieqs.append([0] * self.ambient_dim() + [0]) if eqns is None: eqns = [] nmz_eqns = [] for eqn in eqns: d = LCM_list([denominator(eqn_i) for eqn_i in eqn]) deqn = [ZZ(d * eqn_i) for eqn_i in eqn] b = deqn[0] A = deqn[1:] nmz_eqns.append(A + [b]) data = ["inhom_equations", nmz_eqns, "inhom_inequalities", nmz_ieqs] self._normaliz_cone = PyNormaliz.NmzCone(data) if verbose: print("# Calling PyNormaliz.NmzCone({})".format(data)) cone = PyNormaliz.NmzCone(data) assert cone, "NmzCone({}) did not return a cone".format(data) self._init_from_normaliz_cone(cone)
def _init_from_Vrepresentation(self, vertices, rays, lines, minimize=True, verbose=False): r""" Construct polyhedron from V-representation data. INPUT: - ``vertices`` -- list of point; each point can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements - ``rays`` -- list of rays; each ray can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements - ``lines`` -- list of lines; each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements - ``verbose`` -- boolean (default: ``False``); whether to print verbose output for debugging purposes EXAMPLES:: sage: p = Polyhedron(backend='normaliz') # optional - pynormaliz sage: from sage.geometry.polyhedron.backend_normaliz import Polyhedron_normaliz # optional - pynormaliz sage: Polyhedron_normaliz._init_from_Vrepresentation(p, [], [], []) # optional - pynormaliz """ if vertices is None: vertices = [] nmz_vertices = [] for v in vertices: d = LCM_list([denominator(v_i) for v_i in v]) dv = [ d*v_i for v_i in v ] nmz_vertices.append(dv + [d]) if rays is None: rays = [] nmz_rays = [] for r in rays: d = LCM_list([denominator(r_i) for r_i in r]) dr = [ d*r_i for r_i in r ] nmz_rays.append(dr) if lines is None: lines = [] nmz_lines = [] for l in lines: d = LCM_list([denominator(l_i) for l_i in l]) dl = [ d*l_i for l_i in l ] nmz_lines.append(dl) if not nmz_vertices and not nmz_rays and not nmz_lines: # Special case to avoid: # error: Some error in the normaliz input data detected: # All input matrices empty! self._init_empty_polyhedron() else: data = {"vertices": nmz_vertices, "cone": nmz_rays, "subspace": nmz_lines} self._init_from_normaliz_data(data, verbose=verbose)
def _init_from_Hrepresentation(self, ieqs, eqns, minimize=True, verbose=False): """ Construct polyhedron from H-representation data. INPUT: - ``ieqs`` -- list of inequalities. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``eqns`` -- list of equalities. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_ppl sage: Polyhedron_ppl._init_from_Hrepresentation(p, [], []) """ cs = Constraint_System() if ieqs is None: ieqs = [] for ieq in ieqs: d = LCM_list([denominator(ieq_i) for ieq_i in ieq]) dieq = [ZZ(d * ieq_i) for ieq_i in ieq] b = dieq[0] A = dieq[1:] cs.insert(Linear_Expression(A, b) >= 0) if eqns is None: eqns = [] for eqn in eqns: d = LCM_list([denominator(eqn_i) for eqn_i in eqn]) deqn = [ZZ(d * eqn_i) for eqn_i in eqn] b = deqn[0] A = deqn[1:] cs.insert(Linear_Expression(A, b) == 0) if cs.empty(): self._ppl_polyhedron = C_Polyhedron(self.ambient_dim(), 'universe') else: self._ppl_polyhedron = C_Polyhedron(cs) self._init_Vrepresentation_from_ppl(minimize) self._init_Hrepresentation_from_ppl(minimize)
def _convert_constraint_to_ppl(c, typ): r""" Convert a constraint to ``ppl``. INPUT: - ``c`` -- an inequality or equation. - ``typ`` -- integer; 0 -- inequality; 3 -- equation EXAMPLES:: sage: P = Polyhedron() sage: P._convert_constraint_to_ppl([1, 1/2, 3], 0) x0+6*x1+2>=0 sage: P._convert_constraint_to_ppl([1, 1/2, 3], 1) x0+6*x1+2==0 """ d = LCM_list([denominator(c_i) for c_i in c]) dc = [ZZ(d * c_i) for c_i in c] b = dc[0] A = dc[1:] if typ == 0: return Linear_Expression(A, b) >= 0 else: return Linear_Expression(A, b) == 0
def projective_point(p): """ Return equivalent point with denominators removed INPUT: - ``P``, ``Q`` -- list/tuple of projective coordinates. OUTPUT: List of projective coordinates. EXAMPLES:: sage: from sage.schemes.elliptic_curves.constructor import projective_point sage: projective_point([4/5, 6/5, 8/5]) [2, 3, 4] sage: F = GF(11) sage: projective_point([F(4), F(8), F(2)]) [4, 8, 2] """ from sage.rings.integer import GCD_list from sage.arith.functions import LCM_list try: p_gcd = GCD_list([x.numerator() for x in p]) p_lcm = LCM_list(x.denominator() for x in p) except AttributeError: return p scale = p_lcm / p_gcd return [scale * x for x in p]
def additive_order(self): r""" Return the additive order of this element. EXAMPLES:: sage: G = cartesian_product([Zmod(3), Zmod(6), Zmod(5)]) sage: G((1,1,1)).additive_order() 30 sage: any((i * G((1,1,1))).is_zero() for i in range(1,30)) False sage: 30 * G((1,1,1)) (0, 0, 0) sage: G = cartesian_product([ZZ, ZZ]) sage: G((0,0)).additive_order() 1 sage: G((0,1)).additive_order() +Infinity sage: K = GF(9) sage: H = cartesian_product([cartesian_product([Zmod(2),Zmod(9)]), K]) sage: z = H(((1,2), K.gen())) sage: z.additive_order() 18 """ from sage.rings.infinity import Infinity orders = [x.additive_order() for x in self.cartesian_factors()] if any(o is Infinity for o in orders): return Infinity else: from sage.arith.functions import LCM_list return LCM_list(orders)
def _init_from_Vrepresentation(self, vertices, rays, lines, minimize=True, verbose=False): """ Construct polyhedron from V-representation data. INPUT: - ``vertices`` -- list of point. Each point can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``rays`` -- list of rays. Each ray can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``lines`` -- list of lines. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_ppl sage: Polyhedron_ppl._init_from_Vrepresentation(p, [], [], []) """ gs = Generator_System() if vertices is None: vertices = [] for v in vertices: d = LCM_list([denominator(v_i) for v_i in v]) if d.is_one(): gs.insert(point(Linear_Expression(v, 0))) else: dv = [ d*v_i for v_i in v ] gs.insert(point(Linear_Expression(dv, 0), d)) if rays is None: rays = [] for r in rays: d = LCM_list([denominator(r_i) for r_i in r]) if d.is_one(): gs.insert(ray(Linear_Expression(r, 0))) else: dr = [ d*r_i for r_i in r ] gs.insert(ray(Linear_Expression(dr, 0))) if lines is None: lines = [] for l in lines: d = LCM_list([denominator(l_i) for l_i in l]) if d.is_one(): gs.insert(line(Linear_Expression(l, 0))) else: dl = [ d*l_i for l_i in l ] gs.insert(line(Linear_Expression(dl, 0))) if gs.empty(): self._ppl_polyhedron = C_Polyhedron(self.ambient_dim(), 'empty') else: self._ppl_polyhedron = C_Polyhedron(gs) self._init_Vrepresentation_from_ppl(minimize) self._init_Hrepresentation_from_ppl(minimize)
def _convert_generator_to_ppl(v, typ): r""" Convert a generator to ``ppl``. INPUT: - ``v`` -- a vertex, ray, or line. - ``typ`` -- integer; 2 -- vertex; 3 -- ray; 4 -- line EXAMPLES:: sage: P = Polyhedron() sage: P._convert_generator_to_ppl([1, 1/2, 3], 2) point(2/2, 1/2, 6/2) sage: P._convert_generator_to_ppl([1, 1/2, 3], 3) ray(2, 1, 6) sage: P._convert_generator_to_ppl([1, 1/2, 3], 4) line(2, 1, 6) """ if typ == 2: ob = point elif typ == 3: ob = ray else: ob = line d = LCM_list([denominator(v_i) for v_i in v]) if d.is_one(): return ob(Linear_Expression(v, 0)) else: dv = [d * v_i for v_i in v] if typ == 2: return ob(Linear_Expression(dv, 0), d) else: return ob(Linear_Expression(dv, 0))
def multiplicative_order(self): r""" Return the multiplicative order of this element. EXAMPLES:: sage: G1 = SymmetricGroup(3) sage: G2 = SL(2,3) sage: G = cartesian_product([G1,G2]) sage: G((G1.gen(0), G2.gen(1))).multiplicative_order() 12 """ from sage.rings.infinity import Infinity orders = [x.multiplicative_order() for x in self.cartesian_factors()] if any(o is Infinity for o in orders): return Infinity else: from sage.arith.functions import LCM_list return LCM_list(orders)
def _init_from_Vrepresentation(self, vertices, rays, lines, minimize=True, verbose=False): """ Construct polyhedron from V-representation data. INPUT: - ``vertices`` -- list of point. Each point can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``rays`` -- list of rays. Each ray can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``lines`` -- list of lines. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_ppl sage: Polyhedron_ppl._init_from_Vrepresentation(p, [], [], []) """ gs = Generator_System() if vertices is None: vertices = [] for v in vertices: d = LCM_list([denominator(v_i) for v_i in v]) if d.is_one(): gs.insert(point(Linear_Expression(v, 0))) else: dv = [d * v_i for v_i in v] gs.insert(point(Linear_Expression(dv, 0), d)) if rays is None: rays = [] for r in rays: d = LCM_list([denominator(r_i) for r_i in r]) if d.is_one(): gs.insert(ray(Linear_Expression(r, 0))) else: dr = [d * r_i for r_i in r] gs.insert(ray(Linear_Expression(dr, 0))) if lines is None: lines = [] for l in lines: d = LCM_list([denominator(l_i) for l_i in l]) if d.is_one(): gs.insert(line(Linear_Expression(l, 0))) else: dl = [d * l_i for l_i in l] gs.insert(line(Linear_Expression(dl, 0))) if gs.empty(): self._ppl_polyhedron = C_Polyhedron(self.ambient_dim(), 'empty') else: self._ppl_polyhedron = C_Polyhedron(gs) self._init_Vrepresentation_from_ppl(minimize) self._init_Hrepresentation_from_ppl(minimize)