Ticket #9400: 9400_maximize_at_primes.patch
File 9400_maximize_at_primes.patch, 31.2 KB (added by , 12 years ago) |
---|
-
sage/rings/number_field/number_field.py
# HG changeset patch # User Jeroen Demeyer <jdemeyer@cage.ugent.be> # Date 1282167950 -7200 # Node ID 386ca091266034e666f83b261f71313134a66896 # Parent 5bf585a85edbee49811c2f07ddf33549f6ad6682 [mq]: 9400_maximize_at_primes diff -r 5bf585a85edb -r 386ca0912660 sage/rings/number_field/number_field.py
a b 248 248 249 249 250 250 _nf_cache = {} 251 def NumberField(polynomial, name=None, check=True, names=None, cache=True, embedding=None, latex_name=None): 251 def NumberField(polynomial, name=None, check=True, names=None, cache=True, 252 embedding=None, latex_name=None, 253 assume_disc_small=False, 254 maximize_at_primes=None): 252 255 r""" 253 256 Return *the* number field defined by the given irreducible 254 257 polynomial and with variable with the given name. If check is True … … 257 260 258 261 INPUT: 259 262 260 - ``polynomial`` - a polynomial over `\QQ` or a number 261 field, or a list of polynomials. 262 - ``name`` - a string (default: 'a'), the name of the 263 generator 264 - ``check`` - bool (default: True); do type checking 265 and irreducibility checking. 266 - ``embedding`` - image of the generator in an ambient 267 field (default: None) 263 - ``polynomial`` - a polynomial over `\QQ` or a number field, 264 or a list of polynomials. 265 - ``name`` - a string (default: 'a'), the name of the generator 266 - ``check`` - bool (default: True); do type checking and 267 irreducibility checking. 268 - ``embedding`` - image of the generator in an ambient field 269 (default: None) 270 - ``assume_disc_small`` -- (default: False); if True, assume 271 that no square of a prime greater than PARI's primelimit 272 (which should be 500000); only applies for absolute fields 273 at present. 274 - ``maximize_at_primes`` -- (default: None) None or a list of 275 primes; if not None, then the maximal order is computed by 276 maximizing only at the primes in this list, which completely 277 avoids having to factor the discriminant, but of course can 278 lead to wrong results; only applies for absolute fields at 279 present. 268 280 269 281 EXAMPLES:: 270 282 … … 454 466 455 467 if cache: 456 468 key = (polynomial, polynomial.base_ring(), name, latex_name, 457 embedding, embedding.parent() if embedding is not None else None) 469 embedding, embedding.parent() if embedding is not None else None, 470 assume_disc_small, None if maximize_at_primes is None else tuple(maximize_at_primes)) 458 471 if _nf_cache.has_key(key): 459 472 K = _nf_cache[key]() 460 473 if not K is None: return K … … 466 479 return S 467 480 468 481 if polynomial.degree() == 2: 469 K = NumberField_quadratic(polynomial, name, latex_name, check, embedding) 482 K = NumberField_quadratic(polynomial, name, latex_name, check, embedding, 483 assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes) 470 484 else: 471 K = NumberField_absolute(polynomial, name, latex_name, check, embedding) 485 K = NumberField_absolute(polynomial, name, latex_name, check, embedding, 486 assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes) 472 487 473 488 if cache: 474 489 _nf_cache[key] = weakref.ref(K) … … 926 941 """ 927 942 def __init__(self, polynomial, name, 928 943 latex_name=None, check=True, embedding=None, 929 category = None): 944 category = None, 945 assume_disc_small=False, maximize_at_primes=None): 930 946 """ 931 947 Create a number field. 932 948 … … 978 994 ... 979 995 TypeError: polynomial must be defined over rational field 980 996 """ 981 997 self._assume_disc_small = assume_disc_small 998 self._maximize_at_primes = maximize_at_primes 982 999 from sage.categories.number_fields import NumberFields 983 1000 default_category = NumberFields() 984 1001 if category is None: … … 2165 2182 2166 2183 sage: x = ZZ['x'].gen() 2167 2184 sage: F.<t> = NumberField(x^3 - 2) 2168 2185 2169 2186 :: 2170 2187 2171 2188 sage: P2 = F.prime_above(2) … … 2415 2432 Traceback (most recent call last): 2416 2433 ... 2417 2434 TypeError: Unable to coerce number field defined by non-integral polynomial to PARI. 2435 2436 We illustrate the maximize_at_primes and assume_disc_small parameters:: 2437 2438 sage: p = next_prime(10^40); q = next_prime(p) 2439 sage: K.<a> = NumberField(x^2 - p*q, maximize_at_primes=[p]) 2440 2441 The following would take a very long time without the 2442 maximize_at_primes option above:: 2443 2444 sage: K.pari_nf() 2445 [x^2 - 100000000000000000000...] 2446 2447 I'm not sure this really illustrates anything:: 2448 2449 sage: K.<a> = NumberField(x^2 - 3*5*7*11*13, assume_disc_small=True) 2450 sage: K.pari_nf() 2451 [x^2 - 15015, [2, 0], 60060, 1, ...] 2418 2452 """ 2419 2453 if self.absolute_polynomial().denominator() != 1: 2420 2454 raise TypeError, "Unable to coerce number field defined by non-integral polynomial to PARI." … … 2422 2456 return self.__pari_nf 2423 2457 except AttributeError: 2424 2458 f = self.pari_polynomial() 2425 self.__pari_nf = f.nfinit() 2459 if self._maximize_at_primes: 2460 v = self._normalize_prime_list(self._maximize_at_primes) 2461 m = self._pari_disc_factorization_matrix(v) 2462 s = str(f) 2463 # we use a string since the Sage wrapping of the pari 2464 # c library nfinit doesn't support the third option. 2465 k = pari('nfinit([%s,nfbasis(%s,0,%s)])'%(s,s,str(m))) 2466 elif self._assume_disc_small: 2467 k = f.nfinit(1) 2468 else: 2469 k = f.nfinit() 2470 self.__pari_nf = k 2426 2471 return self.__pari_nf 2427 2472 2428 2473 def _pari_init_(self): … … 2441 2486 [x^2 + x + 1, [0, 1], -3, 1, ... [1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]] 2442 2487 sage: pari(k) 2443 2488 [x^2 + x + 1, [0, 1], -3, 1, ...[1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]] 2444 """ 2489 2490 We illustrate the maximize_at_primes parameter:: 2491 2492 sage: p = next_prime(10^40); q = next_prime(p) 2493 sage: K.<a> = NumberField(x^2 - p*q, maximize_at_primes=[p,q]) 2494 2495 Note that nfbasis is explicitly passed in:: 2496 2497 sage: K._pari_init_() 2498 'nfinit(x^2 - 100000000000000000000000000000000000002600000000000000000000000000000000000016819,nfbasis(x^2 - 100000000000000000000000000000000000002600000000000000000000000000000000000016819,0,[10000000000000000000000000000000000000121, 1; 10000000000000000000000000000000000000139, 1]))' 2499 2500 2501 We illustrate the assume_disc_small parameter (note the 1 option to nfinit):: 2502 2503 sage: K.<a> = NumberField(x^2 - 3*5*7*11*13, assume_disc_small=True) 2504 sage: K._pari_init_() 2505 'nfinit(x^2 - 15015,1)' 2506 """ 2507 f = str(self.pari_polynomial()) 2445 2508 if self.absolute_polynomial().denominator() != 1: 2446 2509 raise TypeError, "Unable to coerce number field defined by non-integral polynomial to PARI." 2447 return 'nfinit(%s)'%self.pari_polynomial() 2448 2510 if self._maximize_at_primes: 2511 v = self._normalize_prime_list(self._maximize_at_primes) 2512 m = self._pari_disc_factorization_matrix(v) 2513 return 'nfinit(%s,nfbasis(%s,0,%s))'%(f,f,str(m)) 2514 elif self._assume_disc_small: 2515 return 'nfinit(%s,1)'%f 2516 else: 2517 return 'nfinit(%s)'%f 2518 2449 2519 def pari_bnf(self, certify=False, units=True): 2450 2520 """ 2451 2521 PARI big number field corresponding to this field. … … 3654 3724 3655 3725 ALGORITHM: Uses the pari library. 3656 3726 """ 3657 return self.maximal_order( ).basis()3727 return self.maximal_order(v=v).basis() 3658 3728 3659 3729 def _compute_integral_basis(self, v=None): 3660 3730 """ … … 3689 3759 sage: K.integral_basis() 3690 3760 [1, 1/2*a^2 + 1/2*a, a^2] 3691 3761 """ 3762 if (v is None or len(v) == 0) and self._maximize_at_primes: 3763 v = self._maximize_at_primes 3764 3692 3765 v = self._normalize_prime_list(v) 3693 3766 try: 3694 3767 return self._integral_basis_dict[v] 3695 3768 except: 3696 3769 f = self.pari_polynomial() 3697 3698 3770 if len(v) == 0: 3699 B = f.nfbasis() 3700 else: 3701 m = pari.matrix(len(v), 2) 3702 d = f.poldisc() 3703 for i in range(len(v)): 3704 p = pari(ZZ(v[i])) 3705 m[i,0] = p 3706 m[i,1] = d.valuation(p) 3771 B = f.nfbasis(1 if self._assume_disc_small else 0) 3772 else: 3773 m = self._pari_disc_factorization_matrix(v) 3707 3774 B = f.nfbasis(p = m) 3708 3775 3709 3776 basis = map(self, B) 3710 3777 self._integral_basis_dict[v] = basis 3711 3778 return basis 3712 3779 3780 def _pari_disc_factorization_matrix(self, v): 3781 """ 3782 Returns a PARI matrix representation for the partial 3783 factorization of the discriminant of the defining polynomial 3784 of self, defined by the list of primes in the Python list v. 3785 This function is used internally by the number fields code. 3786 3787 EXAMPLES:: 3788 3789 sage: x = polygen(QQ,'x') 3790 sage: f = x^3 + 17*x + 393; f.discriminant().factor() 3791 -1 * 5^2 * 29 * 5779 3792 sage: K.<a> = NumberField(f) 3793 sage: K._pari_disc_factorization_matrix([5,29]) 3794 [5, 2; 29, 1] 3795 """ 3796 f = self.pari_polynomial() 3797 m = pari.matrix(len(v), 2) 3798 d = f.poldisc() 3799 for i in range(len(v)): 3800 p = pari(ZZ(v[i])) 3801 m[i,0] = p 3802 m[i,1] = d.valuation(p) 3803 return m 3804 3805 3713 3806 def reduced_basis(self, prec=None): 3714 3807 r""" 3715 3808 This function returns an LLL-reduced basis for the … … 4680 4773 4681 4774 class NumberField_absolute(NumberField_generic): 4682 4775 4683 def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None): 4776 def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None, 4777 assume_disc_small=False, maximize_at_primes=None): 4684 4778 """ 4685 4779 Function to initialize an absolute number field. 4686 4780 … … 4692 4786 <class 'sage.rings.number_field.number_field.NumberField_absolute_with_category'> 4693 4787 sage: TestSuite(K).run() 4694 4788 """ 4695 NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding) 4789 NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding, 4790 assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes) 4696 4791 self._element_class = number_field_element.NumberFieldElement_absolute 4697 4792 self._zero_element = self(0) 4698 4793 self._one_element = self(1) … … 6281 6376 sage: type(cf3(z1)) 6282 6377 <type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'> 6283 6378 """ 6284 def __init__(self, n, names, embedding=None ):6379 def __init__(self, n, names, embedding=None, assume_disc_small=False, maximize_at_primes=None): 6285 6380 """ 6286 6381 A cyclotomic field, i.e., a field obtained by adjoining an n-th 6287 6382 root of unity to the rational numbers. … … 6312 6407 name= names, 6313 6408 latex_name=latex_name, 6314 6409 check=False, 6315 embedding = embedding) 6410 embedding = embedding, 6411 assume_disc_small=assume_disc_small, 6412 maximize_at_primes=maximize_at_primes) 6316 6413 if n%2: 6317 6414 self.__zeta_order = 2*n 6318 6415 else: … … 7099 7196 sage: CyclotomicField(17).integral_basis() == CyclotomicField(17)._compute_integral_basis() 7100 7197 True 7101 7198 """ 7102 return self.integral_basis( )7199 return self.integral_basis(v=v) 7103 7200 7104 7201 7105 7202 def zeta_order(self): … … 7306 7403 sage: QuadraticField(-4, 'b') 7307 7404 Number Field in b with defining polynomial x^2 + 4 7308 7405 """ 7309 def __init__(self, polynomial, name=None, latex_name=None, check=True, embedding=None): 7406 def __init__(self, polynomial, name=None, latex_name=None, check=True, embedding=None, 7407 assume_disc_small=False, maximize_at_primes=None): 7310 7408 """ 7311 7409 Create a quadratic number field. 7312 7410 … … 7330 7428 7331 7429 sage: TestSuite(k).run() 7332 7430 """ 7333 NumberField_absolute.__init__(self, polynomial, name=name, check=check, embedding=embedding, latex_name=latex_name) 7431 NumberField_absolute.__init__(self, polynomial, name=name, check=check, 7432 embedding=embedding, latex_name=latex_name, 7433 assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes) 7334 7434 self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic 7335 7435 c, b, a = [rational.Rational(t) for t in self.defining_polynomial().list()] 7336 7436 # set the generator -
sage/rings/residue_field.pyx
diff -r 5bf585a85edb -r 386ca0912660 sage/rings/residue_field.pyx
a b 14 14 841 15 15 16 16 We reduce mod a prime for which the ring of integers is not 17 monogenic (i.e., 2 is an essential discriminant divisor): 17 monogenic (i.e., 2 is an essential discriminant divisor):: 18 18 19 sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8) 19 20 sage: F = K.factor(2); F 20 21 (Fractional ideal (1/2*a^2 - 1/2*a + 1)) * (Fractional ideal (a^2 - 2*a + 3)) * (Fractional ideal (3/2*a^2 - 5/2*a + 4)) … … 25 26 sage: F[2][0].residue_field() 26 27 Residue field of Fractional ideal (3/2*a^2 - 5/2*a + 4) 27 28 28 We can also form residue fields from ZZ: 29 We can also form residue fields from ZZ:: 30 29 31 sage: ZZ.residue_field(17) 30 32 Residue field of Integers modulo 17 31 33 … … 35 37 -- John Cremona (2008-9): extend reduction maps to the whole valuation ring 36 38 add support for residue fields of ZZ 37 39 38 TESTS: 40 TESTS:: 41 39 42 sage: K.<z> = CyclotomicField(7) 40 43 sage: P = K.factor(17)[0][0] 41 44 sage: ff = K.residue_field(P) … … 43 46 sage: parent(a*a) 44 47 Residue field in zbar of Fractional ideal (17) 45 48 46 Reducing a curve modulo a prime: 49 Reducing a curve modulo a prime:: 50 47 51 sage: K.<s> = NumberField(x^2+23) 48 52 sage: OK = K.ring_of_integers() 49 53 sage: E = EllipticCurve([0,0,0,K(1),K(5)]) … … 52 56 sage: E.base_extend(Fpp) 53 57 Elliptic Curve defined by y^2 = x^3 + x + 5 over Residue field of Fractional ideal (13, s - 4) 54 58 55 Calculating Groebner bases over various residue fields. First over a small non-prime field: 59 Calculating Groebner bases over various residue fields. First over a small non-prime field:: 60 56 61 sage: F1.<u> = NumberField(x^6 + 6*x^5 + 124*x^4 + 452*x^3 + 4336*x^2 + 8200*x + 42316) 57 62 sage: reduct_id = F1.factor(47)[0][0] 58 63 sage: Rf = F1.residue_field(reduct_id) … … 67 72 sage: I.groebner_basis() 68 73 [X + (-19*ubar^2 - 5*ubar - 17)*Y] 69 74 70 And now over a large prime field: 75 And now over a large prime field:: 76 71 77 sage: x = ZZ['x'].0 72 78 sage: F1.<u> = NumberField(x^2 + 6*x + 324) 73 79 sage: reduct_id = F1.prime_above(next_prime(2^42)) … … 125 131 of the ring of integers of a number field. 126 132 127 133 INPUT: 128 p -- a prime ideal of an order in a number field. 129 names -- the variable name for the finite field created. 130 Defaults to the name of the number field variable but 131 with bar placed after it. 132 check -- whether or not to check if p is prime. 134 135 - ``p`` -- a prime ideal of an order in a number field. 136 - ``names`` -- the variable name for the finite field created. 137 Defaults to the name of the number field variable but with 138 bar placed after it. 139 - ``check`` -- whether or not to check if p is prime. 133 140 134 141 OUTPUT: 135 -- The residue field at the prime p. 142 143 - The residue field at the prime p. 136 144 137 EXAMPLES: 145 EXAMPLES:: 146 138 147 sage: K.<a> = NumberField(x^3-7) 139 148 sage: P = K.ideal(29).factor()[0][0] 140 149 sage: ResidueField(P) 141 150 Residue field in abar of Fractional ideal (2*a^2 + 3*a - 10) 142 151 143 The result is cached: 152 The result is cached:: 153 144 154 sage: ResidueField(P) is ResidueField(P) 145 155 True 146 156 sage: k = K.residue_field(P); k … … 149 159 841 150 160 151 161 An example where the generator of the number field doesn't 152 generate the residue class field. 162 generate the residue class field:: 163 153 164 sage: K.<a> = NumberField(x^3-875) 154 165 sage: P = K.ideal(5).factor()[0][0]; k = K.residue_field(P); k 155 166 Residue field in abar of Fractional ideal (5, -2/25*a^2 - 1/5*a + 2) … … 158 169 sage: k.0^3 - 875 159 170 2 160 171 161 An example where the residue class field is large but of degree 1: 172 An example where the residue class field is large but of degree 1:: 173 162 174 sage: K.<a> = NumberField(x^3-875); P = K.ideal(2007).factor()[0][0]; k = K.residue_field(P); k 163 175 Residue field of Fractional ideal (-2/25*a^2 - 2/5*a - 3) 164 176 sage: k(a) … … 167 179 0 168 180 169 181 In this example, 2 is an inessential discriminant divisor, so divides 170 the index of ZZ[a] in the maximal order for all a. 182 the index of ZZ[a] in the maximal order for all a:: 183 171 184 sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8); P = K.ideal(2).factor()[0][0]; P 172 185 Fractional ideal (1/2*a^2 - 1/2*a + 1) 173 186 sage: F = K.residue_field(P); F … … 288 301 """ 289 302 The class representing a generic residue field. 290 303 291 EXAMPLES: 304 EXAMPLES:: 305 292 306 sage: I = QQ[i].factor(2)[0][0]; I 293 307 Fractional ideal (I + 1) 294 308 sage: k = I.residue_field(); k … … 299 313 def __init__(self, p, f, intp): 300 314 """ 301 315 INPUT: 302 p -- the prime (ideal) defining this residue field 303 f -- the morphism from the order to self. 304 intp -- the rational prime that p lives over. 316 317 - ``p`` -- the prime (ideal) defining this residue field 318 - ``f`` -- the morphism from the order to self. 319 - ``intp`` -- the rational prime that p lives over. 305 320 306 321 EXAMPLES:: 307 322 … … 330 345 r""" 331 346 Return the maximal ideal that this residue field is the quotient by. 332 347 333 EXAMPLES: 348 EXAMPLES:: 349 334 350 sage: K.<a> = NumberField(x^3 + x + 1) 335 351 sage: P = K.ideal(29).factor()[0][0] 336 352 sage: k = K.residue_field(P) # indirect doctest … … 346 362 347 363 def coerce_map_from_impl(self, R): 348 364 """ 349 EXAMPLES: 365 EXAMPLES:: 366 350 367 sage: K.<i> = NumberField(x^2+1) 351 368 sage: P = K.ideal(-3*i-2) 352 369 sage: OK = K.maximal_order() … … 365 382 """ 366 383 Returns a string describing this residue field. 367 384 368 EXAMPLES: 385 EXAMPLES:: 386 369 387 sage: K.<a> = NumberField(x^3-7) 370 388 sage: P = K.ideal(29).factor()[0][0] 371 389 sage: k = K.residue_field(P) … … 384 402 Returns a lift of x to the Order, returning a "polynomial" in the 385 403 generator with coefficients between 0 and $p-1$. 386 404 387 EXAMPLES: 405 EXAMPLES:: 406 388 407 sage: K.<a> = NumberField(x^3-7) 389 408 sage: P = K.ideal(29).factor()[0][0] 390 409 sage: k =K.residue_field(P) … … 406 425 Return the partially defined reduction map from the number 407 426 field to this residue class field. 408 427 409 EXAMPLES: 428 EXAMPLES:: 429 410 430 sage: I = QQ[2^(1/3)].factor(2)[0][0]; I 411 431 Fractional ideal (a) 412 432 sage: k = I.residue_field(); k … … 422 442 423 443 def lift_map(self): 424 444 """ 425 EXAMPLES: 445 EXAMPLES:: 446 426 447 sage: I = QQ[3^(1/3)].factor(5)[1][0]; I 427 448 Fractional ideal (a - 2) 428 449 sage: k = I.residue_field(); k … … 443 464 Compares two residue fields: they are equal iff the primes 444 465 defining them are equal. 445 466 446 EXAMPLES: 467 EXAMPLES:: 468 447 469 sage: K.<a> = NumberField(x^3-11) 448 470 sage: F = K.ideal(37).factor(); F 449 471 (Fractional ideal (37, a + 12)) * (Fractional ideal (-2*a + 5)) * (Fractional ideal (37, a + 9)) # 32-bit … … 464 486 r""" 465 487 Return the hash of self. 466 488 467 EXAMPLES: 489 EXAMPLES:: 490 468 491 sage: K.<a> = NumberField(x^3 + x + 1) 469 492 sage: hash(K.residue_field(K.prime_above(17))) # random 470 493 -6463132282686559142 … … 478 501 A reduction map from a (subset) of a number field to this residue 479 502 class field. 480 503 481 EXAMPLES: 504 EXAMPLES:: 505 482 506 sage: I = QQ[sqrt(17)].factor(5)[0][0]; I 483 507 Fractional ideal (5) 484 508 sage: k = I.residue_field(); k … … 490 514 """ 491 515 Create a reduction map. 492 516 493 EXAMPLES: 517 EXAMPLES:: 518 494 519 sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8) 495 520 sage: F = K.factor(2)[0][0].residue_field() 496 521 sage: F.reduction_map() … … 505 530 """ 506 531 Return the domain of this reduction map. 507 532 508 EXAMPLES: 533 EXAMPLES:: 534 509 535 sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 32) 510 536 sage: F = K.factor(2)[0][0].residue_field() 511 537 sage: F.reduction_map().domain() … … 517 543 """ 518 544 Return the codomain of this reduction map. 519 545 520 EXAMPLES: 546 EXAMPLES:: 547 521 548 sage: K.<a> = NumberField(x^3 + 128) 522 549 sage: F = K.factor(2)[0][0].residue_field() 523 550 sage: F.reduction_map().codomain() … … 532 559 If x doesn't map because it has negative valuation, then a 533 560 ZeroDivisionError exception is raised. 534 561 535 EXAMPLES: 562 EXAMPLES:: 563 536 564 sage: K.<a> = NumberField(x^2 + 1) 537 565 sage: F = K.factor(2)[0][0].residue_field() 538 566 sage: r = F.reduction_map(); r … … 545 573 ZeroDivisionError: Cannot reduce field element 1/2*a modulo Fractional ideal (a + 1): it has negative valuation 546 574 547 575 An example to show that the issue raised in trac \#1951 548 has been fixed. 576 has been fixed:: 577 549 578 sage: K.<i> = NumberField(x^2 + 1) 550 579 sage: P1, P2 = [g[0] for g in K.factor(5)]; (P1,P2) 551 580 (Fractional ideal (i + 2), Fractional ideal (-i + 2)) … … 562 591 -1 563 592 sage: F2(a) 564 593 Traceback (most recent call last): 594 ... 565 595 ZeroDivisionError: Cannot reduce field element -2/5*i + 1/5 modulo Fractional ideal (-i + 2): it has negative valuation 566 567 596 """ 568 597 # The reduction map is just x |--> F(to_vs(x) * (PB**(-1))) if 569 598 # either x is integral or the denominator of x is coprime to … … 578 607 except ZeroDivisionError: 579 608 raise ZeroDivisionError, "Cannot reduce rational %s modulo %s: it has negative valuation"%(x,p) 580 609 581 dx = x.denominator() 582 if x.is_integral() or dx.gcd(ZZ(p.absolute_norm())) == 1: 610 try: 583 611 return self.__F(self.__to_vs(x) * self.__PBinv) 612 except: pass 584 613 585 614 # Now we do have to work harder...below this point we handle 586 615 # cases which failed before trac 1951 was fixed. 587 616 R = self.__K.ring_of_integers() 588 dx = R( dx)617 dx = R(x.denominator()) 589 618 nx = R(dx*x) 590 619 vnx = nx.valuation(p) 591 620 vdx = dx.valuation(p) … … 593 622 return self(0) 594 623 if vnx < vdx: 595 624 raise ZeroDivisionError, "Cannot reduce field element %s modulo %s: it has negative valuation"%(x,p) 625 596 626 a = self.__K.uniformizer(p,'negative') ** vnx 597 627 nx /= a 598 628 dx /= a … … 609 639 610 640 def __repr__(self): 611 641 """ 612 EXAMPLES: 642 EXAMPLES:: 643 613 644 sage: K.<theta_5> = CyclotomicField(5) 614 645 sage: F = K.factor(7)[0][0].residue_field() 615 646 sage: F.reduction_map().__repr__() … … 621 652 """ 622 653 Lifting map from residue class field to number field. 623 654 624 EXAMPLES: 655 EXAMPLES:: 656 625 657 sage: K.<a> = NumberField(x^3 + 2) 626 658 sage: F = K.factor(5)[0][0].residue_field() 627 659 sage: F.degree() … … 637 669 """ 638 670 Create a lifting map. 639 671 640 EXAMPLES: 672 EXAMPLES:: 673 641 674 sage: K.<theta_5> = CyclotomicField(5) 642 675 sage: F = K.factor(7)[0][0].residue_field() 643 676 sage: F.lift_map() … … 666 699 """ 667 700 Return the codomain of this lifting map. 668 701 669 EXAMPLES: 702 EXAMPLES:: 703 670 704 sage: K.<a> = CyclotomicField(7) 671 705 sage: F = K.factor(5)[0][0].residue_field() 672 706 sage: L = F.lift_map(); L … … 680 714 """ 681 715 Lift from this residue class field to the number field. 682 716 683 EXAMPLES: 717 EXAMPLES:: 718 684 719 sage: K.<a> = CyclotomicField(7) 685 720 sage: F = K.factor(5)[0][0].residue_field() 686 721 sage: L = F.lift_map(); L … … 700 735 701 736 def __repr__(self): 702 737 """ 703 EXAMPLES: 738 EXAMPLES:: 739 704 740 sage: K.<theta_12> = CyclotomicField(12) 705 741 sage: F.<tmod> = K.factor(7)[0][0].residue_field() 706 742 sage: F.lift_map().__repr__() … … 716 752 The class representing a homomorphism from the order of a number 717 753 field to the residue field at a given prime. 718 754 719 EXAMPLES: 755 EXAMPLES:: 756 720 757 sage: K.<a> = NumberField(x^3-7) 721 758 sage: P = K.ideal(29).factor()[0][0] 722 759 sage: k = K.residue_field(P) … … 738 775 im_gen -- The image of the generator of the number field. 739 776 740 777 EXAMPLES: 741 We create a residue field homomorphism: 778 779 We create a residue field homomorphism:: 780 742 781 sage: K.<theta> = CyclotomicField(5) 743 782 sage: P = K.factor(7)[0][0] 744 783 sage: P.residue_class_degree() … … 759 798 760 799 cpdef Element _call_(self, x): 761 800 """ 762 Applies this morphism to an element 801 Applies this morphism to an element. 763 802 764 EXAMPLES: 803 EXAMPLES:: 804 765 805 sage: K.<a> = NumberField(x^3-x+8) 766 806 sage: P = K.ideal(29).factor()[0][0] 767 807 sage: k =K.residue_field(P) … … 779 819 Returns a lift of x to the Order, returning a "polynomial" in 780 820 the generator with coefficients between 0 and p-1. 781 821 782 EXAMPLES: 822 EXAMPLES:: 823 783 824 sage: K.<a> = NumberField(x^3-7) 784 825 sage: P = K.ideal(29).factor()[0][0] 785 826 sage: k = K.residue_field(P) … … 804 845 """ 805 846 The class representing residue fields of number fields that have prime order. 806 847 807 EXAMPLES: 848 EXAMPLES:: 849 808 850 sage: R.<x> = QQ[] 809 851 sage: K.<a> = NumberField(x^3-7) 810 852 sage: P = K.ideal(29).factor()[1][0] … … 828 870 def __init__(self, p, name, im_gen = None, intp = None): 829 871 """ 830 872 INPUT: 831 p -- A prime ideal of a number field. 832 name -- the name of the generator of this extension 833 im_gen -- the image of the generator of the number field in this finite field. 834 intp -- the rational prime that p lies over. 873 874 - ``p`` -- A prime ideal of a number field. 875 - ``name`` -- the name of the generator of this extension 876 - ``im_gen`` -- the image of the generator of the number field in this finite field. 877 - ``intp`` -- the rational prime that p lies over. 835 878 836 EXAMPLES: 879 EXAMPLES:: 880 837 881 sage: K.<i> = QuadraticField(-1) 838 882 sage: kk = ResidueField(K.factor(5)[0][0]) 839 883 sage: type(kk) … … 851 895 def __call__(self, x): 852 896 """ 853 897 INPUT: 854 x -- something to cast in to self. 898 899 - ``x`` -- something to cast in to self. 855 900 856 EXAMPLES: 901 EXAMPLES:: 902 857 903 sage: R.<x> = QQ[] 858 904 sage: K.<a> = NumberField(x^3-7) 859 905 sage: P = K.ideal(29).factor()[1][0] … … 881 927 """ 882 928 The class representing residue fields of number fields that have non-prime order >= 2^16. 883 929 884 EXAMPLES: 930 EXAMPLES:: 931 885 932 sage: K.<a> = NumberField(x^3-7) 886 933 sage: P = K.ideal(923478923).factor()[0][0] 887 934 sage: k = K.residue_field(P) … … 897 944 """ 898 945 def __init__(self, p, q, name, g, intp): 899 946 """ 900 EXAMPLES: 901 We create an ext_pari residue field: 947 EXAMPLES:: 948 949 We create an ext_pari residue field:: 950 902 951 sage: K.<a> = NumberField(x^3-7) 903 952 sage: P = K.ideal(923478923).factor()[0][0] 904 953 sage: type(P.residue_field()) … … 913 962 """ 914 963 Coerce x into self. 915 964 916 EXAMPLES: 965 EXAMPLES:: 966 917 967 sage: K.<aa> = NumberField(x^3 - 2) 918 968 sage: P = K.factor(10007)[0][0] 919 969 sage: P.residue_class_degree() … … 940 990 """ 941 991 The class representing residue fields of number fields that have non-prime order < 2**16. 942 992 943 EXAMPLES: 993 EXAMPLES:: 994 944 995 sage: R.<x> = QQ[] 945 996 sage: K.<a> = NumberField(x^3-7) 946 997 sage: P = K.ideal(29).factor()[0][0] … … 958 1009 def __init__(self, p, q, name, g, intp): 959 1010 """ 960 1011 INPUT: 961 p -- the prime ideal defining this residue field 962 q -- the order of this residue field (a power of intp) 963 name -- the name of the generator of this extension 964 g -- the polynomial modulus for this extension 965 intp -- the rational prime that p lies over. 1012 1013 - ``p`` -- the prime ideal defining this residue field 1014 - ``q`` -- the order of this residue field (a power of intp) 1015 - ``name`` -- the name of the generator of this extension 1016 - ``g`` -- the polynomial modulus for this extension 1017 - ``intp`` -- the rational prime that p lies over. 966 1018 967 EXAMPLES: 1019 EXAMPLES:: 1020 968 1021 sage: R.<x> = QQ[] 969 1022 sage: K.<a> = NumberField(x^4+3*x^2-17) 970 1023 sage: P = K.ideal(61).factor()[0][0] … … 978 1031 def __call__(self, x): 979 1032 """ 980 1033 INPUT: 981 x -- Something to cast into self. 1034 1035 - x -- Something to cast into self. 982 1036 983 EXAMPLES: 1037 EXAMPLES:: 1038 984 1039 sage: R.<x> = QQ[] 985 1040 sage: K.<a> = NumberField(x^4+3*x^2-17) 986 1041 sage: P = K.ideal(61).factor()[0][0]