コード例 #1
0
ファイル: graphics.py プロジェクト: mghasemi/pyProximation
    def ParamPlot2D(self, funcs, rng, color='blue', legend="", thickness=1):
        """
        Appends a parametric curve to the Graphics object. The parameters are as follows:

                - ``funcs``: the tupleof functions to be plotted,
                - ``rng``: a triple of the form `(t, a, b)`, where `t` is the `funcs`'s independents variable, over the range `[a, b]`,
                - ``color``: the color of the current curve,
                - ``legend``: the text for the legend of the current crve.
        """
        if self.PlotType == '':
            self.PlotType = '2D'
        elif self.PlotType != '2D':
            raise Exception("Cannot combine 2d and 3d plots")

        if self.Env == 'numeric':
            f_0 = funcs[0]
            f_1 = funcs[1]
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_0 = lambdify(rng[0], funcs[0], "numpy")
            f_1 = lambdify(rng[0], funcs[1], "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_0 = fast_callable(funcs[0], vars=[rng[0]])
            f_1 = fast_callable(funcs[1], vars=[rng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_f0 = sympify(funcs[0])
            t_f1 = sympify(funcs[1])
            f_0 = lambdify((xrng[0], yrng[0]), t_f0, "numpy")
            f_1 = lambdify((xrng[0], yrng[0]), t_f1, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted.")

        # if self.X == []:
        stp_lngt = float(rng[2] - rng[1]) / self.NumPoints
        line_points = [rng[1] + i *
                       stp_lngt for i in range(self.NumPoints + 1)]
        TempX = [f_0(t) for t in line_points]
        self.X.append(TempX)
        if self.xmin is None:
            self.xmin = min(TempX)
            self.xmax = max(TempX)
        else:
            self.xmin = min(min(TempX), self.xmin)
            self.xmax = max(max(TempX), self.xmax)
        TempY = [f_1(t) for t in line_points]
        if self.ymin is None:
            self.ymin = min(TempY)
            self.ymax = max(TempY)
        else:
            self.ymin = min(min(TempY), self.ymin)
            self.ymax = max(max(TempY), self.ymax)
        self.Y.append(TempY)
        self.color.append(color)
        self.legend.append(legend)
        self.thickness.append(thickness)
        self.PlotCount += 1
コード例 #2
0
ファイル: graphics.py プロジェクト: mghasemi/pyProximation
    def Plot3D(self, func, xrng, yrng):
        """
        Sets a surface to the Graphics object. The parameters are as follows:

                - ``func``: the function to be plotted,
                - ``xrng``: a triple of the form `(x, a, b)`, where `x` is the first `func`s independents variable, over the range `[a, b]`,
                - ``yrng``: a triple of the form `(y, c, d)`, where `x` is the second `func`'s	independents variable, over the range `[c, d]`.
        """
        import numpy as np
        if self.PlotType == '':
            self.PlotType = '3D'
        elif self.PlotType != '3D':
            raise Exception("Cannot combine 2d and 3d plots")

        if self.Env == 'numeric':
            f_ = func
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_ = lambdify((xrng[0], yrng[0]), func, "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_ = fast_callable(func, vars=[xrng[0], yrng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_func = sympify(func)
            f_ = lambdify((xrng[0], yrng[0]), t_func, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted."
            )
        # self.f_ = f_
        x_stp_lngt = float(xrng[2] - xrng[1]) / self.NumPoints
        y_stp_lngt = float(yrng[2] - yrng[1]) / self.NumPoints
        if self.X == []:
            self.X = [
                xrng[1] + i * x_stp_lngt for i in range(self.NumPoints + 1)
            ]
            self.xmin = xrng[1]
            self.xmax = xrng[2]
            self.Y = [
                yrng[1] + i * y_stp_lngt for i in range(self.NumPoints + 1)
            ]
            self.ymin = yrng[1]
            self.ymax = yrng[2]
        X = np.array(self.X)
        Y = np.array(self.Y)
        self.X, self.Y = np.meshgrid(X, Y)
        self.Z = f_(self.X, self.Y)
        self.intX, self.intY = np.mgrid[xrng[1]:xrng[2]:x_stp_lngt,
                                        yrng[1]:yrng[2]:y_stp_lngt]
        self.intZ = f_(self.intX, self.intY)
コード例 #3
0
    def __init__(self, RS, *args):
        """Create a differential on the Riemann surface `RS`.
        """
        if (len(args) < 1) or (len(args) > 2):
            raise ValueError('Instantiate Differential with Sympy expression '
                             'or numerator/denominator pair.')

        # determine the numerator and denominator of the differentials
        if len(args) == 1:
            self.numer = args[0].numerator()
            self.denom = args[0].denominator()
        elif len(args) == 2:
            self.numer = args[0]
            self.denom = args[1]

        x,y = RS.f.parent().gens()
        self.RS = RS
        self.differential = self.numer / self.denom
        self.numer_n = fast_callable(self.numer.change_ring(CC), vars=[x,y],
                                     domain=numpy.complex)
        self.denom_n = fast_callable(self.denom.change_ring(CC), vars=[x,y],
                                     domain=numpy.complex)
コード例 #4
0
    def __init__(self, RS, *args):
        """Create a differential on the Riemann surface `RS`.
        """
        if (len(args) < 1) or (len(args) > 2):
            raise ValueError('Instantiate Differential with Sympy expression '
                             'or numerator/denominator pair.')

        # determine the numerator and denominator of the differentials
        if len(args) == 1:
            self.numer = args[0].numerator()
            self.denom = args[0].denominator()
        elif len(args) == 2:
            self.numer = args[0]
            self.denom = args[1]

        x,y = RS.f.parent().gens()
        self.RS = RS
        self.differential = self.numer / self.denom
        self.numer_n = fast_callable(self.numer.change_ring(CC), vars=[x,y],
                                     domain=numpy.complex)
        self.denom_n = fast_callable(self.denom.change_ring(CC), vars=[x,y],
                                     domain=numpy.complex)
コード例 #5
0
ファイル: graphics.py プロジェクト: mghasemi/pyProximation
    def Plot2D(self, func, xrng, color='blue', legend="", thickness=1):
        """
        Appends a curve to the Graphics object. The parameters are as follows:

                - `func`: the function to be plotted,
                - `xrng`: a triple of the form `(x, a, b)`, where `x` is the `func`'s independents variable, over the range `[a, b]`,
                - `color`: the color of the current curve,
                - `legend`: the text for the legend of the current crve.
        """
        if self.PlotType == '':
            self.PlotType = '2D'
        elif self.PlotType != '2D':
            raise Exception("Cannot combine 2d and 3d plots")

        if self.Env == 'numeric':
            f_ = func
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_ = lambdify(xrng[0], func, "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_ = fast_callable(func, vars=[xrng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_func = sympify(func)
            f_ = lambdify(xrng[0], t_func, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted."
            )

        # if self.X == []:
        stp_lngt = float(xrng[2] - xrng[1]) / self.NumPoints
        self.X.append(
            [xrng[1] + i * stp_lngt for i in range(self.NumPoints + 1)])
        self.xmin = xrng[1]
        self.xmax = xrng[2]
        TempY = [f_(x) for x in self.X[-1]]
        if self.ymin is None:
            self.ymin = min(TempY)
            self.ymax = max(TempY)
        else:
            self.ymin = min(min(TempY), self.ymin)
            self.ymax = max(max(TempY), self.ymax)
        self.Y.append(TempY)
        self.color.append(color)
        self.legend.append(legend)
        self.thickness.append(thickness)
        self.PlotCount += 1
コード例 #6
0
    def __init__(self, riemann_surface, complex_path, y0, ncheckpoints=16):
        # store a list of all y-derivatives of f (including the zeroth deriv)
        degree = riemann_surface.degree
        f = riemann_surface.f.change_ring(CC)
        x,y = f.parent().gens()
        df = [
            fast_callable(f.derivative(y,k), vars=(x,y), domain=complex)
            for k in range(degree+1)
        ]

        self.degree = degree
        self.df = df
        RiemannSurfacePathPrimitive.__init__(
            self, riemann_surface, complex_path, y0, ncheckpoints=ncheckpoints)
コード例 #7
0
ファイル: graphics.py プロジェクト: mghasemi/pyProximation
    def Plot3D(self, func, xrng, yrng):
        """
        Sets a surface to the Graphics object. The parameters are as follows:

                - ``func``: the function to be plotted,
                - ``xrng``: a triple of the form `(x, a, b)`, where `x` is the first `func`s independents variable, over the range `[a, b]`,
                - ``yrng``: a triple of the form `(y, c, d)`, where `x` is the second `func`'s	independents variable, over the range `[c, d]`.
        """
        import numpy as np
        if self.PlotType == '':
            self.PlotType = '3D'
        elif self.PlotType != '3D':
            raise Exception("Cannot combine 2d and 3d plots")

        if self.Env == 'numeric':
            f_ = func
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_ = lambdify((xrng[0], yrng[0]), func, "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_ = fast_callable(func, vars=[xrng[0], yrng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_func = sympify(func)
            f_ = lambdify((xrng[0], yrng[0]), t_func, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted.")
        # self.f_ = f_
        x_stp_lngt = float(xrng[2] - xrng[1]) / self.NumPoints
        y_stp_lngt = float(yrng[2] - yrng[1]) / self.NumPoints
        if self.X == []:
            self.X = [xrng[1] + i *
                      x_stp_lngt for i in range(self.NumPoints + 1)]
            self.xmin = xrng[1]
            self.xmax = xrng[2]
            self.Y = [yrng[1] + i *
                      y_stp_lngt for i in range(self.NumPoints + 1)]
            self.ymin = yrng[1]
            self.ymax = yrng[2]
        X = np.array(self.X)
        Y = np.array(self.Y)
        self.X, self.Y = np.meshgrid(X, Y)
        self.Z = f_(self.X, self.Y)
        self.intX, self.intY = np.mgrid[xrng[1]:xrng[
            2]:x_stp_lngt, yrng[1]:yrng[2]:y_stp_lngt]
        self.intZ = f_(self.intX, self.intY)
コード例 #8
0
ファイル: graphics.py プロジェクト: mghasemi/pyProximation
    def Plot2D(self, func, xrng, color='blue', legend="", thickness=1):
        """
        Appends a curve to the Graphics object. The parameters are as follows:

                - `func`: the function to be plotted,
                - `xrng`: a triple of the form `(x, a, b)`, where `x` is the `func`'s independents variable, over the range `[a, b]`,
                - `color`: the color of the current curve,
                - `legend`: the text for the legend of the current crve.
        """
        if self.PlotType == '':
            self.PlotType = '2D'
        elif self.PlotType != '2D':
            raise Exception("Cannot combine 2d and 3d plots")

        if self.Env == 'numeric':
            f_ = func
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_ = lambdify(xrng[0], func, "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_ = fast_callable(func, vars=[xrng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_func = sympify(func)
            f_ = lambdify(xrng[0], t_func, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted.")

        # if self.X == []:
        stp_lngt = float(xrng[2] - xrng[1]) / self.NumPoints
        self.X.append(
            [xrng[1] + i * stp_lngt for i in range(self.NumPoints + 1)])
        self.xmin = xrng[1]
        self.xmax = xrng[2]
        TempY = [f_(x) for x in self.X[-1]]
        if self.ymin is None:
            self.ymin = min(TempY)
            self.ymax = max(TempY)
        else:
            self.ymin = min(min(TempY), self.ymin)
            self.ymax = max(max(TempY), self.ymax)
        self.Y.append(TempY)
        self.color.append(color)
        self.legend.append(legend)
        self.thickness.append(thickness)
        self.PlotCount += 1
コード例 #9
0
    def __init__(self, riemann_surface, complex_path, y0, ncheckpoints=16):
        # store a list of all y-derivatives of f (including the zeroth deriv)
        degree = riemann_surface.degree
        f = riemann_surface.f.change_ring(CC)
        x, y = f.parent().gens()
        df = [
            fast_callable(f.derivative(y, k), vars=(x, y), domain=complex)
            for k in range(degree + 1)
        ]

        self.degree = degree
        self.df = df
        RiemannSurfacePathPrimitive.__init__(self,
                                             riemann_surface,
                                             complex_path,
                                             y0,
                                             ncheckpoints=ncheckpoints)
コード例 #10
0
ファイル: orthsys.py プロジェクト: mghasemi/pyProximation
 def inner(self, f, g):
     """
     Computes the inner product of the two parameters with respect to
     the measure ``measure``.
     """
     if self.Env == "sympy":
         from sympy import lambdify
         F = lambdify(self.Vars, f * g, "numpy")
     elif self.Env == "sage":
         from sage.all import fast_callable
         h = f * g + self.Vars[0] * 0
         H = fast_callable(h, vars=self.Vars)
         F = lambda *x: H(*x)
     elif self.Env == 'symengine':
         from symengine import Lambdify
         F = lambda *x: Lambdify(self.Vars, [f * g])(x)[0]
     m = self.measure.integral(F)
     return m
コード例 #11
0
ファイル: orthsys.py プロジェクト: mghasemi/pyProximation
 def inner(self, f, g):
     """
     Computes the inner product of the two parameters with respect to
     the measure ``measure``.
     """
     if self.Env == "sympy":
         from sympy import lambdify
         F = lambdify(self.Vars, f * g, "numpy")
     elif self.Env == "sage":
         from sage.all import fast_callable
         h = f * g + self.Vars[0] * 0
         H = fast_callable(h, vars=self.Vars)
         F = lambda *x: H(*x)
     elif self.Env == 'symengine':
         from symengine import Lambdify
         F = lambda *x: Lambdify(self.Vars, [f * g])(x)[0]
     m = self.measure.integral(F)
     return m
コード例 #12
0
ファイル: special.py プロジェクト: merbst/psage
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)

    
    
                    
コード例 #13
0
ファイル: special.py プロジェクト: Alwnikrotikz/purplesage
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)
コード例 #14
0
ファイル: graphics.py プロジェクト: mghasemi/pyProximation
    def ParamPlot2D(self, funcs, rng, color='blue', legend="", thickness=1):
        """
        Appends a parametric curve to the Graphics object. The parameters are as follows:

                - ``funcs``: the tupleof functions to be plotted,
                - ``rng``: a triple of the form `(t, a, b)`, where `t` is the `funcs`'s independents variable, over the range `[a, b]`,
                - ``color``: the color of the current curve,
                - ``legend``: the text for the legend of the current crve.
        """
        if self.PlotType == '':
            self.PlotType = '2D'
        elif self.PlotType != '2D':
            raise Exception("Cannot combine 2d and 3d plots")

        if self.Env == 'numeric':
            f_0 = funcs[0]
            f_1 = funcs[1]
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_0 = lambdify(rng[0], funcs[0], "numpy")
            f_1 = lambdify(rng[0], funcs[1], "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_0 = fast_callable(funcs[0], vars=[rng[0]])
            f_1 = fast_callable(funcs[1], vars=[rng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_f0 = sympify(funcs[0])
            t_f1 = sympify(funcs[1])
            f_0 = lambdify((xrng[0], yrng[0]), t_f0, "numpy")
            f_1 = lambdify((xrng[0], yrng[0]), t_f1, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted."
            )

        # if self.X == []:
        stp_lngt = float(rng[2] - rng[1]) / self.NumPoints
        line_points = [
            rng[1] + i * stp_lngt for i in range(self.NumPoints + 1)
        ]
        TempX = [f_0(t) for t in line_points]
        self.X.append(TempX)
        if self.xmin is None:
            self.xmin = min(TempX)
            self.xmax = max(TempX)
        else:
            self.xmin = min(min(TempX), self.xmin)
            self.xmax = max(max(TempX), self.xmax)
        TempY = [f_1(t) for t in line_points]
        if self.ymin is None:
            self.ymin = min(TempY)
            self.ymax = max(TempY)
        else:
            self.ymin = min(min(TempY), self.ymin)
            self.ymax = max(max(TempY), self.ymax)
        self.Y.append(TempY)
        self.color.append(color)
        self.legend.append(legend)
        self.thickness.append(thickness)
        self.PlotCount += 1