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 _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 gamma__exact(n): """ Evaluates the exact value of the gamma function at an integer or half-integer argument. EXAMPLES:: sage: gamma__exact(4) 6 sage: gamma__exact(3) 2 sage: gamma__exact(2) 1 sage: gamma__exact(1) 1 sage: gamma__exact(1/2) sqrt(pi) sage: gamma__exact(3/2) 1/2*sqrt(pi) sage: gamma__exact(5/2) 3/4*sqrt(pi) sage: gamma__exact(7/2) 15/8*sqrt(pi) sage: gamma__exact(-1/2) -2*sqrt(pi) sage: gamma__exact(-3/2) 4/3*sqrt(pi) sage: gamma__exact(-5/2) -8/15*sqrt(pi) sage: gamma__exact(-7/2) 16/105*sqrt(pi) """ from sage.all import sqrt ## SANITY CHECK if (not n in QQ) or (denominator(n) > 2): raise TypeError, "Oops! You much give an integer or half-integer argument." if (denominator(n) == 1): if n <= 0: return infinity if n > 0: return factorial(n-1) else: ans = QQ(1) while (n != QQ(1)/2): if (n<0): ans *= QQ(1)/n n = n + 1 elif (n>0): n = n - 1 ans *= n ans *= sqrt(pi) return ans
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 _borcherds_product_polyhedron(self, pole_order, prec, verbose=False): r""" Construct a polyhedron representing a cone of Heegner divisors. For internal use in the methods borcherds_input_basis() and borcherds_input_Qbasis(). INPUT: - ``pole_order`` -- pole order - ``prec`` -- precision OUTPUT: a tuple consisting of an integral matrix M, a Polyhedron p, and a WeilRepModularFormsBasis X EXAMPLES:: sage: from weilrep import * sage: m = ParamodularForms(5) sage: m._borcherds_product_polyhedron(1/4, 5)[1] A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 1 vertex and 2 rays """ S = self.gram_matrix() wt = self.input_wt() w = self.weilrep() rds = w.rds() norm_dict = w.norm_dict() X = w.nearly_holomorphic_modular_forms_basis(wt, pole_order, prec, verbose=verbose) N = len([g for g in rds if not norm_dict[tuple(g)]]) v_list = w.coefficient_vector_exponents(0, 1, starting_from=-pole_order, include_vectors=True) exp_list = [v[1] for v in v_list] v_list = [vector(v[0]) for v in v_list] positive = [None] * len(exp_list) zero = vector([0] * (len(exp_list) + 1)) M = matrix([ x.coefficient_vector(starting_from=-pole_order, ending_with=0)[:-N] for x in X ]) vs = M.transpose().kernel().basis() for i, n in enumerate(exp_list): ieq = copy(zero) ieq[i + 1] = 1 for j, m in enumerate(exp_list[:i]): N = sqrt(m / n) if N in ZZ: v1 = v_list[i] v2 = v_list[j] ieq[j + 1] = denominator(v1 * N - v2) == 1 or denominator(v1 * N + v2) == 1 positive[i] = ieq p = Polyhedron(ieqs=positive, eqns=[vector([0] + list(v)) for v in vs]) return M, p, X
def _init_from_Vrepresentation(self, ambient_dim, vertices, rays, lines, minimize=True): """ Construct polyhedron from V-representation data. INPUT: - ``ambient_dim`` -- integer. The dimension of the ambient space. - ``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. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_QQ_ppl sage: Polyhedron_QQ_ppl._init_from_Vrepresentation(p, 2, [], [], []) """ gs = Generator_System() if vertices is None: vertices = [] for v in vertices: d = lcm([denominator(v_i) for v_i in v]) dv = [ZZ(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([denominator(r_i) for r_i in r]) dr = [ZZ(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([denominator(l_i) for l_i in l]) dl = [ZZ(d * l_i) for l_i in l] gs.insert(line(Linear_Expression(dl, 0))) self._ppl_polyhedron = C_Polyhedron(gs) self._init_Vrepresentation_from_ppl(minimize) self._init_Hrepresentation_from_ppl(minimize)
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 __sub__(self, other): r""" Subtract modular forms, rescaling if necessary. """ if not other: return self if not self.gram_matrix() == other.gram_matrix(): raise ValueError('Incompatible Gram matrices') if not self.weight() == other.weight(): raise ValueError('Incompatible weights') self_v = self.weyl_vector() other_v = other.weyl_vector() if self_v or other_v: if not denominator(self_v - other_v) == 1: raise ValueError('Incompatible characters') self_scale = self.scale() other_scale = other.scale() if not self_scale == other_scale: new_scale = lcm(self_scale, other_scale) X1 = self.rescale(new_scale // self_scale) X2 = other.rescale(new_scale // other_scale) return OrthogonalModularForm( self.__weight, self.__weilrep, X1.true_fourier_expansion() - X2.true_fourier_expansion(), scale=new_scale, weylvec=self_v, qexp_representation=self.qexp_representation()) return OrthogonalModularForm( self.__weight, self.__weilrep, self.true_fourier_expansion() - other.true_fourier_expansion(), scale=self_scale, weylvec=self_v, qexp_representation=self.qexp_representation())
def _init_from_Vrepresentation(self, ambient_dim, vertices, rays, lines, minimize=True): """ Construct polyhedron from V-representation data. INPUT: - ``ambient_dim`` -- integer. The dimension of the ambient space. - ``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. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_QQ_ppl sage: Polyhedron_QQ_ppl._init_from_Vrepresentation(p, 2, [], [], []) """ gs = Generator_System() if vertices is None: vertices = [] for v in vertices: d = lcm([denominator(v_i) for v_i in v]) dv = [ ZZ(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([denominator(r_i) for r_i in r]) dr = [ ZZ(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([denominator(l_i) for l_i in l]) dl = [ ZZ(d*l_i) for l_i in l ] gs.insert(line(Linear_Expression(dl, 0))) self._ppl_polyhedron = C_Polyhedron(gs) self._init_Vrepresentation_from_ppl(minimize) self._init_Hrepresentation_from_ppl(minimize)
def _init_from_Hrepresentation(self, ambient_dim, ieqs, eqns, minimize=True): """ Construct polyhedron from H-representation data. INPUT: - ``ambient_dim`` -- integer. The dimension of the ambient space. - ``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. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_QQ_ppl sage: Polyhedron_QQ_ppl._init_from_Hrepresentation(p, 2, [], []) """ cs = Constraint_System() if ieqs is None: ieqs = [] for ieq in ieqs: d = lcm([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([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) self._ppl_polyhedron = C_Polyhedron(cs) self._init_Vrepresentation_from_ppl(minimize) self._init_Hrepresentation_from_ppl(minimize)
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 __init__(self,frame,slope,verts,length): """ Initialises self. See ``Segment`` for full documentation. """ self.frame = frame self.verts = verts self.slope = slope self.length = length if slope != infinity: self.Eplus = (denominator(self.slope) / gcd(denominator(self.slope),int(self.frame.E))) self.psi = self.frame.find_psi(self.slope*self.Eplus) else: self.Eplus = 1 self._associate_polynomial = self.associate_polynomial(cached=False) self.factors = [AssociatedFactor(self,afact[0],afact[1]) for afact in list(self._associate_polynomial.factor())]
def _init_from_Hrepresentation(self, ambient_dim, ieqs, eqns, minimize=True): """ Construct polyhedron from H-representation data. INPUT: - ``ambient_dim`` -- integer. The dimension of the ambient space. - ``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. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_QQ_ppl sage: Polyhedron_QQ_ppl._init_from_Hrepresentation(p, 2, [], []) """ cs = Constraint_System() if ieqs is None: ieqs = [] for ieq in ieqs: d = lcm([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([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) self._ppl_polyhedron = C_Polyhedron(cs) 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 gamma__exact(n): r""" Evaluates the exact value of the `\Gamma` function at an integer or half-integer argument. EXAMPLES:: sage: gamma__exact(4) 6 sage: gamma__exact(3) 2 sage: gamma__exact(2) 1 sage: gamma__exact(1) 1 sage: gamma__exact(1/2) sqrt(pi) sage: gamma__exact(3/2) 1/2*sqrt(pi) sage: gamma__exact(5/2) 3/4*sqrt(pi) sage: gamma__exact(7/2) 15/8*sqrt(pi) sage: gamma__exact(-1/2) -2*sqrt(pi) sage: gamma__exact(-3/2) 4/3*sqrt(pi) sage: gamma__exact(-5/2) -8/15*sqrt(pi) sage: gamma__exact(-7/2) 16/105*sqrt(pi) TESTS:: sage: gamma__exact(1/3) Traceback (most recent call last): ... TypeError: you must give an integer or half-integer argument """ from sage.all import sqrt n = QQ(n) if denominator(n) == 1: if n <= 0: return infinity if n > 0: return factorial(n - 1) elif denominator(n) == 2: ans = QQ.one() while n != QQ((1, 2)): if n < 0: ans /= n n += 1 elif n > 0: n += -1 ans *= n ans *= sqrt(pi) return ans else: raise TypeError("you must give an integer or half-integer argument")
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 """ import 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 ] 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): """ 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 level(self): r""" Determines the level of the quadratic form over a PID, which is a generator for the smallest ideal `N` of `R` such that N * (the matrix of 2*Q)^(-1) is in R with diagonal in 2*R. Over `\ZZ` this returns a non-negative number. (Caveat: This always returns the unit ideal when working over a field!) EXAMPLES:: sage: Q = QuadraticForm(ZZ, 2, range(1,4)) sage: Q.level() 8 sage: Q1 = QuadraticForm(QQ, 2, range(1,4)) sage: Q1.level() # random UserWarning: Warning -- The level of a quadratic form over a field is always 1. Do you really want to do this?!? 1 sage: Q = DiagonalQuadraticForm(ZZ, [1,3,5,7]) sage: Q.level() 420 """ ## Try to return the cached level try: return self.__level except AttributeError: ## Check that the base ring is a PID if not is_PrincipalIdealDomain(self.base_ring()): raise TypeError("Oops! The level (as a number) is only defined over a Principal Ideal Domain. Try using level_ideal().") ## Warn the user if the form is defined over a field! if self.base_ring().is_field(): warn("Warning -- The level of a quadratic form over a field is always 1. Do you really want to do this?!?") #raise RuntimeError, "Warning -- The level of a quadratic form over a field is always 1. Do you really want to do this?!?" ## Check invertibility and find the inverse try: mat_inv = self.matrix()**(-1) except ZeroDivisionError: raise TypeError("Oops! The quadratic form is degenerate (i.e. det = 0). =(") ## Compute the level inv_denoms = [] for i in range(self.dim()): for j in range(i, self.dim()): if (i == j): inv_denoms += [denominator(mat_inv[i,j] / 2)] else: inv_denoms += [denominator(mat_inv[i,j])] lvl = LCM(inv_denoms) lvl = ideal(self.base_ring()(lvl)).gen() ############################################################## ## To do this properly, the level should be the inverse of the ## fractional ideal (over R) generated by the entries whose ## denominators we take above. =) ############################################################## ## Normalize the result over ZZ if self.base_ring() == IntegerRing(): lvl = abs(lvl) ## Cache and return the level self.__level = lvl return lvl
def gamma__exact(n): """ Evaluates the exact value of the `\Gamma` function at an integer or half-integer argument. EXAMPLES:: sage: gamma__exact(4) 6 sage: gamma__exact(3) 2 sage: gamma__exact(2) 1 sage: gamma__exact(1) 1 sage: gamma__exact(1/2) sqrt(pi) sage: gamma__exact(3/2) 1/2*sqrt(pi) sage: gamma__exact(5/2) 3/4*sqrt(pi) sage: gamma__exact(7/2) 15/8*sqrt(pi) sage: gamma__exact(-1/2) -2*sqrt(pi) sage: gamma__exact(-3/2) 4/3*sqrt(pi) sage: gamma__exact(-5/2) -8/15*sqrt(pi) sage: gamma__exact(-7/2) 16/105*sqrt(pi) TESTS:: sage: gamma__exact(1/3) Traceback (most recent call last): ... TypeError: you must give an integer or half-integer argument """ from sage.all import sqrt n = QQ(n) if denominator(n) == 1: if n <= 0: return infinity if n > 0: return factorial(n-1) elif denominator(n) == 2: ans = QQ.one() while n != QQ((1, 2)): if n < 0: ans /= n n += 1 elif n > 0: n += -1 ans *= n ans *= sqrt(pi) return ans else: raise TypeError("you must give an integer or half-integer argument")
def find_psi(self,val): """ Find a polynomial (as a FrameElt) with given valuation INPUT: - ``val`` - Rational. The desired valuation. The denominator of ``val`` must divide the current level of ramification (``E``). OUTPUT: - A FrameElt with respect to the current frame with valuation ``val``. EXAMPLES:: First we need an appropriate Frame:: sage: from sage.rings.polynomial.padics.factor.frame import * sage: Phi = ZpFM(2,20,'terse')['x'](x^16+16) sage: f = Frame(Phi) sage: f.seed(Phi.parent().gen()) sage: f = f.polygon[0].factors[0].next_frame() sage: f Frame with phi (1 + O(2^20))*x^4 + (1048574 + O(2^20)) We get a valid FrameElt with integer exponents as long as the denominator of ``val`` divides the current ramification:: sage: f.E 4 sage: f.prev.segment.slope 1/4 sage: f.find_psi(7/4) [[1*2^1]phi1^3] sage: f.find_psi(7/4).polynomial() (2 + O(2^20))*x^3 If the denominator does not divide the ramification, then we cannot construct a polynomial of this valuation and an error is raised:: sage: f.find_psi(3/8) Traceback (most recent call last): ... ValueError: Denominator of given valuation does not divide E """ if not self.E % denominator(val) == 0: raise ValueError, "Denominator of given valuation does not divide E" psielt = FrameElt(self) if self.prev == None: psielt.terms = [FrameEltTerm(psielt,self.O(1),val)] else: vphi = self.prev.segment.slope d = self.prev_frame().E vprime = val*d e = vphi * d psimod = denominator(e) s = 0 if not psimod == 1: s = vprime / e if denominator(s) == 1: s = s % psimod else: s = int(s % psimod) val = val - s * vphi psielt.terms = [FrameEltTerm(psielt,self.prev_frame().find_psi(val),s)] return psielt