def _fast_eval(self, x): """ Evaluate affine morphism at point described by ``x``. EXAMPLES:: sage: P.<x,y,z> = AffineSpace(GF(7), 3) sage: H = Hom(P, P) sage: f = H([x^2+y^2,y^2, z^2 + y*z]) sage: f._fast_eval([1, 1, 1]) [2, 1, 2] :: sage: P.<x,y,z> = AffineSpace(GF(19), 3) sage: H = Hom(P, P) sage: f = H([x/(y+1), y, (z^2 + y^2)/(x^2 + 1)]) sage: f._fast_eval([2, 1, 3]) [1, 1, 2] """ R = self.domain().ambient_space().coordinate_ring() P = [] for i in range(len(self._fastpolys[0])): r = self._fastpolys[0][i](*x) if self._fastpolys[1][i] is R.one(): if self._is_prime_finite_field: p = self.base_ring().characteristic() r = Integer(r) % p P.append(r) else: s = self._fastpolys[1][i](*x) if self._is_prime_finite_field: p = self.base_ring().characteristic() r = Integer(r) % p s = Integer(s) % p P.append(r / s) return P
def __init__(self, N, R = QQ, names = None): r""" The Python constructor INPUT: - ``N`` - a list or tuple of positive integers - ``R`` - a ring - ``names`` - a tuple or list of strings. This must either be a single variable name or the complete list of variables. EXAMPLES:: sage: T.<x,y,z,u,v,w> = ProductProjectiveSpaces([2,2],QQ) sage: T Product of projective spaces P^2 x P^2 over Rational Field sage: T.coordinate_ring() Multivariate Polynomial Ring in x, y, z, u, v, w over Rational Field sage: T[1].coordinate_ring() Multivariate Polynomial Ring in u, v, w over Rational Field :: sage: ProductProjectiveSpaces([1,1,1],ZZ, ['x','y','z','u','v','w']) Product of projective spaces P^1 x P^1 x P^1 over Integer Ring :: sage: T = ProductProjectiveSpaces([1,1],QQ,'z') sage: T.coordinate_ring() Multivariate Polynomial Ring in z0, z1, z2, z3 over Rational Field """ assert isinstance(N, (tuple, list)) N = [Integer(n) for n in N] assert is_CommutativeRing(R) if len(N) < 2: raise ValueError("Must be at least two components for a product") AmbientSpace.__init__(self, sum(N), R) self._dims = N start = 0 self._components = [] for i in range(len(N)): self._components.append(ProjectiveSpace(N[i],R,names[start:start+N[i]+1])) start += N[i]+1 #Note that the coordinate ring should really be the tensor product of the component #coordinate rings. But we just deal with them as multihomogeneous polynomial rings self._coordinate_ring = PolynomialRing(R,sum(N)+ len(N),names)
def SymmetricPresentation(n): r""" Build the Symmetric group of order `n!` as a finitely presented group. INPUT: - ``n`` -- The size of the underlying set of arbitrary symbols being acted on by the Symmetric group of order `n!`. OUTPUT: Symmetric group as a finite presentation, implementation uses GAP to find an isomorphism from a permutation representation to a finitely presented group representation. Due to this fact, the exact output presentation may not be the same for every method call on a constant ``n``. EXAMPLES:: sage: S4 = groups.presentation.Symmetric(4) sage: S4.as_permutation_group().is_isomorphic(SymmetricGroup(4)) True TESTS:: sage: S = [groups.presentation.Symmetric(i) for i in range(1,4)]; S[0].order() 1 sage: S[1].order(), S[2].as_permutation_group().is_isomorphic(DihedralGroup(3)) (2, True) sage: S5 = groups.presentation.Symmetric(5) sage: perm_S5 = S5.as_permutation_group(); perm_S5.is_isomorphic(SymmetricGroup(5)) True sage: groups.presentation.Symmetric(8).order() 40320 """ from sage.groups.perm_gps.permgroup_named import SymmetricGroup from sage.groups.free_group import _lexi_gen n = Integer(n) perm_rep = SymmetricGroup(n) GAP_fp_rep = libgap.Image( libgap.IsomorphismFpGroupByGenerators(perm_rep, perm_rep.gens())) image_gens = GAP_fp_rep.FreeGeneratorsOfFpGroup() name_itr = _lexi_gen() # Python generator object for variable names F = FreeGroup([next(name_itr) for x in perm_rep.gens()]) ret_rls = tuple([ F(rel_word.TietzeWordAbstractWord(image_gens).sage()) for rel_word in GAP_fp_rep.RelatorsOfFpGroup() ]) return FinitelyPresentedGroup(F, ret_rls)
def compute_kappa_lambda_Q_from_mu_nu(self): """ Computes some kappa, lambda and Q from mu, nu, which might not be optimal for computational purposes """ try: from sage.functions.other import sqrt from sage.rings.all import Integer from math import pi self.Q_fe = float( sqrt(Integer(self.level)) / 2.**len(self.nu_fe) / pi**(len(self.mu_fe) / 2. + len(self.nu_fe))) self.kappa_fe = [.5 for m in self.mu_fe] + [1. for n in self.nu_fe] self.lambda_fe = [m / 2. for m in self.mu_fe] + [n for n in self.nu_fe] except Exception as e: raise Exception("Expecting a mu and a nu to be defined" + str(e))
def __init__(self, n, R=ZZ): """ TESTS:: sage: from sage.schemes.generic.ambient_space import AmbientSpace sage: A = AmbientSpace(5, ZZ) sage: TestSuite(A).run() # not tested (abstract scheme with no elements?) """ if not isinstance(R, CommutativeRing): raise TypeError("R (=%s) must be a commutative ring" % R) n = Integer(n) if n < 0: raise ValueError("n (=%s) must be nonnegative" % n) self._dimension_relative = n Scheme.__init__(self, R)
def one_charpoly(v, filename=None): """ Compute and factor one characteristic polynomials for all the levels in v. Always compute the charpoly of T_P where P is the smallest prime not dividing the level. """ F = open(filename, 'a') if filename else None P = [p for p in ideals_of_bounded_norm(100) if p.is_prime()] for N in ideals_of_norm(v): NN = Integer(N.norm()) t = cputime() H = sqrt5_fast.IcosiansModP1ModN(N) t0 = cputime(t) for p in P: if Integer(p.norm()).gcd(NN) == 1: break t = cputime() T = H.hecke_matrix(p) t1 = cputime(t) t = cputime() f = T.fcp() t2 = cputime(t) s = '%s\t%s\t%s\t%s\t%s\t(%.1f,%.1f,%.1f)' % ( N.norm(), no_space(canonical_gen(N)), p.smallest_integer(), no_space(canonical_gen(p)), no_space(f), t0, t1, t2, ) print s if F: F.write(s + '\n') F.flush()
def AlternatingPresentation(n): r""" Build the Alternating group of order `n!/2` as a finitely presented group. INPUT: - ``n`` -- The size of the underlying set of arbitrary symbols being acted on by the Alternating group of order `n!/2`. OUTPUT: Alternating group as a finite presentation, implementation uses GAP to find an isomorphism from a permutation representation to a finitely presented group representation. Due to this fact, the exact output presentation may not be the same for every method call on a constant ``n``. EXAMPLES:: sage: A6 = groups.presentation.Alternating(6) sage: A6.as_permutation_group().is_isomorphic(AlternatingGroup(6)), A6.order() (True, 360) TESTS:: sage: #even permutation test.. sage: A1 = groups.presentation.Alternating(1); A2 = groups.presentation.Alternating(2) sage: A1.is_isomorphic(A2), A1.order() (True, 1) sage: A3 = groups.presentation.Alternating(3); A3.order(), A3.as_permutation_group().is_cyclic() (3, True) sage: A8 = groups.presentation.Alternating(8); A8.order() 20160 """ from sage.groups.perm_gps.permgroup_named import AlternatingGroup from sage.groups.free_group import _lexi_gen n = Integer(n) perm_rep = AlternatingGroup(n) GAP_fp_rep = libgap.Image( libgap.IsomorphismFpGroupByGenerators(perm_rep, perm_rep.gens())) image_gens = GAP_fp_rep.FreeGeneratorsOfFpGroup() name_itr = _lexi_gen() # Python generator object for variable names F = FreeGroup([next(name_itr) for x in perm_rep.gens()]) ret_rls = tuple([ F(rel_word.TietzeWordAbstractWord(image_gens).sage()) for rel_word in GAP_fp_rep.RelatorsOfFpGroup() ]) return FinitelyPresentedGroup(F, ret_rls)
def taylor_series(self, a=0, k=6, var='z'): r""" Return the first `k` terms of the Taylor series expansion of the `L`-series about `a`. This is returned as a series in ``var``, where you should view ``var`` as equal to `s-a`. Thus this function returns the formal power series whose coefficients are `L^{(n)}(a)/n!`. INPUT: - ``a`` - complex number (default: 0); point about which to expand - ``k`` - integer (default: 6), series is `O(``var``^k)` - ``var`` - string (default: 'z'), variable of power series EXAMPLES:: sage: L = Dokchitser(conductor=1, gammaV=[0], weight=1, eps=1, poles=[1], residues=[-1], init='1') sage: L.taylor_series(2, 3) 1.64493406684823 - 0.937548254315844*z + 0.994640117149451*z^2 + O(z^3) sage: E = EllipticCurve('37a') sage: L = E.lseries().dokchitser() sage: L.taylor_series(1) 0.000000000000000 + 0.305999773834052*z + 0.186547797268162*z^2 - 0.136791463097188*z^3 + 0.0161066468496401*z^4 + 0.0185955175398802*z^5 + O(z^6) We compute a Taylor series where each coefficient is to high precision. :: sage: E = EllipticCurve('389a') sage: L = E.lseries().dokchitser(200) sage: L.taylor_series(1,3) 6.2240188634103774348273446965620801288836328651973234573133e-73 + (-3.527132447498646306292650465494647003849868770...e-73)*z + 0.75931650028842677023019260789472201907809751649492435158581*z^2 + O(z^3) """ self.__check_init() a = self.__CC(a) k = Integer(k) try: z = self.gp()('Vec(Lseries(%s,,%s))' % (a, k - 1)) except TypeError, msg: raise RuntimeError, "%s\nUnable to compute Taylor expansion (try lowering the number of terms)" % msg
def _element_constructor_(self, x): r""" TESTS:: sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_basicmonoids import * sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_ring import EquivariantMonoidPowerSeriesRing_generic sage: emps = EquivariantMonoidPowerSeriesRing_generic(NNMonoid(True), TrivialCharacterMonoid("1", QQ), TrivialRepresentation("1", QQ)) sage: h = emps(1) sage: h = emps(emps.monoid().zero_element()) sage: h = emps.zero_element() sage: K.<rho> = CyclotomicField(6) sage: emps = EquivariantMonoidPowerSeriesRing_generic(NNMonoid(True), TrivialCharacterMonoid("1", QQ), TrivialRepresentation("1", K)) sage: h = emps(rho) sage: h = emps(1) """ if isinstance(x, int): x = Integer(x) if isinstance(x, Element): P = x.parent() if P is self.coefficient_domain(): return self._element_class( self, { self.characters().one_element(): { self.monoid().zero_element(): x } }, self.action().filter_all()) elif self.coefficient_domain().has_coerce_map_from(P): return self._element_class( self, { self.characters().one_element(): { self.monoid().zero_element(): self.coefficient_domain()(x) } }, self.action().filter_all()) elif P is self.monoid(): return self._element_class(self, { self.characters().one_element(): { x: self.base_ring().one_element() } }, self.action().filter_all(), symmetrise=True) return EquivariantMonoidPowerSeriesAmbient_abstract._element_constructor_( self, x)
def hecke_polynomial(self, n, var='x'): """ Return the n-th Hecke polynomial on this integral homology group. EXAMPLES:: sage: f = J0(43).integral_homology().hecke_polynomial(2) sage: f.base_ring() Integer Ring sage: factor(f) (x + 2)^2 * (x^2 - 2)^2 """ n = Integer(n) M = self.abelian_variety().modular_symbols(sign=1) f = (M.hecke_polynomial(n, var)**2).change_ring(ZZ) return f
def n_facets(self): """ EXAMPLES:: sage: P = polymake.convex_hull([[1,0,0,0], [1,0,0,1], [1,0,1,0], [1,0,1,1], [1,1,0,0], [1,1,0,1], [1,1,1,0], [1,1,1,1]]) # optional - polymake sage: P.n_facets() # optional - polymake 6 """ try: return self.__n_facets except AttributeError: pass s = self.cmd('N_FACETS') i = s.find('\n') self.__n_facets = Integer(s[i:]) return self.__n_facets
def derivative(self, order=1): r""" Return the species-theoretic `n`-th derivative of ``self``, where `n` is ``order``. For a cycle index series `F (p_{1}, p_{2}, p_{3}, \ldots)`, its derivative is the cycle index series `F' = D_{p_{1}} F` (that is, the formal derivative of `F` with respect to the variable `p_{1}`). If `F` is the cycle index series of a species `S` then `F'` is the cycle index series of an associated species `S'` of `S`-structures with a "hole". EXAMPLES: The species `E` of sets satisfies the relationship `E' = E`:: sage: E = species.SetSpecies().cycle_index_series() sage: E.coefficients(8) == E.derivative().coefficients(8) True The species `C` of cyclic orderings and the species `L` of linear orderings satisfy the relationship `C' = L`:: sage: C = species.CycleSpecies().cycle_index_series() sage: L = species.LinearOrderSpecies().cycle_index_series() sage: L.coefficients(8) == C.derivative().coefficients(8) True """ # Make sure that order is integral order = Integer(order) if order < 0: raise ValueError("Order must be a non-negative integer") elif order == 0: return self elif order == 1: parent = self.parent() derivative_term = lambda n: parent.term( self.coefficient(n + 1).derivative_with_respect_to_p1(), n) return parent.sum_generator( derivative_term(i) for i in _integers_from(0)) else: return self.derivative(order - 1)
def eigenvalues(self, primes): """ Return the eigenvalues of the Hecke operators corresponding to the primes in the input list of primes. The eigenvalues match up between one prime and the next. INPUT: - ``primes`` - a list of primes OUTPUT: list of lists of eigenvalues. EXAMPLES:: sage: n = numerical_eigenforms(1,12) sage: n.eigenvalues([3,5,13]) # rel tol 2.4e-10 [[177148.0, 252.00000000001896], [48828126.0, 4830.000000001376], [1792160394038.0, -577737.9999898539]] """ primes = [Integer(p) for p in primes] for p in primes: if not p.is_prime(): raise ValueError('each element of primes must be prime.') phi_x, phi_x_inv, nzp, x_nzp = self._eigendata() B = self._eigenvectors() def phi(y): """ Take coefficients and a basis, and return that linear combination of basis vectors. EXAMPLES:: sage: n = numerical_eigenforms(1,12) # indirect doctest sage: n.eigenvalues([3,5,13]) # rel tol 2.4e-10 [[177148.0, 252.00000000001896], [48828126.0, 4830.000000001376], [1792160394038.0, -577737.9999898539]] """ return y.element() * B ans = [] m = self.modular_symbols().ambient_module() for p in primes: t = m._compute_hecke_matrix_prime(p, nzp) w = phi(x_nzp * t) ans.append([w[i] * phi_x_inv[i] for i in range(w.degree())]) return ans
def character_table(self): r""" Returns the matrix of values of the irreducible characters of this group `G` at its conjugacy classes. The columns represent the conjugacy classes of `G` and the rows represent the different irreducible characters in the ordering given by GAP. OUTPUT: a matrix defined over a cyclotomic field EXAMPLES:: sage: MatrixGroup(SymmetricGroup(2)).character_table() [ 1 -1] [ 1 1] sage: MatrixGroup(SymmetricGroup(3)).character_table() [ 1 1 -1] [ 2 -1 0] [ 1 1 1] sage: MatrixGroup(SymmetricGroup(5)).character_table() [ 1 1 1 1 1 1 1] [ 1 -1 -1 1 -1 1 1] [ 4 0 1 -1 -2 1 0] [ 4 0 -1 -1 2 1 0] [ 5 -1 1 0 1 -1 1] [ 5 1 -1 0 -1 -1 1] [ 6 0 0 1 0 0 -2] """ #code from function in permgroup.py, but modified for #how gap handles these groups. G = self._gap_() cl = self.conjugacy_classes() from sage.rings.all import Integer n = Integer(len(cl)) irrG = G.Irr() ct = [[irrG[i][j] for j in range(n)] for i in range(n)] from sage.rings.all import CyclotomicField e = irrG.Flat().Conductor() K = CyclotomicField(e) ct = [[K(x) for x in v] for v in ct] # Finally return the result as a matrix. from sage.matrix.all import MatrixSpace MS = MatrixSpace(K, n) return MS(ct)
def hecke_matrix(self, n): """ Return the matrix of the n-th Hecke operator acting on this homology group. EXAMPLES:: sage: t = J1(13).homology(GF(3)).hecke_matrix(3); t [0 0 2 1] [1 1 0 2] [1 1 0 0] [0 1 2 1] sage: t.base_ring() Finite Field of size 3 """ n = Integer(n) return self.abelian_variety()._integral_hecke_matrix(n).change_ring(self.base_ring())
def _compute_q_expansion_basis(self, prec=None): """ Compute q-expansions of a basis for self. EXAMPLES:: sage: sage.modular.modform.cuspidal_submodule.CuspidalSubmodule_level1_Q(ModularForms(1,12))._compute_q_expansion_basis() [ q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 + O(q^6) ] """ if prec is None: prec = self.prec() else: prec = Integer(prec) return vm_basis.victor_miller_basis(self.weight(), prec, cusp_only=True, var='q')
def _load_flag_products(self, file_location="FP.txt"): """Retrieve flag products from a file in store.""" """try:""" f = open(file_location, 'r') tp = 0 self.flag_products = [[] for x in self.types] for line in f: ln = line.strip() if len(ln) < 6: #then it's type index tp = int(ln) else: fp = [Integer(x) for x in ln.split(' ')] self.flag_products[tp].append(fp) """except:
def cm_orders(h, proof=None): """ Return a list of all pairs `(D,f)` where there is a CM order of discriminant `D f^2` with class number h, with `D` a fundamental discriminant. INPUT: - `h` -- positive integer - ``proof`` -- (default: proof.number_field()) OUTPUT: - list of 2-tuples `(D,f)` EXAMPLES:: sage: cm_orders(0) [] sage: v = cm_orders(1); v [(-3, 3), (-3, 2), (-3, 1), (-4, 2), (-4, 1), (-7, 2), (-7, 1), (-8, 1), (-11, 1), (-19, 1), (-43, 1), (-67, 1), (-163, 1)] sage: type(v[0][0]), type(v[0][1]) (<type 'sage.rings.integer.Integer'>, <type 'sage.rings.integer.Integer'>) sage: v = cm_orders(2); v [(-3, 7), (-3, 5), (-3, 4), (-4, 5), (-4, 4), (-4, 3), (-7, 4), (-8, 3), (-8, 2), (-11, 3), (-15, 2), (-15, 1), (-20, 1), (-24, 1), (-35, 1), (-40, 1), (-51, 1), (-52, 1), (-88, 1), (-91, 1), (-115, 1), (-123, 1), (-148, 1), (-187, 1), (-232, 1), (-235, 1), (-267, 1), (-403, 1), (-427, 1)] sage: len(v) 29 sage: set([hilbert_class_polynomial(D*f^2).degree() for D,f in v]) set([2]) Any degree up to 100 is implemented, but may be prohibitively slow:: sage: cm_orders(3) [(-3, 9), (-3, 6), (-11, 2), (-19, 2), (-23, 2), (-23, 1), (-31, 2), (-31, 1), (-43, 2), (-59, 1), (-67, 2), (-83, 1), (-107, 1), (-139, 1), (-163, 2), (-211, 1), (-283, 1), (-307, 1), (-331, 1), (-379, 1), (-499, 1), (-547, 1), (-643, 1), (-883, 1), (-907, 1)] sage: len(cm_orders(4)) 84 """ h = Integer(h) T = None if h <= 0: # trivial case return [] # Get information for all discriminants then throw away everything # but for h. If this is replaced by a table it will be faster, # but not now. (David Kohel is rumored to have a large table.) return discriminants_with_bounded_class_number(h, proof=proof)[h]
def nest(f, n, x): """ Return `f(f(...f(x)...))`, where the composition occurs n times. See also :func:`compose()` and :func:`self_compose()` INPUT: - `f` -- a function of one variable - `n` -- a nonnegative integer - `x` -- any input for `f` OUTPUT: `f(f(...f(x)...))`, where the composition occurs n times EXAMPLES:: sage: def f(x): return x^2 + 1 sage: x = var('x') sage: nest(f, 3, x) ((x^2 + 1)^2 + 1)^2 + 1 :: sage: _ = function('f') sage: _ = var('x') sage: nest(f, 10, x) f(f(f(f(f(f(f(f(f(f(x)))))))))) :: sage: _ = function('f') sage: _ = var('x') sage: nest(f, 0, x) x """ from sage.rings.all import Integer n = Integer(n) if n < 0: raise ValueError("n must be a nonnegative integer, not {}.".format(n)) for i in range(n): x = f(x) return x
def dimension(self): """ Return the dimension of this Jacobian. OUTPUT: Integer EXAMPLES:: sage: k.<a> = GF(9); R.<x> = k[] sage: HyperellipticCurve(x^3 + x - 1, x+a).jacobian().dimension() 1 sage: g = HyperellipticCurve(x^6 + x - 1, x+a).jacobian().dimension(); g 2 sage: type(g) <type 'sage.rings.integer.Integer'> """ return Integer(self.curve().genus())
def _compute_q_expansion_basis(self, prec=None): r""" Compute q-expansion basis using Schaeffer's algorithm. EXAMPLES:: sage: CuspForms(DirichletGroup(23, QQ).0, 1).q_echelon_basis() # indirect doctest [ q - q^2 - q^3 + O(q^6) ] """ if prec is None: prec = self.prec() else: prec = Integer(prec) chi = self.character() return [weight1.modular_ratio_to_prec(chi, f, prec) for f in weight1.hecke_stable_subspace(chi)]
def hecke_matrix(self, n): """ Return the matrix of the n-th Hecke operator acting on this homology group. EXAMPLES:: sage: J0(48).integral_homology().hecke_bound() 16 sage: t = J1(13).integral_homology().hecke_matrix(3); t [-2 2 2 -2] [-2 0 2 0] [ 0 0 0 -2] [ 0 0 2 -2] sage: t.base_ring() Integer Ring """ n = Integer(n) return self.abelian_variety()._integral_hecke_matrix(n)
def cuboctahedron(self): """ An Archimedean solid with 12 vertices and 14 faces. Dual to the rhombic dodecahedron. EXAMPLES:: sage: co = polytopes.cuboctahedron() sage: co.n_vertices() 12 sage: co.n_inequalities() 14 """ one = Integer(1) v = [ [0, -one/2, -one/2], [0, one/2, -one/2], [one/2, -one/2, 0], [one/2, one/2, 0], [one/2, 0, one/2], [one/2, 0, -one/2], [0, one/2, one/2], [0, -one/2, one/2], [-one/2, 0, one/2], [-one/2, one/2, 0], [-one/2, 0, -one/2], [-one/2, -one/2, 0] ] return Polyhedron(vertices=v)
def _derivative_(self, n, x, diff_param): """ Return the derivative of the Bessel K function. EXAMPLES:: sage: f(x) = bessel_K(10, x) sage: derivative(f, x) x |--> -1/2*bessel_K(11, x) - 1/2*bessel_K(9, x) sage: nu = var('nu') sage: bessel_K(nu, x).diff(nu) Traceback (most recent call last): ... NotImplementedError: derivative with respect to order """ if diff_param == 1: return -(bessel_K(n - 1, x) + bessel_K(n + 1, x)) / Integer(2) else: raise NotImplementedError('derivative with respect to order')
def _compute_q_expansion_basis(self, prec=None): """ Compute q-expansions of a basis for self (via modular symbols). EXAMPLES:: sage: sage.modular.modform.cuspidal_submodule.CuspidalSubmodule_modsym_qexp(ModularForms(11,2))._compute_q_expansion_basis() [ q - 2*q^2 - q^3 + 2*q^4 + q^5 + O(q^6) ] """ if prec is None: prec = self.prec() else: prec = Integer(prec) if self.dimension() == 0: return [] M = self.modular_symbols(sign = 1) return M.q_expansion_basis(prec)
def validate_label(label): parts = label.split('.') if len(parts) != 3: raise ValueError("it must be of the form g.q.iso, with g a dimension and q a prime power") g, q, iso = parts try: g = int(g) except ValueError: raise ValueError("it must be of the form g.q.iso, where g is an integer") try: q = Integer(q) if not q.is_prime_power(): raise ValueError except ValueError: raise ValueError("it must be of the form g.q.iso, where g is a prime power") coeffs = iso.split("_") if len(coeffs) != g: raise ValueError("the final part must be of the form c1_c2_..._cg, with g=%s components"%(g)) if not all(c.isalpha() and c==c.lower() for c in coeffs): raise ValueError("the final part must be of the form c1_c2_..._cg, with each ci consisting of lower case letters")
def apply_TT(self, j): """ Apply the matrix `TT=[-1,-1,0,1]` to the `j`-th Manin symbol. INPUT: - ``j`` - (int) a symbol index OUTPUT: see documentation for apply() EXAMPLES:: sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0 sage: m = ManinSymbolList_gamma0(5,8) sage: m.apply_TT(4) [(38, 1)] sage: [m.apply_TT(i) for i in range(10)] [[(37, 1)], [(41, 1)], [(39, 1)], [(40, 1)], [(38, 1)], [(36, 1)], [(31, -1), (37, 1)], [(35, -1), (41, 1)], [(33, -1), (39, 1)], [(34, -1), (40, 1)]] """ k = self._weight i, u, v = self._symbol_list[j] u, v = self.__syms.normalize(-u - v, u) if (k - 2 - i) % 2 == 0: s = 1 else: s = -1 z = [] a = Integer(i) for j in range(i + 1): m = self.index((k - 2 - i + j, u, v)) z.append((m, s * a.binomial(j))) s *= -1 return z
def atkin_lehner_eigenvalue_numerical(self, t): (tau1, z, tau2) = t from sage.libs.mpmath import mp from sage.libs.mpmath.mp import exp, pi from sage.libs.mpmath.mp import j as i if not Integer(self.__level()).is_prime(): raise ValueError( "The Atkin Lehner involution is only unique if the level is a prime" ) precision = ParamodularFormD2Filter_trace(self.precision()) s = Sequence([tau1, z, tau2]) if not is_ComplexField(s): mp_precision = 30 else: mp_precision = ceil(3.33 * s.universe().precision()) mp.dps = mp_precision (tau1, z, tau2) = tuple(s) (tau1p, zp, tau2p) = (self.level() * tau1, self.level() * z, self.level() * tau2) (e_tau1, e_z, e_tau2) = (exp(2 * pi * i * tau1), exp(2 * pi * i * z), exp(2 * pi * i * tau2)) (e_tau1p, e_zp, e_tau2p) = (exp(2 * pi * i * tau1p), exp(2 * pi * i * zp), exp(2 * pi * i * tau2p)) self_value = s.universe().zero() trans_value = s.universe().zero() for k in precision: (a, b, c) = apply_GL_to_form(self._P1List()(k[1]), k[0]) self_value = self_value + self[k] * (e_tau1**a * e_z**b * e_tau2**c) trans_value = trans_value + self[k] * (e_tau1p**a * e_zp**b * e_tau2p**c) return trans_value / self_value
def apply_T(self, j): """ Apply the matrix `T=[0,1,-1,-1]` to the `j`-th Manin symbol. INPUT: - ``j`` - (int) a symbol index OUTPUT: see documentation for apply() EXAMPLES:: sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_gamma0 sage: m = ManinSymbolList_gamma0(5,8) sage: m.apply_T(4) [(3, 1), (9, -6), (15, 15), (21, -20), (27, 15), (33, -6), (39, 1)] sage: [m.apply_T(i) for i in range(10)] [[(5, 1), (11, -6), (17, 15), (23, -20), (29, 15), (35, -6), (41, 1)], [(0, 1), (6, -6), (12, 15), (18, -20), (24, 15), (30, -6), (36, 1)], [(4, 1), (10, -6), (16, 15), (22, -20), (28, 15), (34, -6), (40, 1)], [(2, 1), (8, -6), (14, 15), (20, -20), (26, 15), (32, -6), (38, 1)], [(3, 1), (9, -6), (15, 15), (21, -20), (27, 15), (33, -6), (39, 1)], [(1, 1), (7, -6), (13, 15), (19, -20), (25, 15), (31, -6), (37, 1)], [(5, 1), (11, -5), (17, 10), (23, -10), (29, 5), (35, -1)], [(0, 1), (6, -5), (12, 10), (18, -10), (24, 5), (30, -1)], [(4, 1), (10, -5), (16, 10), (22, -10), (28, 5), (34, -1)], [(2, 1), (8, -5), (14, 10), (20, -10), (26, 5), (32, -1)]] """ k = self._weight i, u, v = self._symbol_list[j] u, v = self.__syms.normalize(v, -u - v) if (k - 2) % 2 == 0: s = 1 else: s = -1 z = [] a = Integer(k - 2 - i) for j in range(k - 2 - i + 1): m = self.index((j, u, v)) z.append((m, s * a.binomial(j))) s *= -1 return z
def _some_tuples_sampling(elements, repeat, max_samples, n): """ Internal function for :func:`some_tuples`. TESTS:: sage: from sage.misc.misc import _some_tuples_sampling sage: list(_some_tuples_sampling(range(3), 3, 2, 3)) [(0, 1, 0), (1, 1, 1)] sage: list(_some_tuples_sampling(range(20), None, 4, 20)) [0, 6, 9, 3] """ from sage.rings.integer import Integer N = n if repeat is None else n**repeat # We sample on range(N) and create tuples manually since we don't want to create the list of all possible tuples in memory for a in random.sample(range(N), max_samples): if repeat is None: yield elements[a] else: yield tuple(elements[j] for j in Integer(a).digits(n, padto=repeat))