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  
    213213    ## Routines to compute local masses for ZZ. 
    214214    from sage.quadratic_forms.quadratic_form__mass import \ 
    215215            shimura_mass__maximal, \ 
    216             hanke_mass__maximal, \ 
    217             GHY_mass_maximal 
     216            GHY_mass__maximal 
    218217    from sage.quadratic_forms.quadratic_form__mass__Siegel_densities import \ 
    219218            mass__by_Siegel_densities, \ 
    220219            Pall_mass_density_at_odd_prime, \ 
     
    234233            conway_p_mass, \ 
    235234            conway_standard_p_mass, \ 
    236235            conway_standard_mass, \ 
    237             conway_mass, \ 
    238             conway_generic_mass, \ 
    239             conway_p_mass_adjustment 
     236            conway_mass 
     237#            conway_generic_mass, \ 
     238#            conway_p_mass_adjustment 
    240239 
    241240    ## Routines to check local representability of numbers 
    242241    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  
    856856        True 
    857857        sage: Q.is_locally_represented_number_at_place(7, 5) 
    858858        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 
    859863 
     864        sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1,1,-1]) 
    860865        sage: Q.is_locally_represented_number_at_place(7, infinity) 
    861866        True 
    862867        sage: Q.is_locally_represented_number_at_place(7, 2) 
     
    866871        sage: Q.is_locally_represented_number_at_place(7, 5) 
    867872        True 
    868873 
    869  
    870         sage: Q.is_locally_represented_number_at_place(-1, infinity) 
    871         False 
    872         sage: Q.is_locally_represented_number_at_place(-1, 2) 
    873         False 
    874         sage: Q.is_locally_represented_number_at_place(7, 3) 
    875         True 
    876         sage: Q.is_locally_represented_number_at_place(7, 5) 
    877         True 
    878  
    879874    """ 
    880875    self.local_representation_conditions(silent_flag=True) 
    881876    return self.__local_representability_conditions.is_locally_represented_at_place(m, p) 
     
    893888        boolean 
    894889 
    895890    EXAMPLES: 
    896         sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1,1]) 
     891        sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 
    897892        sage: Q.is_locally_represented_number(2) 
    898893        True 
    899894        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  
    2323        conway_p_mass, \ 
    2424        conway_standard_p_mass, \ 
    2525        conway_standard_mass, \ 
    26         conway_mass, \ 
    27         conway_generic_mass, \ 
    28         conway_p_mass_adjustment 
     26        conway_mass 
     27#        conway_generic_mass, \ 
     28#        conway_p_mass_adjustment 
    2929 
    3030################################################### 
    3131 
    3232 
    33 def shimura_mass__maximal(self, p): 
     33def shimura_mass__maximal(self,): 
    3434    """ 
    3535    Use Shimuras exact mass formula to compute the mass of a maximal 
    3636    quadratic lattice. This works for any totally real number field, 
    3737    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 
    3849    """ 
    3950    pass 
    4051 
    4152 
    42 def hanke_mass__maximal(self, p): 
    43     """ 
    44     Use Shimuras exact mass formula to compute the mass of a maximal  
    45     quadratic lattice.  This works for any totally real number field,  
    46     but has a small technical restriction when n is odd. 
    47     """ 
    48     pass 
    4953 
    50  
    51 def GHY_mass_maximal(self, p): 
     54def GHY_mass__maximal(self): 
    5255    """ 
    5356    Use the GHY formula to compute the mass of a (maximal?) quadratic 
    5457    lattice. This works for any number field. 
    5558 
    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 
    5771    """ 
    5872    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  
    77from sage.quadratic_forms.special_values import gamma__exact, zeta__exact, quadratic_L_function__exact 
    88from sage.calculus.calculus import floor 
    99 
     10 
     11 
    1012def parity(self, allow_rescaling_flag=True): 
    1113    """ 
    1214    Returns the parity ("even" or "odd") of an integer-valued quadratic 
     
    157159 
    158160    OUTPUT: 
    159161        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 
    160174    """ 
    161175    ## Sanity Check: 
    162176    if not ((p>2) and is_prime(p)): 
     
    192206    return species_list 
    193207 
    194208 
     209 
    195210def conway_species_list_at_2(self): 
    196211    """ 
    197212    Returns an integer called the 'species' which determines the type 
     
    209224        a list of integers 
    210225 
    211226    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 
    212235    """ 
    213236    ## Some useful variables 
    214237    n = self.dim() 
     
    277300    unimodular blocks of size <= 2 and the 1x1 blocks are all in the upper 
    278301    leftmost position. 
    279302 
     303    INPUT: 
     304        none 
     305 
    280306    OUTPUT: 
    281307        an integer 0 <= x <= 7 
    282308 
     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 
    283320    """ 
    284321    ## Deal with 'even' forms  
    285322    if self.parity() == "even": 
     
    348385def conway_diagonal_factor(self, p): 
    349386    """ 
    350387    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 
    351400    """ 
    352401     ## Get the species list at p 
    353402    if p == 2: 
     
    376425    """ 
    377426    Computes twice the power of p which evalues the 'cross product' 
    378427    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 
    379450    """ 
    380451    doubled_power = 0 
    381452    dim_list = [J.dim()  for J in self.jordan_blocks_in_unimodular_list_by_scale_power(p)] 
     
    390461def conway_type_factor(self): 
    391462    """ 
    392463    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 
    393476    """ 
    394477    jordan_list = self.jordan_blocks_in_unimodular_list_by_scale_power(2) 
    395478    n2 = sum([J.dim()  for J in jordan_list  if J.is_even()]) 
     
    402485def conway_p_mass(self, p): 
    403486    """ 
    404487    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 
    405502    """ 
    406503    ## Compute the first two factors of the p-mass 
    407504    p_mass = self.conway_diagonal_factor(p) * (p ** (self.conway_cross_product_doubled_power(p) / ZZ(2))) 
     
    419516    """ 
    420517    Computes the standard (generic) Conway-Sloane p-mass. 
    421518 
     519    INPUT: 
     520        p -- a prime number > 0 
     521 
     522    OUTPUT: 
     523        a rational number > 0 
     524 
    422525    EXAMPLES: 
    423526        sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 
    424527        sage: Q.conway_standard_p_mass(2) 
     
    448551    """ 
    449552    Returns the infinite product of the standard mass factors. 
    450553 
     554    INPUT: 
     555        none 
     556 
     557    OUTPUT: 
     558        a rational number > 0 
     559 
    451560    EXAMPLES: 
    452561        sage: Q = QuadraticForm(ZZ, 3, [2, -2, 0, 3, -5, 4]) 
    453562        sage: Q.conway_standard_mass() 
     
    486595    """ 
    487596    Compute the mass by using the Conway-Sloane mass formula.     
    488597 
     598    INPUT: 
     599        none 
     600 
     601    OUTPUT: 
     602        a rational number > 0 
     603 
    489604    EXAMPLES: 
    490605        sage: Q = DiagonalQuadraticForm(ZZ, [1,1,1]) 
    491606        sage: Q.conway_mass() 
     
    524639 
    525640 
    526641 
    527 def conway_generic_mass(self): 
    528     """  
    529     Computes the generic mass given as  
    530          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 to   
    538         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 omitted  
    540     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 / 2 
    547     else: 
    548         s = (n-1) / 2 
    549  
    550     ## Form the generic zeta product 
    551     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-2     
    555         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 answer 
    561     return ans 
     642#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 
    562677 
    563678 
    564679 
    565680 
    566681 
    567682     
    568 def conway_p_mass_adjustment(self, p): 
    569     """ 
    570     Computes the adjustment to give the p-mass from the generic mass. 
    571     """ 
    572     pass 
     683#def conway_p_mass_adjustment(self, p): 
     684#    """ 
     685#    Computes the adjustment to give the p-mass from the generic mass. 
     686#    """ 
     687#    pass 
    573688 
    574689 
    575690######################################################################## 
  • 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  
    194194    Returns the local mass of the quadratic form when p=2, according 
    195195    to Watson's Theorem 1 of "The 2-adic density of a quadratic form" 
    196196    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 
    197208    """ 
    198209    ## Make a 0-dim'l quadratic form (for initialization purposes) 
    199210    Null_Form = copy.deepcopy(self) 
     
    288299    to Theorem 5.6.3 on pp108--9 of Kitaoka's Book "The Arithmetic of 
    289300    Quadratic Forms". 
    290301 
     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 
    291313    """ 
    292314    ## Make a 0-dim'l quadratic form (for initialization purposes) 
    293315    Null_Form = copy.deepcopy(self) 
     
    342364 
    343365            ## Deal with the complicated case: 
    344366            tmp_m = dim2_dict[j].dim() / 2 
    345             if dim2_dict[j].is_hyperbolic(): 
     367            if dim2_dict[j].is_hyperbolic(2): 
    346368                E *= 2 / (1 + 2**(-tmp_m)) 
    347369            else: 
    348370                E *= 2 / (1 - 2**(-tmp_m))  
     
    369391    ## Step 5: Compute the local mass for the prime 2. 
    370392    mass_at_2 = (QQ(2)**(w - q)) * P * E 
    371393    return mass_at_2 
     394 
    372395         
    373396         
    374397def mass_at_two_by_counting_mod_power(self, k): 
     
    376399    Computes the local mass at p=2 assuming that it's stable (mod 2^k). 
    377400 
    378401    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 
    379417    """ 
    380418    R = IntegerModRing(2**k) 
    381419    Q1 = self.base_change_to(R)