Ignore:
Location:
sage
Files:
2 added
24 edited

Legend:

Unmodified
Added
Removed
  • sage/ext/random.pxi

    r2802 r3154  
    66    long random() 
    77    void srandom(unsigned int seed) 
    8 k = randrange(0,2**32) 
     8k = randrange(0, int(2)**32) 
    99srandom(k) 
    1010 
  • sage/functions/transcendental.py

    r2641 r3149  
    3333    return x 
    3434 
    35 I = complex_field.ComplexField().gen(0) 
     35CC = complex_field.ComplexField() 
     36I = CC.gen(0) 
    3637def __eval(x): 
    3738    return eval(x) 
     
    8889    """ 
    8990    Gamma function at s. 
    90     """ 
    91     if not (is_ComplexNumber(s) or is_RealNumber(s)): 
    92         s = RealField()(s) 
    93     return s.gamma() 
    94     #return complex_field.ComplexField()(pari(s).gamma(prec).python(prec)) 
     91 
     92    EXAMPLES: 
     93        sage: gamma(CDF(0.5,14)) 
     94        -4.05370307804e-10 - 5.77329961615e-10*I 
     95        sage: gamma(I) 
     96        -0.154949828301810 - 0.498015668118356*I 
     97        sage: gamma(6) 
     98        120.000000000000 
     99    """ 
     100    try: 
     101        return s.gamma() 
     102    except AttributeError: 
     103        return CC(s).gamma() 
    95104 
    96105def gamma_inc(s, t): 
    97106    """ 
    98107    Incomplete Gamma function Gamma(s,t). 
    99     """ 
    100     if not (is_ComplexNumber(s)): 
    101         if is_ComplexNumber(t): 
    102             C = t.parent() 
    103         else: 
    104             C = ComplexField() 
    105         s = C(s) 
    106     return s.gamma_inc(t) 
    107  
    108     #s = pari.new_with_prec(s, prec) 
    109     #t = pari.new_with_prec(s, prec) 
    110     #return complex_field.ComplexField()(s.incgam(t, prec).python(prec)) 
     108 
     109    EXAMPLES: 
     110        sage: gamma_inc(CDF(0,1), 3) 
     111        0.00320857499337 + 0.0124061862007*I 
     112        sage: gamma_inc(3, 3) 
     113        0.846380162253687 
     114        sage: gamma_inc(RDF(1), 3) 
     115        0.0497870683678639 
     116    """ 
     117    try: 
     118        return s.gamma_inc(t) 
     119    except AttributeError: 
     120        if not (is_ComplexNumber(s)): 
     121            if is_ComplexNumber(t): 
     122                C = t.parent() 
     123            else: 
     124                C = ComplexField() 
     125            s = C(s) 
     126        return s.gamma_inc(t) 
     127 
    111128 
    112129# synonym. 
  • sage/graphs/graph.py

    r3136 r3167  
    1313    -- Robert L. Miller (2007-02-12): vertex color-maps, graph boundaries, 
    1414        graph6 helper functions in SageX 
     15                        SAGE Days 3 (2007-02-17--21): 3d plotting in Tachyon, 
    1516 
    1617TUTORIAL: 
     
    14621463            sage: pl.save('sage.png') 
    14631464             
    1464             C = graphs.CubeGraph(8) 
    1465             P = C.plot(vertex_labels=False, node_size=0, graph_border=True) 
    1466             P.save('sage.png') 
     1465            sage: C = graphs.CubeGraph(8) 
     1466            sage: P = C.plot(vertex_labels=False, node_size=0, graph_border=True) 
     1467            sage: P.save('sage.png') 
    14671468        """ 
    14681469        GG = Graphics() 
     
    15111512        return GG 
    15121513 
     1514    def plot3d(self, bgcolor=(1,1,1), vertex_color=(1,0,0), edge_color=(0,0,0), pos3d=None): 
     1515        """ 
     1516        Plots the graph using Tachyon, and returns a Tachyon object containing 
     1517        a representation of the graph. 
     1518         
     1519        INPUT: 
     1520            bgcolor -- background color  
     1521            vertex_color -- vertex color 
     1522            edge_color -- edge color 
     1523            (pos3d -- currently ignored, pending GSL random point distribution in sphere...) 
     1524         
     1525        EXAMPLES: 
     1526            sage: D = graphs.DodecahedralGraph() 
     1527            sage: P3D = D.plot3d() 
     1528            sage: P3D.save('sage.png') # long time 
     1529             
     1530            sage: G = graphs.PetersenGraph() 
     1531            sage: G.plot3d(vertex_color=(0,0,1)).save('sage.png') # long time 
     1532             
     1533            sage: C = graphs.CubeGraph(4) 
     1534            sage: C.plot3d(edge_color=(0,1,0), vertex_color=(1,1,1), bgcolor=(0,0,0)).save('sage.png') # long time 
     1535        """ 
     1536        import networkx 
     1537        from math import sqrt 
     1538        from sage.plot.tachyon import Tachyon 
     1539        c = [0,0,0] 
     1540        r = [] 
     1541        verts = self.vertices() 
     1542        pos3d = networkx.spring_layout(self._nxg, dim=3) # to be replaced by comment blocks 1, 2 below 
     1543        #spring = False # block 1 
     1544        #if pos3d is None: 
     1545        #    spring = True 
     1546        #    pos3d = networkx.spring_layout(self._nxg, dim=3) 
     1547        for v in verts: 
     1548            c[0] += pos3d[v][0] 
     1549            c[1] += pos3d[v][1] 
     1550            c[2] += pos3d[v][2] 
     1551        order = self.order() 
     1552        c[0] = c[0]/order 
     1553        c[1] = c[1]/order 
     1554        c[2] = c[2]/order 
     1555        for v in verts: 
     1556            pos3d[v][0] = pos3d[v][0] - c[0] 
     1557            pos3d[v][1] = pos3d[v][1] - c[1] 
     1558            pos3d[v][2] = pos3d[v][2] - c[2] 
     1559            r.append(abs(sqrt((pos3d[v][0])**2 + (pos3d[v][1])**2 + (pos3d[v][2])**2))) 
     1560        r = max(r) 
     1561        for v in verts: 
     1562            pos3d[v][0] = pos3d[v][0]/r 
     1563            pos3d[v][1] = pos3d[v][1]/r 
     1564            pos3d[v][2] = pos3d[v][2]/r 
     1565        #if not spring: # block 2 
     1566        #    for v in verts: 
     1567        #        if not v in pos3d: 
     1568        #            pass### place node randomly inside B_1(origin) 
     1569        TT = Tachyon(camera_center=(1.4,1.4,1.4), antialiasing=13) 
     1570        TT.light((4,3,2), 0.02, (1,1,1)) 
     1571        TT.texture('node', ambient=0.1, diffuse=0.9, specular=0.03, opacity=1.0, color=vertex_color) 
     1572        TT.texture('edge', ambient=0.1, diffuse=0.9, specular=0.03, opacity=1.0, color=edge_color) 
     1573        TT.texture('bg', ambient=1, diffuse=1, specular=0, opacity=1.0, color=bgcolor) 
     1574        TT.plane((-1.6,-1.6,-1.6), (1.6,1.6,1.6), 'bg') 
     1575        for v in verts: 
     1576            TT.sphere((pos3d[v][0],pos3d[v][1],pos3d[v][2]), .06, 'node') 
     1577        for u,v,l in self.edges(): 
     1578            TT.fcylinder( (pos3d[u][0],pos3d[u][1],pos3d[u][2]),\ 
     1579                          (pos3d[v][0],pos3d[v][1],pos3d[v][2]), .02,'edge') 
     1580        return TT 
     1581 
    15131582    def show(self, pos=None, layout=None, vertex_labels=True, node_size=200, graph_border=False, color_dict=None, **kwds): 
    15141583        """ 
     
    15501619        """ 
    15511620        self.plot(pos=pos, layout=layout, vertex_labels=vertex_labels, node_size=node_size, color_dict=color_dict, graph_border=graph_border).show(**kwds) 
     1621 
     1622    def show3d(self, bgcolor=(1,1,1), vertex_color=(1,0,0), edge_color=(0,0,0), pos3d=None, **kwds): 
     1623        """ 
     1624        Plots the graph using Tachyon, and shows the resulting plot. 
     1625         
     1626        INPUT: 
     1627            bgcolor -- background color  
     1628            vertex_color -- vertex color 
     1629            edge_color -- edge color 
     1630            (pos3d -- currently ignored, pending GSL random point distribution in sphere...) 
     1631         
     1632        EXAMPLES: 
     1633            sage: D = graphs.DodecahedralGraph() 
     1634            sage: P3D = D.plot3d() 
     1635            sage: P3D.save('sage.png') # long time 
     1636             
     1637            sage: G = graphs.PetersenGraph() 
     1638            sage: G.plot3d(vertex_color=(0,0,1)).save('sage.png') # long time 
     1639             
     1640            sage: C = graphs.CubeGraph(4) 
     1641            sage: C.plot3d(edge_color=(0,1,0), vertex_color=(1,1,1), bgcolor=(0,0,0)).save('sage.png') # long time 
     1642        """ 
     1643        self.plot3d(bgcolor=bgcolor, vertex_color=vertex_color, edge_color=edge_color).show(**kwds) 
    15521644 
    15531645class DiGraph(GenericGraph): 
     
    26512743        return GG 
    26522744 
     2745    def plot3d(self, bgcolor=(1,1,1), vertex_color=(1,0,0), edge_color=(0,0,0), pos3d=None): 
     2746        """ 
     2747        Plots the graph using Tachyon, and returns a Tachyon object containing 
     2748        a representation of the graph. 
     2749         
     2750        INPUT: 
     2751            bgcolor -- background color  
     2752            vertex_color -- vertex color 
     2753            edge_color -- edge color 
     2754            (pos3d -- currently ignored, pending GSL random point distribution in sphere...) 
     2755         
     2756        NOTE: 
     2757            The weaknesses of the NetworkX spring layout are illustrated even further in the 
     2758            case of digraphs: my guess is that digraphs weren't even considered in the authoring 
     2759            of this algorithm. The following example illustrates this. 
     2760         
     2761        EXAMPLE: 
     2762            # This is a running example 
     2763             
     2764            # A directed version of the dodecahedron 
     2765            sage: D = DiGraph( { 0: [1, 10, 19], 1: [8, 2], 2: [3, 6], 3: [19, 4], 4: [17, 5], 5: [6, 15], 6: [7], 7: [8, 14], 8: [9], 9: [10, 13], 10: [11], 11: [12, 18], 12: [16, 13], 13: [14], 14: [15], 15: [16], 16: [17], 17: [18], 18: [19], 19: []} ) 
     2766             
     2767            # If I use an undirected version of my graph, the output is as expected 
     2768            sage: import networkx 
     2769            sage: pos3d=networkx.spring_layout(graphs.DodecahedralGraph()._nxg, dim=3) 
     2770            sage: D.plot3d(pos3d=pos3d).save('sage.png') # long time 
     2771             
     2772            # However, if I use the directed version, everything gets skewed bizarrely: 
     2773            sage: D.plot3d().save('sage.png') # long time 
     2774        """ 
     2775        import networkx 
     2776        from math import sqrt 
     2777        from sage.plot.tachyon import Tachyon 
     2778        c = [0,0,0] 
     2779        r = [] 
     2780        verts = self.vertices() 
     2781        #pos3d = networkx.spring_layout(self._nxg, dim=3) 
     2782        spring = False 
     2783        if pos3d is None: 
     2784            pos3d = networkx.spring_layout(self._nxg, dim=3) 
     2785        for v in verts: 
     2786            c[0] += pos3d[v][0] 
     2787            c[1] += pos3d[v][1] 
     2788            c[2] += pos3d[v][2] 
     2789        order = self.order() 
     2790        c[0] = c[0]/order 
     2791        c[1] = c[1]/order 
     2792        c[2] = c[2]/order 
     2793        for v in verts: 
     2794            pos3d[v][0] = pos3d[v][0] - c[0] 
     2795            pos3d[v][1] = pos3d[v][1] - c[1] 
     2796            pos3d[v][2] = pos3d[v][2] - c[2] 
     2797            r.append(abs(sqrt((pos3d[v][0])**2 + (pos3d[v][1])**2 + (pos3d[v][2])**2))) 
     2798        r = max(r) 
     2799        for v in verts: 
     2800            pos3d[v][0] = pos3d[v][0]/r 
     2801            pos3d[v][1] = pos3d[v][1]/r 
     2802            pos3d[v][2] = pos3d[v][2]/r 
     2803        TT = Tachyon(camera_center=(1.4,1.4,1.4), antialiasing=13) 
     2804        TT.light((4,3,2), 0.02, (1,1,1)) 
     2805        TT.texture('node', ambient=0.1, diffuse=0.9, specular=0.03, opacity=1.0, color=vertex_color) 
     2806        TT.texture('edge', ambient=0.1, diffuse=0.9, specular=0.03, opacity=1.0, color=edge_color) 
     2807        TT.texture('bg', ambient=1, diffuse=1, specular=0, opacity=1.0, color=bgcolor) 
     2808        TT.plane((-1.6,-1.6,-1.6), (1.6,1.6,1.6), 'bg') 
     2809        for v in verts: 
     2810            TT.sphere((pos3d[v][0],pos3d[v][1],pos3d[v][2]), .06, 'node') 
     2811        for u,v,l in self.arcs(): 
     2812            TT.fcylinder( (pos3d[u][0],pos3d[u][1],pos3d[u][2]),\ 
     2813                          (pos3d[v][0],pos3d[v][1],pos3d[v][2]), .02,'edge') 
     2814            TT.fcylinder( (0.25*pos3d[u][0] + 0.75*pos3d[v][0],\ 
     2815                           0.25*pos3d[u][1] + 0.75*pos3d[v][1],\ 
     2816                           0.25*pos3d[u][2] + 0.75*pos3d[v][2],), 
     2817                          (pos3d[v][0],pos3d[v][1],pos3d[v][2]), .0325,'edge') 
     2818        return TT 
     2819 
    26532820    def show(self, pos=None, vertex_labels=True, node_size=200, graph_border=False, color_dict=None, **kwds): 
    26542821        """ 
     
    26882855        self.plot(pos, vertex_labels, node_size=node_size, color_dict=color_dict, graph_border=graph_border).show(**kwds) 
    26892856 
    2690  
    2691  
    2692  
    2693  
    2694  
    2695  
    2696  
    2697  
     2857    def show3d(self, bgcolor=(1,1,1), vertex_color=(1,0,0), edge_color=(0,0,0), pos3d=None, **kwds): 
     2858        """ 
     2859        Plots the graph using Tachyon, and shows the resulting plot. 
     2860         
     2861        INPUT: 
     2862            bgcolor -- background color  
     2863            vertex_color -- vertex color 
     2864            edge_color -- edge color 
     2865            (pos3d -- currently ignored, pending GSL random point distribution in sphere...) 
     2866         
     2867        NOTE: 
     2868            The weaknesses of the NetworkX spring layout are illustrated even further in the 
     2869            case of digraphs: my guess is that digraphs weren't even considered in the authoring 
     2870            of this algorithm. The following example illustrates this. 
     2871         
     2872        EXAMPLE: 
     2873            # This is a running example 
     2874             
     2875            # A directed version of the dodecahedron 
     2876            sage: D = DiGraph( { 0: [1, 10, 19], 1: [8, 2], 2: [3, 6], 3: [19, 4], 4: [17, 5], 5: [6, 15], 6: [7], 7: [8, 14], 8: [9], 9: [10, 13], 10: [11], 11: [12, 18], 12: [16, 13], 13: [14], 14: [15], 15: [16], 16: [17], 17: [18], 18: [19], 19: []} )             
     2877             
     2878            # If I use an undirected version of my graph, the output is as expected 
     2879            sage: import networkx 
     2880            sage: pos3d=networkx.spring_layout(graphs.DodecahedralGraph()._nxg, dim=3) 
     2881            sage: D.plot3d(pos3d=pos3d).save('sage.png') # long time 
     2882             
     2883            # However, if I use the directed version, everything gets skewed bizarrely: 
     2884            sage: D.plot3d().save('sage.png') # long time 
     2885        """ 
     2886        self.plot3d(bgcolor=bgcolor, vertex_color=vertex_color, edge_color=edge_color).show(**kwds) 
     2887 
     2888 
     2889 
     2890 
     2891 
     2892 
     2893 
     2894 
  • sage/graphs/graph_fast.pyx

    r2993 r3154  
    4242    """ 
    4343    # pad on the right to make a multiple of 6 
    44     x = x + ( '0' * ((6 - len(x))%6) ) 
     44    x += '0' * ( (6 - (len(x) % 6)) % 6) 
    4545 
    4646    # split into groups of 6, and convert numbers to decimal, adding 63 
  • sage/interfaces/macaulay2.py

    r3043 r3157  
    408408            sage: X.structure_sheaf()                           # optional 
    409409            OO 
    410               sage6 
     410              sage1 
    411411        """ 
    412412        return self.parent()('OO_%s'%self.name()) 
  • sage/interfaces/octave.py

    r1908 r3158  
    125125        sage: octave.eval("b = [ 1; 3; 13]")                         # optional 
    126126        'b =\n\n 1\n 3\n 13\n\n' 
    127         sage: octave.eval("c=a \\ b") # solves linear equation: a*c = b  # optional 
     127        sage: octave.eval("c=a \\ b") # solves linear equation: a*c = b  # optional random output 
    128128        'c =\n\n 1\n -0\n 0\n\n' 
    129         sage: print octave.eval("c")                                 # optional 
     129        sage: octave.eval("c")                                 # optional random output 
    130130        c = 
    131131        <BLANKLINE> 
     
    257257            sage: V3  = VectorSpace(QQ,3) 
    258258            sage: b   = V3([1,2,3]) 
    259             sage: octave.solve_linear_system(A,b)    # requires optional octave 
     259            sage: octave.solve_linear_system(A,b)    # requires optional octave (and output is slightly random in low order bits) 
    260260            [-0.33333299999999999, 0.66666700000000001, 0] 
    261261 
  • sage/libs/ntl/ntl.pyx

    r3170 r3173  
    168168    if x is None: 
    169169        from random import randint 
    170         seed = make_new_ZZ(str(randint(0,2**64))) 
     170        seed = make_new_ZZ(str(randint(0,int(2)**64))) 
    171171    else: 
    172172        seed = make_new_ZZ(str(x)) 
  • sage/libs/pari/gen.pyx

    r2843 r3145  
    41554155        return idealval(self.g, t0, t1) 
    41564156 
     4157    def modreverse(self): 
     4158        """ 
     4159        modreverse(x): reverse polymod of the polymod x, if it exists. 
     4160 
     4161        EXAMPLES: 
     4162        """ 
     4163        _sig_on 
     4164        return self.new_gen(polymodrecip(self.g)) 
     4165 
    41574166    def nfbasis(self, long flag=0, p=0): 
    41584167        cdef gen _p 
     
    41664175        return self.new_gen(nfbasis0(self.g, flag, g)) 
    41674176 
     4177    def nffactor(self, x): 
     4178        t0GEN(x) 
     4179        _sig_on 
     4180        return self.new_gen(nffactor(self.g, t0)) 
     4181 
    41684182    def nfgenerator(self): 
    41694183        f = self[0] 
     
    41964210        return self.new_gen(rnfelementreltoabs(self.g, t0)) 
    41974211 
    4198     def rnfequation(self, poly): 
     4212    def rnfequation(self, poly, long flag=0): 
    41994213        t0GEN(poly) 
    42004214        _sig_on 
    4201         return self.new_gen(rnfequation0(self.g, t0, 0)) 
     4215        return self.new_gen(rnfequation0(self.g, t0, flag)) 
    42024216 
    42034217    def rnfidealabstorel(self, x): 
     
    44034417        return self.new_gen(polrecip(self.g)) 
    44044418     
     4419    def polred(self, flag=0, fa=None): 
     4420        _sig_on 
     4421        if fa is None: 
     4422            return self.new_gen(polred0(self.g, flag, NULL)) 
     4423        else: 
     4424            t0GEN(fa) 
     4425            return self.new_gen(polred0(self.g, flag, t0)) 
     4426 
    44054427    def polresultant(self, y, var=-1, flag=0): 
    44064428        t0GEN(y) 
  • sage/misc/hg.py

    r2687 r3166  
    172172            t = tmp_filename() 
    173173            open(t,'w').write(cmd) 
    174             os.system('source %s &'%(os.path.abspath(t))) 
     174            P = os.path.abspath(t) 
     175            os.system('chmod +x %s; %s &'%(P, P)) 
    175176        self('serve --port %s'%port) 
    176177 
  • sage/modules/module.pyx

    r2419 r3154  
    7777        False 
    7878    """ 
    79     return isinstance(x, Module) 
     79    return bool(isinstance(x, Module)) 
    8080 
    8181def is_VectorSpace(x): 
     
    9494    """ 
    9595    import sage.modules.free_module 
    96     return isinstance(x, sage.modules.free_module.FreeModule_generic_field) 
     96    return bool(isinstance(x, sage.modules.free_module.FreeModule_generic_field)) 
    9797 
    9898 
  • sage/plot/plot.py

    r2999 r3156  
    441441            Graphics object consisting of 1 graphics primitive 
    442442 
    443             sage: G[1] = p[0];G 
    444             Graphics object consisting of 3 graphics primitives 
     443            sage: G[1] = p[0]; G.save() 
    445444 
    446445        """ 
     
    467466            sage: g2 = plot(h2, 1, 5) 
    468467            sage: h = g1 + g2 
     468            sage: h.save() 
    469469        """ 
    470470        if isinstance(other, int) and other == 0: 
     
    667667        EXAMPLES: 
    668668            sage: c = circle((1,1),1,rgbcolor=(1,0,0)) 
    669             sage.: c.show(xmin=-1,xmax=3,ymin=-1,ymax=3) 
     669            sage: c.save('sage.png', xmin=-1,xmax=3,ymin=-1,ymax=3) 
    670670 
    671671            To correct the apect ratio of certain graphics, it is necessary 
    672672            to show with a 'figsize' of square dimensions. 
    673673 
    674             sage.: c.show(figsize=[5,5],xmin=-1,xmax=3,ymin=-1,ymax=3) 
     674            sage: c.save('sage2.png',figsize=[5,5],xmin=-1,xmax=3,ymin=-1,ymax=3) 
    675675        """ 
    676676        global do_verify 
     
    15871587 
    15881588    A straight, black arrow 
    1589     sage: a1 = arrow((1, 1), (3, 3)) 
     1589       sage: a1 = arrow((1, 1), (3, 3)) 
     1590       sage: a1.save() 
    15901591     
    15911592    Make a red arrow: 
    1592     sage: a2 = arrow((-1, -1), (2, 3), rgbcolor=(1,0,0)) 
     1593       sage: a2 = arrow((-1, -1), (2, 3), rgbcolor=(1,0,0)) 
     1594       sage: a2.save() 
    15931595 
    15941596    You can change the width of an arrow: 
    1595     sage: a3 = arrow((1, 1), (3, 3), width=0.05) 
    1596  
    1597      
     1597        sage: a3 = arrow((1, 1), (3, 3), width=0.05) 
     1598        sage: a3.save() 
    15981599    """ 
    15991600    def _reset(self): 
     
    16171618 
    16181619    EXAMPLES: 
    1619  
    1620         A bar_chart with blue bars: 
     1620    A bar_chart with blue bars: 
    16211621        sage: bc1 = bar_chart([1,2,3,4]) 
    1622  
    1623         A bar_chart with thinner bars: 
     1622        sage: bc1.save() 
     1623 
     1624    A bar_chart with thinner bars: 
    16241625        sage: bc2 = bar_chart([x^2 for x in range(1,20)], width=0.2) 
    1625  
    1626         A bar_chart with negative values and red bars: 
     1626        sage: bc2.save()         
     1627 
     1628    A bar_chart with negative values and red bars: 
    16271629        sage: bc3 = bar_chart([-3,5,-6,11], rgbcolor=(1,0,0)) 
     1630        sage: bc3.save()                 
    16281631 
    16291632    """ 
     
    16581661    EXAMPLES: 
    16591662    sage: c = circle((1,1),1,rgbcolor=(1,0,0)) 
    1660     sage.: c.show(xmin=-1,xmax=3,ymin=-1,ymax=3) 
     1663    sage: c.save() 
    16611664 
    16621665    To correct the apect ratio of certain graphics, it is necessary 
    16631666    to show with a 'figsize' of square dimensions. 
    16641667 
    1665     sage.: c.show(figsize=[5,5],xmin=-1,xmax=3,ymin=-1,ymax=3) 
     1668    sage: c.save(figsize=[5,5],xmin=-1,xmax=3,ymin=-1,ymax=3) 
    16661669 
    16671670    Here we make an more complicated plot with many circles of different colors 
     
    16751678    ...       ocur = (rnext-r)-ocur 
    16761679    ... 
    1677     sage.: g.show(xmin=-(paths+1)^2, xmax=(paths+1)^2, ymin=-(paths+1)^2, ymax=(paths+1)^2, figsize=[6,6]) 
     1680    sage: g.save(xmin=-(paths+1)^2, xmax=(paths+1)^2, ymin=-(paths+1)^2, ymax=(paths+1)^2, figsize=[6,6]) 
    16781681     
    16791682    """ 
     
    17731776        sage: L = [[1+5*cos(pi/2+pi*i/100), tan(pi/2+pi*i/100)*(1+5*cos(pi/2+pi*i/100))] for i in range(1,100)] 
    17741777        sage: p = line(L, rgbcolor=(1/4,1/8,3/4)) 
     1778        sage: p.save() 
    17751779  
    17761780    A blue hypotrochoid (3 leaves): 
     
    17791783        sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] 
    17801784        sage: p = line(L, rgbcolor=(1/4,1/4,3/4)) 
     1785        sage: p.save()         
    17811786  
    17821787    A blue hypotrochoid (4 leaves): 
     
    17851790        sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] 
    17861791        sage: p = line(L, rgbcolor=(1/4,1/4,3/4)) 
     1792        sage: p.save() 
    17871793  
    17881794    A red limacon of Pascal: 
     
    17901796        sage: L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,101)] 
    17911797        sage: p = line(L, rgbcolor=(1,1/4,1/2)) 
     1798        sage: p.save()         
    17921799  
    17931800    A light green trisectrix of Maclaurin: 
     
    17951802        sage: L = [[2*(1-4*cos(-pi/2+pi*i/100)^2),10*tan(-pi/2+pi*i/100)*(1-4*cos(-pi/2+pi*i/100)^2)] for i in range(1,100)] 
    17961803        sage: p = line(L, rgbcolor=(1/4,1,1/8)) 
     1804        sage: p.save()         
    17971805  
    17981806    A green lemniscate of Bernoulli: 
     
    18011809        sage: L = [(a/(a^2+b^2), b/(a^2+b^2)) for a,b in v] 
    18021810        sage: p = line(L, rgbcolor=(1/4,3/4,1/8)) 
     1811        sage: p.save()         
    18031812  
    18041813    A red plot of the Jacobi elliptic function $\text{sn}(x,2)$, $-3<x<3$: 
     
    18061815        sage: L = [(i/100.0, maxima.eval('jacobi_sn (%s/100.0,2.0)'%i)) for i in range(-300,300)] 
    18071816        sage: p = line(L, rgbcolor=(3/4,1/4,1/8)) 
    1808   
     1817        sage: p.save() 
     1818         
    18091819    A red plot of $J$-Bessel function $J_2(x)$, $0<x<10$: 
    18101820 
    18111821        sage: L = [(i/10.0, maxima.eval('bessel_j (2,%s/10.0)'%i)) for i in range(100)] 
    18121822        sage: p = line(L, rgbcolor=(3/4,1/4,5/8)) 
     1823        sage: p.save() 
     1824         
    18131825  
    18141826    A purple plot of the Riemann zeta function $\zeta(1/2 + it)$, $0<t<30$: 
     
    18171829        sage: L = [(z.real(), z.imag()) for z in v] 
    18181830        sage: p = line(L, rgbcolor=(3/4,1/2,5/8)) 
     1831        sage: p.save() 
    18191832  
    18201833    A purple plot of the Hasse-Weil $L$-function $L(E, 1 + it)$, $-1<t<10$: 
     
    18241837        sage: L = [(z[1].real(), z[1].imag()) for z in vals] 
    18251838        sage: p = line(L, rgbcolor=(3/4,1/2,5/8)) 
     1839        sage: p.save() 
    18261840  
    18271841    A red, blue, and green "cool cat": 
     
    18321846        sage: Q = polygon([(-x,y) for x,y in P[0]], rgbcolor=(0,0,1)) 
    18331847        sage: H = G + P + Q 
     1848        sage: H.save() 
    18341849    """ 
    18351850    def _reset(self): 
     
    18681883    A matrix over ZZ colored with different grey levels: 
    18691884     
    1870     sage: M1 = Matrix(ZZ,3,4,[[1,3,5,1],[2,4,5,6],[1,3,5,7]])  
    1871     sage: MP1 = matrix_plot(M1) 
     1885        sage: M1 = Matrix(ZZ,3,4,[[1,3,5,1],[2,4,5,6],[1,3,5,7]])  
     1886        sage: MP1 = matrix_plot(M1) 
     1887        sage: MP1.save() 
    18721888 
    18731889    Here we make a random matrix over RR and use cmap='hsv' 
    18741890    to color the matrix elements different RGB colors: 
    18751891 
    1876     sage: n = 22 
    1877     sage: L = [n*random() for i in range(n*n)] 
    1878     sage: M2 = Matrix(RR, n, n, L) 
    1879     sage: MP2 = matrix_plot(M2, cmap='hsv') 
    1880      
     1892        sage: n = 22 
     1893        sage: L = [n*random() for i in range(n*n)] 
     1894        sage: M2 = Matrix(RR, n, n, L) 
     1895        sage: MP2 = matrix_plot(M2, cmap='hsv') 
     1896        sage: MP2.save() 
    18811897    """ 
    18821898    def _reset(self): 
     
    19431959        sage: br = disk((0.0,0.0), 1, (3*pi/2, 2*pi), rgbcolor=(0,0,0)) 
    19441960        sage: P  = tl+tr+bl+br 
    1945         sage.: P.show(figsize=(4,4),xmin=-2,xmax=2,ymin=-2,ymax=2) 
     1961        sage: P.save(figsize=(4,4),xmin=-2,xmax=2,ymin=-2,ymax=2) 
    19461962 
    19471963    """ 
     
    19701986        A purple point from a single tuple or coordinates: 
    19711987        sage: p1 = point((0.5, 0.5), rgbcolor=hue(0.75)) 
     1988        sage: p1.save() 
    19721989 
    19731990        Here are some random larger red points, given as a list of tuples 
    19741991        sage: p2 = point(((0.5, 0.5), (1, 2), (0.5, 0.9), (-1, -1)), rgbcolor=hue(1), pointsize=30) 
     1992        sage: p2.save() 
    19751993 
    19761994    """ 
     
    20172035        sage: L = [[cos(pi*i/3),sin(pi*i/3)] for i in range(6)] 
    20182036        sage: p = polygon(L, rgbcolor=(1,0,1)) 
     2037        sage: p.save() 
    20192038 
    20202039    A green deltoid: 
     
    20222041        sage: L = [[-1+cos(pi*i/100)*(1+cos(pi*i/100)),2*sin(pi*i/100)*(1-cos(pi*i/100))] for i in range(200)] 
    20232042        sage: p = polygon(L, rgbcolor=(1/8,3/4,1/2)) 
     2043        sage: p.save() 
    20242044 
    20252045    A blue hypotrochoid: 
     
    20272047        sage: L = [[6*cos(pi*i/100)+5*cos((6/2)*pi*i/100),6*sin(pi*i/100)-5*sin((6/2)*pi*i/100)] for i in range(200)] 
    20282048        sage: p = polygon(L, rgbcolor=(1/8,1/4,1/2)) 
    2029  
     2049        sage: p.save() 
     2050         
    20302051    Another one: 
    20312052 
     
    20332054        sage: L = [[n*cos(pi*i/100)+h*cos((n/b)*pi*i/100),n*sin(pi*i/100)-h*sin((n/b)*pi*i/100)] for i in range(200)] 
    20342055        sage: p = polygon(L, rgbcolor=(1/8,1/4,3/4)) 
     2056        sage: p.save()         
    20352057 
    20362058    A purple epicycloid: 
     
    20392061        sage: L = [[m*cos(pi*i/100)+b*cos((m/b)*pi*i/100),m*sin(pi*i/100)-b*sin((m/b)*pi*i/100)] for i in range(200)] 
    20402062        sage: p = polygon(L, rgbcolor=(7/8,1/4,3/4)) 
     2063        sage: p.save()         
    20412064 
    20422065    A brown astroid: 
     
    20442067        sage: L = [[cos(pi*i/100)^3,sin(pi*i/100)^3] for i in range(200)] 
    20452068        sage: p = polygon(L, rgbcolor=(3/4,1/4,1/4)) 
     2069        sage: p.save() 
    20462070 
    20472071    And, my favorite, a greenish blob: 
     
    20492073        sage: L = [[cos(pi*i/100)*(1+cos(pi*i/50)), sin(pi*i/100)*(1+sin(pi*i/50))] for i in range(200)] 
    20502074        sage: p = polygon(L, rgbcolor=(1/8, 3/4, 1/2)) 
     2075        sage: p.save()         
    20512076 
    20522077    This one is for my wife: 
     
    20542079        sage: L = [[sin(pi*i/100)+sin(pi*i/50),-(1+cos(pi*i/100)+cos(pi*i/50))] for i in range(-100,100)] 
    20552080        sage: p = polygon(L, rgbcolor=(1,1/4,1/2)) 
     2081        sage: p.save() 
    20562082 
    20572083    AUTHORS: 
     
    21462172        sage: len(P[0])  # how many points were computed 
    21472173        201 
     2174        sage: P.save()   # render 
     2175         
    21482176        sage: P = plot(sin, 0,10, plot_points=10); P 
    21492177        Graphics object consisting of 1 graphics primitive 
    2150         sage: len(P[0])   # random output 
     2178        sage: len(P[0])  # random output 
    21512179        80 
     2180        sage: P.save()   # render 
    21522181         
    21532182    Use \code{show(plot(sin, 0,10))} or \code{plot(sin,0,10).show()} 
     
    21582187        sage: def h1(x): return abs(sqrt(x^3  - 1)) 
    21592188        sage: def h2(x): return -abs(sqrt(x^3  - 1)) 
    2160         sage: plot([h1, h2], 1,4)    # slightly random output because of random sampling 
     2189        sage: P = plot([h1, h2], 1,4)    # slightly random output because of random sampling 
    21612190        Graphics object consisting of 2 graphics primitives 
     2191        sage: P.save() 
    21622192 
    21632193    We can also directly plot the elliptic curve: 
    21642194        sage: E = EllipticCurve([0,-1]) 
    21652195        sage: P = plot(E, 1, 4, rgbcolor=hue(0.6)) 
     2196        sage: P.save()         
    21662197 
    21672198    We can change the line style to one of '--' (dashed), '-.' (dash dot), 
     
    22412272                data.append((x, float(y))) 
    22422273            except (TypeError, ValueError), msg: 
    2243                 raise ValueError, "%s\nUnable to compute f(%s)"%(msg, x) 
     2274                #raise ValueError, "%s\nUnable to compute f(%s)"%(msg, x) 
     2275                pass 
    22442276        # adaptive refinement 
    22452277        i, j = 0, 0 
     
    23072339        sage: t2 = text("World", (1,0.5), horizontal_alignment="left") 
    23082340 
     2341        sage: (t1+t2).save() 
     2342 
    23092343    """ 
    23102344    def _reset(self): 
     
    23432377        sage: f = lambda t: sin(t) 
    23442378        sage: g = lambda t: sin(2*t) 
    2345         sage: parametric_plot((f,g),0,2*pi,rgbcolor=hue(0.6)) 
    2346         Graphics object consisting of 1 graphics primitive 
     2379        sage: G = parametric_plot((f,g),0,2*pi,rgbcolor=hue(0.6)) 
     2380        sage: G.save() 
    23472381    """ 
    23482382    if show is None: 
     
    23582392    Here is a blue 8-leaved petal: 
    23592393        sage: p1 = polar_plot(lambda x:sin(5*x)^2, 0, 2*pi, rgbcolor=hue(0.6)) 
     2394        sage: p1.save() 
    23602395 
    23612396    A red figure-8: 
    23622397        sage: p2 = polar_plot(lambda x:abs(sqrt(1 - sin(x)^2)), 0, 2*pi, rgbcolor=hue(1.0)) 
     2398        sage: p2.save() 
    23632399 
    23642400    A green limacon of Pascal: 
    23652401        sage: p3 = polar_plot(lambda x:2 + 2*cos(x), 0, 2*pi, rgbcolor=hue(0.3)) 
     2402        sage: p3.save() 
    23662403         
    23672404    """ 
     
    23822419     
    23832420    EXAMPLES: 
    2384         sage: list_plot([i^2 for i in range(5)]) 
    2385         Graphics object consisting of 1 graphics primitive 
    2386  
     2421        sage: L = list_plot([i^2 for i in range(5)]) 
     2422        sage: L.save() 
     2423 
     2424    Here are a bunch of random red points: 
    23872425        sage: r = [(random(),random()) for _ in range(20)] 
    2388  
    2389     Here are a bunch of random red points: 
    2390         sage: list_plot(r,rgbcolor=(1,0,0)) 
    2391         Graphics object consisting of 1 graphics primitive 
     2426        sage: L = list_plot(r,rgbcolor=(1,0,0)) 
     2427        sage: L.save() 
    23922428 
    23932429    This gives all the random points joined in a purple line: 
    2394         sage: list_plot(r, plotjoined=True, rgbcolor=(1,0,1)) 
    2395         Graphics object consisting of 1 graphics primitive 
     2430        sage: L = list_plot(r, plotjoined=True, rgbcolor=(1,0,1)) 
     2431        sage: L.save() 
    23962432    """ 
    23972433    if show is None: 
     
    24402476        (0.0, 0.40000000000000036, 1.0) 
    24412477 
    2442         hue is an easy way of getting a broader 
    2443         range of colors for graphics 
     2478      hue is an easy way of getting a broader 
     2479      range of colors for graphics 
    24442480         
    24452481        sage: p = plot(sin, -2, 2, rgbcolor=hue(0.6)) 
     2482        sage: p.save() 
    24462483 
    24472484    """ 
     
    26182655 
    26192656        sage: ga = graphics_array(((p1,p2),(p3,p4))) 
     2657        sage: ga.save() 
    26202658 
    26212659    Here we give only one row: 
    26222660        sage: p1 = plot(sin,-4,4) 
    26232661        sage: p2 = plot(cos,-4,4) 
    2624         sage: graphics_array([p1, p2]) 
     2662        sage: g = graphics_array([p1, p2]); g 
    26252663        Graphics Array of size 1 x 2 
     2664        sage: g.save() 
    26262665 
    26272666    """ 
     
    26332672    return GraphicsArray(array) 
    26342673 
     2674""" 
     2675Clean up the png's left laying around during the test process: 
     2676 
     2677   sage: os.system('rm *.png') 
     2678   0 
     2679""" 
  • sage/plot/tachyon.py

    r2691 r3161  
    223223            self.save(filename, verbose=verbose, extra_opts=extra_opts) 
    224224        else: 
    225             raise NotImplementedError 
     225            filename = sage.misc.misc.tmp_filename() + '.png' 
     226            self.save(filename, verbose=verbose, extra_opts=extra_opts) 
     227            os.system('%s %s 2>/dev/null 1>/dev/null &'%(sage.misc.viewer.browser(), filename)) 
    226228 
    227229 
  • sage/rings/complex_double.pyx

    r3124 r3148  
    303303        return real_double.RDF 
    304304 
     305    def pi(self): 
     306        """ 
     307        Returns pi as a double precision complex number. 
     308 
     309        EXAMPLES: 
     310            sage: CDF.pi() 
     311            3.14159265359 
     312        """ 
     313        return self(3.1415926535897932384626433832) 
     314     
     315 
    305316def new_ComplexDoubleElement(): 
    306317    cdef ComplexDoubleElement z 
  • sage/rings/integer_mod.pyx

    r2817 r3154  
    9595        True 
    9696    """ 
    97     return isinstance(x, IntegerMod_abstract) 
     97    return bool(isinstance(x, IntegerMod_abstract)) 
    9898 
    9999def makeNativeIntStruct(sage.rings.integer.Integer z): 
  • sage/rings/mpfi.pxi

    r2617 r3140  
    44cdef extern from "mpfi.h": 
    55    ctypedef struct __mpfi_struct: 
    6         pass 
     6        __mpfr_struct left 
     7        __mpfr_struct right 
    78    #ctypedef __mpfi_struct mpfi_t[1] 
    89    ctypedef __mpfi_struct* mpfi_t 
  • sage/rings/mpfr.pxi

    r2616 r3140  
    130130    int mpfr_neg (mpfr_ptr rop, mpfr_srcptr op, mp_rnd_t rnd) 
    131131    # int mpfr_eq (mpfr_srcptr rop, mpfr_srcptr op, unsigned long i) 
    132     # int mpfr_less_p (mpfr_t op1, mpfr_t op2) 
     132    int mpfr_less_p (mpfr_t op1, mpfr_t op2) 
     133    int mpfr_lessequal_p (mpfr_t op1, mpfr_t op2) 
    133134    int mpfr_cmp (mpfr_t op1, mpfr_t op2) 
  • sage/rings/rational_field.py

    r2802 r3168  
    176176 
    177177    def __iter__(self): 
    178         yield self(0) 
    179         yield self(1) 
    180         yield self(-1) 
    181         from integer_ring import IntegerRing 
    182         for n in IntegerRing(): 
    183             m = abs(n) 
    184             for d in abs(n).coprime_integers(m): 
    185                 yield n/d 
    186                 yield d/n 
     178        r""" 
     179        Creates an iterator that generates the rational numbers without 
     180        repetition. It uses the sequence defined by $a_0=0$ and 
     181        $a_{n+1}=\frac{1}{2\lfloor a_n\rfloor+1-a_n}$ and generates the 
     182        sequence $$a_0,a_1,-a_1,a_2,-a_2,\ldots$$ 
     183 
     184        EXAMPLES: 
     185 
     186        This example creates a list consisting of the first 10 terms 
     187        generated by this function. 
     188 
     189            sage: import itertools 
     190            sage: [a for a in itertools.islice(Rationals(),10)] 
     191            [0, 1, -1, 1/2, -1/2, 2, -2, 1/3, -1/3, 3/2] 
     192 
     193        NOTES: 
     194            A proof of the correctness of this formula is attributed to 
     195            Sam Vandervelde and Don Zagier [A002487], but a better 
     196            reference for the origin of this formula would be welcome. 
     197 
     198            REFERENCES: 
     199                 [A002487] Sloane's OLEIS, 
     200                 http://www.research.att.com/~njas/sequences/A002487 
     201 
     202        AUTHORS: 
     203            - Nils Bruin (2007-02-20) 
     204        """ 
     205 
     206        from sage.rings.arith import floor 
     207 
     208        n=self(0) 
     209        yield n 
     210        while True: 
     211          n=1/(2*floor(n)+1-n) 
     212          yield n 
     213          yield -n 
    187214 
    188215    def complex_embedding(self, prec=53): 
  • sage/rings/real_double.pyx

    r2869 r3148  
    209209 
    210210        EXAMPLES: 
    211             sage: R = RealField(100) 
    212211            sage: RDF.pi() 
    213212            3.14159265359 
  • sage/rings/real_mpfi.pyx

    r2833 r3142  
    4545    sage: a == 2 
    4646    False 
     47 
     48COMPARISONS: 
     49 
     50Comparison operations (==,!=,<,<=,>,>=) return true if every value in 
     51the first interval has the given relation to every value in the second 
     52interval.  The cmp(a, b) function works differently; it compares two 
     53intervals lexicographically.  (However, the behavior is not specified 
     54if given a non-interval and an interval.) 
     55 
     56This convention for comparison operators has good and bad points.  The 
     57good: 
     58* Expected transitivity properties hold (if a > b and b == c, then a > c; 
     59etc.) 
     60* if a>b, then cmp(a, b) == 1; if a==b, then cmp(a,b) == 0; if a<b, then 
     61cmp(a, b) == -1 
     62* a==0 is true if the interval contains only the floating-point number 0; 
     63similarly for a==1 
     64* a>0 means something useful (that every value in the interval is greater 
     65than 0) 
     66 
     67The bad: 
     68* Trichotomy fails to hold: there are values (a,b) such that none of a<b, 
     69a==b, or a>b are true 
     70* It is not the case that if cmp(a, b) == 0 then a==b, or that if 
     71cmp(a, b) == 1 then a>b, or that if cmp(a, b) == -1 then a<b 
     72* There are values a,b such that a<=b but neither a<b nor a==b hold 
     73 
     74Note that intervals a and b overlap iff not(a != b). 
     75 
     76EXAMPLES: 
     77    sage: 0 < RIF(1, 2) 
     78    True 
     79    sage: 0 == RIF(0) 
     80    True 
     81    sage: not(0 == RIF(0, 1)) 
     82    True 
     83    sage: not(0 != RIF(0, 1)) 
     84    True 
     85    sage: 0 <= RIF(0, 1) 
     86    True 
     87    sage: not(0 < RIF(0, 1)) 
     88    True 
     89    sage: cmp(RIF(0), RIF(0, 1)) 
     90    -1 
     91    sage: cmp(RIF(0, 1), RIF(0)) 
     92    1 
     93    sage: cmp(RIF(0, 1), RIF(1)) 
     94    -1 
     95    sage: cmp(RIF(0, 1), RIF(0, 1)) 
     96    0     
    4797""" 
    4898  
     
    706756        EXAMPLES: 
    707757            sage: a = RIF(5,5.5) 
    708             sage: loads(dumps(a)) == a 
    709             True         
     758            sage: cmp(loads(dumps(a)), a) 
     759            0         
    710760            sage: R = RealIntervalField(sci_not=1, prec=200) 
    711761            sage: b = R('393.39203845902384098234098230948209384028340') 
    712             sage: loads(dumps(b)) == b 
    713             True 
     762            sage: cmp(loads(dumps(b)), b) 
     763            0 
    714764            sage: b = R(1)/R(0); b 
    715765            [+infinity ... +infinity] 
     
    722772            sage: b = R('[2 ... 3]'); b 
    723773            [2.0000000000000000000000000000000000000000000000000000000000000e0 ... 3.0000000000000000000000000000000000000000000000000000000000000e0] 
    724             sage: loads(dumps(b)) == b 
    725             True 
     774            sage: cmp(loads(dumps(b)), b) 
     775            0 
    726776        """ 
    727777        s = self.str(32, no_sci=False, e='@') 
     
    934984    def relative_diameter(self): 
    935985        """ 
    936         XXX This MPFI function is buggy! 
    937  
    938986        The relative diameter of this interval (for [a ... b], 
    939987        this is (b-a)/((a+b)/2)), rounded upward, as a RealNumber. 
    940988 
    941989        EXAMPLES: 
    942             sage: RIF(1, pi).relative_diameter() # todo: not implemented 
     990            sage: RIF(1, pi).relative_diameter() 
     991            1.03418797197910 
    943992        """ 
    944993        cdef RealNumber x 
     
    949998    def diameter(self): 
    950999        """ 
    951         XXX This MPFI function is buggy! 
    952  
    9531000        If (0 in self), returns self.absolute_diameter(), 
    9541001        otherwise self.relative_diameter(). 
     
    9561003        EXAMPLES: 
    9571004            sage: RIF(1, 2).diameter() 
    958             1.00000000000000 
     1005            0.666666666666666 
    9591006            sage: RIF(1, 2).absolute_diameter() 
    9601007            1.00000000000000 
    9611008            sage: RIF(1, 2).relative_diameter() 
    962             1.00000000000000 
     1009            0.666666666666666 
    9631010            sage: RIF(pi).diameter() 
    964             0.000000000000000444089209850062 
     1011            0.000000000000000141357985842822 
    9651012            sage: RIF(pi).absolute_diameter() 
    9661013            0.000000000000000444089209850062 
    9671014            sage: RIF(pi).relative_diameter() 
    968             0.000000000000000444089209850062 
    969             sage: (RIF(pi) - RIF(pi).square().sqrt()).diameter() 
    970             0.00000000000000177635683940025 
    971             sage: (RIF(pi) - RIF(pi).square().sqrt()).absolute_diameter() 
    972             0.00000000000000177635683940025 
    973             sage: (RIF(pi) - RIF(pi).square().sqrt()).relative_diameter() 
    974             +infinity 
     1015            0.000000000000000141357985842822 
     1016            sage: (RIF(pi) - RIF(3, 22/7)).diameter() 
     1017            0.142857142857143 
     1018            sage: (RIF(pi) - RIF(3, 22/7)).absolute_diameter() 
     1019            0.142857142857143 
     1020            sage: (RIF(pi) - RIF(3, 22/7)).relative_diameter() 
     1021            2.03604377705517 
    9751022        """ 
    9761023        cdef RealNumber x 
     
    9941041        return x 
    9951042 
    996     # I'm skipping mignitude (mpfi_mig()).  Is this a useful function? 
     1043    def mignitude(self): 
     1044        """ 
     1045        The smallest absolute value of the elements of the interval. 
     1046 
     1047        EXAMPLES: 
     1048            sage: RIF(-2, 1).mignitude() 
     1049            0.000000000000000 
     1050            sage: RIF(-2, -1).mignitude() 
     1051            1.00000000000000 
     1052            sage: RIF(3, 4).mignitude() 
     1053            3.00000000000000 
     1054        """ 
     1055        cdef RealNumber x 
     1056        x = (<RealIntervalField>self._parent).__middle_field._new() 
     1057        mpfi_mig(<mpfr_t> x.value, self.value) 
     1058        return x 
    9971059 
    9981060    def center(self): 
     
    14421504 
    14431505    def __richcmp__(left, right, int op): 
    1444         return (<RingElement>left)._richcmp(right, op) 
     1506        return (<Element>left)._richcmp(right, op) 
     1507     
     1508    cdef _richcmp_c_impl(left, Element right, int op): 
     1509        """ 
     1510        Implements comparisons between intervals.  (See the file header 
     1511        comment for more information on interval comparison.) 
     1512 
     1513        EXAMPLES: 
     1514            sage: 0 < RIF(1, 3) 
     1515            True 
     1516            sage: 1 < RIF(1, 3) 
     1517            False 
     1518            sage: 2 < RIF(1, 3) 
     1519            False 
     1520            sage: 4 < RIF(1, 3) 
     1521            False 
     1522            sage: RIF(0, 1/2) < RIF(1, 3) 
     1523            True 
     1524            sage: RIF(0, 1) < RIF(1, 3) 
     1525            False 
     1526            sage: RIF(0, 2) < RIF(1, 3) 
     1527            False 
     1528            sage: RIF(1, 2) < RIF(1, 3) 
     1529            False 
     1530            sage: RIF(1, 3) < 4 
     1531            True 
     1532            sage: RIF(1, 3) < 3 
     1533            False 
     1534            sage: RIF(1, 3) < 2 
     1535            False 
     1536            sage: RIF(1, 3) < 0 
     1537            False 
     1538            sage: 0 <= RIF(1, 3) 
     1539            True 
     1540            sage: 1 <= RIF(1, 3) 
     1541            True 
     1542            sage: 2 <= RIF(1, 3) 
     1543            False 
     1544            sage: 4 <= RIF(1, 3) 
     1545            False 
     1546            sage: RIF(0, 1/2) <= RIF(1, 3) 
     1547            True 
     1548            sage: RIF(0, 1) <= RIF(1, 3) 
     1549            True 
     1550            sage: RIF(0, 2) <= RIF(1, 3) 
     1551            False 
     1552            sage: RIF(1, 2) <= RIF(1, 3) 
     1553            False 
     1554            sage: RIF(1, 3) <= 4 
     1555            True 
     1556            sage: RIF(1, 3) <= 3 
     1557            True 
     1558            sage: RIF(1, 3) <= 2 
     1559            False 
     1560            sage: RIF(1, 3) <= 0 
     1561            False 
     1562            sage: RIF(1, 3) > 0 
     1563            True 
     1564            sage: RIF(1, 3) > 1 
     1565            False 
     1566            sage: RIF(1, 3) > 2 
     1567            False 
     1568            sage: RIF(1, 3) > 4 
     1569            False 
     1570            sage: RIF(1, 3) > RIF(0, 1/2) 
     1571            True 
     1572            sage: RIF(1, 3) > RIF(0, 1) 
     1573            False 
     1574            sage: RIF(1, 3) > RIF(0, 2) 
     1575            False 
     1576            sage: RIF(1, 3) > RIF(1, 2) 
     1577            False 
     1578            sage: 4 > RIF(1, 3) 
     1579            True 
     1580            sage: 3 > RIF(1, 3) 
     1581            False 
     1582            sage: 2 > RIF(1, 3) 
     1583            False 
     1584            sage: 0 > RIF(1, 3) 
     1585            False 
     1586            sage: RIF(1, 3) >= 0 
     1587            True 
     1588            sage: RIF(1, 3) >= 1 
     1589            True 
     1590            sage: RIF(1, 3) >= 2 
     1591            False 
     1592            sage: RIF(1, 3) >= 4 
     1593            False 
     1594            sage: RIF(1, 3) >= RIF(0, 1/2) 
     1595            True 
     1596            sage: RIF(1, 3) >= RIF(0, 1) 
     1597            True 
     1598            sage: RIF(1, 3) >= RIF(0, 2) 
     1599            False 
     1600            sage: RIF(1, 3) >= RIF(1, 2) 
     1601            False 
     1602            sage: 4 >= RIF(1, 3) 
     1603            True 
     1604            sage: 3 >= RIF(1, 3) 
     1605            True 
     1606            sage: 2 >= RIF(1, 3) 
     1607            False 
     1608            sage: 0 >= RIF(1, 3) 
     1609            False 
     1610            sage: 0 == RIF(0) 
     1611            True 
     1612            sage: 0 == RIF(1) 
     1613            False 
     1614            sage: 1 == RIF(0) 
     1615            False 
     1616            sage: 0 == RIF(0, 1) 
     1617            False 
     1618            sage: 1 == RIF(0, 1) 
     1619            False 
     1620            sage: RIF(0, 1) == RIF(0, 1) 
     1621            False 
     1622            sage: RIF(1) == 0 
     1623            False 
     1624            sage: RIF(1) == 1 
     1625            True 
     1626            sage: RIF(0) == RIF(0) 
     1627            True 
     1628            sage: RIF(pi) == RIF(pi) 
     1629            False 
     1630            sage: RIF(0, 1) == RIF(1, 2) 
     1631            False 
     1632            sage: RIF(1, 2) == RIF(0, 1) 
     1633            False 
     1634            sage: 0 != RIF(0) 
     1635            False 
     1636            sage: 0 != RIF(1) 
     1637            True 
     1638            sage: 1 != RIF(0) 
     1639            True 
     1640            sage: 0 != RIF(0, 1) 
     1641            False 
     1642            sage: 1 != RIF(0, 1) 
     1643            False 
     1644            sage: RIF(0, 1) != RIF(0, 1) 
     1645            False 
     1646            sage: RIF(1) != 0 
     1647            True 
     1648            sage: RIF(1) != 1 
     1649            False 
     1650            sage: RIF(0) != RIF(0) 
     1651            False 
     1652            sage: RIF(pi) != RIF(pi) 
     1653            False 
     1654            sage: RIF(0, 1) != RIF(1, 2) 
     1655            False 
     1656            sage: RIF(1, 2) != RIF(0, 1) 
     1657            False 
     1658        """ 
     1659        cdef RealIntervalFieldElement lt, rt 
     1660 
     1661        lt = left 
     1662        rt = right 
     1663 
     1664        if op == 0: #< 
     1665            return PyBool_FromLong(mpfr_less_p(&lt.value.right, &rt.value.left)) 
     1666        elif op == 2: #== 
     1667            # a == b iff a<=b and b <= a 
     1668            # (this gives a result with two comparisons, where the 
     1669            # obvious approach would use three) 
     1670            return PyBool_FromLong(mpfr_lessequal_p(&lt.value.right, &rt.value.left)) \ 
     1671                and PyBool_FromLong(mpfr_lessequal_p(&rt.value.right, &lt.value.left)) 
     1672        elif op == 4: #> 
     1673            return PyBool_FromLong(mpfr_less_p(&rt.value.right, &lt.value.left)) 
     1674        elif op == 1: #<= 
     1675            return PyBool_FromLong(mpfr_lessequal_p(&lt.value.right, &rt.value.left)) 
     1676        elif op == 3: #!= 
     1677            return PyBool_FromLong(mpfr_less_p(&lt.value.right, &rt.value.left)) \ 
     1678                or PyBool_FromLong(mpfr_less_p(&rt.value.right, &lt.value.left)) 
     1679        elif op == 5: #>= 
     1680            return PyBool_FromLong(mpfr_lessequal_p(&rt.value.right, &lt.value.left)) 
     1681 
     1682    def __cmp__(left, right): 
     1683        """ 
     1684        Compare two intervals lexicographically.  Returns 0 if they 
     1685        are the same interval, -1 if the second is larger, or 1 if 
     1686        the first is larger. 
     1687 
     1688        EXAMPLES: 
     1689            sage: cmp(RIF(0), RIF(1)) 
     1690            -1 
     1691            sage: cmp(RIF(0, 1), RIF(1)) 
     1692            -1 
     1693            sage: cmp(RIF(0, 1), RIF(1, 2)) 
     1694            -1 
     1695            sage: cmp(RIF(0, 0.99999), RIF(1, 2)) 
     1696            -1 
     1697            sage: cmp(RIF(1, 2), RIF(0, 1)) 
     1698            1 
     1699            sage: cmp(RIF(1, 2), RIF(0)) 
     1700            1 
     1701            sage: cmp(RIF(0, 1), RIF(0, 2)) 
     1702            -1 
     1703            sage: cmp(RIF(0, 1), RIF(0, 1)) 
     1704            0 
     1705            sage: cmp(RIF(0, 1), RIF(0, 1/2)) 
     1706            1 
     1707        """ 
     1708        return (<Element>left)._cmp(right) 
    14451709 
    14461710    cdef int _cmp_c_impl(left, Element right) except -2: 
    14471711        """ 
    1448         Compare two intervals.  Returns 0 if they overlap, -1 if the 
    1449         second is larger, or 1 if the first is larger. 
    1450  
    1451         EXAMPLES: 
    1452             sage: RIF(0) < RIF(1) 
    1453             True 
    1454             sage: RIF(0, 1) < RIF(1) 
    1455             False 
    1456             sage: RIF(0, 1) == RIF(1, 2) 
    1457             True 
    1458             sage: RIF(0, 0.99999) == RIF(1, 2) 
    1459             False 
    1460             sage: RIF(1, 2) > RIF(0, 1) 
    1461             False 
    1462             sage: RIF(1, 2) > RIF(0) 
    1463             True 
    1464         """ 
    1465         cdef RealIntervalFieldElement self, x 
    1466         self = left 
    1467         x = right  
     1712        Implements the lexicographic total order on intervals. 
     1713        """ 
     1714        cdef RealIntervalFieldElement lt, rt 
     1715 
     1716        lt = left 
     1717        rt = right 
    14681718 
    14691719        cdef int i 
    1470         i = mpfi_cmp(self.value, x.value) 
     1720        i = mpfr_cmp(&lt.value.left, &rt.value.left) 
    14711721        if i < 0: 
    14721722            return -1 
    1473         elif i == 0: 
    1474             return 0 
     1723        elif i > 0: 
     1724            return 1 
     1725        i = mpfr_cmp(&lt.value.right, &rt.value.right) 
     1726        if i < 0: 
     1727            return -1 
     1728        elif i > 0: 
     1729            return 1 
    14751730        else: 
    1476             return 1 
    1477      
     1731            return 0     
    14781732 
    14791733    def __contains__(self, other): 
     
    15111765            return False 
    15121766 
    1513     # Skipping mpfi_intersect(), because it can return an empty 
    1514     # interval (where nothing else can), and I don't want to 
    1515     # deal with empty intervals everywhere. 
     1767    def intersection(self, other): 
     1768        """ 
     1769        Return the intersection of two intervals.  If the intervals 
     1770        do not overlap, raises a ValueError. 
     1771 
     1772        EXAMPLES: 
     1773            sage: RIF(1, 2).intersection(RIF(1.5, 3)) 
     1774            [1.5000000000000000 ... 2.0000000000000000] 
     1775            sage: RIF(1, 2).intersection(RIF(4/3, 5/3)) 
     1776            [1.3333333333333332 ... 1.6666666666666668] 
     1777            sage: RIF(1, 2).intersection(RIF(3, 4)) 
     1778            Traceback (most recent call last): 
     1779            ... 
     1780            ValueError: intersection of non-overlapping intervals 
     1781        """ 
     1782        cdef RealIntervalFieldElement x 
     1783        x = self._new() 
     1784        cdef RealIntervalFieldElement other_intv 
     1785        if PY_TYPE_CHECK(other, RealIntervalFieldElement): 
     1786            other_intv = other 
     1787        else: 
     1788            # Let type errors from _coerce_ propagate... 
     1789            other_intv = self._parent._coerce_(other) 
     1790 
     1791        mpfi_intersect(x.value, self.value, other_intv.value) 
     1792        if mpfr_less_p(&x.value.right, &x.value.left): 
     1793            raise ValueError, "intersection of non-overlapping intervals" 
     1794        return x 
    15161795 
    15171796    def union(self, other): 
     
    15551834    def sqrt(self): 
    15561835        """ 
    1557         Return a square root of self. 
    1558  
    1559         If self is negative a complex number is returned. 
    1560  
    1561         If you use self.square_root() then a real number will always 
    1562         be returned (though it will be NaN if self is negative). 
     1836        Return a square root of self.  Raises an error if self is 
     1837        nonpositive. 
     1838 
     1839        If you use self.square_root() then an interval will always 
     1840        be returned (though it will be NaN if self is nonpositive). 
    15631841 
    15641842        EXAMPLES: 
     
    15731851            [65.909028213136323 ... 65.909028213136339] 
    15741852            sage: r.sqrt()^2 == r 
     1853            False 
     1854            sage: r in r.sqrt()^2 
    15751855            True 
    15761856            sage: r.sqrt()^2 - r             
     
    15971877        """ 
    15981878        Return a square root of self.  An interval will always be 
    1599         returned (though it will be NaN if self is negative). 
     1879        returned (though it will be NaN if self is nonpositive). 
    16001880 
    16011881        EXAMPLES: 
     
    18182098            sage: a.is_int() 
    18192099            (True, -1) 
    1820         """ 
    1821         if self.diameter() >= 1: 
    1822             return False, None 
    1823         a = (self.lower()+1).floor() 
     2100            sage: a = RIF(0.1, 1.9) 
     2101            sage: a.is_int() 
     2102            (True, 1) 
     2103        """ 
     2104        a = (self.lower()).ceil() 
    18242105        b = (self.upper()).floor() 
    18252106        if a == b: 
    1826              
    18272107            return True, a 
    18282108        else: 
     
    19372217            sage: q2 = i.acos(); q2 
    19382218            [1.0471975511965974 ... 1.0471975511965981] 
    1939             sage: q2 == q 
    1940             True 
     2219            sage: q == q2 
     2220            False 
     2221            sage: q != q2 
     2222            False 
    19412223            sage: q2.lower() == q.lower() 
    19422224            False 
     
    19642246            sage: q2 = i.asin(); q2 
    19652247            [0.62831853071795851 ... 0.62831853071795885] 
    1966             sage: q2 == q 
    1967             True 
     2248            sage: q == q2 
     2249            False 
     2250            sage: q != q2 
     2251            False 
    19682252            sage: q2.lower() == q.lower() 
    19692253            False 
     
    19912275            sage: q2 = i.atan(); q2 
    19922276            [0.62831853071795851 ... 0.62831853071795885] 
    1993             sage: q2 == q 
    1994             True 
     2277            sage: q == q2 
     2278            False 
     2279            sage: q != q2 
     2280            False 
    19952281            sage: q2.lower() == q.lower() 
    19962282            False 
     
    22542540 
    22552541def is_RealIntervalFieldElement(x): 
    2256     return PY_TYPE_CHECK(x, RealIntervalFieldElementClass) 
     2542    return PY_TYPE_CHECK(x, RealIntervalFieldElement) 
    22572543 
    22582544 
     
    22642550def __create__RealIntervalFieldElement_version0(parent, x, base=10): 
    22652551    return RealIntervalFieldElement(parent, x, base=base) 
    2266  
  • sage/server/notebook/cell.py

    r3136 r3150  
    491491        dir = self.directory() 
    492492        D = os.listdir(dir) 
     493        D.sort() 
    493494        if len(D) == 0: 
    494495            return '' 
     
    547548        r = '' 
    548549        r += '&nbsp;'*(7-len(r)) 
    549         if do_print: 
    550             btn = "" 
    551         else: 
    552             btn = """ 
    553                 <span class="hidden" id="evaluate_button_%s"><img 
    554                     src="/evaluate.png"  
    555                     onMouseOver="this.src='/evaluate_over.png'" 
    556                     onMouseOut="this.src='/evaluate.png'"  
    557                     onClick="evaluate_cell(%s,0);"></span> 
    558                   """%(self.__id,self.__id) 
    559         tbl = btn + """ 
     550##         if do_print: 
     551##             btn = "" 
     552##         else: 
     553##             btn = """ 
     554##                 <span class="hidden" id="evaluate_button_%s"><img 
     555##                     src="/evaluate.png"  
     556##                     onMouseOver="this.src='/evaluate_over.png'" 
     557##                     onMouseOut="this.src='/evaluate.png'"  
     558##                     onClick="evaluate_cell(%s,0);"></span> 
     559##                   """%(self.__id,self.__id) 
     560##        tbl = btn + """ 
     561        tbl = """ 
    560562               <table class="cell_output_box"><tr> 
    561563               <td class="cell_number" id="cell_number_%s" onClick="cycle_cell_output_type(%s);"> 
  • sage/server/notebook/css.py

    r3126 r3145  
    923923  color:#000000; 
    924924  background-color: #e8e8e8; 
    925   border: 0px solid white; 
    926   /* border-left: 2px solid green; */ 
     925  border: 2px solid white; 
    927926  font-family: courier, monospace; 
    928927  font-size:12pt; 
    929 /*  overflow:hidden; */ 
    930928  overflow:auto; 
    931929  padding-left:5px; 
    932930  padding-top:3px; 
    933931  padding-bottom:0px; 
    934 /*  margin:0px; */ 
    935932  width: 100%; 
    936933  margin-bottom:0px; 
  • sage/server/notebook/js.py

    r3126 r3153  
    761761    e.className="cell_input_active"; 
    762762    cell_input_resize(e); 
    763     set_class('evaluate_button_'+id, 'evaluate_button') 
     763    /* set_class('evaluate_button_'+id, 'evaluate_button') */ 
    764764    return true; 
    765765} 
     
    771771    e.className="cell_input";  
    772772    cell_input_minimize_size(e); 
    773     setTimeout("set_class('evaluate_button_"+id+"', 'hidden')", 100); 
     773    /* setTimeout("set_class('evaluate_button_"+id+"', 'hidden')", 100); */ 
    774774    return true; 
    775775} 
     
    819819 
    820820function cell_input_resize(cell_input) { 
    821     var rows = 2; 
    822     //var rows = cell_input.value.split('\n').length - 1; 
    823821    var rows = cell_input.value.split('\n').length + 1; 
    824     if (rows <= 1) { 
    825       rows = 2; 
    826     } else { 
    827       /* to avoid bottom chop off */ 
    828 /*      rows = rows + 1; */ 
     822    if (rows < 1) { 
     823      rows = 1; 
    829824    } 
    830825    try { 
    831         cell_input.style.height = rows + 'em'; // this sort of works in konqueror... 
     826        cell_input.style.height = 1.3*rows + 'em'; // this sort of works in konqueror... 
    832827    } catch(e) {} 
    833     try{ 
     828/*    try{ 
    834829        cell_input.rows = rows; 
    835830    } catch(e) {} 
     831    */ 
    836832 
    837833    if(slide_hidden) { 
     
    861857    
    862858    cell_input.className = 'cell_input'; 
    863     var rows = v.split('\n').length ; 
     859    var rows = v.split('\n').length + 1; 
    864860    if (rows < 1) { 
    865861      rows = 1; 
    866862    } 
    867     cell_input.rows = rows; 
     863    try { 
     864        cell_input.style.height = 1.3*rows + 'em'; // this sort of works in konqueror... 
     865    } catch(e) {} 
     866   /*    try{ 
     867        cell_input.rows = rows; 
     868    } catch(e) {} 
     869    */ 
    868870    if (rows == 1) { 
    869871       // hack because of bug in firefox with 1-row textarea 
  • sage/structure/element.pxd

    r2866 r3141  
    1212cdef class Element(sage_object.SageObject): 
    1313    cdef ParentWithBase _parent 
     14    cdef _richcmp_c_impl(left, Element right, int op) 
    1415    cdef int _cmp_c_impl(left, Element right) except -2 
    1516    cdef public _richcmp(self, right, int op) 
     17    cdef public _cmp(self, right) 
    1618    cdef _set_parent_c(self, ParentWithBase parent) 
    1719    cdef base_extend_c(self, ParentWithBase R)       # do *NOT* override, but OK to call directly 
  • sage/structure/element.pyx

    r3074 r3143  
    315315        return PyBool_FromLong(self == self._parent(0)) 
    316316 
    317     def _richcmp_(left, right, op): 
    318         return left._richcmp(right, op) 
    319  
    320     cdef _richcmp(left, right, int op): 
    321         """ 
    322         Compare left and right.  
     317    def _cmp_(left, right): 
     318        return left._cmp(right) 
     319 
     320    cdef _cmp(left, right): 
     321        """ 
     322        Compare left and right. 
    323323        """ 
    324324        cdef int r 
     
    326326            try: 
    327327                _left, _right = canonical_coercion_c(left, right) 
    328                 r = cmp(_left, _right) 
     328                if PY_IS_NUMERIC(_left): 
     329                    return cmp(_left, _right) 
     330                else: 
     331                    return _left._cmp_(_right) 
    329332            except TypeError: 
    330333                r = cmp(type(left), type(right)) 
    331334                if r == 0: 
    332335                    r = -1 
     336                return r 
     337        else: 
     338            return left._cmp_c_impl(right) 
     339 
     340    def _richcmp_(left, right, op): 
     341        return left._richcmp(right, op) 
     342 
     343    cdef _richcmp(left, right, int op): 
     344        """ 
     345        Compare left and right, according to the comparison operator op. 
     346        """ 
     347        cdef int r 
     348        if not have_same_parent(left, right): 
     349            try: 
     350                _left, _right = canonical_coercion_c(left, right) 
     351                if PY_IS_NUMERIC(_left): 
     352                    r = cmp(_left, _right) 
     353                else: 
     354                    return _left._richcmp_(_right, op) 
     355            except TypeError: 
     356                r = cmp(type(left), type(right)) 
     357                if r == 0: 
     358                    r = -1 
    333359        else: 
    334360            if HAS_DICTIONARY(left):   # fast check 
    335361                r = left.__cmp__(right) 
    336362            else: 
    337                 r = left._cmp_c_impl(right) 
     363                return left._richcmp_c_impl(right, op) 
    338364 
    339365        return left._rich_to_bool(op, r) 
     
    357383    # your subclasses, in order for it to take advantage of the 
    358384    # above generic comparison code.  You must also define 
    359     # _cmp_c_impl. 
     385    # either _cmp_c_impl (if your subclass is totally ordered), 
     386    # _richcmp_c_impl (if your subclass is partially ordered), or both 
     387    # (if your class has both a total order and a partial order; 
     388    # then the total order will be available with cmp(), and the partial 
     389    # order will be available with the relation operators; in this case 
     390    # you must also define __cmp__ in your subclass). 
    360391    # This is simply how Python works. 
    361392    # 
     
    367398        return (<Element>left)._richcmp(right, op) 
    368399     
     400    #################################################################### 
     401    # If your subclass has both a partial order (available with the 
     402    # relation operators) and a total order (available with cmp()), 
     403    # you **must** put the following in your subclass. 
     404    #  
     405    # Note that in this case the total order defined by cmp() will 
     406    # not properly respect coercions. 
     407    #################################################################### 
     408    def __cmp__(left, right): 
     409        return (<Element>left)._cmp(right) 
     410 
     411    cdef _richcmp_c_impl(left, Element right, int op): 
     412        return left._rich_to_bool(op, left._cmp_c_impl(right)) 
     413 
    369414    cdef int _cmp_c_impl(left, Element right) except -2: 
    370415        ### For derived SAGEX code, you *MUST* ALSO COPY the __richcmp__ above 
    371416        ### into your class!!!  For Python code just use __cmp__. 
    372417        raise NotImplementedError, "BUG: sort algorithm for elements of '%s' not implemented"%right.parent() 
    373  
    374     def __cmp__(left, right): 
    375         return left._cmp_c_impl(right)   # default 
    376418 
    377419def is_ModuleElement(x): 
Note: See TracChangeset for help on using the changeset viewer.