Exemplo n.º 1
0
def formtest_2(minD, maxD):
    s = 0
    for D in range(minD, maxD):
        if is_fundamental_discriminant(-D):
            for d in divisors(D):
                if is_fundamental_discriminant(-d):
                    sd = RR(
                        RR(1) / RR(6) * (RR(d) + old_div(RR(D), RR(d))) -
                        RR(sqrt(D)) / RR(pi) * log(d))
                    print(D, d, sd)
                    s += sd
        if s <= 0:
            print("s= {0}  D={1}".format(s, D))
Exemplo n.º 2
0
def class_nr_pos_def_qf(D):
    r"""
    Compute the class number of positive definite quadratic forms.
    For fundamental discriminants this is the class number of Q(sqrt(D)),
    otherwise it is computed using: Cohen 'A course in Computational Algebraic Number Theory', p. 233
    """
    if D>0:
        return 0
    D4 = D % 4
    if D4 == 3 or D4==2:
        return 0
    K = QuadraticField(D)
    if is_fundamental_discriminant(D):
        return K.class_number()
    else:
        D0 = K.discriminant()
        Df = ZZ(D).divide_knowing_divisible_by(D0)
        if not is_square(Df):
            raise ArithmeticError,"DId not get a discrinimant * square! D={0} disc(D)={1}".format(D,D0)
        D2 = sqrt(Df)
        h0 = QuadraticField(D0).class_number()
        w0 = _get_w(D0)
        w = _get_w(D)
        #print "w,w0=",w,w0
        #print "h0=",h0
        h = 1
        for p in prime_divisors(D2):
            h = QQ(h)*(1-kronecker(D0,p)/QQ(p))
        #print "h=",h
        #print "fak=",
        h=QQ(h*h0*D2*w)/QQ(w0)
        return h
Exemplo n.º 3
0
def neg_fdd_div(D):
    s = 0
    for d in divisors(D):
        if is_fundamental_discriminant(-d):
            if Zmod(d)(old_div(D, d)).is_square():
                s += 1
    return s
Exemplo n.º 4
0
def orbittest(minD, maxD, eps=-1):
    for D in range(minD, maxD + 1):
        if is_fundamental_discriminant(eps * D) and is_odd(D):
            print(D)
            print(
                CMorbits(eps * D) -
                len(Newforms(kronecker_character(eps * D), 3, names='a')))
Exemplo n.º 5
0
def CMorbits(D):
    s = sum([
        2**(len(prime_divisors(old_div(D, d))))
        for d in divisors(D) if is_fundamental_discriminant(-d) and Zmod(d)
        (old_div(D, d)).is_square()
    ]) + 1
    return s
Exemplo n.º 6
0
def class_nr_pos_def_qf(D):
    r"""
    Compute the class number of positive definite quadratic forms.
    For fundamental discriminants this is the class number of Q(sqrt(D)),
    otherwise it is computed using: Cohen 'A course in Computational Algebraic Number Theory', p. 233
    """
    if D>0:
        return 0
    D4 = D % 4
    if D4 == 3 or D4==2:
        return 0
    K = QuadraticField(D)
    if is_fundamental_discriminant(D):
        return K.class_number()
    else:
        D0 = K.discriminant()
        Df = ZZ(D).divide_knowing_divisible_by(D0)
        if not is_square(Df):
            raise ArithmeticError("Did not get a discrimimant * square! D={0} disc(D)={1}".format(D,D0))
        D2 = sqrt(Df)
        h0 = QuadraticField(D0).class_number()
        w0 = _get_w(D0)
        w = _get_w(D)
        #print "w,w0=",w,w0
        #print "h0=",h0
        h = 1
        for p in prime_divisors(D2):
            h = QQ(h)*(1-kronecker(D0,p)/QQ(p))
        #print "h=",h
        #print "fak=",
        h=QQ(h*h0*D2*w)/QQ(w0)
        return h
Exemplo n.º 7
0
def compare_formulas_2a(D, k):
    d1 = dimension_new_cusp_forms(kronecker_character(D), k)
    if D < 0:
        D = -D
    d2 = RR(1 / pi * sqrt(D) * sum([
        log(d) * sigma(old_div(D, d), 0) for d in divisors(D) if Zmod(d)
        (old_div(D, d)).is_square() and is_fundamental_discriminant(-d)
    ]))
    return d1 - d2
Exemplo n.º 8
0
def sigma_rep(Delta, print_divisors=False):
    s = 0
    for DD in divisors(Delta):
        if is_fundamental_discriminant(-DD):
            D = -DD
            for d in divisors(old_div(Delta, D)):
                s += kronecker(D, d)
                if print_divisors:
                    print(D, d, kronecker(D, d))
    return s
Exemplo n.º 9
0
def compare_formulas_2(D, k):
    d1 = old_div(RR(abs(D)), RR(6))
    if D < 0:
        D = -D
    s1 = RR(
        sqrt(abs(D)) * sum([
            log(d) for d in divisors(D) if is_fundamental_discriminant(-d)
            and kronecker(-d, old_div(D, d)) == 1
        ]))
    d2 = RR((old_div(2, (sqrt(3) * pi))) * s1)
    return d1 - d2, d2, RR(2 * sqrt(D) * log(D) / pi)
Exemplo n.º 10
0
def quadratic_twist_zeros(D, n, algorithm='clib'):
    """
    Return imaginary parts of the first n zeros of all the Dirichlet
    character corresponding to the quadratic field of discriminant D.

    INPUT:
        - D -- fundamental discriminant
        - n -- number of zeros to find
        - algorithm -- 'clib' (use C library) or 'subprocess' (open another process)
    """
    if algorithm == 'clib':
        L = Lfunction_from_character(kronecker_character(D), type="int")
        return L.find_zeros_via_N(n)
    elif algorithm == 'subprocess':
        assert is_fundamental_discriminant(D)
        cmd = "lcalc -z %s --twist-quadratic --start %s --finish %s"%(n, D, D)
        out = os.popen(cmd).read().split()
        return [float(out[i]) for i in range(len(out)) if i%2!=0]
    else:
        raise ValueError, "unknown algorithm '%s'"%algorithm
Exemplo n.º 11
0
def quadratic_twist_zeros(D, n, algorithm='clib'):
    """
    Return imaginary parts of the first n zeros of all the Dirichlet
    character corresponding to the quadratic field of discriminant D.

    INPUT:
        - D -- fundamental discriminant
        - n -- number of zeros to find
        - algorithm -- 'clib' (use C library) or 'subprocess' (open another process)
    """
    if algorithm == 'clib':
        L = Lfunction_from_character(kronecker_character(D), type="int")
        return L.find_zeros_via_N(n)
    elif algorithm == 'subprocess':
        assert is_fundamental_discriminant(D)
        cmd = "lcalc -z %s --twist-quadratic --start %s --finish %s" % (n, D,
                                                                        D)
        out = os.popen(cmd).read().split()
        return [float(out[i]) for i in range(len(out)) if i % 2 != 0]
    else:
        raise ValueError, "unknown algorithm '%s'" % algorithm
Exemplo n.º 12
0
def test_sigma_rep(Dmin=1, Dmax=1000, print_divisors=False):
    n = 0
    sa = 0
    sw = [1, 0]
    sm = [1, 0]
    for D in range(Dmin, Dmax):
        if is_fundamental_discriminant(-D):
            n += 1
            sr = sigma_rep(D, True)
            sa += sr
            sm[1] = max(sr, sm[1])
            swt = old_div(sr, D)
            sw[1] = max(swt, RR(sw[1]))
            if sm[1] == sr:
                sm[0] = -D
            if sw[1] == swt:
                sw[0] = -D
            ct = RR(100) * (RR(D)**(old_div(1.0, 25)))
            #if ct<=RR(sr):
            print(-D, sr, ct, sigma(D, 0))
    sa = old_div(sa, n)
    print("Max: {0}".format(sm))
    print("Avg: {0}, {1}".format(sa, RR(sa)))
    print("Worst case: {0}".format(sw))
Exemplo n.º 13
0
def compare_formulas_1(D, k):
    DG = DirichletGroup(abs(D))
    chi = DG(kronecker_character(D))
    d1 = dimension_new_cusp_forms(chi, k)
    #if D>0:
    #    lvals=sage.lfunctions.all.lcalc.twist_values(1,2,D)
    #else:
    #    lvals=sage.lfunctions.all.lcalc.twist_values(1,D,0)
    #s1=RR(sum([sqrt(abs(lv[0]))*lv[1]*2**len(prime_factors(D/lv[0])) for lv in lvals if lv[0].divides(D) and Zmod(lv[0])(abs(D/lv[0])).is_square()]))
    #d2=RR(1/pi*s1)
    d2 = 0
    for d in divisors(D):
        if is_fundamental_discriminant(-d):
            K = QuadraticField(-d)
            DD = old_div(ZZ(D), ZZ(d))
            ep = euler_phi((chi * DG(kronecker_character(-d))).conductor())
            #ep=euler_phi(squarefree_part(abs(D*d)))
            print("ep=", ep, D, d)
            ids = [a for a in K.ideals_of_bdd_norm(-DD)[-DD]]
            eulers1 = []
            for a in ids:
                e = a.euler_phi()
                if e != 1 and ep == 1:
                    if K(-1).mod(a) != K(1).mod(a):
                        e = old_div(e, (2 * ep))
                else:
                    e = old_div(e, ep)
                eulers1.append(e)
            print(eulers1, ep)
            s = sum(eulers1)
            if ep == 1 and not (d.divides(DD) or abs(DD) == 1):
                continue
            print(d, s)
            if len(eulers1) > 0:
                d2 += s * K.class_number()
    return d1 - d2
Exemplo n.º 14
0
def fundamental_discriminants(A, B):
    """Return the fundamental discriminants between A and B (inclusive), as Sage integers,
    ordered by absolute value, with negatives first when abs same."""
    v = [ZZ(D) for D in range(A, B + 1) if is_fundamental_discriminant(D)]
    v.sort(lambda x, y: cmp((abs(x), sgn(x)), (abs(y), sgn(y))))
    return v
Exemplo n.º 15
0
def test_neg_fdd_div(minD, maxD):
    for D in range(minD, maxD):
        if is_fundamental_discriminant(-D):
            print("{0}, {1}, {2}".format(D, neg_fdd_div(D),
                                         old_div(sigma(D, 0), 2)))
Exemplo n.º 16
0
def fundamental_discriminants(A, B):
    """Return the fundamental discriminants between A and B (inclusive), as Sage integers,
    ordered by absolute value, with negatives first when abs same."""
    v = [ZZ(D) for D in range(A, B+1) if is_fundamental_discriminant(D)]
    v.sort(lambda x,y: cmp((abs(x),sgn(x)),(abs(y),sgn(y))))
    return v