Esempio n. 1
0
 def padically_evaluate(self, shuffle=False):
     if self.root() is None:
         return SR(1)
     r = ((1 - SR('q')**(-1))**(-1) * LocalZetaProcessor.padically_evaluate(
         self, shuffle=shuffle)).factor()
     return r if self.translation is None else r(t=self.translation *
                                                 SR('t')).factor()
Esempio n. 2
0
 def padically_evaluate(self, shuffle=False):
     if self.root() is None:
         return SR(1)
     r = ((1 - SR('q')**(-1))**self.nvertices *
          LocalZetaProcessor.padically_evaluate(self,
                                                shuffle=shuffle)).factor()
     return r
Esempio n. 3
0
def taylor_processor_factored(new_ring, Phi, scalar, alpha, I, omega):
    k = alpha.nrows() - 1
    tau = SR.var('tau')
    y = [SR('y%d' % i) for i in range(k + 1)]

    R = PolynomialRing(QQ, len(y), y)
    beta = [a * Phi for a in alpha]

    ell = len(I)

    def f(i):
        if i == 0:
            return QQ(scalar) * y[0] * exp(tau * omega[0])
        elif i in I:
            return tau / (1 - exp(tau * omega[i]))
        else:
            return 1 / (1 - y[i] * exp(tau * omega[i]))

    H = [
        f(i).series(tau, ell + 1).truncate().collect(tau) for i in range(k + 1)
    ]

    for i in range(k + 1):
        H[i] = [H[i].coefficient(tau, j) for j in range(ell + 1)]

    r = []

    # Get coefficient of tau^ell in prod(H)

    for w in NonnegativeCompositions(ell, k + 1):
        r = prod(
            CyclotomicRationalFunction.from_split_expression(H[i][
                w[i]], y, R).monomial_substitution(new_ring, beta)
            for i in range(k + 1))
        yield r
Esempio n. 4
0
    def build_vts_poly(ts, tcs, mpp_opt):
        vts = [[t.subs(tc) for t in ts] for tc in tcs]
        vts = vset(vts, idfun=repr)

        #add 0 to the end of each vertex and identity elem to terms
        vts = [vt + [SR(0)] for vt in vts]
        ts = ts + [SR(0)]  #the identity element is 0 in MPP

        if mpp_opt == IeqMPP.opt_max_then_min:

            def worker_(Q, ts, is_max_plus):
                Q.put(IeqMPPGen.build_poly(vts, ts, is_max_plus))

            Q = mp.Queue()
            workers = [
                mp.Process(target=worker_, args=(Q, ts, is_max_plus))
                for is_max_plus in [True, False]
            ]
            for w in workers:
                w.start()
            rs = []
            for _ in workers:
                rs.extend(Q.get())

        else:
            is_max_plus = mpp_opt == IeqMPP.opt_max_plus
            rs = IeqMPPGen.build_poly(vts, ts, is_max_plus=is_max_plus)

        return rs
Esempio n. 5
0
 def __init__(self, precision):
     Parent.__init__(self)
     self._precision = precision
     self.register_coercion(MorphismToSPN(ZZ, self, self._precision))
     self.register_coercion(MorphismToSPN(QQ, self, self._precision))
     to_SR = Hom(self, SR, Sets())(lambda x: SR(x.sage()))
     SR.register_coercion(to_SR)
Esempio n. 6
0
 def assertIsReduced(t, m_path, x_name, eps_name):
     M = fuchsia.import_matrix_from_file(m_path)
     x = SR.var(x_name)
     eps = SR.var(eps_name)
     pranks = fuchsia.singularities(M, x).values()
     t.assertEqual(pranks, [0]*len(pranks))
     t.assertTrue(eps not in (M/eps).simplify_rational().variables())
Esempio n. 7
0
    def test_normalize_3(t):
        # Test with non-zero normalized eigenvalues
        x = SR.var("x")
        e = SR.var("epsilon")
        M = matrix([[(1 - e) / x, 0], [0, (1 + e) / 3 / x]])

        with t.assertRaises(FuchsiaError):
            N, T = normalize(M, x, e)
Esempio n. 8
0
 def test_factorize_1(t):
     x = SR.var("x")
     e = SR.var("epsilon")
     M = matrix([[1 / x, 0, 0], [0, 2 / x, 0], [0, 0, 3 / x]]) * e
     M = transform(M, x, matrix([[1, 1, 0], [0, 1, 0], [1 + 2 * e, 0, e]]))
     F, T = factorize(M, x, e)
     F = F.simplify_rational()
     for f in F.list():
         t.assertEqual(limit_fixed(f, e, 0), 0)
Esempio n. 9
0
 def test_is_normalized_1(t):
     x = SR.var("x")
     e = SR.var("epsilon")
     t.assertFalse(is_normalized(matrix([[1 / x / 2]]), x, e))
     t.assertFalse(is_normalized(matrix([[-1 / x / 2]]), x, e))
     t.assertTrue(is_normalized(matrix([[1 / x / 3]]), x, e))
     t.assertFalse(is_normalized(matrix([[x]]), x, e))
     t.assertFalse(is_normalized(matrix([[1 / x**2]]), x, e))
     t.assertTrue (is_normalized( \
             matrix([[(e+SR(1)/3)/x-SR(1)/2/(x-1)]]), x, e))
Esempio n. 10
0
    def test_normalize_1(t):
        # Test with apparent singularities at 0 and oo, but not at 1.
        x = SR.var("x")
        M = matrix([[1 / x, 5 / (x - 1), 0, 6 / (x - 1)], [0, 2 / x, 0, 0],
                    [0, 0, 3 / x, 7 / (x - 1)], [6 / (x - 1), 0, 0, 1 / x]])

        N, T = normalize(M, x, SR.var("epsilon"))
        N = N.simplify_rational()
        t.assertEqual(N, transform(M, x, T).simplify_rational())
        for point, prank in singularities(N, x).iteritems():
            R = matrix_c0(N, x, point, prank)
            evlist = R.eigenvalues()
            t.assertEqual(evlist, [0] * len(evlist))
Esempio n. 11
0
    def test_normalize_4(t):
        # Test with non-zero normalized eigenvalues
        x, e = SR.var("x eps")
        M = matrix([[1 / x / 2, 0], [0, 0]])

        with t.assertRaises(FuchsiaError):
            N, T = normalize(M, x, e)
Esempio n. 12
0
def symbolic_to_polynomial(f, vars):
    # Rewrite a symbolic expression as a polynomial over SR in a given
    # list of variables.

    poly = f.polynomial(QQ)
    allvars = poly.variables()

    indices = []
    for x in allvars:
        try:
            indices.append(vars.index(x))
        except ValueError:
            indices.append(None)

    R = PolynomialRing(SR, len(vars), vars)
    res = R.zero()
    for coeff, alpha in zip(poly.coefficients(), poly.exponents()):
        if type(alpha) == int:
            # Once again, univariate polynomials receive special treatment
            # in Sage.
            alpha = [alpha]

        term = R(coeff)
        for i, e in enumerate(alpha):
            if not e:
                continue
            if indices[i] is None:
                term *= SR(allvars[i]**e)
            else:
                term *= R.gen(indices[i])**e
        res += term
    return res
Esempio n. 13
0
 def __init__(self,dof,name,shortname=None):
   
   self.dof = int(dof)
   self.name = name
   if shortname == None :
     self.shortname = name.replace(' ','_').replace('.','_')
   else :
     self.shortname = shortname.replace(' ','_').replace('.','_')
   
   for i in range(1 ,1 +dof):
     var('q'+str(i),domain=RR)
   
   
   (alpha , a , d , theta) = SR.var('alpha,a,d,theta',domain=RR)
   default_params_dh = [ alpha , a , d , theta  ]
   default_T_dh = matrix( \
   [[ cos(theta), -sin(theta)*cos(alpha), sin(theta)*sin(alpha), a*cos(theta) ], \
   [ sin(theta), cos(theta)*cos(alpha), -cos(theta)*sin(alpha), a*sin(theta) ], \
   [ 0.0, sin(alpha), cos(alpha), d ]
   ,[ 0.0, 0.0, 0.0, 1.0] ] )
   
   #g_a = SR.var('g_a',domain=RR)
   g_a = 9.81
   self.grav = matrix([[0.0],[0.0],[-g_a]])
   
   self.params_dh = default_params_dh
   self.T_dh = default_T_dh
   
   self.links_dh = []
   
   self.motors = []
   self.Imzi = []
   
   self._gensymbols()
Esempio n. 14
0
    def assertReductionWorks(t, filename):
        M = import_matrix_from_file(filename)
        x, eps = SR.var("x eps")
        t.assertIn(x, M.variables())
        M_pranks = singularities(M, x).values()
        t.assertNotEqual(M_pranks, [0] * len(M_pranks))

        #1 Fuchsify
        m, t1 = simplify_by_factorization(M, x)
        Mf, t2 = fuchsify(m, x)
        Tf = t1 * t2
        t.assertTrue((Mf - transform(M, x, Tf)).simplify_rational().is_zero())
        Mf_pranks = singularities(Mf, x).values()
        t.assertEqual(Mf_pranks, [0] * len(Mf_pranks))

        #2 Normalize
        t.assertFalse(is_normalized(Mf, x, eps))
        m, t1 = simplify_by_factorization(Mf, x)
        Mn, t2 = normalize(m, x, eps)
        Tn = t1 * t2
        t.assertTrue((Mn - transform(Mf, x, Tn)).simplify_rational().is_zero())
        t.assertTrue(is_normalized(Mn, x, eps))

        #3 Factorize
        t.assertIn(eps, Mn.variables())
        m, t1 = simplify_by_factorization(Mn, x)
        Mc, t2 = factorize(m, x, eps, seed=3)
        Tc = t1 * t2
        t.assertTrue((Mc - transform(Mn, x, Tc)).simplify_rational().is_zero())
        t.assertNotIn(eps, (Mc / eps).simplify_rational().variables())
Esempio n. 15
0
    def slope(self):        # It was before named "coefficient"
        """
        return the angular coefficient of line.

        This is the coefficient a in the equation
        y = ax + b

        This is not the same as the coefficient a in self.equation
        ax + by + c == 0

        of the points.

        OUTPUT:
        a number

        EXAMPLES::

            sage: from yanntricks import *
            sage: Segment(Point(0,0),Point(1,1)).slope
            1
            sage: Segment(Point(1,1),Point(0,0)).slope
            1
            sage: Segment(Point(1,2),Point(-1,8)).slope
            -3

        NOTE:

        If the line is vertical, raise a ZeroDivisionError
        """
        return SR(self.Dy)/self.Dx
Esempio n. 16
0
    def __init__(self, arg, mode=None):
        if mode is None:
            mode = 'O'

        if mode not in ['O', 'K', 'BO', 'BK', 'TO', 'TK']:
            raise ValueError("invalid mode")

        self.translation = SR('q')**(arg.nrows() -
                                     arg.ncols()) if 'T' in mode else None
        self.R = arg
        for x in mode[:-1]:
            if x == 'B':
                self.R = bullet_dual(self.R)
            elif x == 'T':
                self.R = self.R.transpose()
            else:
                raise ValueError

        self.d = self.R.nrows()
        self.e = self.R.ncols()

        self.mode = mode[-1]
        self.ring = self.R.base_ring()
        self.ell = self.ring.ngens()

        self.basis = [
            evaluate_matrix(self.R, y) for y in identity_matrix(QQ, self.ell)
        ]
Esempio n. 17
0
 def test_import_export_mathematica(t):
     a, b = SR.var("v1 v2")
     M = matrix([[1, a, b], [a + b, Rational((2, 3)), a / b]])
     fout = StringIO()
     export_matrix_mathematica(fout, M)
     MM = import_matrix_mathematica(StringIO(fout.getvalue()))
     t.assertEqual(M, MM)
Esempio n. 18
0
    def place_list(self, mx, Mx, frac=1, mark_origin=True):
        """
        return a tuple of 
        1. values that are all the integer multiple of 
                <frac>*self.numerical_value 
            between mx and Mx
        2. the multiple of the basis unit.

        Give <frac> as literal real. Recall that python evaluates 1/2 to 0. If you pass 0.5, it will be converted back to 1/2 for a nice display.
        """
        try:
            # If the user enters "0.5", it is converted to 1/2
            frac = Rational(frac)
        except TypeError:
            pass
        if frac == 0:
            raise ValueError(
                "frac is zero in AxesUnit.place_list(). Maybe you ignore that python evaluates 1/2 to 0 ? (writes literal 0.5 instead) \n Or are you trying to push me in an infinite loop ?"
            )
        l = []
        k = SR.var("TheTag")
        for x in MultipleBetween(frac * self.numerical_value, mx, Mx,
                                 mark_origin):
            if self.latex_symbol == "":
                l.append((x, "$" + latex(x) + "$"))
            else:
                pos = (x / self.numerical_value) * k
                # This risks to be Sage-version dependent.
                text = "$" + latex(pos).replace("TheTag",
                                                self.latex_symbol) + "$"
                l.append((x, text))
        return l
Esempio n. 19
0
    def test_reduce_at_one_point_1(t):
        x = SR.var("x")
        M0 = matrix([[1 / x, 4, 0, 5], [0, 2 / x, 0, 0], [0, 0, 3 / x, 6],
                     [0, 0, 0, 4 / x]])

        u = matrix([[0, Rational((3, 5)),
                     Rational((4, 5)), 0],
                    [Rational((5, 13)), 0, 0,
                     Rational((12, 13))]])
        M1 = transform(M0, x, balance(u.transpose() * u, 0, 1, x))
        M1 = M1.simplify_rational()

        u = matrix([[8, 0, 15, 0]]) / 17
        M2 = transform(M1, x, balance(u.transpose() * u, 0, 2, x))
        M2 = M2.simplify_rational()

        M2_sing = singularities(M2, x)
        t.assertIn(0, M2_sing)
        t.assertEqual(M2_sing[0], 2)

        M3, T23 = reduce_at_one_point(M2, x, 0, 2)
        M3 = M3.simplify_rational()
        t.assertEqual(M3, transform(M2, x, T23).simplify_rational())

        M3_sing = singularities(M3, x)
        t.assertIn(0, M3_sing)
        t.assertEqual(M3_sing[0], 1)

        M4, T34 = reduce_at_one_point(M3, x, 0, 1)
        M4 = M4.simplify_rational()
        t.assertEqual(M4, transform(M3, x, T34).simplify_rational())

        M4_sing = singularities(M4, x)
        t.assertIn(0, M4_sing)
        t.assertEqual(M4_sing[0], 0)
Esempio n. 20
0
    def get_rels_elems1(self, tcs):
        if __debug__:
            assert len(tcs) >= 1, tcs

        aeterms = tcs[0].keys()

        #Find rels among array elements
        logger.debug('Find linear eqts over {} array elems'
                     .format(len(aeterms)))
        aeterms = [SR(1)] + aeterms

        from dig_polynomials import Eqt
        solverE = Eqt(aeterms, tcs, self.xinfo)
        
        logger.info('Select traces (note: |tcs|=|terms|={})'.format(len(aeterms)))
        
        ntcs_extra = 200
        solverE.tcs, solverE.tcs_extra = get_traces(tcs,len(aeterms),ntcs_extra=200)

        solverE.do_refine=False
        solverE._go()
        
        from dig_refine import Refine
        rf = Refine(solverE.sols)
        rf.rfilter(tcs=solverE.tcs_extra)
        ps = [p.p for p in rf.ps]
        
        return ps
Esempio n. 21
0
    def sreduce(ps):
        """
        Return the basis (e.g., a min subset of ps that implies ps) 
        of the set of eqts input ps using Groebner basis
       Examples:

        sage: var('a y b q k')
        (a, y, b, q, k)

        sage: rs =  InvEqt.sreduce([a*y-b==0,q*y+k-x==0,a*x-a*k-b*q==0])
        sage: assert set(rs) == set([a*y - b == 0, q*y + k - x == 0])

        sage: rs =  InvEqt.sreduce([x*y==6,y==2,x==3])
        sage: assert set(rs) == set([x - 3 == 0, y - 2 == 0])

        #Attribute error occurs when only 1 var, thus return as is
        sage: rs =  InvEqt.sreduce([x*x==4,x==2])
        sage: assert set(rs) == set([x == 2, x^2 == 4])


        """
        if __debug__:
            assert all(p.operator() == operator.eq for p in ps), ps

        try:
            Q = PolynomialRing(QQ, get_vars(ps))
            I = Q * ps
            #ps_ = I.radical().groebner_basis()
            ps = I.radical().interreduced_basis()
            ps = [(SR(p) == 0) for p in ps]
        except AttributeError:
            pass

        return ps
Esempio n. 22
0
def Llenar_Vector_Funciones(nombreArchTxt):
    """Funcion que lee un archivo de texto, extrae las expresiones que estan despues de un signo '=' y las almacena en un vector columna"""
    try:
        # Se ubica a dos directorios anteriores porque esta funcion es llamada desde un programa en el directorio donde esta la funcion principal
        archFun = open(f"{nombreArchTxt}.txt", "r")
    except:
        print("\nNo es posible abrir el archivo")
        print(
            "Crea un archivo de texto nuevo e ingresa las funciones ahí, guardalo con el formato 'txt' y vuelve a correr el programa\n"
        )
        sys.exit(1)

    # Bucle que recorre el archivo para extraer lo que aparece despues del signo '=' en el archivo de texto
    for linea in archFun:
        indIn = linea.find("=")
        funciones = linea[(indIn + 1):]
    # Elimina las llaves que hay en la cadena
    indLlave1 = funciones.find("[")
    indLlave2 = funciones.find("]")
    funciones = funciones[(indLlave1 + 1):indLlave2]

    # Separa las funciones delimitadas por comas
    funciones = funciones.split(',')

    # Crea vector que contendra las expresiones que escriba el usuario en el archivo de texto
    matFun = np.empty((len(funciones), 1), dtype=type(SR()))

    contFun = 0
    # Recorre la lista de funciones, intenta convertir a formato de funciones de sagemath y las almacena en el vector de funciones
    for funcion in funciones:
        try:
            matFun[contFun, 0] = SR(funcion)
        except:
            print(
                "\nNo ha sido posible convertir alguna de las expresiones en un formato compatible con el programa"
            )
            print(
                "Revise la documentacion de SageMath para ver como se pueden ingresar las expresiones\n"
            )
            sys.exit(1)
        contFun += 1

    # Cierra el archivo
    archFun.close()

    # Regresa el vector columna con las expresiones leidas desde el archivo de texto
    return matFun
Esempio n. 23
0
def quadratic_L_function__exact(n, d):
    r"""
    Returns the exact value of a quadratic twist of the Riemann Zeta function
    by `\chi_d(x) = \left(\frac{d}{x}\right)`.

    The input `n` must be a critical value.

    EXAMPLES::

        sage: quadratic_L_function__exact(1, -4)
        1/4*pi
        sage: quadratic_L_function__exact(-4, -4)
        5/2
        sage: quadratic_L_function__exact(2, 1)
        1/6*pi^2

    TESTS::

        sage: quadratic_L_function__exact(2, -4)
        Traceback (most recent call last):
        ...
        TypeError: n must be a critical value (i.e. odd > 0 or even <= 0)

    REFERENCES:

    - [Iwa1972]_, pp 16-17, Special values of `L(1-n, \chi)` and `L(n, \chi)`
    - [IR1990]_
    - [Was1997]_
    """
    from sage.all import SR, sqrt
    if n <= 0:
        return QuadraticBernoulliNumber(1 - n, d) / (n - 1)
    elif n >= 1:
        # Compute the kind of critical values (p10)
        if kronecker_symbol(fundamental_discriminant(d), -1) == 1:
            delta = 0
        else:
            delta = 1

        # Compute the positive special values (p17)
        if ((n - delta) % 2 == 0):
            f = abs(fundamental_discriminant(d))
            if delta == 0:
                GS = sqrt(f)
            else:
                GS = I * sqrt(f)
            ans = SR(ZZ(-1)**(1 + (n - delta) / 2))
            ans *= (2 * pi / f)**n
            ans *= GS  # Evaluate the Gauss sum here! =0
            ans *= QQ.one() / (2 * I**delta)
            ans *= QuadraticBernoulliNumber(n, d) / factorial(n)
            return ans
        else:
            if delta == 0:
                raise TypeError(
                    "n must be a critical value (i.e. even > 0 or odd < 0)")
            if delta == 1:
                raise TypeError(
                    "n must be a critical value (i.e. odd > 0 or even <= 0)")
Esempio n. 24
0
    def __init__(self, a, b):
        self.x = SR(a)
        self.y = SR(b)
        ObjectGraph.__init__(self, self)
        self.point = self.obj
        self.add_option("PointSymbol=*")
        self._advised_mark_angle = None

        try:
            ax = abs(numerical_approx(self.x))
            if ax < 0.00001 and ax > 0:
                self.x = 0
            ay = abs(numerical_approx(self.y))
            if ay < 0.00001 and ay > 0:
                self.y = 0
        except TypeError:
            pass
Esempio n. 25
0
    def padically_evaluate_regular(self, datum):
        T = datum.toric_datum
        if not T.is_regular():
            raise ValueError('Can only processed regular toric data')

        M = Set(range(T.length()))
        q = SR.var('q')

        alpha = {}

        for I in Subsets(M):
            F = [T.initials[i] for i in I]
            V = SubvarietyOfTorus(F, torus_dim=T.ambient_dim)
            alpha[I] = V.count()

        def cat(u, v):
            return vector(list(u) + list(v))

        for I in Subsets(M):
            cnt = sum((-1)**len(J) * alpha[I + J] for J in Subsets(M - I))
            if not cnt:
                continue

            P = DirectProductOfPolyhedra(T.polyhedron,
                                         StrictlyPositiveOrthant(len(I)))

            it = iter(identity_matrix(ZZ, len(I)).rows())
            ieqs = []
            for i in M:
                ieqs.append(
                    cat(
                        vector(ZZ, (0, )),
                        cat(
                            vector(ZZ, T.initials[i].exponents()[0]) -
                            vector(ZZ, T.lhs[i].exponents()[0]),
                            next(it) if i in I else zero_vector(ZZ, len(I)))))

            if not ieqs:
                ieqs = [vector(ZZ, (T.ambient_dim + len(I) + 1) * [0])]

            Q = Polyhedron(ieqs=ieqs,
                           base_ring=QQ,
                           ambient_dim=T.ambient_dim + len(I))

            foo, ring = symbolic_to_ratfun(
                cnt * (q - 1)**len(I) / q**(T.ambient_dim),
                [var('t'), var('q')])
            corr_cnt = CyclotomicRationalFunction.from_laurent_polynomial(
                foo, ring)

            Phi = matrix([
                cat(T.integrand[0], zero_vector(ZZ, len(I))),
                cat(T.integrand[1], vector(ZZ,
                                           len(I) * [-1]))
            ]).transpose()
            sm = RationalSet([P.intersection(Q)]).generating_function()
            for z in sm.monomial_substitution(QQ['t', 'q'], Phi):
                yield corr_cnt * z
Esempio n. 26
0
 def test_fuchsify_by_blocks_05(test):
     x, eps = SR.var("x eps")
     m = matrix([
         [eps / x, 0, 0],
         [0, 2 * eps / x, -eps / x],
         [x**2, 0, 3 * eps / x],
     ])
     b = [(0, 1), (1, 2)]
     test.assert_fuchsify_by_blocks_works(m, b, x, eps)
Esempio n. 27
0
 def test_fuchsify_by_blocks_03(test):
     x, eps = SR.var("x eps")
     m = matrix([
         [eps / x, 0, 0],
         [1 / x**2, 2 * eps / x, 0],
         [1 / x**2, 2 / x**2, 3 * eps / x],
     ])
     b = [(0, 1), (1, 1), (2, 1)]
     test.assert_fuchsify_by_blocks_works(m, b, x, eps)
Esempio n. 28
0
def _gen_rbt_Si( rbt ):
    
    var('a theta alpha d',domain=RR)
    D_exp2trig = { e**(SR.wild(0)) : e**SR.wild(0).real_part() * ( cos(SR.wild(0).imag_part()) + I*sin(SR.wild(0).imag_part()) ) }
    M = matrix(SR,[[1,0,0,a],[0,cos(alpha),-sin(alpha),0],[0,sin(alpha),cos(alpha),d],[0,0,0,1]])
    P = matrix([[0,-1,0,0],[1,0,0,0],[0,0,0,0],[0,0,0,0]])
    ePtM = (exp(P*theta)*M).expand().subs(D_exp2trig).simplify_rational()
    restore('a theta alpha d')
    if bool( ePtM != rbt.T_dh ):
        raise Exception('_gen_rbt_Si: interlink transformation does not follows implemented DH formulation')
    S = ( inverse_T(M) * P * M ).expand().simplify_trig()
    
    dof = rbt.dof
    
    Si = range(dof+1)
    for l in range(dof): Si[l+1] = se3unskew( S.subs(LoP_to_D(zip(rbt.params_dh , rbt.links_dh[l]))) )
    
    return Si
Esempio n. 29
0
 def count(self):
     for i in ([0, 1, 2] if common.symbolic else [0]):
         try:
             return SR(self._count_general(level=i)).expand()
         except CountException:
             logger.debug('count (level=%d) failed: %s' % (i, self))
     raise CountException(
         'Failed to count number of rational points. Try switching to symbolic mode.'
     )
Esempio n. 30
0
 def test_transform_2(t):
     # transform(transform(M, x, I), x, I^-1) == M
     x = SR.var("x")
     M = randpolym(x, 2)
     T = randpolym(x, 2)
     invT = T.inverse()
     M1 = transform(M, x, T)
     M2 = transform(M1, x, invT)
     t.assertEqual(M2.simplify_rational(), M)
Esempio n. 31
0
    def get_background_graphic(self, **bdry_options):
        r"""
        Return a graphic object that makes the model easier to visualize.
        For the hyperboloid model, the background object is the hyperboloid
        itself.

        EXAMPLES::

            sage: H = HyperbolicPlane().HM().get_background_graphic()
        """
        from sage.plot.plot3d.all import plot3d
        from sage.all import SR
        hyperboloid_opacity = bdry_options.get('hyperboloid_opacity', .1)
        z_height = bdry_options.get('z_height', 7.0)
        x_max = sqrt((z_height ** 2 - 1) / 2.0)
        x = SR.var('x')
        y = SR.var('y')
        return plot3d((1 + x ** 2 + y ** 2).sqrt(),
                      (x, -x_max, x_max), (y,-x_max, x_max),
                      opacity=hyperboloid_opacity, **bdry_options)
Esempio n. 32
0
def elliptic_cm_form(E, n, prec, aplist_only=False, anlist_only=False):
    """
    Return q-expansion of the CM modular form associated to the n-th
    power of the Grossencharacter associated to the elliptic curve E.

    INPUT:
        - E -- CM elliptic curve
        - n -- positive integer
        - prec -- positive integer
        - aplist_only -- return list only of ap for p prime
        - anlist_only -- return list only of an

    OUTPUT:
        - power series with integer coefficients

    EXAMPLES::

        sage: from psage.modform.rational.special import elliptic_cm_form
        sage: f = CuspForms(121,4).newforms(names='a')[0]; f
        q + 8*q^3 - 8*q^4 + 18*q^5 + O(q^6)
        sage: E = EllipticCurve('121b')
        sage: elliptic_cm_form(E, 3, 7)
        q + 8*q^3 - 8*q^4 + 18*q^5 + O(q^7)
        sage: g = elliptic_cm_form(E, 3, 100)
        sage: g == f.q_expansion(100)
        True
    """
    if not E.has_cm():
        raise ValueError, "E must have CM"
    n = ZZ(n)
    if n <= 0:
        raise ValueError, "n must be positive"

    prec = ZZ(prec)
    if prec <= 0:
        return []
    elif prec <= 1:
        return [ZZ(0)]
    elif prec <= 2:
        return [ZZ(0), ZZ(1)]
    
    # Derive formula for sum of n-th powers of roots
    a,p,T = SR.var('a,p,T')
    roots = (T**2 - a*T + p).roots(multiplicities=False)
    s = sum(alpha**n for alpha in roots).simplify_full()
    
    # Create fast callable expression from formula
    g = fast_callable(s.polynomial(ZZ))

    # Compute aplist for the curve
    v = E.aplist(prec)

    # Use aplist to compute ap values for the CM form attached to n-th
    # power of Grossencharacter.
    P = prime_range(prec)

    if aplist_only:
        # case when we only want the a_p (maybe for computing an
        # L-series via Euler product)
        return [g(ap,p) for ap,p in zip(v,P)]

    # Default cause where we want all a_n
    anlist = [ZZ(0),ZZ(1)] + [None]*(prec-2)
    for ap,p in zip(v,P):
        anlist[p] = g(ap,p)

    # Fill in the prime power a_{p^r} for r >= 2.
    N = E.conductor()
    for p in P:
        prm2 = 1
        prm1 = p
        pr = p*p
        pn = p**n
        e = 1 if N%p else 0
        while pr < prec:
            anlist[pr] = anlist[prm1] * anlist[p]
            if e:
                anlist[pr] -= pn * anlist[prm2]
            prm2 = prm1
            prm1 = pr
            pr *= p

    # fill in a_n with n divisible by at least 2 primes
    extend_multiplicatively_generic(anlist)

    if anlist_only:
        return anlist

    f = Integer_list_to_polynomial(anlist, 'q')
    return ZZ[['q']](f, prec=prec)