예제 #1
0
def get_new_and_oldspace_decomposition(k, N, xi=0):
    r"""
    Get decomposition of the new and oldspace S_k(N,xi) into submodules.



    """
    M = ModularSymbols(N, k, sign=1).cuspidal_submodule()
    L = list()
    L = [M.new_submodule().dimension()]
    check_dim = M.new_submodule().dimension()
    for d in divisors(N):
        if (d == 1):
            continue
        O = M.old_submodule(d)
        Od = O.dimension()
        if (d == N and k == 2 or Od == 0):
            continue
        S = ModularSymbols(ZZ(N / d), k,
                           sign=1).cuspidal_submodule().new_submodule()
        Sd = S.dimension()
        if (Sd == 0):
            logger.info("%s, %s" % (O, Od))
            logger.info("%s, %s" % (S, Sd))
        mult = len(divisors(ZZ(d)))
        check_dim = check_dim + mult * Sd
        L.append((ZZ(N / d), mult, Sd))
    check_dim = check_dim - M.dimension()
    if (check_dim <> 0):
        raise ArithmeticError, "Something wrong! check_dim=%s" % check_dim
    return str(M.dimension(), L)
예제 #2
0
def get_new_and_oldspace_decomposition(k,N,xi=0):
    r"""
    Get decomposition of the new and oldspace S_k(N,xi) into submodules.



    """
    M=ModularSymbols(N,k,sign=1).cuspidal_submodule()
    L=list()
    L=[M.new_submodule().dimension()]
    check_dim=M.new_submodule().dimension()
    for d in divisors(N):
        if(d==1):
            continue
        O=M.old_submodule(d); Od=O.dimension()
        if(d==N and k==2 or Od==0):
            continue
        S=ModularSymbols(ZZ(N/d),k,sign=1).cuspidal_submodule().new_submodule(); Sd=S.dimension()
        if(Sd==0):
          logger.info("%s, %s" % (O,Od))
          logger.info("%s, %s" % (S,Sd))
        mult=len(divisors(ZZ(d)))
        check_dim=check_dim+mult*Sd
        L.append((ZZ(N/d),mult,Sd))
    check_dim=check_dim-M.dimension()
    if(check_dim<>0):
        raise ArithmeticError, "Something wrong! check_dim=%s" % check_dim
    return str(M.dimension(),L)
예제 #3
0
def html_table(tbl):
    r""" Takes a dictonary and returns an html-table.

    INPUT:
    
    -''tbl'' -- dictionary with the following keys
              - headersh // horozontal headers
              - headersv // vertical headers
              - rows -- dictionary of rows of data
              
    """
    ncols = len(tbl["headersh"])
    nrows = len(tbl["headersv"])
    data = tbl['data']
    if (len(data) <> nrows):
        logger.error("wrong number of rows!")
    for i in range(nrows):
        logger.info("len(%s)=%s" % (i, len(data[i])))
        if (len(data[i]) <> ncols):
            logger.error("wrong number of cols [=%s]!" % ncols)

    if (tbl.has_key('atts')):
        s = "<table " + str(tbl['atts']) + ">\n"
    else:
        s = "<table>\n"
    format = dict()
    for i in range(ncols):
        format[i] = ''
        if (tbl.has_key('data_format')):
            if isinstance(tbl['data_format'], dict):
                if (tbl['data_format'].has_key(i)):
                    format[i] = tbl['data_format'][i]
            elif (isinstance(tbl['data_format'], str)):
                format[i] = tbl['data_format']
    if (tbl.has_key('header')):
        s += "<thead><tr><th><td colspan=\"" + str(
            ncols) + "\">" + tbl['header'] + "</td></th></tr></thead>"
    s = s + "<tbody>"
    #smath="<span class=\"math\">"
    # check which type of content we have
    h1 = tbl['headersh'][0]
    sheaderh = ""
    sheaderv = ""
    h1 = tbl['headersv'][0]
    col_width = dict()
    if not tbl.has_key('col_width'):
        # use maximum width as default
        maxw = 0
        for k in range(ncols):
            for r in range(nrows):
                l = len_as_printed(str(data[r][k]))
                if l > maxw:
                    maxw = l
        l = l * 10.0  # use true font size?
        for k in range(ncols):
            col_width[k] = maxw
    else:
        for i in range(ncols):
            col_width[i] = 0
            if tbl.has_key('col_width'):
                if tbl['col_width'].has_key(i):
                    col_width[i] = tbl['col_width'][i]
    if (tbl.has_key("corner_label")):
        l = len_as_printed(str(tbl["corner_label"])) * 10
        row = "<tr><td width=\"%s\">" % l
        row += str(tbl["corner_label"]) + "</td>"
    else:
        row = "<tr><td></td>"
    for k in range(ncols):
        row = row + "<td>" + sheaderh + str(tbl['headersh'][k]) + "</td> \n"

    row = row + "</tr> \n"
    s = s + row
    for r in range(nrows):
        l = len_as_printed(str(tbl["headersv"][r])) * 10
        logger.info("l=%s  head=%s" % (l, tbl["headersv"]))
        row = "<tr><td width=\"%s\">" % l
        row += sheaderv + str(tbl['headersv'][r]) + "</td>"
        for k in range(ncols):
            wid = col_width[k]
            if format[k] == 'html' or format[k] == 'text':
                row = row + "\t<td halign=\"center\" width=\"" + str(
                    wid) + "\">"
                if isinstance(data[r][k], list):
                    for ss in data[r][k]:
                        sss = str(ss)
                        if (len(sss) > 0):
                            row += sss
                else:
                    sss = str(data[r][k])
                    row += sss
                row = row + "</td> \n"
            else:
                row = row + "\t<td width=\"" + str(wid) + "\">"
                if isinstance(data[r][k], list):
                    for ss in data[r][k]:
                        sss = latex(ss)
                        if (len(sss) > 0):
                            row += "\(" + sss + "\)"
                else:
                    sss = latex(data[r][k])
                    if (len(sss) > 0):
                        row = row + "\(" + sss + "\)</td> \n"
                row += "</td>\n"
        # allow for different format in different columns
        row = row + "</tr> \n"
        s = s + row
    s = s + "</tbody></table>"
    return s
예제 #4
0
def find_inverse_images_of_twists(k, N=1, chi=0, fi=0, prec=10, verbose=0):
    r"""
    Checks if f is minimal and if not, returns the associated
    minimal form to precision prec.

    INPUT:

    - ''k'' -- positive integer : the weight
    - ''N'' -- positive integer (default 1) : level
    - ''chi'' -- non-neg. integer (default 0) use character nr. chi
    - ''fi'' -- non-neg. integer (default 0) We want to use the element nr. fi f=Newforms(N,k)[fi]
    - ''prec'' -- integer (the number of coefficients to get)
    - ''verbose'' -- integer 
    OUTPUT:

    -''[t,l]'' -- tuple of a Bool t and a list l. The list l contains all tuples of forms which twists to the given form.
              The actual minimal one is the first element of this list.

    EXAMPLES::



    """
    (t, f) = _get_newform(k, N, chi, fi)

    if (not t):
        return f
    if (is_squarefree(ZZ(N))):
        return [True, f]
    # We need to check all square factors of N
    logger.info("investigating: %s" % f)
    N_sqfree = squarefree_part(ZZ(N))
    Nsq = ZZ(N / N_sqfree)
    twist_candidates = list()
    KF = f.base_ring()
    # check how many Hecke eigenvalues we need to check
    max_nump = number_of_hecke_to_check(f)
    maxp = max(primes_first_n(max_nump))
    for d in divisors(N):
        # we look at all d such that d^2 divdes N
        if (not ZZ(d**2).divides(ZZ(N))):
            continue
        D = DirichletGroup(d)
        # check possible candidates to twist into f
        # g in S_k(M,chi) wit M=N/d^2
        M = ZZ(N / d**2)
        logger.info("Checking level %s" % M)
        for xig in range(euler_phi(M)):
            (t, glist) = _get_newform(k, M, xig)
            if (not t):
                return glist
            for g in glist:
                logger.debug("Comparing to function %s" % g)
                KG = g.base_ring()
                # we now see if twisting of g by xi in D gives us f
                for xi in D:
                    try:
                        for p in primes_first_n(max_nump):
                            if (ZZ(p).divides(ZZ(N))):
                                continue
                            bf = f.q_expansion(maxp + 1)[p]
                            bg = g.q_expansion(maxp + 1)[p]
                            if (bf == 0 and bg == 0):
                                continue
                            elif (bf == 0 and bg <> 0 or bg == 0 and bf <> 0):
                                raise StopIteration()
                            if (ZZ(p).divides(xi.conductor())):
                                raise ArithmeticError, ""
                            xip = xi(p)
                            # make a preliminary check that the base rings match with respect to being real or not
                            try:
                                QQ(xip)
                                XF = QQ
                                if (KF <> QQ or KG <> QQ):
                                    raise StopIteration
                            except TypeError:
                                # we have a  non-rational (i.e. complex) value of the character
                                XF = xip.parent()
                                if ((KF == QQ or KF.is_totally_real()) and
                                    (KG == QQ or KG.is_totally_real())):
                                    raise StopIteration
                            ## it is diffcult to compare elements from diferent rings in general but we make some checcks
                            ## is it possible to see if there is a larger ring which everything can be coerced into?
                            ok = False
                            try:
                                a = KF(bg / xip)
                                b = KF(bf)
                                ok = True
                                if (a <> b):
                                    raise StopIteration()
                            except TypeError:
                                pass
                            try:
                                a = KG(bg)
                                b = KG(xip * bf)
                                ok = True
                                if (a <> b):
                                    raise StopIteration()
                            except TypeError:
                                pass
                            if (
                                    not ok
                            ):  # we could coerce and the coefficients were equal
                                return "Could not compare against possible candidates!"
                            # otherwise if we are here we are ok and found a candidate
                        twist_candidates.append([dd, g.q_expansion(prec), xi])
                    except StopIteration:
                        # they are not equal
                        pass
    #logger.debug("Candidates=%s" % twist_candidates)
    if (len(twist_candidates) == 0):
        return (True, None)
    else:
        return (False, twist_candidates)
예제 #5
0
def html_table(tbl):
    r""" Takes a dictonary and returns an html-table.

    INPUT:
    
    -''tbl'' -- dictionary with the following keys
              - headersh // horozontal headers
              - headersv // vertical headers
              - rows -- dictionary of rows of data
              
    """
    ncols=len(tbl["headersh"])
    nrows=len(tbl["headersv"])
    data=tbl['data']
    if(len(data)<>nrows):
        logger.error("wrong number of rows!")
    for i in range(nrows):
        logger.info("len(%s)=%s" % (i,len(data[i])))
        if(len(data[i])<>ncols):
            logger.error("wrong number of cols [=%s]!" % ncols)

    if(tbl.has_key('atts')):
        s="<table "+str(tbl['atts'])+">\n"
    else:
        s="<table>\n"
    format = dict()
    for i in range(ncols):
        format[i]=''
        if(tbl.has_key('data_format')):
            if isinstance(tbl['data_format'],dict):
                if(tbl['data_format'].has_key(i)):
                    format[i]=tbl['data_format'][i]
            elif(isinstance(tbl['data_format'],str)):
                format[i]=tbl['data_format']
    if(tbl.has_key('header')):
        s+="<thead><tr><th><td colspan=\""+str(ncols)+"\">"+tbl['header']+"</td></th></tr></thead>"
    s=s+"<tbody>"
    #smath="<span class=\"math\">"
    # check which type of content we have
    h1=tbl['headersh'][0]
    sheaderh="";    sheaderv=""
    h1=tbl['headersv'][0]
    col_width=dict()
    if not tbl.has_key('col_width'):
        # use maximum width as default
        maxw = 0
        for k in range(ncols):
            for r in range(nrows):
                l =len_as_printed(str(data[r][k]))
                if l>maxw:
                    maxw = l
        l = l*10.0 # use true font size?
        for k in range(ncols):
            col_width[k]=maxw
    else:
        for i in range(ncols):        
            col_width[i]=0
            if tbl.has_key('col_width'):
                if tbl['col_width'].has_key(i):
                    col_width[i]=tbl['col_width'][i]
    if(tbl.has_key("corner_label")):
        l = len_as_printed(str(tbl["corner_label"]))*10
        row="<tr><td width=\"%s\">" % l
        row+=str(tbl["corner_label"])+"</td>"
    else:
        row="<tr><td></td>"
    for k in range(ncols):
        row=row+"<td>"+sheaderh+str(tbl['headersh'][k])+"</td> \n"

    row=row+"</tr> \n"
    s=s+row
    for r in range(nrows):
        l = len_as_printed(str(tbl["headersv"][r]))*10
        logger.info("l=%s  head=%s" % (l,tbl["headersv"]))
        row="<tr><td width=\"%s\">" %l
        row+=sheaderv+str(tbl['headersv'][r])+"</td>"
        for k in range(ncols):
            wid = col_width[k]
            if format[k]=='html' or format[k]=='text':
                row=row+"\t<td halign=\"center\" width=\""+str(wid)+"\">"
                if isinstance(data[r][k],list):
                    for ss in data[r][k]:
                        sss = str(ss)
                        if(len(sss)>0):
                            row+=sss
                else:
                    sss = str(data[r][k])
                    row+=sss
                row=row+"</td> \n"
            else:
                row=row+"\t<td width=\""+str(wid)+"\">"
                if isinstance(data[r][k],list):
                    for ss in data[r][k]:
                        sss = latex(ss)
                        if(len(sss)>0):
                            row+="\("+sss+"\)"
                else:
                    sss=latex(data[r][k])
                    if(len(sss)>0):
                        row=row+"\("+sss+"\)</td> \n"
                row+="</td>\n"
        # allow for different format in different columns
        row=row+"</tr> \n"
        s=s+row
    s=s+"</tbody></table>"
    return s
예제 #6
0
def find_inverse_images_of_twists(k,N=1,chi=0,fi=0,prec=10,verbose=0):
    r"""
    Checks if f is minimal and if not, returns the associated
    minimal form to precision prec.

    INPUT:

    - ''k'' -- positive integer : the weight
    - ''N'' -- positive integer (default 1) : level
    - ''chi'' -- non-neg. integer (default 0) use character nr. chi
    - ''fi'' -- non-neg. integer (default 0) We want to use the element nr. fi f=Newforms(N,k)[fi]
    - ''prec'' -- integer (the number of coefficients to get)
    - ''verbose'' -- integer 
    OUTPUT:

    -''[t,l]'' -- tuple of a Bool t and a list l. The list l contains all tuples of forms which twists to the given form.
              The actual minimal one is the first element of this list.

    EXAMPLES::



    """
    (t,f) = _get_newform(k,N,chi,fi)

    if(not t):
        return f
    if(is_squarefree(ZZ(N))):
        return [True,f]
    # We need to check all square factors of N
    logger.info("investigating: %s" % f)
    N_sqfree=squarefree_part(ZZ(N))
    Nsq=ZZ(N/N_sqfree)
    twist_candidates=list()
    KF=f.base_ring()
    # check how many Hecke eigenvalues we need to check
    max_nump=number_of_hecke_to_check(f)
    maxp=max(primes_first_n(max_nump))
    for d in divisors(N):
        # we look at all d such that d^2 divdes N
        if(not ZZ(d**2).divides(ZZ(N))):
            continue
        D=DirichletGroup(d)
        # check possible candidates to twist into f
        # g in S_k(M,chi) wit M=N/d^2
        M=ZZ(N/d**2)
        logger.info("Checking level %s"%M)
        for xig in range(euler_phi(M)):
            (t,glist) = _get_newform(k,M,xig)
            if(not t):
                return glist
            for g in glist:
                logger.debug("Comparing to function %s" %g)
                KG=g.base_ring()
                # we now see if twisting of g by xi in D gives us f
                for xi in D:
                    try:
                        for p in primes_first_n(max_nump):
                            if(ZZ(p).divides(ZZ(N))):
                                continue
                            bf=f.q_expansion(maxp+1)[p]
                            bg=g.q_expansion(maxp+1)[p]
                            if(bf == 0 and bg == 0):
                                continue
                            elif(bf==0 and bg<>0 or bg==0 and bf<>0):
                                raise StopIteration()
                            if(ZZ(p).divides(xi.conductor())):
                                raise ArithmeticError,""
                            xip=xi(p)
                            # make a preliminary check that the base rings match with respect to being real or not
                            try:
                                QQ(xip)
                                XF=QQ
                                if( KF<>QQ or KG<>QQ):
                                    raise StopIteration
                            except TypeError:
                                # we have a  non-rational (i.e. complex) value of the character
                                XF=xip.parent() 
                                if( (KF == QQ or KF.is_totally_real()) and (KG == QQ or KG.is_totally_real())):
                                    raise StopIteration
                            ## it is diffcult to compare elements from diferent rings in general but we make some checcks
                            ## is it possible to see if there is a larger ring which everything can be coerced into?
                            ok=False
                            try:
                                a=KF(bg/xip); b=KF(bf)
                                ok=True
                                if(a<>b):
                                    raise StopIteration()
                            except TypeError:
                                pass
                            try:
                                a=KG(bg); b=KG(xip*bf)
                                ok=True
                                if(a<>b):
                                    raise StopIteration()
                            except TypeError:
                                pass
                            if(not ok): # we could coerce and the coefficients were equal
                                return "Could not compare against possible candidates!"
                            # otherwise if we are here we are ok and found a candidate
                        twist_candidates.append([dd,g.q_expansion(prec),xi])
                    except StopIteration:
                        # they are not equal
                        pass
    #logger.debug("Candidates=%s" % twist_candidates)
    if(len(twist_candidates)==0):
        return (True,None)
    else:
        return (False,twist_candidates)