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
def dc_calc_jacobi(modulus, number): arg = request.args.get("val", []) if not arg: return flask.abort(404) arg = map(int, arg.split('.')) try: num = arg[0] from dirichlet_conrey import DirichletGroup_conrey chi = DirichletGroup_conrey(modulus)[number] psi = DirichletGroup_conrey(modulus)[num] chi = chi.sage_character() psi = psi.sage_character() jacobi_sum = chi.jacobi_sum(psi) return r"\( \displaystyle J(\chi_{%s}(%s,·),\chi_{%s}(%s,·)) = \sum_{r\in \mathbb{Z}/%s\mathbb{Z}} \chi_{%s}(%s,r) \chi_{%s}(%s,1-r) = %s.\)" % (modulus, number, modulus, num, modulus, modulus, number, modulus, num, latex(jacobi_sum)) except Exception, e: return "<span style='color:red;'>ERROR: %s</span>" % e
def dc_calc_gauss(modulus, number): arg = request.args.get("val", []) if not arg: return flask.abort(404) try: if modulus == 1: # there is a bug in sage for modulus = 1 return r"""\(\displaystyle \tau_{%s}(\chi_{1}(1,·)) = \sum_{r\in \mathbb{Z}/\mathbb{Z}} \chi_{1}(1,r) 1^{%s}= 1. \)""" % (int(arg), int(arg)) from dirichlet_conrey import DirichletGroup_conrey chi = DirichletGroup_conrey(modulus)[number] chi = chi.sage_character() g = chi.gauss_sum_numerical(100, int(arg)) real = round(g.real(), 10) imag = round(g.imag(), 10) if imag == 0.: g = str(real) elif real == 0.: g = str(imag) + "i" else: g = latex(g) from sage.rings.rational import Rational x = Rational('%s/%s' % (int(arg), modulus)) n = x.numerator() n = str(n) + "r" if not n == 1 else "r" d = x.denominator() return r"\(\displaystyle \tau_{%s}(\chi_{%s}(%s,·)) = \sum_{r\in \mathbb{Z}/%s\mathbb{Z}} \chi_{%s}(%s,r) e\left(\frac{%s}{%s}\right) = %s. \)" % (int(arg), modulus, number, modulus, modulus, number, n, d, g) except Exception, e: return "<span style='color:red;'>ERROR: %s</span>" % e
def dc_calc_gauss(modulus, number): arg = request.args.get("val", []) if not arg: return flask.abort(404) try: if modulus == 1: # there is a bug in sage for modulus = 1 return r"""\(\displaystyle \tau_{%s}(\chi_{1}(1,·)) = \sum_{r\in \mathbb{Z}/\mathbb{Z}} \chi_{1}(1,r) 1^{%s}= 1. \)""" % ( int(arg), int(arg)) from dirichlet_conrey import DirichletGroup_conrey chi = DirichletGroup_conrey(modulus)[number] chi = chi.sage_character() g = chi.gauss_sum_numerical(100, int(arg)) real = round(g.real(), 10) imag = round(g.imag(), 10) if imag == 0.: g = str(real) elif real == 0.: g = str(imag) + "i" else: g = latex(g) from sage.rings.rational import Rational x = Rational('%s/%s' % (int(arg), modulus)) n = x.numerator() n = str(n) + "r" if not n == 1 else "r" d = x.denominator() return r"\(\displaystyle \tau_{%s}(\chi_{%s}(%s,·)) = \sum_{r\in \mathbb{Z}/%s\mathbb{Z}} \chi_{%s}(%s,r) e\left(\frac{%s}{%s}\right) = %s. \)" % ( int(arg), modulus, number, modulus, modulus, number, n, d, g) except Exception, e: return "<span style='color:red;'>ERROR: %s</span>" % e
def dc_calc_jacobi(modulus, number): arg = request.args.get("val", []) if not arg: return flask.abort(404) arg = map(int, arg.split('.')) try: num = arg[0] from dirichlet_conrey import DirichletGroup_conrey chi = DirichletGroup_conrey(modulus)[number] psi = DirichletGroup_conrey(modulus)[num] chi = chi.sage_character() psi = psi.sage_character() jacobi_sum = chi.jacobi_sum(psi) return r"\( \displaystyle J(\chi_{%s}(%s,·),\chi_{%s}(%s,·)) = \sum_{r\in \mathbb{Z}/%s\mathbb{Z}} \chi_{%s}(%s,r) \chi_{%s}(%s,1-r) = %s.\)" % ( modulus, number, modulus, num, modulus, modulus, number, modulus, num, latex(jacobi_sum)) except Exception, e: return "<span style='color:red;'>ERROR: %s</span>" % e