Changeset 8376:fe09ee4c519e
- Timestamp:
- 11/18/07 13:26:19 (6 years ago)
- Branch:
- default
- Location:
- sage/rings/number_field
- Files:
-
- 5 edited
-
all.py (modified) (1 diff)
-
totallyreal.py (modified) (1 diff)
-
totallyreal_data.pyx (modified) (1 diff)
-
totallyreal_dsage.py (modified) (1 diff)
-
totallyreal_rel.py (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/rings/number_field/all.py
r8354 r8376 14 14 from totallyreal_data import hermite_constant 15 15 from totallyreal_dsage import totallyreal_dsage 16 from totallyreal_rel import enumerate_totallyreal_fields_imprim, enumerate_totallyreal_fields_rel 17 from hot import my_matrix -
sage/rings/number_field/totallyreal.py
r8375 r8376 225 225 d = nf.poldisc() 226 226 counts[0] += 1 227 if d > 0 and nf.polsturm_full() == n:227 if d > 0: 228 228 da = int_has_small_square_divisor(Integer(d)) 229 229 if d > dB or d <= B*da: -
sage/rings/number_field/totallyreal_data.pyx
r8371 r8376 630 630 print "" 631 631 632 # Check for double roots633 632 for i from 0 <= i < n-k-1: 634 633 if abs(self.beta[k*np1+i] 635 - self.beta[k*np1+(i+1)]) < 2*eps_global:634 - self.beta[k*np1+(i+1)]) < 10*eps_global: 636 635 # This happens reasonably infrequently, so calling 637 636 # the Python routine should be sufficiently fast... 638 637 f = ZZx([self.gnk[(k+1)*n+i] for i in range(n-(k+1)+1)]) 639 df = ZZx([self.gnk[(k+2)*n+i] for i in range(n-(k+2)+1)]) 638 # Could just take self.gnk(k+2)*n+i, but this may not be initialized... 639 df = ZZx([i*self.gnk[(k+1)*n+i] for i in range(1,n-(k+1)+1)]) 640 640 if gcd(f,df) <> 1: 641 641 if verbose: -
sage/rings/number_field/totallyreal_dsage.py
r8369 r8376 316 316 while True: 317 317 time.sleep(self.timeout) 318 self.split_timed_out_jobs()319 318 self.compile_fields() 319 self.split_all_jobs() 320 320 321 321 def num_jobs(self): -
sage/rings/number_field/totallyreal_rel.py
r8375 r8376 22 22 #*********************************************************************************************** 23 23 24 from sage.rings.arith import binomial, gcd 25 from sage.rings.number_field.totallyreal_data import ZZx, lagrange_degree_3, int_has_small_square_divisor 24 from sage.rings.arith import binomial, gcd, divisors 25 from sage.rings.integer import Integer 26 from sage.rings.integer_ring import IntegerRing 27 from sage.rings.number_field.totallyreal_data import ZZx, lagrange_degree_3, int_has_small_square_divisor, hermite_constant 26 28 from sage.rings.number_field.number_field import NumberField 27 28 from sage.rings.number_field.totallyreal import weed_fields, odlyzko_bound_totallyreal 29 30 import math, numpy, bisect 29 from sage.rings.polynomial.polynomial_ring import PolynomialRing 30 from sage.rings.number_field.totallyreal import weed_fields, odlyzko_bound_totallyreal, enumerate_totallyreal_fields 31 from sage.libs.pari.gen import pari 32 33 import math, numpy, bisect, sys 34 from numpy.linalg import inv 31 35 32 36 #*********************************************************************************************** … … 42 46 B = Z_F.reduced_basis 43 47 44 L = matrix([ [v(b) for b in B] for v in Foo])45 Linv = L.inverse()48 L = numpy.array([ [v(b) for b in B] for v in Foo]) 49 Linv = numpy.linalg.inv(L) 46 50 Vi = [[C[0][0]],[C[0][1]]] 47 51 for i in range(1,d): 48 52 Vi = sum([ [v + [C[i][0]], v + [C[i][1]]] for v in Vi], []) 49 V = Linv*(matrix(Vi).transpose())53 V = numpy.matrix(Linv)*(numpy.matrix(Vi).transpose()) 50 54 j = 0 51 55 while j < 2**d: 52 56 for i in range(d): 53 57 if V[i,j] < V[i,j+1]: 54 V[i,j] = floor(V[i,j])55 V[i,j+1] = ceil(V[i,j+1])58 V[i,j] = math.floor(V[i,j]) 59 V[i,j+1] = math.ceil(V[i,j+1]) 56 60 else: 57 V[i,j] = ceil(V[i,j])58 V[i,j+1] = floor(V[i,j+1])61 V[i,j] = math.ceil(V[i,j]) 62 V[i,j+1] = math.floor(V[i,j+1]) 59 63 j += 2 60 W0 = Linv*matrix([Vi[0]]*d).transpose()61 W = Linv*matrix([Vi[2**i] for i in range(d)]).transpose()64 W0 = (Linv*numpy.array([Vi[0]]*d)).transpose() 65 W = (Linv*numpy.array([Vi[2**i] for i in range(d)])).transpose() 62 66 for j in range(d): 63 67 for i in range(d): 64 68 if W[i,j] < W0[i,j]: 65 W[i,j] = floor(W[i,j])66 W0[i,j] = ceil(W0[i,j])69 W[i,j] = math.floor(W[i,j]) 70 W0[i,j] = math.ceil(W0[i,j]) 67 71 else: 68 W[i,j] = ceil(W[i,j]) 69 W0[i,j] = floor(W0[i,j]) 70 M = matrix(ZZ,d,2**d,[floor(v) for v in V.list()]).columns() 71 M += matrix(ZZ,d,d,[floor(w) for w in W0.list()]).columns() 72 M += matrix(ZZ,d,d,[floor(w) for w in W.list()]).columns() 72 W[i,j] = math.ceil(W[i,j]) 73 W0[i,j] = math.floor(W0[i,j]) 74 M = [[int(V[i,j]) for i in range(V.shape[0])] for j in range(V.shape[1])] 75 M += [[int(W0[i,j]) for j in range(W0.shape[0])] for i in range(W0.shape[0])] 76 M += [[int(W[i,j]) for j in range(W.shape[1])] for i in range(W.shape[0])] 77 78 from sage.matrix.constructor import matrix 79 M = (matrix(IntegerRing(),len(M),len(M[0]), M).transpose()).columns() 80 73 81 i = 0 74 82 while i < len(M): … … 81 89 i += 1 82 90 91 from sage.geometry.lattice_polytope import LatticePolytope 83 92 P = LatticePolytope(matrix(M).transpose()) 84 93 S = [] … … 91 100 for p in pts: 92 101 theta = sum([ p.list()[i]*B[i] for i in range(d)]) 93 if prod([Foo[i](theta) >= C[i][0] and Foo[i](theta) <= C[i][1] for i in range(d)]): 102 inbounds = True 103 for i in range(d): 104 inbounds = inbounds and Foo[i](theta) >= C[i][0] and Foo[i](theta) <= C[i][1] 105 if inbounds: 94 106 S.append(theta) 95 107 return S … … 98 110 r""" 99 111 """ 112 Z_F = F.maximal_order() 113 B = Z_F.reduced_basis 114 T = Z_F.T 115 P = T.qfminim((C[1]**2)*(1./2), 10**6)[2] 116 117 S = [] 118 for p in P: 119 theta = sum([ p.list()[i]*B[i] for i in range(F.degree())]) 120 if theta.trace() >= C[0] and theta.trace() <= C[1]: 121 inbounds = True 122 for v in F.real_embeddings(): 123 inbounds = inbounds and v(theta) > 0 124 if inbounds: 125 S.append(F(theta)) 126 return S 127 128 r""" 129 def integral_elements_with_trace(F, C): 100 130 if C[0] == C[1]: 101 131 C = [C[0]-0.5, C[1]+0.5] 132 133 print F, C 102 134 103 135 d = F.degree() … … 106 138 B = Z_F.reduced_basis 107 139 108 L = matrix([ [v(b) for b in B] for v in Foo])109 Linv = L.inverse()140 L = numpy.array([ [v(b) for b in B] for v in Foo]) 141 Linv = numpy.linalg.inv(L) 110 142 V = [ [[0]*i + [C[0]] + [0]*(d-1-i), [0]*i + [C[1]] + [0]*(d-1-i) ] for i in range(d) ] 111 143 V = sum(V, []) 112 V = Linv*(matrix(V).transpose())144 V = numpy.matrix(Linv)*(numpy.matrix(V).transpose()) 113 145 j = 0 114 146 while j < 2*d: 115 147 for i in range(d): 116 148 if V[i,j] < V[i,j+1]: 117 V[i,j] = floor(V[i,j])118 V[i,j+1] = ceil(V[i,j+1])149 V[i,j] = math.floor(V[i,j]) 150 V[i,j+1] = math.ceil(V[i,j+1]) 119 151 else: 120 V[i,j] = ceil(V[i,j])121 V[i,j+1] = floor(V[i,j+1])152 V[i,j] = math.ceil(V[i,j]) 153 V[i,j+1] = math.floor(V[i,j+1]) 122 154 j += 2 123 M = matrix(ZZ,d,2*d,[floor(v) for v in V.list()]).columns() 155 M = [[int(V[i,j]) for j in range(V.shape[1])] for i in range(V.shape[0])] 156 157 M = (matrix(IntegerRing(),d,2*d, M).transpose()).columns() 124 158 i = 0 125 159 while i < len(M): … … 139 173 S.append(theta) 140 174 return S 175 """ 141 176 142 177 #*********************************************************************************************** … … 181 216 # Initialize constants. 182 217 self.m = m 183 self.d = F.degree() 184 self.n = m*self.d 218 d = F.degree() 219 self.d = d 220 self.n = m*d 185 221 self.B = B 186 222 self.gamma = hermite_constant(self.n-self.d) … … 198 234 199 235 Z_Fbasis = self.Z_F.basis() 200 T = pari(matrix([[(x*y).trace() for x in Z_Fbasis] for y in Z_Fbasis])).qflllgram() 236 from sage.matrix.constructor import matrix 237 M = matrix(IntegerRing(),self.d,self.d, [[(x*y).trace() for x in Z_Fbasis] for y in Z_Fbasis]) 238 T = pari(M).qflllgram() 201 239 self.Z_F.reduced_basis = [sum([T[i][j].__int__()*Z_Fbasis[j] for j in range(self.d)]) for i in range(self.d)] 240 self.Z_F.T = pari(matrix(IntegerRing(),self.d,self.d, [[(x*y).trace() for x in self.Z_F.reduced_basis] for y in self.Z_F.reduced_basis])) 202 241 203 242 # Initialize variables. … … 215 254 for i in range(len(anm1s)): 216 255 Q = [ [ v(m*x) for v in self.Foo] + [0] for x in self.Z_F.basis()] + [[v(anm1s[i]) for v in self.Foo] + [10**6]] 217 adj = pari(matrix(Q).transpose()).qflll()[self.d] 256 Q = str(numpy.array(Q).transpose()) 257 Q = Q.replace(']\n [',';').replace('\n ', '').replace(' ', ',') 258 Q = Q[1:len(Q)-1] 259 adj = pari(Q).qflll()[self.d] 218 260 anm1s[i] += sum([m*self.Z_F.basis()[i]*adj[i].__int__()//adj[self.d].__int__() for i in range(self.d)]) 219 261 … … 221 263 self.a[m-1] = self.amaxvals[m-1].pop() 222 264 self.k = m-2 265 266 bl = math.ceil(1.7719*self.n) 267 br = max([1./m*(am1**2).trace() + \ 268 self.gamma*(1./(m**d)*self.B/self.dF)**(1./(self.n-d)) for am1 in anm1s]) 269 br = math.floor(br) 270 T2s = integral_elements_with_trace(self.F, [bl,br]) 271 self.trace_elts.append([bl,br,T2s]) 223 272 224 273 elif len(a) <= m+1: … … 241 290 # Bounds come from an application of Lagrange multipliers in degrees 2,3. 242 291 self.b_lower = [-1./m*(v(self.a[m-1]) + 243 (m-1.)* sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo]292 (m-1.)*math.sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo] 244 293 self.b_upper = [-1./m*(v(self.a[m-1]) - 245 (m-1.)* sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo]294 (m-1.)*math.sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo] 246 295 if k < m-2: 247 296 bminmax = [lagrange_degree_3(n,v(self.a[m-1]),v(self.a[m-2]),v(self.a[m-3])) for v in self.Foo] … … 332 381 333 382 if k == m-2: 334 # We only know the value of a[n-1], the trace. Need to apply 335 # basic bounds from Hunter's theorem and Siegel's theorem, with 336 # improvements due to Smyth, to get bounds on T_2. 383 # We only know the value of a[n-1], the trace. 337 384 bl = max(math.ceil(1.7719*self.n), ((self.a[m-1]**2).trace()*1./m)) 338 br = 1./m*(self.a[m-1] .trace())**2+ \385 br = 1./m*(self.a[m-1]**2).trace() + \ 339 386 self.gamma*(1./(m**d)*self.B/self.dF)**(1./(self.n-d)) 340 387 br = math.floor(br) … … 371 418 for t2 in T2s: 372 419 am2 = (self.a[m-1]**2-t2)/2 373 if am2.is_integral() and prod([v((m-1)*self.a[m-1]**2-2*m*am2) > 0 for v in self.Foo]): 374 am2s.append(am2) 420 if am2.is_integral(): 421 ispositive = True 422 for v in self.Foo: 423 ispositive = ispositive and v((m-1)*self.a[m-1]**2-2*m*am2) > 0 424 if ispositive: 425 am2s.append(am2) 375 426 376 427 if verbose >= 2: … … 389 440 # Initialize the second derivative. 390 441 self.b_lower = [-1./m*(v(self.a[m-1]) + 391 (m-1.)* sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo]442 (m-1.)*math.sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo] 392 443 self.b_upper = [-1./m*(v(self.a[m-1]) - 393 (m-1.)* sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo]444 (m-1.)*math.sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo] 394 445 self.beta[k] = [[self.b_lower[i], -self.Foo[i](self.a[m-1])/m, self.b_upper[i]] for i in range(d)] 395 446 self.gnk[k] = [0, (m-1)*self.a[m-1], m*(m-1)/2] … … 429 480 if k == m-3: 430 481 self.b_lower = [-1./m*(v(self.a[m-1]) + 431 (m-1.)* sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo]482 (m-1.)*math.sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo] 432 483 self.b_upper = [-1./m*(v(self.a[m-1]) - 433 (m-1.)* sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo]484 (m-1.)*math.sqrt(v(self.a[m-1])**2 - 2.*(1+1./(m-1))*v(self.a[m-2]))) for v in self.Foo] 434 485 elif k == m-4: 435 486 # New bounds from Lagrange multiplier in degree 3. … … 768 819 S.insert(ind, [d,ng]) 769 820 Srel.insert(ind, Fx([-1,1,1])) 770 el se:821 elif d == 2: 771 822 for ff in [[1,-7,13,-7,1],[1,-8,14,-7,1]]: 772 823 f = Fx(ff).factor()[0][0] … … 823 874 for d in divisors(n): 824 875 if d > 1 and d < n: 825 Sds = enumerate_totallyreal_fields(d, floor((1.*B)**(1.*d/n)), verbose=verbose)876 Sds = enumerate_totallyreal_fields(d, int(math.floor((1.*B)**(1.*d/n))), verbose=verbose) 826 877 for i in range(len(Sds)): 827 878 if verbose: … … 837 888 S += [[t[0],t[1]] for t in T] 838 889 j = i+1 839 for E in enumerate_totallyreal_fields(n/d, floor((1.*B)**(1./d)/(1.*Sds[i][0])**(n*1./d**2))):890 for E in enumerate_totallyreal_fields(n/d, int(math.floor((1.*B)**(1./d)/(1.*Sds[i][0])**(n*1./d**2)))): 840 891 for EF in F.composite_fields(NumberField(ZZx(E[1]), 'u')): 841 if EF.degree() == n :892 if EF.degree() == n and EF.disc() <= B: 842 893 S.append([EF.disc(), pari(EF.absolute_polynomial())]) 843 894 S.sort()
Note: See TracChangeset
for help on using the changeset viewer.
