Example #1
0
def render_zeroesLfunction(request, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9):
    ''' Renders the first few zeroes of the L-function with the given arguments.
    '''
    L = generateLfunctionFromUrl(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, to_dict(request.args))

    if hasattr(L,"lfunc_data"):
        website_zeros = p2sage(L.lfunc_data['zeros'])
    else:
        # This depends on mathematical information, all below is formatting
        # More semantic this way
        # Allow 10 seconds
        website_zeros = L.compute_web_zeros(time_allowed = 10)

    positiveZeros = []
    negativeZeros = []

    for zero in website_zeros:
        if zero.abs() < 1e-10:
            zero = 0
        if zero < 0:
            negativeZeros.append(zero)
        else:
            positiveZeros.append(zero)

    # Format the html string to render
    positiveZeros = str(positiveZeros)
    negativeZeros = str(negativeZeros)
    if len(positiveZeros) > 2 and len(negativeZeros) > 2:  # Add comma and empty space between negative and positive
        negativeZeros = negativeZeros.replace("]", ", ]")

    return "<span class='redhighlight'>{0}</span><span class='bluehighlight'>{1}</span>".format(
        negativeZeros[1:len(negativeZeros) - 1], positiveZeros[1:len(positiveZeros) - 1])
Example #2
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
Example #3
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 hasattr(pythonL,"lfunc_data"):
        F = p2sage(pythonL.lfunc_data['plot'])
    else:    
        L = pythonL.sageLfunction
        # HSY: I got exceptions that "L.hardy_z_function" doesn't exist
        # SL: Reason, it's not in the distribution of Sage
        if not hasattr(L, "hardy_z_function"):
            return None
        # FIXME there could be a filename collission
        #F = [(i, L.hardy_z_function(CC(.5, i)).real()) for i in srange(-30, 30, .1)]
        plotStep = .1
        F = [(i, L.hardy_z_function(i).real()) for i in srange(-30, 30, plotStep)]
    p = line(F)
    styleLfunctionPlot(p, 10)
    fn = tempfile.mktemp(suffix=".png")
    p.save(filename=fn)
    data = file(fn).read()
    os.remove(fn)
    return data
Example #4
0
def parse_complex_number(z):
    zs = p2sage(z)
    z_parsed = "(" + str(real_part(zs)) + "," + str(imag_part(zs)) + ")"
    return z_parsed
Example #5
0
def getGenus2Ldata(label,label_type="url"):
    connection = base.getDBConnection()
#    g2 = connection.genus2_curves
    db = connection.Lfunctions
    try:
    #    Ldata = g2.Lfunctions.find_one({'hash': hash})
   #     Lpointer = db.instances.find_one({'url': label})
        if label_type == "url":
            Lpointer = db.instances.find_one({'url': label})
            Lhash = Lpointer['Lhash']
            Ldata = db.Lfunctions.find_one({'Lhash': Lhash})
        elif label_type == "Lhash":
            Ldata = db.Lfunctions.find_one({'Lhash': label})
            # just return what we have, because
            # we are just filling in the dual data  
            return Ldata
            
        if Ldata['order_of_vanishing']:
            central_value = [0.5 + 0.5*Ldata['motivic_weight'], 0]
        else:
            central_value = [0.5 + 0.5*Ldata['motivic_weight'],Ldata['leading_term']]
        if 'values' not in Ldata:
            Ldata['values'] = [ central_value ]
        else:
            Ldata['values'] += [ central_value ]

        pos_plot = [ 
                  [j * Ldata['plot_delta'], Ldata['plot_values'][j]]
                          for j in range(min(200, len(Ldata['plot_values'])))]

        if Ldata['self_dual']:
            neg_zeros = ["-" + str(pos_zero) for pos_zero in Ldata['positive_zeros']]
            root_number = p2sage(Ldata['root_number'])
            neg_plot = [ [-1*pt[0], root_number * pt[1]] for pt in pos_plot ][1:]

        else:   # can't happen for genus 2 curves
            dual_L_label = Ldata['conjugate']
            dual_L_data = getGenus2Ldata(dual_L_label, label_type="Lhash")
            neg_zeros = ["-" + str(pos_zero) for pos_zero in dual_L_data['positive_zeros']]

            neg_plot = [
                  [-1 * j * dual_L_data['plot_delta'], dual_L_data['plot_values'][j]]
                          for j in range(1,min(200,len(dual_L_data['plot_values'])))]
#        if label.startswith('Character'):  # because those temporarily are missing the plot
#            Ldata['plot'] = ""
#        else:
#        pos_plot = [
#                  [j * Ldata['plot_delta'], Ldata['plot_values'][j]]
#                          for j in range(len(Ldata['plot_values']))]
#        if Ldata['self_dual']:
#            neg_plot = [ [-1*pt[0], Ldata['root_number'] * pt[1]] for pt in pos_plot ][1:]
#            neg_plot.reverse()
#        else:
#            pass  # need to add this case
#        Ldata['plot'] = neg_plot[:] + pos_plot[:]

        neg_zeros.reverse()
        Ldata['zeros'] = neg_zeros[:]
        Ldata['zeros'] += [0 for _ in range(Ldata['order_of_vanishing'])]
        Ldata['zeros'] += [str(pos_zero) for pos_zero in Ldata['positive_zeros']]

        neg_plot.reverse()
        Ldata['plot'] = neg_plot[:] + pos_plot[:]
        #print "Ldata['plot']",Ldata['plot']

    except ValueError:
        Ldata = None
    return Ldata
Example #6
0
def getGenus2Ldata(label,label_type="url"):
    connection = base.getDBConnection()
#    g2 = connection.genus2_curves
    db = connection.Lfunctions
    try:
    #    Ldata = g2.Lfunctions.find_one({'hash': hash})
   #     Lpointer = db.instances.find_one({'url': label})
        if label_type == "url":
            Lpointer = db.instances.find_one({'url': label})
            Lhash = Lpointer['Lhash']
            Ldata = db.Lfunctions.find_one({'Lhash': Lhash})
        elif label_type == "Lhash":
            Ldata = db.Lfunctions.find_one({'Lhash': label})
            # just return what we have, because
            # we are just filling in the dual data  
            return Ldata
            
        if Ldata['order_of_vanishing'] or 'leading_term' not in Ldata.keys():
            central_value = [0.5 + 0.5*Ldata['motivic_weight'], 0]
        else:
            central_value = [0.5 + 0.5*Ldata['motivic_weight'],Ldata['leading_term']]
        if 'values' not in Ldata:
            Ldata['values'] = [ central_value ]
        else:
            Ldata['values'] += [ central_value ]

        pos_plot = [ 
                  [j * Ldata['plot_delta'], Ldata['plot_values'][j]]
                          for j in range(min(200, len(Ldata['plot_values'])))]

        if Ldata['self_dual']:
            neg_zeros = ["-" + str(pos_zero) for pos_zero in Ldata['positive_zeros']]
            root_number = p2sage(Ldata['root_number'])
            neg_plot = [ [-1*pt[0], root_number * pt[1]] for pt in pos_plot ][1:]

        else:   # can't happen for genus 2 curves
            dual_L_label = Ldata['conjugate']
            dual_L_data = getGenus2Ldata(dual_L_label, label_type="Lhash")
            neg_zeros = ["-" + str(pos_zero) for pos_zero in dual_L_data['positive_zeros']]

            neg_plot = [
                  [-1 * j * dual_L_data['plot_delta'], dual_L_data['plot_values'][j]]
                          for j in range(1,min(200,len(dual_L_data['plot_values'])))]
#        if label.startswith('Character'):  # because those temporarily are missing the plot
#            Ldata['plot'] = ""
#        else:
#        pos_plot = [
#                  [j * Ldata['plot_delta'], Ldata['plot_values'][j]]
#                          for j in range(len(Ldata['plot_values']))]
#        if Ldata['self_dual']:
#            neg_plot = [ [-1*pt[0], Ldata['root_number'] * pt[1]] for pt in pos_plot ][1:]
#            neg_plot.reverse()
#        else:
#            pass  # need to add this case
#        Ldata['plot'] = neg_plot[:] + pos_plot[:]

        neg_zeros.reverse()
        Ldata['zeros'] = neg_zeros[:]
        Ldata['zeros'] += [0 for _ in range(Ldata['order_of_vanishing'])]
        Ldata['zeros'] += [str(pos_zero) for pos_zero in Ldata['positive_zeros']]

        neg_plot.reverse()
        Ldata['plot'] = neg_plot[:] + pos_plot[:]
        #print "Ldata['plot']",Ldata['plot']

    except ValueError:
        Ldata = None
    return Ldata
Example #7
0
def parse_complex_number(z):
    zs = p2sage(z)
    z_parsed = "(" + str(real_part(zs)) + "," + str(imag_part(zs)) + ")"
    return z_parsed