Пример #1
0
def circle_image(A, B):
    G = Graphics()
    G += circle((0, 0), 1, color='grey')
    from collections import defaultdict
    tmp = defaultdict(int)
    for a in A:
        for j in range(a):
            if gcd(j, a) == 1:
                rational = Rational(j) / Rational(a)
                tmp[(rational.numerator(), rational.denominator())] += 1

    for b in B:
        for j in range(b):
            if gcd(j, b) == 1:
                rational = Rational(j) / Rational(b)
                tmp[(rational.numerator(), rational.denominator())] -= 1
    C = ComplexField()
    for val in tmp:
        if tmp[val] > 0:
            G += text(str(tmp[val]),
                      exp(C(-.2 + 2 * 3.14159 * I * val[0] / val[1])),
                      fontsize=30,
                      axes=False,
                      color="green")
        if tmp[val] < 0:
            G += text(str(abs(tmp[val])),
                      exp(C(.2 + 2 * 3.14159 * I * val[0] / val[1])),
                      fontsize=30,
                      axes=False,
                      color="blue")
    return G
Пример #2
0
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,&middot;)) =
          \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,&middot;)) = \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
Пример #3
0
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,&middot;)) =
          \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,&middot;)) = \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
Пример #4
0
def circle_image(A,B):
    G = Graphics()
    G += circle((0,0), 1 , color = 'grey')
    from collections import defaultdict
    tmp = defaultdict(int)
    for a in A:
        for j in range(a):
            if gcd(j,a) == 1:
                rational = Rational(j)/Rational(a)
                tmp[(rational.numerator(),rational.denominator())] += 1
    
    for b in B:
        for j in range(b):
            if gcd(j,b) == 1:
                rational = Rational(j)/Rational(b)
                tmp[(rational.numerator(),rational.denominator())] -= 1
    C = ComplexField()
    for val in tmp:
        if tmp[val] > 0:
            G += text(str(tmp[val]),exp(C(2*3.14159*I*val[0]/val[1])), fontsize = 30, axes = False, color = "green")
        if tmp[val] < 0:
            G += text(str(abs(tmp[val])),exp(C(2*3.14159*I*val[0]/val[1])), fontsize = 30, axes = False, color = "red")
    return G
Пример #5
0
def circle_image(A, B):
    G = Graphics()
    G += circle((0, 0), 1, color='black', thickness=3)
    G += circle(
        (0, 0), 1.4, color='black', alpha=0
    )  # This adds an invisible framing circle to the plot, which protects the aspect ratio from being skewed.
    from collections import defaultdict
    tmp = defaultdict(int)
    for a in A:
        for j in range(a):
            if gcd(j, a) == 1:
                rational = Rational(j) / Rational(a)
                tmp[(rational.numerator(), rational.denominator())] += 1

    for b in B:
        for j in range(b):
            if gcd(j, b) == 1:
                rational = Rational(j) / Rational(b)
                tmp[(rational.numerator(), rational.denominator())] -= 1
    C = ComplexField()
    color1 = (41 / 255, 95 / 255, 45 / 255)
    color2 = (0 / 255, 0 / 255, 150 / 255)
    for val in tmp:
        if tmp[val] > 0:
            G += text(str(tmp[val]),
                      exp(C(-.2 + 2 * 3.14159 * I * val[0] / val[1])),
                      fontsize=30,
                      axes=False,
                      color=color1)
        if tmp[val] < 0:
            G += text(str(abs(tmp[val])),
                      exp(C(.2 + 2 * 3.14159 * I * val[0] / val[1])),
                      fontsize=30,
                      axes=False,
                      color=color2)
    return G
Пример #6
0
 def gauss_sum(self, val):
     val = int(val)
     mod, num = self.modulus, self.number
     chi = self.chi.sage_character()
     g = chi.gauss_sum_numerical(100, val)
     g = complex2str(g)
     from sage.rings.rational import Rational
     x = Rational('%s/%s' % (val, mod))
     n = x.numerator()
     n = str(n) + "r" if not n == 1 else "r"
     d = x.denominator()
     Gtex = '\Z/%s\Z' % mod
     chitex = self.char2tex(mod, num, tag=False)
     chitexr = self.char2tex(mod, num, 'r', tag=False)
     deftex = r'\sum_{r\in %s} %s e\left(\frac{%s}{%s}\right)'%(Gtex,chitexr,n,d)
     return r"\(\displaystyle \tau_{%s}(%s) = %s = %s. \)" % (val, chitex, deftex, g)
Пример #7
0
 def gauss_sum(self, val):
     val = int(val)
     mod, num = self.modulus, self.number
     chi = self.chi.sage_character()
     g = chi.gauss_sum_numerical(100, val)
     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' % (val, mod))
     n = x.numerator()
     n = str(n) + "r" if not n == 1 else "r"
     d = x.denominator()
     Gtex = '\mathbb{Z}/%s\mathbb{Z}' % mod
     chitex = self.char2tex(mod, num, tag=False)
     chitexr = self.char2tex(mod, num, 'r', tag=False)
     deftex = r'\sum_{r\in %s} %s e\left(\frac{%s}{%s}\right)'%(Gtex,chitexr,n,d)
     return r"\(\displaystyle \tau_{%s}(%s) = %s = %s. \)" % (val, chitex, deftex, g)