Ticket #3967: 9865.patch

File 9865.patch, 3.8 kB (added by jvoight, 4 months ago)
  • a/sage/rings/number_field/totallyreal.py

    old new  
    8787    return dB 
    8888 
    8989def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False, \ 
    90     phc=False, keep_fields=False, t_2=False): 
     90    phc=False, keep_fields=False, t_2=False, just_print=False): 
    9191    r""" 
    9292    This function enumerates primitive totally real fields of 
    9393    degree $n>1$ with discriminant $d \leq B$; optionally one can 
     
    197197    dB_odlyzko = odlyzko_bound_totallyreal(n) 
    198198    dB = math.ceil(40000*dB_odlyzko**n) 
    199199    counts = [0,0,0,0] 
     200   
     201    if just_print: 
     202        jp = open(just_print, "w") 
    200203 
    201204    if keep_fields: 
    202205        if type(keep_fields) == bool: 
     
    252255                        # Find a minimal lattice element 
    253256                        counts[3] += 1 
    254257                        ng = pari([nf,zk]).polredabs() 
     258                        ngt2 = ng[n-1]**2-2*ng[n-2] 
    255259 
    256260                        # Check if K is contained in the list. 
    257                         found = False 
    258                         ind = bisect.bisect_left(S, [d,ng]) 
    259                         while ind < len(S) and S[ind][0] == d: 
    260                             if S[ind][1] == ng: 
     261                        if not just_print: 
     262                            found = False 
     263                            ind = bisect.bisect_left(S, [d,ng]) 
     264                            while ind < len(S) and S[ind][0] == d: 
     265                                if S[ind][1] == ng: 
     266                                    if verbose: 
     267                                        print "but is not new" 
     268                                    found = True 
     269                                    break 
     270                                ind += 1 
     271                            if not found and (type(t_2) == bool and (not t_2 or ngt2 >= t_2val)) or \ 
     272                                (type(t_2) == Integer and ngt2 >= t_2): 
    261273                                if verbose: 
    262                                     print "but is not new" 
    263                                 found = True 
    264                                 break 
    265                             ind += 1 
    266                         ngt2 = ng[n-1]**2-2*ng[n-2] 
    267                         if not found and (type(t_2) == bool and (not t_2 or ngt2 >= t_2val)) or \ 
    268                             (type(t_2) == Integer and ngt2 >= t_2): 
    269                             if verbose: 
    270                                 print "and is new!" 
    271                             S.insert(ind, [d,ng]) 
    272  
     274                                    print "and is new!" 
     275                                S.insert(ind, [d,ng]) 
     276                        else: 
     277                            if (type(t_2) == bool and (not t_2 or ngt2 >= t_2val)) or \ 
     278                                (type(t_2) == Integer and ngt2 >= t_2): 
     279                                jp.write(str([d,ng.reverse().Vec()]) + "\n") 
    273280                    else: 
    274281                        if verbose: 
    275282                            print "has discriminant", abs(d), "> B" 
     
    290297            T.incr(f_out,verbose=verbose,phc=phc) 
    291298        else: 
    292299            T.incr(f_out,phc=phc) 
     300 
     301    if just_print: 
     302        jp.close() 
    293303 
    294304    # In the application of Smyth's theorem above (and easy 
    295305    # irreducibility test), we exclude finitely many possibilities