Ticket #6040: patch-4__QF_more_doctests__3.4.1.patch
| File patch-4__QF_more_doctests__3.4.1.patch, 15.2 KB (added by jonhanke, 4 years ago) |
|---|
-
sage/quadratic_forms/quadratic_form.py
# HG changeset patch # User Jonathan Hanke <jonhanke@gmail.com> # Date 1242387616 25200 # Node ID 5f887515ed65d071b4120088339ae40e657b0a7e # Parent 12d1fb4068effe1cd9d790a740a6a1841e0a323a Added more doctests to bring QuadraticForm coverage to 100%. diff -r 12d1fb4068ef -r 5f887515ed65 sage/quadratic_forms/quadratic_form.py
a b 213 213 ## Routines to compute local masses for ZZ. 214 214 from sage.quadratic_forms.quadratic_form__mass import \ 215 215 shimura_mass__maximal, \ 216 hanke_mass__maximal, \ 217 GHY_mass_maximal 216 GHY_mass__maximal 218 217 from sage.quadratic_forms.quadratic_form__mass__Siegel_densities import \ 219 218 mass__by_Siegel_densities, \ 220 219 Pall_mass_density_at_odd_prime, \ … … 234 233 conway_p_mass, \ 235 234 conway_standard_p_mass, \ 236 235 conway_standard_mass, \ 237 conway_mass , \238 conway_generic_mass, \239 conway_p_mass_adjustment236 conway_mass 237 # conway_generic_mass, \ 238 # conway_p_mass_adjustment 240 239 241 240 ## Routines to check local representability of numbers 242 241 from sage.quadratic_forms.quadratic_form__local_representation_conditions import \ -
sage/quadratic_forms/quadratic_form__local_representation_conditions.py
diff -r 12d1fb4068ef -r 5f887515ed65 sage/quadratic_forms/quadratic_form__local_representation_conditions.py
a b 856 856 True 857 857 sage: Q.is_locally_represented_number_at_place(7, 5) 858 858 True 859 sage: Q.is_locally_represented_number_at_place(-1, infinity) 860 False 861 sage: Q.is_locally_represented_number_at_place(-1, 2) 862 False 859 863 864 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1,1,-1]) 860 865 sage: Q.is_locally_represented_number_at_place(7, infinity) 861 866 True 862 867 sage: Q.is_locally_represented_number_at_place(7, 2) … … 866 871 sage: Q.is_locally_represented_number_at_place(7, 5) 867 872 True 868 873 869 870 sage: Q.is_locally_represented_number_at_place(-1, infinity)871 False872 sage: Q.is_locally_represented_number_at_place(-1, 2)873 False874 sage: Q.is_locally_represented_number_at_place(7, 3)875 True876 sage: Q.is_locally_represented_number_at_place(7, 5)877 True878 879 874 """ 880 875 self.local_representation_conditions(silent_flag=True) 881 876 return self.__local_representability_conditions.is_locally_represented_at_place(m, p) … … 893 888 boolean 894 889 895 890 EXAMPLES: 896 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1 ,1])891 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 897 892 sage: Q.is_locally_represented_number(2) 898 893 True 899 894 sage: Q.is_locally_represented_number(7) -
sage/quadratic_forms/quadratic_form__mass.py
diff -r 12d1fb4068ef -r 5f887515ed65 sage/quadratic_forms/quadratic_form__mass.py
a b 23 23 conway_p_mass, \ 24 24 conway_standard_p_mass, \ 25 25 conway_standard_mass, \ 26 conway_mass , \27 conway_generic_mass, \28 conway_p_mass_adjustment26 conway_mass 27 # conway_generic_mass, \ 28 # conway_p_mass_adjustment 29 29 30 30 ################################################### 31 31 32 32 33 def shimura_mass__maximal(self, p):33 def shimura_mass__maximal(self,): 34 34 """ 35 35 Use Shimuras exact mass formula to compute the mass of a maximal 36 36 quadratic lattice. This works for any totally real number field, 37 37 but has a small technical restriction when n is odd. 38 39 INPUT: 40 none 41 42 OUTPUT: 43 a rational number 44 45 EXAMPLE: 46 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 47 sage: Q.shimura_mass__maximal() 48 38 49 """ 39 50 pass 40 51 41 52 42 def hanke_mass__maximal(self, p):43 """44 Use Shimuras exact mass formula to compute the mass of a maximal45 quadratic lattice. This works for any totally real number field,46 but has a small technical restriction when n is odd.47 """48 pass49 53 50 51 def GHY_mass_maximal(self, p): 54 def GHY_mass__maximal(self): 52 55 """ 53 56 Use the GHY formula to compute the mass of a (maximal?) quadratic 54 57 lattice. This works for any number field. 55 58 56 See [GHY, Prop 7.4 and 7.5, p121] and [GY, Thrm 10.20, p25]. 59 Reference: See [GHY, Prop 7.4 and 7.5, p121] and [GY, Thrm 10.20, p25]. 60 61 INPUT: 62 none 63 64 OUTPUT: 65 a rational number 66 67 EXAMPLE: 68 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 69 sage: Q.GHY_mass__maximal() 70 57 71 """ 58 72 pass -
sage/quadratic_forms/quadratic_form__mass__Conway_Sloane_masses.py
diff -r 12d1fb4068ef -r 5f887515ed65 sage/quadratic_forms/quadratic_form__mass__Conway_Sloane_masses.py
a b 7 7 from sage.quadratic_forms.special_values import gamma__exact, zeta__exact, quadratic_L_function__exact 8 8 from sage.calculus.calculus import floor 9 9 10 11 10 12 def parity(self, allow_rescaling_flag=True): 11 13 """ 12 14 Returns the parity ("even" or "odd") of an integer-valued quadratic … … 157 159 158 160 OUTPUT: 159 161 a list of integers 162 163 EXAMPLES: 164 sage: Q = DiagonalQuadraticForm(ZZ, range(1,10)) 165 sage: Q.conway_species_list_at_odd_prime(3) 166 [6, 2, 1] 167 168 sage: Q = DiagonalQuadraticForm(ZZ, range(1,8)) 169 sage: Q.conway_species_list_at_odd_prime(3) 170 [5, 2] 171 sage: Q.conway_species_list_at_odd_prime(5) 172 [-6, 1] 173 160 174 """ 161 175 ## Sanity Check: 162 176 if not ((p>2) and is_prime(p)): … … 192 206 return species_list 193 207 194 208 209 195 210 def conway_species_list_at_2(self): 196 211 """ 197 212 Returns an integer called the 'species' which determines the type … … 209 224 a list of integers 210 225 211 226 EXAMPLES: 227 sage: Q = DiagonalQuadraticForm(ZZ, range(1,10)) 228 sage: Q.conway_species_list_at_2() 229 [1, 5, 1, 1, 1, 1] 230 231 sage: Q = DiagonalQuadraticForm(ZZ, range(1,8)) 232 sage: Q.conway_species_list_at_2() 233 [1, 3, 1, 1, 1] 234 212 235 """ 213 236 ## Some useful variables 214 237 n = self.dim() … … 277 300 unimodular blocks of size <= 2 and the 1x1 blocks are all in the upper 278 301 leftmost position. 279 302 303 INPUT: 304 none 305 280 306 OUTPUT: 281 307 an integer 0 <= x <= 7 282 308 309 EXAMPLES: 310 sage: Q = DiagonalQuadraticForm(ZZ, [1,3,5,7]) 311 sage: Q.conway_octane_of_this_unimodular_Jordan_block_at_2() 312 0 313 sage: Q = DiagonalQuadraticForm(ZZ, [1,5,13]) 314 sage: Q.conway_octane_of_this_unimodular_Jordan_block_at_2() 315 3 316 sage: Q = DiagonalQuadraticForm(ZZ, [3,7,13]) 317 sage: Q.conway_octane_of_this_unimodular_Jordan_block_at_2() 318 7 319 283 320 """ 284 321 ## Deal with 'even' forms 285 322 if self.parity() == "even": … … 348 385 def conway_diagonal_factor(self, p): 349 386 """ 350 387 Computes the diagonal factor of Conway's p-mass. 388 389 INPUT: 390 p -- a prime number > 0 391 392 OUTPUT: 393 a rational number > 0 394 395 EXAMPLES: 396 sage: sage: Q = DiagonalQuadraticForm(ZZ, range(1,6)) 397 sage: Q.conway_diagonal_factor(3) 398 81/256 399 351 400 """ 352 401 ## Get the species list at p 353 402 if p == 2: … … 376 425 """ 377 426 Computes twice the power of p which evalues the 'cross product' 378 427 term in Conway's mass formula. 428 429 INPUT: 430 p -- a prime number > 0 431 432 OUTPUT: 433 a rational number 434 435 EXAMPLES: 436 sage: Q = DiagonalQuadraticForm(ZZ, range(1,8)) 437 sage: Q.conway_cross_product_doubled_power(2) 438 18 439 sage: Q.conway_cross_product_doubled_power(3) 440 10 441 sage: Q.conway_cross_product_doubled_power(5) 442 6 443 sage: Q.conway_cross_product_doubled_power(7) 444 6 445 sage: Q.conway_cross_product_doubled_power(11) 446 0 447 sage: Q.conway_cross_product_doubled_power(13) 448 0 449 379 450 """ 380 451 doubled_power = 0 381 452 dim_list = [J.dim() for J in self.jordan_blocks_in_unimodular_list_by_scale_power(p)] … … 390 461 def conway_type_factor(self): 391 462 """ 392 463 This is a special factor only present in the mass formula when p=2. 464 465 INPUT: 466 none 467 468 OUTPUT: 469 a rational number 470 471 EXAMPLES: 472 sage: Q = DiagonalQuadraticForm(ZZ, range(1,8)) 473 sage: Q.conway_type_factor() 474 4 475 393 476 """ 394 477 jordan_list = self.jordan_blocks_in_unimodular_list_by_scale_power(2) 395 478 n2 = sum([J.dim() for J in jordan_list if J.is_even()]) … … 402 485 def conway_p_mass(self, p): 403 486 """ 404 487 Computes Conway's p-mass. 488 489 INPUT: 490 p -- a prime number > 0 491 492 OUTPUT: 493 a rational number > 0 494 495 EXAMPLES: 496 sage: Q = DiagonalQuadraticForm(ZZ, range(1, 6)) 497 sage: Q.conway_p_mass(2) 498 16/3 499 sage: Q.conway_p_mass(3) 500 729/256 501 405 502 """ 406 503 ## Compute the first two factors of the p-mass 407 504 p_mass = self.conway_diagonal_factor(p) * (p ** (self.conway_cross_product_doubled_power(p) / ZZ(2))) … … 419 516 """ 420 517 Computes the standard (generic) Conway-Sloane p-mass. 421 518 519 INPUT: 520 p -- a prime number > 0 521 522 OUTPUT: 523 a rational number > 0 524 422 525 EXAMPLES: 423 526 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 424 527 sage: Q.conway_standard_p_mass(2) … … 448 551 """ 449 552 Returns the infinite product of the standard mass factors. 450 553 554 INPUT: 555 none 556 557 OUTPUT: 558 a rational number > 0 559 451 560 EXAMPLES: 452 561 sage: Q = QuadraticForm(ZZ, 3, [2, -2, 0, 3, -5, 4]) 453 562 sage: Q.conway_standard_mass() … … 486 595 """ 487 596 Compute the mass by using the Conway-Sloane mass formula. 488 597 598 INPUT: 599 none 600 601 OUTPUT: 602 a rational number > 0 603 489 604 EXAMPLES: 490 605 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 491 606 sage: Q.conway_mass() … … 524 639 525 640 526 641 527 def conway_generic_mass(self):528 """529 Computes the generic mass given as530 2 \pi^{-n(n+1)/4} \prod_{j=1}^{n} \Gamma\(\tfrac{j}{2}\)531 \zeta(2) \cdots \zeta(2s-2) \zeta_{D}(s)532 where $n = 2s$ or $2s-1$ depending on the parity of $n$,533 and $D = (-1)^{s} d$. We interpret the symbol $\(\frac{D}{p}\)$534 as 0 if $p\mid 2d$.535 (Conway and Sloane, Mass formula paper, p??)536 537 This is possibly equal to538 2^{-td} * \tau(G) *[\prod_{i=1}^{t} \zeta(1-2i) ]* L(1-t, \chi)539 where $\dim(Q) = n = 2t$ or $2t+1$, and the last factor is omitted540 when $n$ is odd.541 (GHY, Prop 7.4 and 7.5, p121)542 """543 RR = RealField(200)544 n = self.dim()545 if n % 2 == 0:546 s = n / 2547 else:548 s = (n-1) / 2549 550 ## Form the generic zeta product551 ans = 2 * RR(pi)^(-n * (n+1) / 4)552 for j in range(1,n+1):553 ans *= gamma(RR(j/2))554 for j in range(2, 2*s, 2): ## j = 2, ..., 2s-2555 ans *= zeta(RR(j))556 557 ## Extra L-factor for even dimensional forms -- DO THIS!!!558 raise NotImplementedError, "This routine is not finished yet... =("559 560 ## Return the answer561 return ans642 #def conway_generic_mass(self): 643 # """ 644 # Computes the generic mass given as 645 # 2 \pi^{-n(n+1)/4} \prod_{j=1}^{n} \Gamma\(\tfrac{j}{2}\) 646 # \zeta(2) \cdots \zeta(2s-2) \zeta_{D}(s) 647 # where $n = 2s$ or $2s-1$ depending on the parity of $n$, 648 # and $D = (-1)^{s} d$. We interpret the symbol $\(\frac{D}{p}\)$ 649 # as 0 if $p\mid 2d$. 650 # (Conway and Sloane, Mass formula paper, p??) 651 # 652 # This is possibly equal to 653 # 2^{-td} * \tau(G) *[\prod_{i=1}^{t} \zeta(1-2i) ]* L(1-t, \chi) 654 # where $\dim(Q) = n = 2t$ or $2t+1$, and the last factor is omitted 655 # when $n$ is odd. 656 # (GHY, Prop 7.4 and 7.5, p121) 657 # """ 658 # RR = RealField(200) 659 # n = self.dim() 660 # if n % 2 == 0: 661 # s = n / 2 662 # else: 663 # s = (n-1) / 2 664 # 665 # ## Form the generic zeta product 666 # ans = 2 * RR(pi)^(-n * (n+1) / 4) 667 # for j in range(1,n+1): 668 # ans *= gamma(RR(j/2)) 669 # for j in range(2, 2*s, 2): ## j = 2, ..., 2s-2 670 # ans *= zeta(RR(j)) 671 # 672 # ## Extra L-factor for even dimensional forms -- DO THIS!!! 673 # raise NotImplementedError, "This routine is not finished yet... =(" 674 # 675 # ## Return the answer 676 # return ans 562 677 563 678 564 679 565 680 566 681 567 682 568 def conway_p_mass_adjustment(self, p):569 """570 Computes the adjustment to give the p-mass from the generic mass.571 """572 pass683 #def conway_p_mass_adjustment(self, p): 684 # """ 685 # Computes the adjustment to give the p-mass from the generic mass. 686 # """ 687 # pass 573 688 574 689 575 690 ######################################################################## -
sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py
diff -r 12d1fb4068ef -r 5f887515ed65 sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py
a b 194 194 Returns the local mass of the quadratic form when p=2, according 195 195 to Watson's Theorem 1 of "The 2-adic density of a quadratic form" 196 196 in Mathematika 23 (1976), pp 94--106. 197 198 INPUT: 199 none 200 201 OUTPUT: 202 a rational number 203 204 EXAMPLES: 205 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 206 sage: Q.Watson_mass_at_2() ## WARNING: WE NEED TO CHECK THIS CAREFULLY! 207 384 197 208 """ 198 209 ## Make a 0-dim'l quadratic form (for initialization purposes) 199 210 Null_Form = copy.deepcopy(self) … … 288 299 to Theorem 5.6.3 on pp108--9 of Kitaoka's Book "The Arithmetic of 289 300 Quadratic Forms". 290 301 302 INPUT: 303 none 304 305 OUTPUT: 306 a rational number > 0 307 308 EXAMPLES: 309 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 310 sage: Q.Kitaoka_mass_at_2() ## WARNING: WE NEED TO CHECK THIS CAREFULLY! 311 1/2 312 291 313 """ 292 314 ## Make a 0-dim'l quadratic form (for initialization purposes) 293 315 Null_Form = copy.deepcopy(self) … … 342 364 343 365 ## Deal with the complicated case: 344 366 tmp_m = dim2_dict[j].dim() / 2 345 if dim2_dict[j].is_hyperbolic( ):367 if dim2_dict[j].is_hyperbolic(2): 346 368 E *= 2 / (1 + 2**(-tmp_m)) 347 369 else: 348 370 E *= 2 / (1 - 2**(-tmp_m)) … … 369 391 ## Step 5: Compute the local mass for the prime 2. 370 392 mass_at_2 = (QQ(2)**(w - q)) * P * E 371 393 return mass_at_2 394 372 395 373 396 374 397 def mass_at_two_by_counting_mod_power(self, k): … … 376 399 Computes the local mass at p=2 assuming that it's stable (mod 2^k). 377 400 378 401 Note: This is **way** too slow to be useful, even when k=1!!! 402 403 TO DO: Remove this routine, or try to compile it! 404 405 406 INPUT: 407 k -- an integer >= 1 408 409 OUTPUT: 410 a rational number 411 412 EXAMPLE: 413 sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 414 sage: Q.mass_at_two_by_counting_mod_power(1) 415 4 416 379 417 """ 380 418 R = IntegerModRing(2**k) 381 419 Q1 = self.base_change_to(R)
