Changeset 1:bf5417bc8931


Ignore:
Timestamp:
02/11/06 13:33:33 (7 years ago)
Author:
tornaria@…
Branch:
default
Message:

[project @ patch to sage-0.10.13]

Files:
1 added
30 edited

Legend:

Unmodified
Added
Removed
  • PKG-INFO

    r0 r1  
    11Metadata-Version: 1.0 
    22Name: sage 
    3 Version: 0.10.12 
     3Version: 0.10.13 
    44Summary: SAGE: System for Algebra and Geometry Experimentation 
    55Home-page: http://modular.ucsd.edu/sage 
  • boring

    r0 r1  
    1616\.orig$ 
    1717(^|/)vssver\.scc$ 
    18 \.swp$ 
     18\.sw?$ 
    1919(^|/)MT($|/) 
    2020(^|/)\{arch\}($|/) 
     
    3232(^|/)Thumbs\.db$ 
    3333# sage files to ignore: 
     34(^|/).doctest($|/) 
    3435^build($|/) 
    3536^sage/ext/arith.c$ 
  • sage/categories/homset.py

    r0 r1  
    6666    if cat is None: 
    6767        if cat_X.is_subcategory(cat_Y): 
    68             cat = cat_X 
    69         if cat_Y.is_subcategory(cat_X): 
     68            cat = cat_Y 
     69        elif cat_Y.is_subcategory(cat_X): 
    7070            if not (cat is None) and not (cat_X is cat_Y): 
    7171                raise ValueError, "No unambiguous category found for Hom from %s to %s."%(X,Y) 
    72             cat = cat_Y 
     72            cat = cat_X 
    7373        else: 
    7474            raise TypeError, "No suitable category found for Hom from %s to %s."%(X,Y) 
     
    202202            if not isinstance(cat, category.Category): 
    203203                raise TypeError, "cat (=%s) must be a category"%cat 
    204             if not X in cat: 
    205                 raise TypeError, "X (=%s) must be in cat (=%s)"%(X, cat) 
    206             if not Y in cat: 
    207                 raise TypeError, "Y (=%s) must be in cat (=%s)"%(Y, cat) 
     204            #if not X in cat: 
     205            #    raise TypeError, "X (=%s) must be in cat (=%s)"%(X, cat) 
     206            #if not Y in cat: 
     207            #    raise TypeError, "Y (=%s) must be in cat (=%s)"%(Y, cat) 
    208208 
    209209    def _repr_(self): 
  • sage/coding/linear_code.py

    r0 r1  
    1 r""" 
     1r"""nodoctest 
    22Linear Codes 
    33 
     
    99    -- David Joyner (2005-11-22, 2006-12-03): written 
    1010    -- William Stein (2006-01-23) -- Inclusion in SAGE 
    11     -- David Joyner (2006-01-25, 2006-12-03): small fixed to use sage_eval 
     11    -- David Joyner (2006-01-30, 2006-12-03): small fixes to use sage_eval 
    1212     
    1313This file contains 
     
    2323\end{enumerate} 
    2424 
     25 
     26    EXAMPLES: 
     27        sage: MS = MatrixSpace(GF(2),4,7) 
     28        sage: G = MS([[1,1,1,0,0,0,0], [ 1, 0, 0, 1, 1, 0, 0], [ 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 1, 0, 0, 1]]) 
     29        sage: C = LinearCode(G) 
     30        sage: C.basis() 
     31 
     32        [(1, 1, 1, 0, 0, 0, 0), 
     33         (1, 0, 0, 1, 1, 0, 0), 
     34         (0, 1, 0, 1, 0, 1, 0), 
     35         (1, 1, 0, 1, 0, 0, 1)] 
     36        sage: c = C.basis()[1] 
     37        sage: c in C 
     38        True 
     39        sage: c.nonzero_positions() 
     40        [0, 3, 4] 
     41        sage: c.support() 
     42        [0, 3, 4] 
     43        sage: c.parent() 
     44        Vector space of dimension 7 over Finite Field of size 2 
     45 
    2546To be added: 
    2647\begin{enumerate} 
     
    7091 
    7192    EXAMPLES: 
    72     sage: Gstr = 'Z(2)*[[1,1,1,0,0,0,0], [1,0,0,1,1,0,0], [0,1,0,1,0,1,0], [1,1,0,1,0,0,1]]' 
    73     sage: F = GF(2) 
    74     sage: wtdist(Gstr, F) 
    75     [1, 0, 0, 7, 7, 0, 0, 1] 
     93        sage: Gstr = 'Z(2)*[[1,1,1,0,0,0,0], [1,0,0,1,1,0,0], [0,1,0,1,0,1,0], [1,1,0,1,0,0,1]]' 
     94        sage: F = GF(2) 
     95        sage: sage.coding.linear_code.wtdist(Gstr, F) 
     96        [1, 0, 0, 7, 7, 0, 0, 1] 
    7697 
    7798    Here Gstr is a generator matrix of the Hamming [7,4,3] binary code.  
    7899 
    79     ALGORITHM: Uses C programs written by Steve Linton in the kernel 
    80     of GAP, so is fairly fast. 
     100    ALGORITHM:  
     101        Uses C programs written by Steve Linton in the kernel 
     102        of GAP, so is fairly fast. 
    81103 
    82104    AUTHOR: David Joyner (2005-11) 
     
    88110    n = int(C.WordLength()) 
    89111    z = 'Z(%s)*%s'%(q, [0]*n)     # GAP zero vector as a string 
    90     d = G.DistancesDistributionMatFFEVecFFE(k, z) 
    91     return d.sage() 
     112    dist = gap.eval("w:=DistancesDistributionMatFFEVecFFE("+Gmat+", GF("+str(q)+"),"+z+")") 
     113    #d = G.DistancesDistributionMatFFEVecFFE(k, z) 
     114    v = [sage_eval(gap.eval("w["+str(i)+"]")) for i in range(1,n+2)] 
     115    return v 
    92116 
    93117def min_wt_vec(Gmat,F):  
    94118    """ 
     119    Uses C programs written by Steve Linton in the kernel of GAP, so is fairly fast. 
     120 
    95121    INPUT: 
    96     Same as wtdist. 
    97     OUTPUT: 
    98     Returns a minimum weight vector v, the "message" vector m such that m*G = v,  
     122        Same as wtdist. 
     123     
     124    OUTPUT: 
     125        Returns a minimum weight vector v, the "message" vector m such that m*G = v,  
    99126    and the (minimum) weight, as a triple. 
    100127 
    101128    EXAMPLES: 
    102     sage: Gstr = "Z(2)*[[1,1,1,0,0,0,0], [1,0,0,1,1,0,0], [0,1,0,1,0,1,0], [1,1,0,1,0,0,1]]" 
    103     sage: min_wt_vec(Gstr,GF(2)) 
    104     [[0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0], 3] 
     129        sage: Gstr = "Z(2)*[[1,1,1,0,0,0,0], [1,0,0,1,1,0,0], [0,1,0,1,0,1,0], [1,1,0,1,0,0,1]]" 
     130        sage: sage.coding.linear_code.min_wt_vec(Gstr,GF(2)) 
     131        [[0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0], 3] 
    105132 
    106133    Here Gstr is a generator matrix of the Hamming [7,4,3] binary code.  
    107     Uses C programs written by Steve Linton in the kernel of GAP, so it fairly fast. 
    108134 
    109135    AUTHOR: David Joyner (11-2005) 
     
    142168 
    143169        EXAMPLES: 
    144         sage: coding.minimum_distance_upper_bound(7,4,GF(2)) 
    145         3 
     170            sage: sage.coding.linear_code.minimum_distance_upper_bound(7,4,GF(2)) 
     171            3 
    146172 
    147173        Obviously requires an internet connection. 
     
    158184         
    159185        EXAMPLES: 
    160         sage: coding.minimum_distance_upper_bound(7,4,GF(2)) 
    161         3 
     186            sage: sage.coding.linear_code.minimum_distance_upper_bound(7,4,GF(2)) 
     187            3 
    162188         
    163189        Obviously requires an internet connection. 
     
    174200         
    175201        EXAMPLES: 
    176         sage: coding.minimum_distance_why(7,4,GF(2)) 
    177         Lb(7,4) = 3 is found by truncation of: 
    178         Lb(8,4) = 4 is found by the (u|u+v) construction 
    179         applied to [4,3,2] and [4,1,4]-codes 
    180         Ub(7,4) = 3 follows by the Griesmer bound. 
     202            sage: sage.coding.linear_code.minimum_distance_why(7,4,GF(2)) 
     203            Lb(7,4) = 3 is found by truncation of: 
     204            Lb(8,4) = 4 is found by the (u|u+v) construction 
     205            applied to [4,3,2] and [4,1,4]-codes 
     206            Ub(7,4) = 3 follows by the Griesmer bound. 
    181207 
    182208        Obviously requires an internet connection. 
     
    191217class LinearCode(module.Module): 
    192218    """ 
    193     class for linear codes over a finite field or finite ring 
     219    A class for linear codes over a finite field or finite ring. 
     220     
    194221    INPUT: 
    195     A $k\times n$ matrix $G$ of rank $k$, $k\leq n$, over  
    196     a finite field $F$. 
    197     OUTPUT: 
    198     The linear code of length $n$ over $F$ having $G$ as a 
    199     generator matrix. 
     222        G -- A $k\times n$ matrix of (full) rank $k$, $k\leq n$, over  
     223             a finite field $F$. 
     224    
     225    OUTPUT: 
     226        The linear code of length $n$ over $F$ having $G$ as a 
     227        generator matrix. 
    200228  
    201229    EXAMPLES: 
     
    204232        sage: C  = LinearCode(G) 
    205233        sage: C 
    206         Linear code of length 7, dimension 4 over Finite field of size 2 
     234        Linear code of length 7, dimension 4 over Finite Field of size 2 
    207235        sage: C.minimum_distance_upper_bound() 
    208236        3 
    209237        sage: C.base_ring() 
    210         Finite field of size 2 
     238        Finite Field of size 2 
    211239        sage: C.dimension() 
    212240        4 
     
    298326 
    299327        EXAMPLES: 
    300         sage: MS = MatrixSpace(GF(3),4,7) 
    301         sage: G = MS([[1,1,1,0,0,0,0], [1,0,0,1,1,0,0], [0,1,0,1,0,1,0], [1,1,0,1,0,0,1]]) 
    302         sage: C = LinearCode(G) 
    303         sage: C.minimum_distance() 
    304               3 
    305         sage: C=RandomLinearCode(10,5,GF(4)) 
    306         sage: C.gen_mat() 
    307  
    308 [    1     0     0     0     0 x + 1     1     0     0     0] 
    309 [x + 1     1     0     1     0 x + 1     1     1     0     0] 
    310 [    0 x + 1     0 x + 1     0     x x + 1 x + 1 x + 1     0] 
    311 [    1     0     x     0     1     0     0     0     0     1] 
    312 [    0     0     1     1     0     0     0     0     x x + 1] 
    313         sage: C.minimum_distance() 
    314       2 
    315         sage: C.minimum_distance_upper_bound() 
    316       5 
    317         sage: C.minimum_distance_why() 
    318 Ub(10,5) = 5 follows by the Griesmer bound. 
     328            sage: MS = MatrixSpace(GF(3),4,7) 
     329            sage: G = MS([[1,1,1,0,0,0,0], [1,0,0,1,1,0,0], [0,1,0,1,0,1,0], [1,1,0,1,0,0,1]]) 
     330            sage: C = LinearCode(G) 
     331            sage: C.minimum_distance() 
     332            3 
     333            sage: C=RandomLinearCode(10,5,GF(4)) 
     334            sage: C.gen_mat()                ## random 
     335            [    1     0     0     0     0 x + 1     1     0     0     0] 
     336            [x + 1     1     0     1     0 x + 1     1     1     0     0] 
     337            [    0 x + 1     0 x + 1     0     x x + 1 x + 1 x + 1     0] 
     338            [    1     0     x     0     1     0     0     0     0     1] 
     339            [    0     0     1     1     0     0     0     0     x x + 1] 
     340            sage: C.minimum_distance()       ## random 
     341            2 
     342            sage: C.minimum_distance_upper_bound() 
     343            5 
     344            sage: C.minimum_distance_why()        
     345            Ub(10,5) = 5 follows by the Griesmer bound. 
    319346 
    320347 
     
    332359        """ 
    333360        Uses a GAP kernel function (in C) written by Steve Linton.  
     361 
    334362        EXAMPLES: 
     363            sage: MS = MatrixSpace(GF(2),4,7) 
     364            sage: G = MS([[1,1,1,0,0,0,0], [ 1, 0, 0, 1, 1, 0, 0], [ 0, 1, 0,1, 0, 1, 0], [1, 1, 0, 1, 0, 0, 1]]) 
     365            sage: C = LinearCode(G) 
     366            sage: C.spectrum() 
     367            [1, 0, 0, 7, 7, 0, 0, 1] 
    335368 
    336369        """ 
     
    352385    def decode(self, right): 
    353386        """ 
    354         Wraps GUAVA's Decodeword. 
     387        Wraps GUAVA's Decodeword. Hamming codes have a special  
     388        decoding algorithm. Otherwise, syndrome decoding is used.  
     389 
    355390        INPUT:  
    356         right must be a vector of length = length(self) 
     391            right must be a vector of length = length(self) 
     392         
    357393        OUTPUT: 
    358         The codeword c in C closest to r.  
    359  
    360         Hamming codes have a special decoding algorithm. Otherwise, syndrome decoding is used.  
     394            The codeword c in C closest to r.  
    361395 
    362396        EXAMPLES: 
    363         sage: C = HammingCode(3,GF(2)) 
    364         sage: MS = MatrixSpace(GF(2),1,7) 
    365         sage: F=GF(2); a=F.gen() 
    366         sage: v=MS([a,a,F(0),a,a,F(0),a]); v 
    367         [1 1 0 1 1 0 1] 
    368         sage: C.decode(v) 
    369         [1 1 0 1 0 0 1] 
     397            sage: C = HammingCode(3,GF(2)) 
     398            sage: MS = MatrixSpace(GF(2),1,7) 
     399            sage: F=GF(2); a=F.gen() 
     400            sage: v=MS([a,a,F(0),a,a,F(0),a]); v 
     401            [1 1 0 1 1 0 1] 
     402            sage: C.decode(v) 
     403            [1, 1, 0, 1, 0, 0, 1] 
    370404 
    371405        Does not work for very long codes since the syndrome table grows too large. 
     
    376410        n = len(G.columns()) 
    377411        k = len(G.rows()) 
    378         Gstr = sage2gap_matrix_finite_field_string(G,k,n,F)          
    379         vstr = sage2gap_matrix_finite_field_string(right,1,n,F) 
     412        Gstr = str(gap(G))          
     413        vstr = str(gap(right)) 
    380414        v = vstr[1:-1] 
    381415        gap.eval("C:=GeneratorMatCode("+Gstr+",GF("+str(q)+"))") 
    382         ans = gap.eval("c:=VectorCodeword(Decodeword( C, Codeword( "+v+" )))") 
    383         return gap2sage_matrix_finite_field(ans,1,n,F) 
    384  
     416        gap.eval("c:=VectorCodeword(Decodeword( C, Codeword( "+v+" )))") 
     417        ans = [sage_eval(gap.eval("c["+str(i)+"]")) for i in range(1,n+1)] 
     418        return ans 
    385419 
    386420    def dual_code(self): 
    387421        """ 
    388422        Wraps GUAVA's DualCode. 
     423         
    389424        OUTPUT: 
    390         The dual code.  
     425            The dual code.  
    391426 
    392427        EXAMPLES: 
    393         sage: C = HammingCode(3,GF(2)) 
    394         sage: C.dual_code() 
    395         Linear code of length 7, dimension 3 over Finite field of size 2 
    396         sage: C = HammingCode(3,GF(4)) 
    397         sage: C.dual_code() 
    398         Linear code of length 21, dimension 3 over Finite field in x of size 2^2 
     428            sage: C = HammingCode(3,GF(2)) 
     429            sage: C.dual_code() 
     430            Linear code of length 7, dimension 3 over Finite Field of size 2 
     431            sage: C = HammingCode(3,GF(4)) 
     432            sage: C.dual_code() 
     433            Linear code of length 21, dimension 3 over Finite Field in x of size 2^2 
    399434 
    400435        """ 
     
    417452 
    418453        EXAMPLES: 
    419  
    420         sage: C = HammingCode(3,GF(2)) 
    421         sage: Cperp = C.dual_code() 
    422         sage: C; Cperp 
    423 Linear code of length 7, dimension 4 over Finite field of size 2 
    424 Linear code of length 7, dimension 3 over Finite field of size 2 
    425         sage: C.gen_mat() 
    426  
    427 [1 1 1 0 0 0 0] 
    428 [1 0 0 1 1 0 0] 
    429 [0 1 0 1 0 1 0] 
    430 [1 1 0 1 0 0 1] 
    431         sage: C.check_mat() 
    432  
    433 [0 1 1 1 1 0 0] 
    434 [1 0 1 1 0 1 0] 
    435 [1 1 0 1 0 0 1] 
    436         sage: Cperp.check_mat() 
    437  
    438 [1 1 1 0 0 0 0] 
    439 [1 0 0 1 1 0 0] 
    440 [0 1 0 1 0 1 0] 
    441 [1 1 0 1 0 0 1] 
    442         sage: Cperp.gen_mat() 
    443  
    444 [0 1 1 1 1 0 0] 
    445 [1 0 1 1 0 1 0] 
    446 [1 1 0 1 0 0 1] 
    447  
    448  
     454            sage: C = HammingCode(3,GF(2)) 
     455            sage: Cperp = C.dual_code() 
     456            sage: C; Cperp 
     457            Linear code of length 7, dimension 4 over Finite Field of size 2 
     458            Linear code of length 7, dimension 3 over Finite Field of size 2 
     459            sage: C.gen_mat() 
     460            [1 1 1 0 0 0 0] 
     461            [1 0 0 1 1 0 0] 
     462            [0 1 0 1 0 1 0] 
     463            [1 1 0 1 0 0 1] 
     464            sage: C.check_mat() 
     465            [0 1 1 1 1 0 0] 
     466            [1 0 1 1 0 1 0] 
     467            [1 1 0 1 0 0 1] 
     468            sage: Cperp.check_mat() 
     469            [1 1 1 0 0 0 0] 
     470            [1 0 0 1 1 0 0] 
     471            [0 1 0 1 0 1 0] 
     472            [1 1 0 1 0 0 1] 
     473            sage: Cperp.gen_mat() 
     474            [0 1 1 1 1 0 0] 
     475            [1 0 1 1 0 1 0] 
     476            [1 1 0 1 0 0 1] 
    449477        """ 
    450478        Cperp = self.dual_code() 
     
    455483Codeword.support = fme.FreeModuleElement.nonzero_positions 
    456484is_Codeword = fme.is_FreeModuleElement 
    457 """ 
    458     EXAMPLE: 
    459     sage: MS = MatrixSpace(GF(2),4,7) 
    460     sage: G = MS([[1,1,1,0,0,0,0], [ 1, 0, 0, 1, 1, 0, 0], [ 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 1, 0, 0, 1]]) 
    461     sage: C = LinearCode(G) 
    462     sage: C.basis() 
    463  
    464           [(1, 1, 1, 0, 0, 0, 0), 
    465            (1, 0, 0, 1, 1, 0, 0), 
    466            (0, 1, 0, 1, 0, 1, 0), 
    467            (1, 1, 0, 1, 0, 0, 1)] 
    468     sage: c = C.basis()[1] 
    469     sage: c in C 
    470           True 
    471     sage: c.nonzero_positions() 
    472           [0, 3, 4] 
    473     sage: c.support() 
    474           [0, 3, 4] 
    475     sage: is_Codeword(c) 
    476           True 
    477     sage: c.parent() 
    478           Vector space of dimension 7 over Finite field of size 2 
    479 """ 
     485 
    480486 
    481487##################### wrapped GUAVA functions ############################ 
     
    484490    """ 
    485491    INPUT: 
    486     Integer r>1 and finite field F. 
    487     OUTPUT: 
    488     Returns the $r^{th}$ Hamming code over $F=GF(q)$ of length $n=(q^r-1)/(q-1)$. 
     492        r, F -- r>1 an integer, F a finite field. 
     493     
     494    OUTPUT: 
     495        Returns the $r^{th}$ Hamming code over $F=GF(q)$ of length $n=(q^r-1)/(q-1)$. 
     496     
    489497    Requires GUAVA. 
    490498 
    491499    EXAMPLES: 
    492     sage: C = HammingCode(3,GF(3)) 
    493     sage: C 
    494           Linear code of length 13, dimension 10 over Finite field of size 3 
    495     sage: C.minimum_distance() 
    496           3 
    497     sage: C.gen_mat() 
    498  
    499 [2 2 1 0 0 0 0 0 0 0 0 0 0] 
    500 [1 2 0 1 0 0 0 0 0 0 0 0 0] 
    501 [2 0 0 0 2 1 0 0 0 0 0 0 0] 
    502 [1 0 0 0 2 0 1 0 0 0 0 0 0] 
    503 [0 2 0 0 2 0 0 1 0 0 0 0 0] 
    504 [2 2 0 0 2 0 0 0 1 0 0 0 0] 
    505 [1 2 0 0 2 0 0 0 0 1 0 0 0] 
    506 [0 1 0 0 2 0 0 0 0 0 1 0 0] 
    507 [2 1 0 0 2 0 0 0 0 0 0 1 0] 
    508 [1 1 0 0 2 0 0 0 0 0 0 0 1] 
    509     sage: C = HammingCode(3,GF(4)) 
    510     sage: C 
    511       Linear code of length 21, dimension 16 over Finite field in x of size 2^2 
     500        sage: C = HammingCode(3,GF(3)) 
     501        sage: C 
     502        Linear code of length 13, dimension 10 over Finite Field of size 3 
     503        sage: C.minimum_distance() 
     504        3 
     505        sage: C.gen_mat() 
     506        [2 2 1 0 0 0 0 0 0 0 0 0 0] 
     507        [1 2 0 1 0 0 0 0 0 0 0 0 0] 
     508        [2 0 0 0 2 1 0 0 0 0 0 0 0] 
     509        [1 0 0 0 2 0 1 0 0 0 0 0 0] 
     510        [0 2 0 0 2 0 0 1 0 0 0 0 0] 
     511        [2 2 0 0 2 0 0 0 1 0 0 0 0] 
     512        [1 2 0 0 2 0 0 0 0 1 0 0 0] 
     513        [0 1 0 0 2 0 0 0 0 0 1 0 0] 
     514        [2 1 0 0 2 0 0 0 0 0 0 1 0] 
     515        [1 1 0 0 2 0 0 0 0 0 0 0 1] 
     516        sage: C = HammingCode(3,GF(4)) 
     517        sage: C 
     518        Linear code of length 21, dimension 16 over Finite Field in x of size 2^2 
    512519 
    513520    AUTHOR: David Joyner (11-2005) 
     
    525532    """ 
    526533    INPUT: 
    527     Prime n>2 and finite prime field F of order q. Moreover,  
    528     q must be a quadratic residue modulo n.  
    529     OUTPUT: 
    530     Returns a quadratic residue code. Its generator polynomial is the product  
    531     of the polynomials $x-\alpha^i$ ($\alpha$ is a primitive $n^{th}$ root of unity,  
    532     and $i$ is an integer in the set of quadratic residues modulo $n$). 
     534        n, F -- n>2 a prime and F a finite prime field F of order q.  
     535                Moreover, q must be a quadratic residue modulo n.  
     536     
     537    OUTPUT: 
     538        Returns a quadratic residue code. Its generator polynomial  
     539        is the product of the polynomials $x-\alpha^i$  
     540        ($\alpha$ is a primitive $n^{th}$ root of unity,  
     541        and $i$ is an integer in the set of quadratic residues  
     542        modulo $n$). 
     543     
     544    EXAMPLES: 
     545        sage: C = QuadraticResidueCode(7,GF(2)) 
     546        sage: C 
     547        Linear code of length 7, dimension 4 over Finite Field of size 2 
     548        sage: C = QuadraticResidueCode(17,GF(2)) 
     549        sage: C 
     550        Linear code of length 17, dimension 9 over Finite Field of size 2 
     551     
    533552    Requires GUAVA. 
    534  
    535     EXAMPLES: 
    536     sage: C = QuadraticResidueCode(7,GF(2)) 
    537     sage: C 
    538           Linear code of length 7, dimension 4 over Finite field of size 2 
    539     sage: C = QuadraticResidueCode(17,GF(2)) 
    540     sage: C 
    541           Linear code of length 17, dimension 9 over Finite field of size 2 
    542553 
    543554    AUTHOR: David Joyner (11-2005) 
     
    555566    """ 
    556567    INPUT: 
    557     p must be a prime >2. 
     568        p -- a prime >2. 
     569     
    558570    OUTPUT:  
    559     Returns a (binary) quasi-quadratic residue code, as defined by  
    560     Proposition 2.2 in Bazzi-Mittel ({\it Some constructions of codes from group actions}, 
    561     (preprint March 2003). Its generator matrix has the block form $G=(Q,N)$.  
    562     Here $Q$ is a $p\times p$ circulant matrix whose top row  
    563     is $(0,x_1,...,x_{p-1})$, where $x_i=1$ if and only if $i$  
    564     is a quadratic residue $\mod p$, and $N$ is a $p\times p$  
    565     circulant matrix whose top row is $(0,y_1,...,y_{p-1})$, where  
    566     $x_i+y_i=1$ for all i. (In fact, this matrix can be recovered  
    567     as the component DoublyCirculant of the code.) 
     571        Returns a (binary) quasi-quadratic residue code, as defined by  
     572        Proposition 2.2 in Bazzi-Mittel ({\it Some constructions of  
     573        codes from group actions}, (preprint March 2003). Its  
     574        generator matrix has the block form $G=(Q,N)$.  
     575        Here $Q$ is a $p\times p$ circulant matrix whose top row  
     576        is $(0,x_1,...,x_{p-1})$, where $x_i=1$ if and only if $i$  
     577        is a quadratic residue $\mod p$, and $N$ is a $p\times p$  
     578        circulant matrix whose top row is $(0,y_1,...,y_{p-1})$, where  
     579        $x_i+y_i=1$ for all i. (In fact, this matrix can be recovered  
     580        as the component DoublyCirculant of the code.) 
     581     
     582    EXAMPLES: 
     583        sage: C = QuasiQuadraticResidueCode(31) 
     584        sage: C 
     585        Linear code of length 62, dimension 31 over Finite Field of size 2 
     586 
    568587    Requires GUAVA. 
    569  
    570     EXAMPLES: 
    571     sage: time C = QuasiQuadraticResidueCode(31) 
    572 Time: CPU 2.11 s, Wall: 102.49 s 
    573     sage: C 
    574       Linear code of length 62, dimension 31 over Finite field of size 2 
    575588 
    576589    AUTHOR: David Joyner (11-2005) 
     
    588601    """ 
    589602    INPUT: 
    590     Positive integers r,k with $2^k>r$. 
    591     OUTPUT: 
    592     Returns a binary 'Reed-Muller code' with dimension k and order r.   
    593     This is a code with length $2^k$ and minimum distance $2^k-r$ (see  
    594     for example, section 1.10 in Huffman-Pless {\it Fundamentals of Coding Theory}).  
    595     By definition, the $r^{th}$ order binary Reed-Muller code of  
    596     length $n=2^m$, for $0 \leq r \leq m$, is the set of  
    597     all vectors $(f(p)\ |\ p in GF(2)^m)$, where $f$ is a  
    598     multivariate polynomial of degree at most $r$ in $m$ variables. 
    599     Requires GUAVA. 
    600  
     603        r, k -- positive integers with $2^k>r$. 
     604     
     605    OUTPUT: 
     606        Returns a binary 'Reed-Muller code' with dimension k and  
     607        order r. This is a code with length $2^k$ and minimum  
     608        distance $2^k-r$ (see for example, section 1.10 in  
     609        Huffman-Pless {\it Fundamentals of Coding Theory}).  
     610        By definition, the $r^{th}$ order binary Reed-Muller code of  
     611        length $n=2^m$, for $0 \leq r \leq m$, is the set of  
     612        all vectors $(f(p)\ |\ p in GF(2)^m)$, where $f$ is a  
     613        multivariate polynomial of degree at most $r$ in $m$ variables. 
     614     
    601615    EXAMPLE: 
    602     sage: C = BinaryReedMullerCode(2,4) 
    603     sage: C 
    604           Linear code of length 16, dimension 11 over Finite field of size 2 
    605     sage: C.minimum_distance() 
    606           4 
    607     sage: C.gen_mat() 
    608  
     616        sage: C = BinaryReedMullerCode(2,4) 
     617        sage: C 
     618        Linear code of length 16, dimension 11 over Finite Field of size 2 
     619        sage: C.minimum_distance() 
     620        4 
     621        sage: C.gen_mat() 
    609622        [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1] 
    610623        [0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1] 
     
    619632        [0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1] 
    620633 
     634    Requires GUAVA. 
     635 
    621636    AUTHOR: David Joyner (11-2005) 
    622637    """ 
     
    632647def BinaryGolayCode(): 
    633648    """ 
    634     BinaryGolayCode returns a binary Golay code. This is a  
    635     perfect [23,12,7] code. It is also cyclic, and has  
    636     generator polynomial $g(x)=1+x^2+x^4+x^5+x^6+x^{10}+x^{11}$.  
    637     Extending it results in an extended Golay code (see  
    638     ExtendedBinaryGolayCode).  
     649    OUTPUT: 
     650        BinaryGolayCode returns a binary Golay code. This is a  
     651        perfect [23,12,7] code. It is also cyclic, and has  
     652        generator polynomial $g(x)=1+x^2+x^4+x^5+x^6+x^{10}+x^{11}$.  
     653        Extending it results in an extended Golay code (see  
     654        ExtendedBinaryGolayCode).  
     655 
     656    EXAMPLE: 
     657        sage: C = BinaryGolayCode() 
     658        sage: C 
     659        Linear code of length 23, dimension 12 over Finite Field of size 2 
     660        sage: C.minimum_distance() 
     661        7 
     662 
    639663    Requires GUAVA. 
    640  
    641     EXAMPLE: 
    642     sage: C = BinaryGolayCode() 
    643     sage: C 
    644           Linear code of length 23, dimension 12 over Finite field of size 2 
    645     sage: C.minimum_distance() 
    646           7 
    647664 
    648665    AUTHOR: David Joyner (11-2005) 
     
    659676def ExtendedBinaryGolayCode(): 
    660677    """ 
    661     BinaryGolayCode returns the extended binary Golay code. This  
    662     is a perfect [24,12,8] code. This code is self-dual. 
     678    OUTPUT: 
     679        BinaryGolayCode returns the extended binary Golay code. This  
     680        is a perfect [24,12,8] code. This code is self-dual. 
     681     
     682    EXAMPLES: 
     683        sage: C = ExtendedBinaryGolayCode() 
     684        sage: C 
     685        Linear code of length 24, dimension 12 over Finite Field of size 2 
     686        sage: C.minimum_distance() 
     687        8 
     688 
    663689    Requires GUAVA. 
    664  
    665     EXAMPLE: 
    666     sage: C = ExtendedBinaryGolayCode() 
    667     sage: C 
    668           Linear code of length 24, dimension 12 over Finite field of size 2 
    669     sage: C.minimum_distance() 
    670           8 
    671  
     690     
    672691    AUTHOR: David Joyner (11-2005) 
    673692    """ 
     
    683702def TernaryGolayCode(): 
    684703    """ 
    685     TernaryGolayCode returns a ternary Golay code. This is a  
    686     perfect [11,6,5] code. It is also cyclic, and has generator  
    687     polynomial $g(x)=2+x^2+2x^3+x^4+x^5$.  
     704    OUTPUT: 
     705        TernaryGolayCode returns a ternary Golay code. This is a  
     706        perfect [11,6,5] code. It is also cyclic, and has generator  
     707        polynomial $g(x)=2+x^2+2x^3+x^4+x^5$.  
     708     
     709    EXAMPLES: 
     710        sage: C = TernaryGolayCode() 
     711        sage: C 
     712        Linear code of length 11, dimension 6 over Finite Field of size 3 
     713        sage: C.minimum_distance() 
     714        5 
     715 
    688716    Requires GUAVA. 
    689  
    690     EXAMPLE: 
    691     sage: C = TernaryGolayCode() 
    692     sage: C 
    693           Linear code of length 11, dimension 6 over Finite field of size 3 
    694     sage: C.minimum_distance() 
    695           5 
    696717 
    697718    AUTHOR: David Joyner (11-2005) 
     
    708729def ExtendedTernaryGolayCode(): 
    709730    """ 
    710     ExtendedTernaryGolayCode returns a ternary Golay code.  
    711     This is a self-dual perfect [12,6,6] code.  
    712     Requires GUAVA. 
    713  
    714     EXAMPLE: 
    715     sage: C = ExtendedTernaryGolayCode() 
    716     sage: C 
    717           Linear code of length 11, dimension 6 over Finite field of size 3 
    718     sage: C.minimum_distance() 
    719           6 
    720     sage: C.gen_mat() 
    721  
     731    OUTPUT: 
     732        ExtendedTernaryGolayCode returns a ternary Golay code.  
     733        This is a self-dual perfect [12,6,6] code.  
     734 
     735    EXAMPLES: 
     736        sage: C = ExtendedTernaryGolayCode() 
     737        sage: C 
     738        Linear code of length 11, dimension 6 over Finite Field of size 3 
     739        sage: C.minimum_distance() 
     740        6 
     741        sage: C.gen_mat() 
    722742        [1 0 2 1 2 2 0 0 0 0 0 1] 
    723743        [0 1 0 2 1 2 2 0 0 0 0 1] 
     
    726746        [0 0 0 0 1 0 2 1 2 2 0 1] 
    727747        [0 0 0 0 0 1 0 2 1 2 2 1] 
     748 
     749    Requires GUAVA. 
    728750 
    729751    AUTHOR: David Joyner (11-2005) 
     
    741763    """ 
    742764    INPUT: 
    743     Integers n,k, with n>k>1. 
    744     OUTPUT: 
    745     Returns a random linear code with length n, dimension k over field F.  
    746     The method used is to first construct a $k\times n$ matrix of the block form $(I,A)$,  
    747     where $I$ is a $k\times k$ identity matrix and $A$ is a $k\times (n-k)$  
    748     matrix constructed using random elements of $F$. Then the columns are permuted  
    749     using a randomly selected element of SymmetricGroup(n). 
     765        Integers n,k, with n>k>1. 
     766     
     767    OUTPUT: 
     768        Returns a "random" linear code with length n,  
     769        dimension k over field F. The method used is to first  
     770        construct a $k\times n$ matrix of the block form $(I,A)$,  
     771        where $I$ is a $k\times k$ identity matrix and $A$ is a  
     772        $k\times (n-k)$ matrix constructed using random elements  
     773        of $F$. Then the columns are permuted  
     774        using a randomly selected element of SymmetricGroup(n). 
     775 
     776    EXAMPLES: 
     777        sage: C = RandomLinearCode(30,15,GF(2)) 
     778        sage: C 
     779        Linear code of length 30, dimension 15 over Finite Field of size 2 
     780        sage: C = RandomLinearCode(10,5,GF(4)) 
     781        sage: C 
     782        Linear code of length 10, dimension 5 over Finite Field in x of size 2^2 
     783 
    750784    Requires GUAVA. 
    751  
    752     EXAMPLES: 
    753     sage: time C = RandomLinearCode(30,15,GF(2)) 
    754 Time: CPU 0.31 s, Wall: 0.44 s 
    755     sage: C 
    756       Linear code of length 30, dimension 15 over Finite field of size 2 
    757     sage: time C = RandomLinearCode(10,5,GF(4)) 
    758 Time: CPU 0.02 s, Wall: 0.10 s 
    759     sage: C 
    760       Linear code of length 10, dimension 5 over Finite field in x of size 2^2 
    761785 
    762786    AUTHOR: David Joyner (11-2005) 
  • sage/databases/sloane.py

    r0 r1  
    9595        """ 
    9696        return "Sloane Online Encyclopedia of Integer Sequences" 
    97      
     97  
    9898    def __iter__(self): 
    9999        """ 
     
    222222def sloane_sequence(number): 
    223223    try: 
    224         print "Looking up in Sloane's online database (this requires a net connection and is slow)..."         
    225         f = urllib.urlopen("http://www.research.att.com/cgi-bin/access.cgi/as/njas/sequences/eisA2.cgi?Anum=A%s"%number) 
     224        print "Looking up in Sloane's online database (this requires a net connection and is slow)..." 
     225        url = "http://www.research.att.com/cgi-bin/access.cgi/as/njas/sequences/eisA2.cgi?Anum=A%s"%number 
     226        f = urllib.urlopen(url) 
    226227        s = f.read() 
    227228        f.close() 
    228     except IOError: 
    229         s = '' 
    230          
    231     i = s.find("<PRE>") 
    232     j = s.find("</PRE>") 
     229    except IOError, msg: 
     230        raise IOError, "%s\nError fetching the following website:\n    %s\nTry checking your internet connection."%(msg, url) 
     231 
     232    t = s.lower() 
     233    i = t.find("<pre>") 
     234    j = t.find("</pre>") 
    233235    if i == -1 or j == -1: 
    234236        raise IOError, "Error parsing data (missing pre tags)." 
     
    247249    try: 
    248250        print "Searching Sloane's online database (this requires a net connection and is slow)..." 
    249         f = urllib.urlopen("http://www.research.att.com/cgi-bin/access.cgi/as/njas/sequences/eismum2.cgi", urlparams); 
     251        url = "http://www.research.att.com/cgi-bin/access.cgi/as/njas/sequences/eismum2.cgi" 
     252        f = urllib.urlopen(url, urlparams); 
    250253        s = f.read() 
    251254        f.close() 
    252     except IOError: 
    253         s = '' 
    254  
    255     i = s.find("<PRE>") 
    256     j = s.find("</PRE>") 
     255    except IOError, msg: 
     256        raise IOError, "%s\nError fetching the following website:\n    %s\nTry checking your internet connection."%(msg, url) 
     257 
     258    t = s.lower() 
     259    i = t.find("<pre>") 
     260    j = t.find("</pre>") 
    257261    if i == -1 or j == -1: 
    258262        raise IOError, "Error parsing data (missing pre tags)." 
  • sage/ext/integer.pyx

    r0 r1  
    3232import sage.rings.coerce 
    3333import sage.rings.infinity 
     34import sage.rings.complex_field 
    3435import rational as rational 
    3536import sage.libs.pari.all 
     
    792793         
    793794     
    794     def sqrt(self, int bits=53): 
     795    def sqrt(self, bits=None): 
    795796        r""" 
    796         Returns the positive square root of self \emph{as a real 
    797         number} to the given number of bits of precision if self is 
    798         nonnegative, and raises a \exception{ValueError} exception 
    799         otherwise. 
    800  
    801         For the integer square root of a perfect square (with error 
    802         checking), use \code{self.square_root()}. 
     797        Returns the positive square root of self, possibly as a 
     798        \emph{a real number} if self is not a perfect integer 
     799        square. 
     800 
     801        INPUT: 
     802            bits -- number of bits of precision. 
     803                    If bits is not specified, the number of 
     804                    bits of precision is at least twice the 
     805                    number of bits of self (the precision 
     806                    is always at least 53 bits if not specified). 
     807        OUTPUT: 
     808            integer, real number, or complex number. 
     809 
     810        For the guaranteed integer square root of a perfect square 
     811        (with error checking), use \code{self.square_root()}. 
    803812         
    804813        EXAMPLE: 
    805814            sage: Z = IntegerRing() 
    806             sage: Z(2).sqrt() 
     815            sage: Z(2).sqrt(53) 
    807816            1.4142135623730951 
    808817            sage: Z(2).sqrt(100) 
     
    810819            sage: 39188072418583779289.square_root() 
    811820            6260037733 
    812             sage: 39188072418583779289.sqrt() 
    813             6260037732.9999990 
    814         """ 
     821            sage: (100^100).sqrt() 
     822            10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 
     823            sage: (-1).sqrt() 
     824            1.0000000000000000*I 
     825            sage: sqrt(-2) 
     826            1.4142135623730949*I 
     827            sage: sqrt(97) 
     828            9.8488578017961039 
     829            sage: 97.sqrt(200) 
     830            9.8488578017961047217462114149176244816961362874427641717231516 
     831        """ 
     832        if bits is None: 
     833            bits = max(53, 2*(mpz_sizeinbase(self.value, 2)+2)) 
    815834        if self < 0: 
    816             raise ValueError, "square root of negative number not (yet) defined." 
    817         R = mpfr.RealField(bits) 
    818         return self._mpfr_(R).sqrt() 
     835            x = sage.rings.complex_field.ComplexField(bits)(self) 
     836            return x.sqrt() 
     837        else: 
     838            try: 
     839                return self.square_root() 
     840            except ValueError: 
     841                pass 
     842            R = mpfr.RealField(bits) 
     843            return self._mpfr_(R).sqrt() 
    819844 
    820845    def square_root(self): 
  • sage/ext/ring.pyx

    r0 r1  
    2121import sage.rings.coerce 
    2222 
     23import sage.rings.finite_field 
     24import sage.rings.integer_ring 
     25import sage.rings.rational_field 
    2326 
    2427cdef class Ring(gens.Generators): 
     
    109112        return self(x) 
    110113 
     114    def base_ring(self): 
     115        return sage.rings.integer_ring.Z 
     116 
    111117    def category(self): 
    112118        """ 
     
    430436    Generic field 
    431437    """ 
     438    def base_ring(self): 
     439        """ 
     440        Return the base ring of this field.  This is the prime 
     441        subfield of this field. 
     442        """ 
     443        p = self.characteristic() 
     444        if p == 0: 
     445            return sage.rings.rational_field.Q 
     446        return sage.rings.finite_field.GF(p) 
     447 
     448    def category(self): 
     449        from sage.categories.all import Fields 
     450        return Fields() 
     451         
    432452    def fraction_field(self): 
    433453        """ 
  • sage/ext/sage_object.pyx

    r0 r1  
    192192        from sage.categories.all import Objects 
    193193        return Objects() 
     194 
     195##     def category(self): 
     196##         try: 
     197##             return self.__category 
     198##         except AttributeError: 
     199##             from sage.categories.all import Objects 
     200##             return Objects() 
     201 
     202##     def _set_category(self, C): 
     203##         self.__category = C 
    194204     
    195205    ############################################################################# 
  • sage/interfaces/expect.py

    r0 r1  
    133133        self._eval_line('') 
    134134 
     135    def pid(self): 
     136        if self._expect is None: 
     137            self._start() 
     138        return self._expect.pid 
     139 
    135140    def _start(self, alt_message=None): 
     141        self.quit()  # in case one is already running 
    136142        global failed_to_start 
    137143        if self.__name in failed_to_start: 
     
    196202        if self._expect is None: 
    197203            return 
    198         try: 
    199             self._expect.timeout = 1  # give it at most 1 second to quit 
    200             #self._expect.sendline(self._quit_string()+';;') 
    201             self._eval_line(self._quit_string(), allow_use_file=False) 
    202             self._expect.timeout = 9999999 
    203         except (OSError, pexpect.TIMEOUT, pexpect.EOF, RuntimeError): # intentional EOF or RuntimeError if already quit 
    204             pass 
     204        # Send a kill -9 to the process *group*. 
     205        # this is *very useful* when external binaries are started up 
     206        # by shell scripts, and killing the shell script doesn't 
     207        # kill the binary. 
     208        try: 
     209            os.killpg(self._expect.pid, 9) 
     210        except OSError: 
     211            # this is OK, it just means the process was already dead. 
     212            pass  
    205213 
    206214    def _quit_string(self): 
     
    218226 
    219227    def _eval_line(self, line, allow_use_file=True): 
    220         if line.find('\n') != -1: 
    221             raise ValueError, "line must not contain any newlines" 
     228        #if line.find('\n') != -1: 
     229        #    raise ValueError, "line must not contain any newlines" 
    222230        if allow_use_file and self._eval_using_file_cutoff and len(line) > self._eval_using_file_cutoff: 
    223231            return self._eval_line_using_file(line, tmp) 
     
    239247                    print "** %s crashed or quit executing '%s' **"%(self, line) 
    240248                    print "Restarting %s and trying again"%self 
    241                     self._expect.close(force=1) 
    242249                    self._start() 
    243250                    if line != '': 
     
    252259            self._keyboard_interrupt() 
    253260            raise KeyboardInterrupt, "Ctrl-c pressed while running %s"%self 
    254  
    255261        i = out.find("\n") 
    256262        j = out.rfind("\r") 
  • sage/interfaces/gap.py

    r0 r1  
    108108 
    109109    sage: t = '"%s"'%10^10000   # ten thousand character string. 
    110     sage: a = gap(t)             
     110    sage: a = gap(t) 
     111 
     112AUTHORS: 
     113    -- David Joyner and William Stein; initial version(s) 
     114    -- William Stein (2006-02-01): modified gap_console command 
     115       so it uses exactly the same startup command as Gap.__init__. 
    111116 
    112117""" 
     
    133138WORKSPACE = "%s/tmp/gap-workspace"%SAGE_ROOT 
    134139 
     140def gap_command(use_workspace_cache=True): 
     141    if use_workspace_cache and os.path.exists(WORKSPACE): 
     142        return "gap -L %s"%WORKSPACE, False 
     143    else: 
     144        return "gap ", True 
     145     
     146 
    135147class Gap(Expect): 
    136148    r""" 
     
    146158 
    147159        self.__use_workspace_cache = use_workspace_cache 
    148         if use_workspace_cache and os.path.exists(WORKSPACE): 
    149             cmd = "gap -T -n -b -L %s"%WORKSPACE 
    150             self.__make_workspace = False             
    151         else: 
    152             cmd = "gap -T -n -b" 
    153             self.__make_workspace = True 
     160        cmd, self.__make_workspace = gap_command(use_workspace_cache) 
     161        cmd += ' -T -n -b ' 
    154162        if max_workspace_size != None: 
    155163            cmd += " -o %s"%int(max_workspace_size) 
     
    419427import os 
    420428def gap_console(use_workspace_cache=True): 
    421     if use_workspace_cache and os.path.exists(WORKSPACE): 
    422         cmd = "gap -L %s"%WORKSPACE 
    423     else: 
    424         cmd = "gap" 
     429    cmd, _ = gap_command(use_workspace_cache=use_workspace_cache) 
    425430    os.system(cmd) 
    426431 
  • sage/interfaces/maple.py

    r0 r1  
    1 """ 
     1r""" 
    22Interface to Maple 
    33 
    4 You must have the maple interpreter installed and available as 
    5 the command "maple" in your PATH in order to use this interface.  
     4You must have the optional commercial Maple interpreter installed and 
     5available as the command \code{maple} in your PATH in order to use 
     6this interface.  You do not have to install any special \sage packages. 
     7 
    68 
    79EXAMPLES: 
    8     sage: maple('3 * 5')                       # needs optional maple 
     10    sage: maple('3 * 5')                        
    911    15 
    10     sage: maple.eval('ifactor(2005)')          # needs optional maple 
     12    sage: maple.eval('ifactor(2005)')           
    1113    '``(5)*``(401)' 
    12     sage: maple.ifactor(2005)                  # needs optional maple 
     14    sage: maple.ifactor(2005)                   
    1315    ``(5)*``(401) 
    14     sage: maple.fsolve('x^2=cos(x)+4', 'x=0..5')   # needs optional maple 
     16    sage: maple.fsolve('x^2=cos(x)+4', 'x=0..5')   
    1517    1.914020619 
    16     sage: maple.factor('x^5 - y^5')            # needs optional maple 
     18    sage: maple.factor('x^5 - y^5')             
    1719    (x-y)*(x^4+x^3*y+x^2*y^2+x*y^3+y^4)     
    1820 
     
    2022output of anything from Maple, a RuntimeError exception is raised. 
    2123 
     24\subsection{Tutorial} 
     25 
     26AUTHOR: 
     27    -- Gregg Musiker (2006-02-02): initial version. 
     28 
     29     
     30This tutorial is based on the Maple Tutorial for number theory 
     31from  \url{http://www.math.mun.ca/~drideout/m3370/numtheory.html}. 
     32 
     33There are several ways to use the Maple Interface in \SAGE.  We will 
     34discuss two of those ways in this tutorial. 
     35 
     36\begin{enumerate} 
     37\item If you have a maple expression such as 
     38\begin{verbatim} 
     39factor( (x^5-1)); 
     40\end{verbatim}         
     41We can write that in sage as 
     42 
     43    sage: maple('factor(x^5-1)') 
     44    (x-1)*(x^4+x^3+x^2+x+1) 
     45    
     46Notice, there is no need to use a semicolon. 
     47 
     48\item Since \SAGE is written in Python, we can also import maple 
     49commands and write our scripts in a pythonic way. 
     50For example, \code{factor()} is a maple command, so we can also factor 
     51in \sage using 
     52 
     53    sage: maple('(x^5-1)').factor() 
     54    (x-1)*(x^4+x^3+x^2+x+1) 
     55 
     56where \code{expression.command()} means the same thing as 
     57\code{command(expression)} in Maple.  We will use this second type of 
     58syntax whenever possible, resorting to the first when needed. 
     59 
     60    sage: maple('(x^12-1)/(x-1)').simplify() 
     61    x^11+x^10+x^9+x^8+x^7+x^6+x^5+x^4+x^3+x^2+x+1 
     62 
     63\end{enumerate} 
     64 
     65The normal command will always reduce a rational function to the 
     66lowest terms. The factor command will factor a polynomial with 
     67rational coefficients into irreducible factors over the ring of 
     68integers. So for example, 
     69 
     70    sage: maple('(x^12-1)').factor( ) 
     71    (x-1)*(x+1)*(x^2+x+1)*(x^2-x+1)*(x^2+1)*(x^4-x^2+1) 
     72 
     73    sage: maple('(x^28-1)').factor( ) 
     74    (x-1)*(x^6+x^5+x^4+x^3+x^2+x+1)*(x+1)*(1-x+x^2-x^3+x^4-x^5+x^6)*(x^2+1)*(x^12- 
     75    x^10+x^8-x^6+x^4-x^2+1) 
     76 
     77 
     78Another important feature of maple is its online help.  We can access 
     79this through sage as well.  After reading the description of the 
     80command, you can press q to immediately get back to your original 
     81prompt. 
     82 
     83% NOTE: DOESN'T BRING UP NEW SCREEN IN SSH 
     84 
     85Incidentally you can always get into a maple console by the command 
     86 
     87    sage.: maple.console()          
     88    sage.: !maple 
     89 
     90Note that the above two commands are slightly different, and the first 
     91is preferred.  
     92         
     93For example, for help on the maple command fibonacci, we type 
     94 
     95    sage.: maple.help('fibonacci') 
     96         
     97We see there are two choices.  Type 
     98 
     99    sage.: maple.help('combinat, fibonacci') 
     100         
     101We now see how the Maple command fibonacci works under the 
     102combinatorics package.  Try typing in 
     103 
     104    sage: maple.fibonacci(10) 
     105    fibonacci(10) 
     106     
     107You will get fibonacci(10) as output since Maple has not loaded the combinatorics package yet.  To rectify this type 
     108 
     109    sage: maple('combinat[fibonacci]')(10) 
     110    55 
     111 
     112instead. 
     113         
     114If you want to load the combinatorics package for future calculations, 
     115in \sage this can be done as 
     116 
     117    sage: maple.with('combinat') 
     118 
     119or 
     120     
     121    sage: maple.load('combinat') 
     122         
     123Now if we type \code{maple.fibonacci(10)}, we get the correct output: 
     124 
     125    sage: maple.fibonacci(10) 
     126    55 
     127 
     128Some common maple packages include \code{combinat}, \code{linalg}, and 
     129\code{numtheory}.  To produce the first 19 Fibonacci 
     130numbers, use the sequence command. 
     131 
     132    sage: maple('seq(fibonacci(i),i=1..19)') 
     133    1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 
     134    4181 
     135 
     136Two other useful Maple commands are ifactor and isprime. For example 
     137 
     138    sage: maple.isprime(maple.fibonacci(27)) 
     139    false 
     140    sage: maple.ifactor(maple.fibonacci(27)) 
     141    ``(2)*``(17)*``(53)*``(109) 
     142 
     143Note that the isprime function that is included with \sage (which uses 
     144PARI) is better than the Maple one (it is faster and gives a provably 
     145correct answer, whereas Maple is sometimes wrong). 
     146 
     147    sage: alpha = maple('(1+sqrt(5))/2') 
     148    sage: beta = maple('(1-sqrt(5))/2') 
     149    sage: f19  = alpha^19 - beta^19/maple('sqrt(5)') 
     150    sage: f19 
     151    (1/2+1/2*5^(1/2))^19-1/5*(1/2-1/2*5^(1/2))^19*5^(1/2) 
     152    sage: f19.simplify() 
     153    5778/5*5^(1/2)+6765 
     154 
     155Let's say we want to write a maple program now that squares a number 
     156if it is positive and cubes it if it is negative.  In maple, that 
     157would look like 
     158 
     159\begin{verbatim} 
     160mysqcu := proc(x)  
     161if x > 0 then x^2; 
     162else x^3; fi; 
     163end; 
     164\end{verbatim} 
     165In SAGE, we write  
     166 
     167   sage: mysqcu = maple('proc(x) if x > 0 then x^2 else x^3 fi end') 
     168   sage: mysqcu(5) 
     169   25 
     170   sage: mysqcu(-5) 
     171   -125 
     172         
     173More complicated programs should be put in a separate file and 
     174loaded. 
    22175""" 
    23176 
     
    184337        the appropriate package. 
    185338         
    186             sage: maple('partition(10)')               # optional 
     339            sage.: maple('partition(10)')              # optional 
    187340            partition(10) 
    188             sage: maple('bell(10)')                    # optional 
     341            sage.: maple('bell(10)')                   # optional 
    189342            bell(10) 
    190343            sage: maple.with('combinat')               # optional 
    191             sage: maple('partition(10)')               # optional 
    192             [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 
    193             1, 2, 2], [1, 1, 1, 1, 2, 2, 2], [1, 1, 2, 2, 2, 2], [2, 2, 2, 2, 2], [1, 1, 1 
    194             , 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 2, 2, 3], [1, 2, 2, 2, 3], 
    195             [1, 1, 1, 1, 3, 3], [1, 1, 2, 3, 3], [2, 2, 3, 3], [1, 3, 3, 3], [1, 1, 1, 1, 
    196             1, 1, 4], [1, 1, 1, 1, 2, 4], [1, 1, 2, 2, 4], [2, 2, 2, 4], [1, 1, 1, 3, 4], 
    197             [1, 2, 3, 4], [3, 3, 4], [1, 1, 4, 4], [2, 4, 4], [1, 1, 1, 1, 1, 5], [1, 1, 1 
    198             , 2, 5], [1, 2, 2, 5], [1, 1, 3, 5], [2, 3, 5], [1, 4, 5], [5, 5], [1, 1, 1, 1 
    199             , 6], [1, 1, 2, 6], [2, 2, 6], [1, 3, 6], [4, 6], [1, 1, 1, 7], [1, 2, 7], [3, 
    200             7], [1, 1, 8], [2, 8], [1, 9], [10]] 
     344            sage: maple('partition(10)')               # optional   
     345             [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 
     346             1, 2, 2], [1, 1, 1, 1, 2, 2, 2], [1, 1, 2, 2, 2, 2], [2, 2, 2, 2, 2], [1, 1, 1 
     347             , 1, 1, 1, 1, 3], [1, 1, 1, 1, 1, 2, 3], [1, 1, 1, 2, 2, 3], [1, 2, 2, 2, 3], 
     348             [1, 1, 1, 1, 3, 3], [1, 1, 2, 3, 3], [2, 2, 3, 3], [1, 3, 3, 3], [1, 1, 1, 1, 
     349             1, 1, 4], [1, 1, 1, 1, 2, 4], [1, 1, 2, 2, 4], [2, 2, 2, 4], [1, 1, 1, 3, 4], 
     350             [1, 2, 3, 4], [3, 3, 4], [1, 1, 4, 4], [2, 4, 4], [1, 1, 1, 1, 1, 5], [1, 1, 1 
     351             , 2, 5], [1, 2, 2, 5], [1, 1, 3, 5], [2, 3, 5], [1, 4, 5], [5, 5], [1, 1, 1, 1 
     352             , 6], [1, 1, 2, 6], [2, 2, 6], [1, 3, 6], [4, 6], [1, 1, 1, 7], [1, 2, 7], [3, 
     353             7], [1, 1, 8], [2, 8], [1, 9], [10]] 
    201354            sage: maple('bell(10)')                   # optional 
    202355            115975 
  • sage/interfaces/maxima.py

    r0 r1  
    903903        return self.comma('numer') 
    904904 
     905    def real(self): 
     906        return self.realpart() 
     907 
     908    def imag(self): 
     909        return self.imagpart() 
     910 
    905911    def str(self): 
    906912        self._check_valid() 
  • sage/interfaces/singular.py

    r0 r1  
    268268    AUTHORS: David Joyner and William Stein 
    269269    """ 
    270     def __init__(self, maxread=100000, script_subdirectory="user", logfile=None, server=None): 
     270    def __init__(self, maxread=1000, script_subdirectory="user", 
     271                 logfile=None, server=None): 
    271272        Expect.__init__(self, 
    272273                        name = 'singular', 
     
    279280                        verbose_start = False, 
    280281                        logfile = logfile, 
    281                         eval_using_file_cutoff=100) 
     282                        eval_using_file_cutoff=1000) 
    282283        self.__libs  = [] 
    283284 
     
    302303        return '< "%s";'%filename 
    303304 
    304     def __to_delete_xxx_eval_line(self, line, allow_use_file=True): 
     305    def xxx_eval_line(self, line, allow_use_file=True): 
    305306        if line.find('\n') != -1: 
    306307            raise ValueError, "line must not contain any newlines" 
     
    313314        E.expect('__SAGE_START__') 
    314315        E.expect(self._prompt) 
    315         E.sendline(line) 
     316        E.sendline(line+';') 
    316317        E.sendline('"__SAGE_END__";') 
    317318        E.expect('__SAGE_END__') 
     
    339340 
    340341        s = Expect.eval(self, x) 
    341  
    342342        if s.find("error") != -1 or s.find("Segment fault") != -1: 
    343343            raise RuntimeError, 'Singular error:\n%s'%s 
  • sage/misc/functional.py

    r0 r1  
    3737from sage.libs.all import pari 
    3838 
    39 import math 
    40  
    4139############################################################################## 
    4240# There are many functions on elements of a ring, which mathematicians 
     
    151149    """ 
    152150    try: return x.cos() 
    153     except AttributeError: return math.cos(float(x)) 
     151    except AttributeError: return R(x).cos() 
    154152 
    155153## def cuspidal_submodule(x): 
     
    265263    """ 
    266264    try: return x.exp() 
    267     except AttributeError: return math.exp(x) 
     265    except AttributeError: return R(x).exp() 
    268266 
    269267def factor(x, *args, **kwds): 
     
    516514        3.3219280948873626 
    517515        sage: log(8,2) 
    518         3.0 
     516        3.0000000000000000 
    519517        sage: log(10) 
    520518        2.3025850929940459 
     
    525523        try: return x.log() 
    526524        except AttributeError: 
    527             #return math.log(x) 
    528             return float(pari(x).log()) 
     525            return R(x).log() 
    529526    else: 
    530527        try: return x.log(b) 
     
    572569 
    573570    EXAMPLES: 
    574     sage: z = CC(1+2*i) 
    575     sage: norm(z) 
    576     5.0000000000000000 
     571        sage: z = CC(1+2*i) 
     572        sage: norm(z) 
     573        5.0000000000000000 
    577574    """ 
    578575    return x.norm() 
     
    583580 
    584581    EXAMPLES: 
    585     sage: R = PolynomialRing(RationalField(), 'x') 
    586     sage: F = FractionField(R) 
    587     sage: r = (x+1)/(x-1) 
    588     sage: numerator(r) 
    589     x + 1 
    590     sage: numerator(17/11111) 
    591     17 
     582        sage: R = PolynomialRing(RationalField(), 'x') 
     583        sage: F = FractionField(R) 
     584        sage: r = (x+1)/(x-1) 
     585        sage: numerator(r) 
     586        x + 1 
     587        sage: numerator(17/11111) 
     588        17 
    592589    """ 
    593590    if isinstance(x, (int, long)): 
     
    637634 
    638635    EXAMPLES: 
    639     sage: C = CyclicPermutationGroup(10) 
    640     sage: order(C) 
    641     10 
    642     sage: F = GF(7) 
    643     sage: order(F) 
    644     7 
    645  
     636        sage: C = CyclicPermutationGroup(10) 
     637        sage: order(C) 
     638        10 
     639        sage: F = GF(7) 
     640        sage: order(F) 
     641        7 
    646642    """ 
    647643    return x.order() 
     
    652648     
    653649    EXAMPLES: 
    654     sage: M = MatrixSpace(QQ,3,3) 
    655     sage: A = M([1,2,3,4,5,6,7,8,9]) 
    656     sage: rank(A) 
    657     2 
    658  
     650        sage: M = MatrixSpace(QQ,3,3) 
     651        sage: A = M([1,2,3,4,5,6,7,8,9]) 
     652        sage: rank(A) 
     653        2 
    659654    """ 
    660655    return x.rank() 
     
    665660 
    666661    EXAMPLES: 
    667     sage: z = CC(1+2*i) 
    668     sage: real(z) 
    669     1.0000000000000000 
    670  
     662        sage: z = CC(1+2*i) 
     663        sage: real(z) 
     664        1.0000000000000000 
    671665    """ 
    672666    try: return x.real() 
     
    696690 
    697691    EXAMPLES: 
    698     sage: sqrt(10.1) 
    699     3.1780497164141406 
    700     sage: sqrt(9) 
    701     3.0000000000000000 
    702  
     692        sage: sqrt(10.1) 
     693        3.1780497164141406 
     694        sage: sqrt(9) 
     695        3 
    703696    """ 
    704697    try: return x.sqrt() 
     
    711704 
    712705    EXAMPLES: 
    713     sage: isqrt(10) 
    714     3 
    715  
     706        sage: isqrt(10) 
     707        3 
    716708    """ 
    717709    try: return x.isqrt() 
     
    724716    """ 
    725717    try: return x.sin() 
    726     except AttributeError: return math.sin(float(x)) 
     718    except AttributeError: return R(x).sin() 
    727719 
    728720def square_free_part(x): 
     
    769761 
    770762    EXAMPLES: 
    771     sage: square_root(9) 
    772     3 
    773     sage: square_root(100) 
    774     10 
    775  
     763        sage: square_root(9) 
     764        3 
     765        sage: square_root(100) 
     766        10 
    776767    """ 
    777768    try: 
     
    785776 
    786777    EXAMPLES: 
    787     sage: tan(3.1415) 
    788     -0.000092653590058635411 
    789     sage: tan(3.1415/4) 
    790     0.99995367427815607 
    791  
     778        sage: tan(3.1415) 
     779        -0.000092653590058635411 
     780        sage: tan(3.1415/4) 
     781        0.99995367427815607 
    792782    """ 
    793783    try: return x.tan() 
    794     except AttributeError: return math.tan(float(x)) 
     784    except AttributeError: return R(x).tan() 
    795785 
    796786def transpose(x): 
    797787    """ 
    798788    EXAMPLES: 
    799     sage: M = MatrixSpace(QQ,3,3) 
    800     sage: A = M([1,2,3,4,5,6,7,8,9]) 
    801     sage: transpose(A) 
    802     [1 4 7] 
    803     [2 5 8] 
    804     [3 6 9] 
    805  
     789        sage: M = MatrixSpace(QQ,3,3) 
     790        sage: A = M([1,2,3,4,5,6,7,8,9]) 
     791        sage: transpose(A) 
     792        [1 4 7] 
     793        [2 5 8] 
     794        [3 6 9] 
    806795    """ 
    807796    return x.transpose() 
     
    823812 
    824813    EXAMPLES: 
    825     sage: R = PolynomialRing(RationalField(), 'x') 
    826     sage: zero(R) in R 
    827     True 
    828     sage: zero(R)*x == zero(R) 
    829     True 
     814        sage: R = PolynomialRing(RationalField(), 'x') 
     815        sage: zero(R) in R 
     816        True 
     817        sage: zero(R)*x == zero(R) 
     818        True 
    830819    """ 
    831820    return R(0) 
  • sage/rings/all.py

    r0 r1  
    116116 
    117117# Arithmetic 
    118 from arith import * 
    119 from arith import factor as integer_factor 
    120  
     118from arith import *                    
    121119 
    122120from morphism import is_RingHomomorphism 
  • sage/rings/arith.py

    r0 r1  
    834834 
    835835def mqrr_rational_reconstruction(u, m, T): 
    836     """Maximal Quotient Rational Reconstruction. 
     836    """ 
     837    Maximal Quotient Rational Reconstruction. 
    837838 
    838839    Input: 
  • sage/rings/fraction_field.py

    r0 r1  
    8484 
    8585    def base_ring(self): 
    86         return self.__R.base_ring() 
     86        return self.__R.base_ring().fraction_field() 
    8787 
    8888    def characteristic(self): 
  • sage/rings/laurent_series_ring.py

    r0 r1  
    155155            return self.__power_series_ring             
    156156 
    157 class LaurentSeriesRing_domain(integral_domain.IntegralDomain, LaurentSeriesRing_generic): 
     157class LaurentSeriesRing_domain(LaurentSeriesRing_generic, integral_domain.IntegralDomain): 
    158158    def __init__(self, base_ring, name=None): 
    159159        LaurentSeriesRing_generic.__init__(self, base_ring, name) 
     
    166166            return self.__fraction_field 
    167167     
    168 class LaurentSeriesRing_field(field.Field, LaurentSeriesRing_generic): 
     168class LaurentSeriesRing_field(LaurentSeriesRing_generic, field.Field): 
    169169    def __init__(self, base_ring, name=None): 
    170170        LaurentSeriesRing_generic.__init__(self, base_ring, name) 
  • sage/rings/multi_polynomial_element.py

    r0 r1  
    9595        y = K(0)  
    9696        for (m,c) in self.element().dict().iteritems():   
    97             y += K(c)*misc.mul([ x[i]**m[i] for i in range(n) ])       
     97            y += c*misc.mul([ x[i]**m[i] for i in range(n) ])       
    9898        return y  
    9999 
     
    750750     
    751751    def factor(self): 
    752         """ 
     752        r""" 
    753753        Compute the irreducible factorization of this polynomial. 
    754754 
    755755        ALGORITHM: Use Singular. 
    756          
     756 
    757757        EXAMPLES: 
    758758            sage: x, y = PolynomialRing(QQ, 2, ['x','y']).gens() 
     
    771771            sage: F 
    772772            2 * x * (2 + x)^2 * (y + x) * (y + 2*x) 
     773 
     774        Next we factor a larger product involving many variables. 
     775            sage:  
    773776        """ 
    774777        R = self.parent() 
  • sage/rings/multi_polynomial_ideal.py

    r0 r1  
    99    sage: I = ideal(x^5 + y^4 + z^3 - 1,  x^3 + y^3 + z^2 - 1) 
    1010    sage: B = I.groebner_basis() 
    11     sage: B[0] 
    12     5*z^2 - 3*z^3 - 10*z^4 + 13*z^6 - 5*z^8 - z^9 + z^10 + 5*y^3 - 20*y^3*z^2 + 30*y^3*z^4 - 20*y^3*z^6 + 5*y^3*z^8 - 3*y^4 + 6*y^4*z^3 - 3*y^4*z^6 - 10*y^6 + 30*y^6*z^2 - 30*y^6*z^4 + 10*y^6*z^6 + 3*y^8 - 3*y^8*z^3 + 10*y^9 - 20*y^9*z^2 + 10*y^9*z^4 - 6*y^12 + 5*y^12*z^2 + y^15 
    1311    sage: len(B) 
    1412    8 
     
    2725    x^2 
    2826     
     27We compute a Groebner basis for cyclic 6, which is a standard 
     28benchmark and test ideal. 
     29    
     30    sage: x,y,z,t,u,v = QQ['x,y,z,t,u,v'].gens() 
     31    sage: I = ideal(x + y + z + t + u + v, x*y + y*z + z*t + t*u + u*v + v*x, x*y*z + y*z*t + z*t*u + t*u*v + u*v*x + v*x*y, x*y*z*t + y*z*t*u + z*t*u*v + t*u*v*x + u*v*x*y + v*x*y*z, x*y*z*t*u + y*z*t*u*v + z*t*u*v*x + t*u*v*x*y + u*v*x*y*z + v*x*y*z*t, x*y*z*t*u*v - 1) 
     32    sage: B = I.groebner_basis() 
     33    sage: len(B) 
     34    17 
    2935""" 
    3036 
     
    232238            Ideal (d + c + b + a, -1 + a*b*c*d, c*d + b*c + a*d + a*b, b*c*d + a*c*d + a*b*d + a*b*c) of Polynomial Ring in a, b, c, d over Rational Field 
    233239            sage: I.groebner_basis() 
    234             [1 - d^4 - c^2*d^2 + c^2*d^6, 
    235              -1*d - c + c^2*d^3 + c^3*d^2, 
    236              -1*d + d^5 - b + b*d^4, 
    237              -1*d^2 - d^6 + c*d + c^2*d^4 - b*d^5 + b*c, 
    238              d^2 + 2*b*d + b^2, 
    239              d + c + b + a] 
     240            [d^2 + 2*b*d + b^2, 
     241             1 - d^4 - c^2*d^2 + c^2*d^6, 
     242            -1*d + d^5 - b + b*d^4, 
     243            -1*d - c + c^2*d^3 + c^3*d^2, 
     244             d + c + b + a, 
     245            -1*d^2 - d^6 + c*d + c^2*d^4 - b*d^5 + b*c] 
    240246        """ 
    241247        try: 
  • sage/rings/multi_polynomial_ring.py

    r0 r1  
    295295        return multi_polynomial_element.MPolynomial_polydict(self, {self._zero_tuple:c}) 
    296296 
    297 class MPolynomialRing_polydict_domain(MPolynomialRing_polydict, integral_domain.IntegralDomain): 
     297class MPolynomialRing_polydict_domain(integral_domain.IntegralDomain, MPolynomialRing_polydict): 
    298298    pass 
    299299     
  • sage/schemes/elliptic_curves/ell_rational_field.py

    r0 r1  
    330330                       as a small divisor of the order is detected. 
    331331 
     332        \note{As of 2006-02-02 this function does not work on 
     333        Microsoft Windows.} 
     334 
    332335        EXAMPLES: 
    333336            sage: E = EllipticCurve('37a') 
     
    627630        """ 
    628631        if self.torsion_order() % 2 == 0: 
    629             raise ArithmeticError, "curve must not have rational 2-torsion" 
     632            raise ArithmeticError, "curve must not have rational 2-torsion\nThe *only* reason for this is that I haven't finished implementing the wrapper\nin this case.  It wouldn't be too difficult.\nPerhaps you could do it?!  Email me (wstein@ucsd.edu)." 
    630633        F = self.weierstrass_model() 
    631634        a1,a2,a3,a4,a6 = F.a_invariants() 
     
    670673            if not only_use_mwrank: 
    671674                N = self.conductor() 
    672                 prec = int(4*sqrt(N)) + 10 
     675                prec = int(4*float(sqrt(N))) + 10 
    673676                if self.root_number() == 1: 
    674677                    L, err = self.Lseries_at1(prec)             
     
    11731176        if self.root_number() == -1: 
    11741177            return 0 
    1175         sqrtN = self.conductor().sqrt() 
     1178        sqrtN = float(self.conductor().sqrt()) 
    11761179        k = int(k) 
    11771180        if k == 0: k = int(math.ceil(sqrtN)) 
     
    12301233        if self.root_number() == 1: return 0 
    12311234        k = int(k) 
    1232         sqrtN = self.conductor().sqrt() 
     1235        sqrtN = float(self.conductor().sqrt()) 
    12331236        if k == 0: k = int(math.ceil(sqrtN)) 
    12341237        an = self.anlist(k)           # list of C ints 
     
    12831286        a = self.anlist(prec) 
    12841287        eps = self.root_number() 
    1285         sqrtN = arith.sqrt(N) 
     1288        sqrtN = float(arith.sqrt(N)) 
    12861289        def F(n, t): 
    12871290            return Gamma_inc(t+1, 2*pi*n/sqrtN) * C(sqrtN/(2*pi*n))**(t+1) 
     
    13111314        a = self.anlist(prec) 
    13121315        eps = self.root_number() 
    1313         sqrtN = arith.sqrt(N) 
     1316        sqrtN = float(arith.sqrt(N)) 
    13141317        def F(n, t): 
    13151318            return Gamma_inc(t+1, 2*pi*n/sqrtN) * C(sqrtN/(2*pi*n))**(t+1) 
     
    23872390            ind2 = ht/(h/2) 
    23882391            misc.verbose("index squared = %s"%ind2) 
    2389             ind = ind2.sqrt() 
     2392            ind = float(ind2.sqrt()) 
    23902393            misc.verbose("index = %s"%ind) 
    23912394            # Compute upper bound on square root of index. 
  • sage/schemes/generic/algebraic_scheme.py

    r0 r1  
    185185            return self._coordinate_ring 
    186186        except AttributeError: 
    187             R = self.__A.coordinate_ring() 
     187            try: 
     188                R = self.__A.coordinate_ring() 
     189            except AttributeError: 
     190                raise NotImplementedError, "computation of coordinate ring of %s not implmented"%self 
    188191            if len(self.__X) == 0: 
    189192                Q = R 
  • sage/schemes/generic/divisor.py

    r0 r1  
    9494        3*(0 : 0 : 1) - 4*(1/4 : -5/8 : 1) 
    9595    """ 
    96     def __init__(self, v, check=True, reduce=True): 
     96    def __init__(self, v, check=True, reduce=True, parent=None): 
    9797        """ 
    9898        INPUT: 
     
    114114        else: 
    115115            C = v[0][1].scheme() 
     116             
    116117        if check: 
    117118            w = [] 
     
    123124            v = w 
    124125 
     126        if parent is None: 
     127            parent = DivisorGroup(C) 
     128 
    125129        Divisor_generic.__init__(self, v, check=False, reduce=True, 
    126                                  parent = DivisorGroup(C)) 
     130                                 parent = parent) 
    127131 
    128132 
  • sage/schemes/generic/homset.py

    r0 r1  
    4949        """ 
    5050        EXAMPLES: 
    51             sage: f = Z.hom(Q); f 
     51            sage: f = ZZ.hom(QQ); f 
    5252            Coercion morphism: 
    5353              From: Integer Ring 
    5454              To:   Rational Field 
    5555 
    56             sage: H = Hom(Spec(Q), Spec(Z)); H 
     56            sage: H = Hom(Spec(QQ, ZZ), Spec(ZZ)); H 
    5757            Set of points of Spectrum of Integer Ring defined over Rational Field 
    5858             
  • sage/schemes/generic/spec.py

    r0 r1  
    7676            raise TypeError, "R (=%s) must be a commutative ring"%R 
    7777        self.__R = R 
    78         if not S is None: 
    79             if not is_CommutativeRing(S): 
    80                 raise TypeError, "S (=%s) must be a commutative ring"%S 
    81             try: 
    82                 S.hom(R) 
    83             except TypeError: 
    84                 raise ValueError, "There must be a natural map S --> R, but S = %s and R = %s"%(S,R) 
    85             self._base_ring = S 
     78        if S is None: 
     79            if R == Z: 
     80                return 
     81            else: 
     82                S = R.base_ring() 
     83        if not is_CommutativeRing(S): 
     84            raise TypeError, "S (=%s) must be a commutative ring"%S 
     85        try: 
     86            S.hom(R) 
     87        except TypeError: 
     88            raise ValueError, "There must be a natural map S --> R, but S = %s and R = %s"%(S,R) 
     89        self._base_ring = S 
    8690 
    8791    def _cmp_(self, X): 
  • sage/schemes/plane_curves/affine_curve.py

    r0 r1  
    148148        b = ["c["+str(i)+",1]," for i in range(2,N/2-4)] 
    149149        b = ''.join(b) 
    150         b = b[:len(b)-1] #to cut off the trailing comma 
     150        b = b[:len(b)-1] # to cut off the trailing comma 
    151151        cmd = 'ideal I = '+b 
    152152        S.eval(cmd) 
     153        S.eval('short=0')    # print using *'s and ^'s. 
    153154        c = S.eval('slimgb(I)') 
    154155        d = c.split("=") 
  • sage/schemes/plane_curves/projective_curve.py

    r0 r1  
    298298            sage: C = Curve(f); pts = C.rational_points() 
    299299            sage: D = C.divisor([ (3, pts[0]), (-1,pts[1]), (10, pts[5]) ]) 
    300             sage: C.riemann_roch_basis(D)    # output is somewhat random 
     300            sage: C.riemann_roch_basis(D)    # output is random (!!!!) 
    301301            [x/(y + x), (z + y)/(y + x)] 
    302302 
    303         \note{The Brill-Noether package does not always work (i.e., the 'bn' 
    304         algorithm.  When it fails a RuntimeError exception is raised.} 
     303        \note{The Brill-Noether package does not always work (i.e., 
     304        the 'bn' algorithm.  Do *not* trust this.} 
    305305        """ 
    306306        f = self.defining_polynomial()._singular_() 
  • sage/structure/formal_sum.py

    r0 r1  
    2323 
    2424from sage.ext.element import AdditiveGroupElement 
     25from sage.ext.group import AbelianGroup 
     26 
     27class FormalSums(AbelianGroup): 
     28    def _repr_(self): 
     29        return "Abelian Group of all Formal Finite Sums" 
     30 
     31formal_sums = FormalSums() 
    2532 
    2633class FormalSum(AdditiveGroupElement, list): 
    27     def __init__(self, x, check=True, reduce=True, parent=None): 
     34    def __init__(self, x, parent=None, check=True, reduce=True): 
    2835        if x == 0: 
    2936            x = [] 
     
    3340                    raise TypeError, "Invalid formal sum" 
    3441        list.__init__(self, x) 
    35         if not parent is None: 
    36             AdditiveGroupElement.__init__(self, parent) 
     42        if parent is None: 
     43            parent = formal_sums 
     44        AdditiveGroupElement.__init__(self, parent) 
    3745        self.reduce() 
    3846 
     
    4856 
    4957    def _add_(self, other): 
    50         return self.__class__(list.__add__(self,other)) 
     58        return self.__class__(list.__add__(self,other), parent=self.parent()) 
    5159 
    5260    def __mul__(self, s): 
    53         return self.__class__([(c*s, x) for c,x in self], check=False) 
     61        return self.__class__([(c*s, x) for c,x in self], check=False, parent=self.parent()) 
    5462         
    5563    def __rmul__(self, s): 
    56         return self.__class__([(s*c, x) for c,x in self]) 
     64        return self.__class__([(s*c, x) for c,x in self], parent=self.parent()) 
    5765 
    5866    def reduce(self): 
  • sage/version.py

    r0 r1  
    1 version='0.10.12'; date='2006-01-30-0901' 
     1version='0.10.13'; date='2006-02-03-0358' 
Note: See TracChangeset for help on using the changeset viewer.