Exemple #1
0
def getLfunctionPlot(request, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9):
    pythonL = generateLfunctionFromUrl(
        arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, to_dict(request.args))
    if not pythonL:
        return ""
    plotrange = 30
    if hasattr(pythonL, 'plotpoints'):
        F = p2sage(pythonL.plotpoints)
        plotrange = min(plotrange, F[-1][0]) #  F[-1][0] is the highest t-coordinated that we have a value for L
    else:
     # obsolete, because lfunc_data comes from DB?
        L = pythonL.sageLfunction
        if not hasattr(L, "hardy_z_function"):
            return None
        plotStep = .1
        if pythonL._Ltype not in ["riemann", "maass", "ellipticmodularform", "ellipticcurve"]:
            plotrange = 12
        F = [(i, L.hardy_z_function(i).real()) for i in srange(-1*plotrange, plotrange, plotStep)]
    interpolation = spline(F)
    F_interp = [(i, interpolation(i)) for i in srange(-1*plotrange, plotrange, 0.05)]
    p = line(F_interp)
#    p = line(F)    # temporary hack while the correct interpolation is being implemented

    styleLfunctionPlot(p, 10)
    fn = tempfile.mktemp(suffix=".png")
    p.save(filename=fn)
    data = file(fn).read()
    os.remove(fn)
    return data
Exemple #2
0
        def fourier_series_partial_sum(cls, self, parameters, variable, N, L):
            r"""
            Returns the partial sum

            .. math::

               f(x) \sim \frac{a_0}{2} + \sum_{n=1}^N [a_n\cos(\frac{n\pi x}{L}) + b_n\sin(\frac{n\pi x}{L})],

            as a string.

            EXAMPLE::

                sage: f(x) = x^2
                sage: f = piecewise([[(-1,1),f]])
                sage: f.fourier_series_partial_sum(3,1)
                cos(2*pi*x)/pi^2 - 4*cos(pi*x)/pi^2 + 1/3
                sage: f1(x) = -1
                sage: f2(x) = 2
                sage: f = piecewise([[(-pi,pi/2),f1],[(pi/2,pi),f2]])
                sage: f.fourier_series_partial_sum(3,pi)
                -3*cos(x)/pi - 3*sin(2*x)/pi + 3*sin(x)/pi - 1/4
            """
            from sage.all import pi, sin, cos, srange
            x = self.default_variable()
            a0 = self.fourier_series_cosine_coefficient(0, L)
            result = a0 / 2 + sum(
                [(self.fourier_series_cosine_coefficient(n, L) *
                  cos(n * pi * x / L) + self.fourier_series_sine_coefficient(
                      n, L) * sin(n * pi * x / L)) for n in srange(1, N)])
            return SR(result).expand()
Exemple #3
0
        def fourier_series_partial_sum(cls, self, parameters, variable, N, L):
            r"""
            Returns the partial sum

            .. math::

               f(x) \sim \frac{a_0}{2} + \sum_{n=1}^N [a_n\cos(\frac{n\pi x}{L}) + b_n\sin(\frac{n\pi x}{L})],

            as a string.

            EXAMPLE::

                sage: f(x) = x^2
                sage: f = piecewise([[(-1,1),f]])
                sage: f.fourier_series_partial_sum(3,1)
                cos(2*pi*x)/pi^2 - 4*cos(pi*x)/pi^2 + 1/3
                sage: f1(x) = -1
                sage: f2(x) = 2
                sage: f = piecewise([[(-pi,pi/2),f1],[(pi/2,pi),f2]])
                sage: f.fourier_series_partial_sum(3,pi)
                -3*cos(x)/pi - 3*sin(2*x)/pi + 3*sin(x)/pi - 1/4
            """
            from sage.all import pi, sin, cos, srange
            x = self.default_variable()
            a0 = self.fourier_series_cosine_coefficient(0,L)
            result = a0/2 + sum([(self.fourier_series_cosine_coefficient(n,L)*cos(n*pi*x/L) +
                                  self.fourier_series_sine_coefficient(n,L)*sin(n*pi*x/L))
                                 for n in srange(1,N)])
            return SR(result).expand()
Exemple #4
0
def make_hash(p, N1, N2, np=20):
    plist = [next_prime(400000)]
    while len(plist) < np:
        plist.append(next_prime(plist[-1]))

    hashtab = {}
    nc = 0
    for E in cremona_optimal_curves(srange(N1, N2 + 1)):
        nc += 1
        h = hash1(p, E, plist)
        lab = E.label()
        if nc % 1000 == 0:
            print(lab)
        #print("{} has hash = {}".format(lab,h))
        if h in hashtab:
            hashtab[h].append(lab)
            #print("new set {}".format(hashtab[h]))
        else:
            hashtab[h] = [lab]

    ns = 0
    for s in hashtab.values():
        if len(s) > 1:
            ns += 1
            #print s
    print("{} sets of conjugate curves".format(ns))
    return hashtab
Exemple #5
0
def make_hash_many(plist, N1, N2, nq=20):
    qlist = [next_prime(400000)]
    while len(qlist) < nq:
        qlist.append(next_prime(qlist[-1]))

    hashtabs = dict([(p, dict()) for p in plist])
    nc = 0
    for E in cremona_optimal_curves(srange(N1, N2 + 1)):
        nc += 1
        lab = E.label()
        if nc % 1000 == 0:
            print(lab)
        h = hash1many(plist, E, qlist)

        for p in plist:
            hp = h[p]
            if hp in hashtabs[p]:
                hashtabs[p][hp].append(lab)
                print("p={}, new set {}".format(p, hashtabs[p][hp]))
            else:
                hashtabs[p][hp] = [lab]

    ns = dict([(p, len([v for v in hashtabs[p].values() if len(v) > 1]))
               for p in plist])
    for p in plist:
        print("p={}: {} nontrivial sets of congruent curves".format(p, ns[p]))
    return hashtabs
Exemple #6
0
def find_cong_db(Nmin, Nmax, p, ofile=None, verbose=False):
    if ofile:
        ofile = open(ofile, mode='a')
    nc = 0
    for N in srange(Nmin, Nmax + 1):
        if N % 100 == 0:
            print(N)
        curves_N = get_curves(N)
        if curves_N:
            if verbose:
                print("N1 = {} ({} classes)".format(N, len(curves_N)))
            for M in srange(11, N + 1):
                #for M in srange(11,42000):
                curves_M = get_curves(M)
                if curves_M and verbose:
                    pass
                    print("...N2 = {} ({} classes)".format(M, len(curves_M)))
                for c1 in curves_N:
                    ap1 = c1['aplist']
                    iso1 = c1['iso_nlabel']
                    lab1 = str(c1['label'])
                    curves2 = [
                        c2 for c2 in curves_M
                        if M < N or c2['iso_nlabel'] < iso1
                    ]
                    curves2 = [
                        c2 for c2 in curves2
                        if test2(N, ap1, M, c2['aplist'], p)
                    ]
                    for c2 in curves2:
                        lab2 = str(c2['label'])
                        print("Candidate for congruence mod {}: {} {}".format(
                            p, lab1, lab2))
                        E1 = EllipticCurve(lab1)
                        E2 = EllipticCurve(lab2)
                        res, reason = test_cong(p, E1, E2)
                        report(res, reason, p, lab1, lab2)
                        if res:
                            nc += 1
                            if ofile:
                                ofile.write("{} {} {}\n".format(p, lab1, lab2))
    if ofile:
        ofile.close()
    print("{} pairs of congruent curves found".format(nc))
def min_formula(N,t):
    """
    Function MinFormula in Mark his code 
    """
    N = ZZ(N); t = QQ(t)
    if N < 2:
        raise ValueError
    if N == 2:
        return 4 * t -1
    if N == 3:
        return 9 * min(t, ZZ(1)/3) - 8*t
    return sum(N * Phi(gcd(i,N)) * (min(t, i/N) - 4*(i/N)*(1-i/N)*t) for i in srange(1,(N-1)//2+1))
Exemple #8
0
def prod_plot_values(factor_plot_deltas, factor_values):
    assert len(factor_plot_deltas) == len(factor_values)
    halfdegree = len(factor_values)
    if halfdegree == 1:
        return factor_plot_deltas[0], factor_values[0]
    factor_plot_values = [ [ ( j * factor_plot_deltas[k],  z) for j, z in enumerate(values) ] for k, values in enumerate(factor_values)]
    interpolations = [spline(elt) for elt in factor_plot_values]
    max_delta = max(factor_plot_deltas)
    new_delta = max_delta/halfdegree
    plot_range = min( [elt[-1][0] for elt in factor_plot_values] )
    values = [prod([elt(i) for elt in interpolations]) for i in srange(0, plot_range, new_delta)]
    return new_delta, values
Exemple #9
0
    def genTemplate(name,d):
        if name == 'coef':
            assert(len(d.values())==1)
            coefVal = d.values()[0]
            template = None if coefVal == 0 else '(%s)'%str(coefVal)
        else:
            idxVals= ['[%s]'%d[name+str(idx)] for idx in srange(len(d)-1)]
            if d['coef'] == -1:
                coefStr = '-'
            elif d['coef'] == 1:
                coefStr = ''
            else:
                coefStr = "({}) *".format(d['coef'])

            template = '(%s%s%s)'%(coefStr,name,list_str(idxVals,''))

        return template
Exemple #10
0
def download_Rub_data():
    import gridfs
    label = (request.args.get('label'))
    limit = (request.args.get('limit'))
    C = base.getDBConnection()
    fs = gridfs.GridFS(C.quadratic_twists, 'isogeny')
    isogeny = C.quadratic_twists.isogeny.files
    filename = isogeny.find_one({'label': label})['filename']
    d = fs.get_last_version(filename)
    if limit is None:
        response = flask.Response(d.__iter__())
        response.headers['Content-disposition'] = 'attachment; filename=%s' % label
        response.content_length = d.length
    else:
        limit = int(limit)
        response = make_response(''.join(str(d.readline()) for i in srange(limit)))
    response.headers['Content-type'] = 'text/plain'
    return response
Exemple #11
0
def download_Rub_data():
    import gridfs
    label = (request.args.get('label'))
    limit = (request.args.get('limit'))
    C = base.getDBConnection()
    fs = gridfs.GridFS(C.quadratic_twists, 'isogeny')
    isogeny = C.quadratic_twists.isogeny.files
    filename = isogeny.find_one({'label': label})['filename']
    d = fs.get_last_version(filename)
    if limit is None:
        response = flask.Response(d.__iter__())
        response.headers['Content-disposition'] = 'attachment; filename=%s' % label
        response.content_length = d.length
    else:
        limit = int(limit)
        response = make_response(''.join(str(d.readline()) for i in srange(limit)))
    response.headers['Content-type'] = 'text/plain'
    return response
Exemple #12
0
        def compute_traces(aname, acontents, ainfo, tsinfo):
            vi = Miscs.travel(acontents)
            vals = Miscs.getVals(vi)
            idxs = Miscs.getIdxs(vi)
            aname = str(aname)
            newvars = [var(aname + '_' + list_str(idx, '_')) for idx in idxs]

            if aname not in tsinfo:
                tsinfo[aname] = newvars
            else:
                assert tsinfo[aname] == newvars
            
            dVals = dict(zip(newvars,vals)) #{A_0_0_1:'w'}
            for nv,idx in zip(newvars,idxs):
                if nv not in ainfo:
                    idx_ = zip([var('{}{}'.format(aname,li))
                                 for li in srange(len(idx))],idx)
                    ainfo[nv]={'name':aname, 'idx_':idx_}

            return dVals
Exemple #13
0
def rqf_iterator(d1, d2):
    from lmfdb.WebNumberField import is_fundamental_discriminant
    for d in srange(d1, d2 + 1):
        if is_fundamental_discriminant(d):
            yield d, '2.2.%s.1' % d
Exemple #14
0
        def fourier_series_partial_sum(self, parameters, variable, N,
                                       L=None):
            r"""
            Returns the partial sum up to a given order of the Fourier series
            of the periodic function `f` extending the piecewise-defined
            function ``self``.

            The Fourier partial sum of order `N` is defined as

            .. MATH::

                S_{N}(x) = \frac{a_0}{2} + \sum_{n=1}^{N} \left[
                      a_n\cos\left(\frac{n\pi x}{L}\right)
                    + b_n\sin\left(\frac{n\pi x}{L}\right)\right],

            where `L` is the half-period of `f` and the `a_n`'s and `b_n`'s
            are respectively the cosine coefficients and sine coefficients
            of the Fourier series of `f` (cf.
            :meth:`fourier_series_cosine_coefficient` and
            :meth:`fourier_series_sine_coefficient`).

            INPUT:

            - ``N`` -- a positive integer; the order of the partial sum

            - ``L`` -- (default: ``None``) the half-period of `f`; if none
              is provided, `L` is assumed to be the half-width of the domain
              of ``self``

            OUTPUT:

            - the partial sum `S_{N}(x)`, as a symbolic expression

            EXAMPLES:

            A square wave function of period 2::

                sage: f = piecewise([((-1,0), -1), ((0,1), 1)])
                sage: f.fourier_series_partial_sum(5)
                4/5*sin(5*pi*x)/pi + 4/3*sin(3*pi*x)/pi + 4*sin(pi*x)/pi

            If the domain of the piecewise-defined function encompasses
            more than one period, the half-period must be passed as the
            second argument; for instance::

                sage: f2 = piecewise([((-1,0), -1), ((0,1), 1),
                ....:                 ((1,2), -1), ((2,3), 1)])
                sage: bool(f2.restriction((-1,1)) == f)  # f2 extends f on (-1,3)
                True
                sage: f2.fourier_series_partial_sum(5, 1)  # half-period = 1
                4/5*sin(5*pi*x)/pi + 4/3*sin(3*pi*x)/pi + 4*sin(pi*x)/pi
                sage: bool(f2.fourier_series_partial_sum(5, 1) ==
                ....:      f.fourier_series_partial_sum(5))
                True

            The default half-period is 2, so that skipping the second
            argument yields a different result::

                sage: f2.fourier_series_partial_sum(5)  # half-period = 2
                4*sin(pi*x)/pi

            An example of partial sum involving both cosine and sine terms::

                sage: f = piecewise([((-1,0), 0), ((0,1/2), 2*x),
                ....:                ((1/2,1), 2*(1-x))])
                sage: f.fourier_series_partial_sum(5)
                -2*cos(2*pi*x)/pi^2 + 4/25*sin(5*pi*x)/pi^2
                 - 4/9*sin(3*pi*x)/pi^2 + 4*sin(pi*x)/pi^2 + 1/4

            """
            from sage.all import pi, sin, cos, srange
            if not L:
                L = (self.domain().sup() - self.domain().inf()) / 2
            x = self.default_variable()
            a0 = self.fourier_series_cosine_coefficient(0, L)
            result = a0/2 + sum([(self.fourier_series_cosine_coefficient(n, L)*cos(n*pi*x/L) +
                                  self.fourier_series_sine_coefficient(n, L)*sin(n*pi*x/L))
                                 for n in srange(1, N+1)])
            return SR(result).expand()
def divisor_F_bc(N,k):
    """
    Function Divisor_F_bc in Mark his code, return the divisor of F_k as function on X_1(N) 
    """
    N = ZZ(N); k = ZZ(k)
    return vector([min_formula(k, i/N) * inverse_gcd(i,N) for i in srange(0,N//2+1)])
Exemple #16
0
        def fourier_series_partial_sum(self, parameters, variable, N, L=None):
            r"""
            Returns the partial sum up to a given order of the Fourier series
            of the periodic function `f` extending the piecewise-defined
            function ``self``.

            The Fourier partial sum of order `N` is defined as

            .. MATH::

                S_{N}(x) = \frac{a_0}{2} + \sum_{n=1}^{N} \left[
                      a_n\cos\left(\frac{n\pi x}{L}\right)
                    + b_n\sin\left(\frac{n\pi x}{L}\right)\right],

            where `L` is the half-period of `f` and the `a_n`'s and `b_n`'s
            are respectively the cosine coefficients and sine coefficients
            of the Fourier series of `f` (cf.
            :meth:`fourier_series_cosine_coefficient` and
            :meth:`fourier_series_sine_coefficient`).

            INPUT:

            - ``N`` -- a positive integer; the order of the partial sum

            - ``L`` -- (default: ``None``) the half-period of `f`; if none
              is provided, `L` is assumed to be the half-width of the domain
              of ``self``

            OUTPUT:

            - the partial sum `S_{N}(x)`, as a symbolic expression

            EXAMPLES:

            A square wave function of period 2::

                sage: f = piecewise([((-1,0), -1), ((0,1), 1)])
                sage: f.fourier_series_partial_sum(5)
                4/5*sin(5*pi*x)/pi + 4/3*sin(3*pi*x)/pi + 4*sin(pi*x)/pi

            If the domain of the piecewise-defined function encompasses
            more than one period, the half-period must be passed as the
            second argument; for instance::

                sage: f2 = piecewise([((-1,0), -1), ((0,1), 1),
                ....:                 ((1,2), -1), ((2,3), 1)])
                sage: bool(f2.restriction((-1,1)) == f)  # f2 extends f on (-1,3)
                True
                sage: f2.fourier_series_partial_sum(5, 1)  # half-period = 1
                4/5*sin(5*pi*x)/pi + 4/3*sin(3*pi*x)/pi + 4*sin(pi*x)/pi
                sage: bool(f2.fourier_series_partial_sum(5, 1) ==
                ....:      f.fourier_series_partial_sum(5))
                True

            The default half-period is 2, so that skipping the second
            argument yields a different result::

                sage: f2.fourier_series_partial_sum(5)  # half-period = 2
                4*sin(pi*x)/pi

            An example of partial sum involving both cosine and sine terms::

                sage: f = piecewise([((-1,0), 0), ((0,1/2), 2*x),
                ....:                ((1/2,1), 2*(1-x))])
                sage: f.fourier_series_partial_sum(5)
                -2*cos(2*pi*x)/pi^2 + 4/25*sin(5*pi*x)/pi^2
                 - 4/9*sin(3*pi*x)/pi^2 + 4*sin(pi*x)/pi^2 + 1/4

            """
            from sage.all import pi, sin, cos, srange
            if not L:
                L = (self.domain().sup() - self.domain().inf()) / 2
            x = self.default_variable()
            a0 = self.fourier_series_cosine_coefficient(0, L)
            result = a0 / 2 + sum(
                [(self.fourier_series_cosine_coefficient(n, L) *
                  cos(n * pi * x / L) + self.fourier_series_sine_coefficient(
                      n, L) * sin(n * pi * x / L)) for n in srange(1, N + 1)])
            return SR(result).expand()
Exemple #17
0
def rqf_iterator(d1, d2):
    from lmfdb.WebNumberField import is_fundamental_discriminant
    for d in srange(d1, d2 + 1):
        if is_fundamental_discriminant(d):
            yield d, '2.2.%s.1' % d
Exemple #18
0
def ideals_iterator(K, minnorm=1, maxnorm=Infinity):
    r""" Return an iterator over all ideals of norm n up to maxnorm (sorted).
    """
    for n in srange(minnorm, maxnorm + 1):
        for I in ideals_of_norm(K, n):
            yield I
Exemple #19
0
def ideals_iterator(K,minnorm=1,maxnorm=Infinity):
    r""" Return an iterator over all ideals of norm n up to maxnorm (sorted).
    """
    for n in srange(minnorm,maxnorm+1):
        for I in ideals_of_norm(K,n):
            yield I
def LB_c(N):
    N = ZZ(N);
    return [divisor_F_bc(N,k) for k in srange(2,N//2+2)]