def dc_calc_kloosterman(modulus, number):
    arg = request.args.get("val", [])
    if not arg:
        return flask.abort(404)
    try:
        a, b = map(int, arg.split(','))
        if modulus == 1:
            # there is a bug in sage for modulus = 1
            return r"""
            \( \displaystyle K(%s,%s,\chi_{1}(1,·))
            = \sum_{r \in \mathbb{Z}/\mathbb{Z}}
                 \chi_{1}(1,r) 1^{%s r + %s r^{-1}}
            = 1 \)
            """ % (a, b, a, b)
        from dirichlet_conrey import DirichletGroup_conrey
        chi = DirichletGroup_conrey(modulus)[number]
        chi = chi.sage_character()
        k = chi.kloosterman_sum_numerical(100, a, b)
        real = round(k.real(), 5)
        imag = round(k.imag(), 5)
        if imag == 0:
            k = str(real)
        elif real == 0:
            k = str(imag) + "i"
        else:
            k = latex(k)
        return r"""
        \( \displaystyle K(%s,%s,\chi_{%s}(%s,·))
        = \sum_{r \in \mathbb{Z}/%s\mathbb{Z}}
             \chi_{%s}(%s,r) e\left(\frac{%s r + %s r^{-1}}{%s}\right)
        = %s. \)""" % (a, b, modulus, number, modulus, modulus, number, a, b, modulus, k)
    except Exception, e:
        return "<span style='color:red;'>ERROR: %s</span>" % e
Example #2
0
def dc_calc_kloosterman(modulus, number):
    arg = request.args.get("val", [])
    if not arg:
        return flask.abort(404)
    try:
        a, b = map(int, arg.split(','))
        if modulus == 1:
            # there is a bug in sage for modulus = 1
            return r"""
            \( \displaystyle K(%s,%s,\chi_{1}(1,&middot;))
            = \sum_{r \in \mathbb{Z}/\mathbb{Z}}
                 \chi_{1}(1,r) 1^{%s r + %s r^{-1}}
            = 1 \)
            """ % (a, b, a, b)
        from dirichlet_conrey import DirichletGroup_conrey
        chi = DirichletGroup_conrey(modulus)[number]
        chi = chi.sage_character()
        k = chi.kloosterman_sum_numerical(100, a, b)
        real = round(k.real(), 5)
        imag = round(k.imag(), 5)
        if imag == 0:
            k = str(real)
        elif real == 0:
            k = str(imag) + "i"
        else:
            k = latex(k)
        return r"""
        \( \displaystyle K(%s,%s,\chi_{%s}(%s,&middot;))
        = \sum_{r \in \mathbb{Z}/%s\mathbb{Z}}
             \chi_{%s}(%s,r) e\left(\frac{%s r + %s r^{-1}}{%s}\right)
        = %s. \)""" % (a, b, modulus, number, modulus, modulus, number, a, b,
                       modulus, k)
    except Exception, e:
        return "<span style='color:red;'>ERROR: %s</span>" % e