Changes in [3172:2b664e2fb661:3173:8ef6a6e960f0]
- Location:
- sage
- Files:
-
- 2 added
- 24 edited
-
ext/random.pxi (modified) (1 diff)
-
functions/transcendental.py (modified) (2 diffs)
-
graphs/graph.py (modified) (6 diffs)
-
graphs/graph_fast.pyx (modified) (1 diff)
-
gsl/README.txt (added)
-
interfaces/macaulay2.py (modified) (1 diff)
-
interfaces/octave.py (modified) (2 diffs)
-
libs/ntl/ntl.pyx (modified) (1 diff)
-
libs/pari/gen.pyx (modified) (4 diffs)
-
misc/hg.py (modified) (1 diff)
-
modules/module.pyx (modified) (2 diffs)
-
plot/mpl3d/nodoctest.py (added)
-
plot/plot.py (modified) (38 diffs)
-
plot/tachyon.py (modified) (1 diff)
-
rings/complex_double.pyx (modified) (1 diff)
-
rings/integer_mod.pyx (modified) (1 diff)
-
rings/mpfi.pxi (modified) (1 diff)
-
rings/mpfr.pxi (modified) (1 diff)
-
rings/rational_field.py (modified) (1 diff)
-
rings/real_double.pyx (modified) (1 diff)
-
rings/real_mpfi.pyx (modified) (18 diffs)
-
server/notebook/cell.py (modified) (2 diffs)
-
server/notebook/css.py (modified) (1 diff)
-
server/notebook/js.py (modified) (4 diffs)
-
structure/element.pxd (modified) (1 diff)
-
structure/element.pyx (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/ext/random.pxi
r2802 r3154 6 6 long random() 7 7 void srandom(unsigned int seed) 8 k = randrange(0, 2**32)8 k = randrange(0, int(2)**32) 9 9 srandom(k) 10 10 -
sage/functions/transcendental.py
r2641 r3149 33 33 return x 34 34 35 I = complex_field.ComplexField().gen(0) 35 CC = complex_field.ComplexField() 36 I = CC.gen(0) 36 37 def __eval(x): 37 38 return eval(x) … … 88 89 """ 89 90 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() 95 104 96 105 def gamma_inc(s, t): 97 106 """ 98 107 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 111 128 112 129 # synonym. -
sage/graphs/graph.py
r3136 r3167 13 13 -- Robert L. Miller (2007-02-12): vertex color-maps, graph boundaries, 14 14 graph6 helper functions in SageX 15 SAGE Days 3 (2007-02-17--21): 3d plotting in Tachyon, 15 16 16 17 TUTORIAL: … … 1462 1463 sage: pl.save('sage.png') 1463 1464 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') 1467 1468 """ 1468 1469 GG = Graphics() … … 1511 1512 return GG 1512 1513 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 1513 1582 def show(self, pos=None, layout=None, vertex_labels=True, node_size=200, graph_border=False, color_dict=None, **kwds): 1514 1583 """ … … 1550 1619 """ 1551 1620 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) 1552 1644 1553 1645 class DiGraph(GenericGraph): … … 2651 2743 return GG 2652 2744 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 2653 2820 def show(self, pos=None, vertex_labels=True, node_size=200, graph_border=False, color_dict=None, **kwds): 2654 2821 """ … … 2688 2855 self.plot(pos, vertex_labels, node_size=node_size, color_dict=color_dict, graph_border=graph_border).show(**kwds) 2689 2856 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 42 42 """ 43 43 # 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) 45 45 46 46 # split into groups of 6, and convert numbers to decimal, adding 63 -
sage/interfaces/macaulay2.py
r3043 r3157 408 408 sage: X.structure_sheaf() # optional 409 409 OO 410 sage 6410 sage1 411 411 """ 412 412 return self.parent()('OO_%s'%self.name()) -
sage/interfaces/octave.py
r1908 r3158 125 125 sage: octave.eval("b = [ 1; 3; 13]") # optional 126 126 '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 128 128 'c =\n\n 1\n -0\n 0\n\n' 129 sage: print octave.eval("c") # optional129 sage: octave.eval("c") # optional random output 130 130 c = 131 131 <BLANKLINE> … … 257 257 sage: V3 = VectorSpace(QQ,3) 258 258 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) 260 260 [-0.33333299999999999, 0.66666700000000001, 0] 261 261 -
sage/libs/ntl/ntl.pyx
r3170 r3173 168 168 if x is None: 169 169 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))) 171 171 else: 172 172 seed = make_new_ZZ(str(x)) -
sage/libs/pari/gen.pyx
r2843 r3145 4155 4155 return idealval(self.g, t0, t1) 4156 4156 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 4157 4166 def nfbasis(self, long flag=0, p=0): 4158 4167 cdef gen _p … … 4166 4175 return self.new_gen(nfbasis0(self.g, flag, g)) 4167 4176 4177 def nffactor(self, x): 4178 t0GEN(x) 4179 _sig_on 4180 return self.new_gen(nffactor(self.g, t0)) 4181 4168 4182 def nfgenerator(self): 4169 4183 f = self[0] … … 4196 4210 return self.new_gen(rnfelementreltoabs(self.g, t0)) 4197 4211 4198 def rnfequation(self, poly ):4212 def rnfequation(self, poly, long flag=0): 4199 4213 t0GEN(poly) 4200 4214 _sig_on 4201 return self.new_gen(rnfequation0(self.g, t0, 0))4215 return self.new_gen(rnfequation0(self.g, t0, flag)) 4202 4216 4203 4217 def rnfidealabstorel(self, x): … … 4403 4417 return self.new_gen(polrecip(self.g)) 4404 4418 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 4405 4427 def polresultant(self, y, var=-1, flag=0): 4406 4428 t0GEN(y) -
sage/misc/hg.py
r2687 r3166 172 172 t = tmp_filename() 173 173 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)) 175 176 self('serve --port %s'%port) 176 177 -
sage/modules/module.pyx
r2419 r3154 77 77 False 78 78 """ 79 return isinstance(x, Module)79 return bool(isinstance(x, Module)) 80 80 81 81 def is_VectorSpace(x): … … 94 94 """ 95 95 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)) 97 97 98 98 -
sage/plot/plot.py
r2999 r3156 441 441 Graphics object consisting of 1 graphics primitive 442 442 443 sage: G[1] = p[0];G 444 Graphics object consisting of 3 graphics primitives 443 sage: G[1] = p[0]; G.save() 445 444 446 445 """ … … 467 466 sage: g2 = plot(h2, 1, 5) 468 467 sage: h = g1 + g2 468 sage: h.save() 469 469 """ 470 470 if isinstance(other, int) and other == 0: … … 667 667 EXAMPLES: 668 668 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) 670 670 671 671 To correct the apect ratio of certain graphics, it is necessary 672 672 to show with a 'figsize' of square dimensions. 673 673 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) 675 675 """ 676 676 global do_verify … … 1587 1587 1588 1588 A straight, black arrow 1589 sage: a1 = arrow((1, 1), (3, 3)) 1589 sage: a1 = arrow((1, 1), (3, 3)) 1590 sage: a1.save() 1590 1591 1591 1592 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() 1593 1595 1594 1596 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() 1598 1599 """ 1599 1600 def _reset(self): … … 1617 1618 1618 1619 EXAMPLES: 1619 1620 A bar_chart with blue bars: 1620 A bar_chart with blue bars: 1621 1621 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: 1624 1625 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: 1627 1629 sage: bc3 = bar_chart([-3,5,-6,11], rgbcolor=(1,0,0)) 1630 sage: bc3.save() 1628 1631 1629 1632 """ … … 1658 1661 EXAMPLES: 1659 1662 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() 1661 1664 1662 1665 To correct the apect ratio of certain graphics, it is necessary 1663 1666 to show with a 'figsize' of square dimensions. 1664 1667 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) 1666 1669 1667 1670 Here we make an more complicated plot with many circles of different colors … … 1675 1678 ... ocur = (rnext-r)-ocur 1676 1679 ... 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]) 1678 1681 1679 1682 """ … … 1773 1776 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)] 1774 1777 sage: p = line(L, rgbcolor=(1/4,1/8,3/4)) 1778 sage: p.save() 1775 1779 1776 1780 A blue hypotrochoid (3 leaves): … … 1779 1783 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)] 1780 1784 sage: p = line(L, rgbcolor=(1/4,1/4,3/4)) 1785 sage: p.save() 1781 1786 1782 1787 A blue hypotrochoid (4 leaves): … … 1785 1790 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)] 1786 1791 sage: p = line(L, rgbcolor=(1/4,1/4,3/4)) 1792 sage: p.save() 1787 1793 1788 1794 A red limacon of Pascal: … … 1790 1796 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)] 1791 1797 sage: p = line(L, rgbcolor=(1,1/4,1/2)) 1798 sage: p.save() 1792 1799 1793 1800 A light green trisectrix of Maclaurin: … … 1795 1802 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)] 1796 1803 sage: p = line(L, rgbcolor=(1/4,1,1/8)) 1804 sage: p.save() 1797 1805 1798 1806 A green lemniscate of Bernoulli: … … 1801 1809 sage: L = [(a/(a^2+b^2), b/(a^2+b^2)) for a,b in v] 1802 1810 sage: p = line(L, rgbcolor=(1/4,3/4,1/8)) 1811 sage: p.save() 1803 1812 1804 1813 A red plot of the Jacobi elliptic function $\text{sn}(x,2)$, $-3<x<3$: … … 1806 1815 sage: L = [(i/100.0, maxima.eval('jacobi_sn (%s/100.0,2.0)'%i)) for i in range(-300,300)] 1807 1816 sage: p = line(L, rgbcolor=(3/4,1/4,1/8)) 1808 1817 sage: p.save() 1818 1809 1819 A red plot of $J$-Bessel function $J_2(x)$, $0<x<10$: 1810 1820 1811 1821 sage: L = [(i/10.0, maxima.eval('bessel_j (2,%s/10.0)'%i)) for i in range(100)] 1812 1822 sage: p = line(L, rgbcolor=(3/4,1/4,5/8)) 1823 sage: p.save() 1824 1813 1825 1814 1826 A purple plot of the Riemann zeta function $\zeta(1/2 + it)$, $0<t<30$: … … 1817 1829 sage: L = [(z.real(), z.imag()) for z in v] 1818 1830 sage: p = line(L, rgbcolor=(3/4,1/2,5/8)) 1831 sage: p.save() 1819 1832 1820 1833 A purple plot of the Hasse-Weil $L$-function $L(E, 1 + it)$, $-1<t<10$: … … 1824 1837 sage: L = [(z[1].real(), z[1].imag()) for z in vals] 1825 1838 sage: p = line(L, rgbcolor=(3/4,1/2,5/8)) 1839 sage: p.save() 1826 1840 1827 1841 A red, blue, and green "cool cat": … … 1832 1846 sage: Q = polygon([(-x,y) for x,y in P[0]], rgbcolor=(0,0,1)) 1833 1847 sage: H = G + P + Q 1848 sage: H.save() 1834 1849 """ 1835 1850 def _reset(self): … … 1868 1883 A matrix over ZZ colored with different grey levels: 1869 1884 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() 1872 1888 1873 1889 Here we make a random matrix over RR and use cmap='hsv' 1874 1890 to color the matrix elements different RGB colors: 1875 1891 1876 sage: n = 221877 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() 1881 1897 """ 1882 1898 def _reset(self): … … 1943 1959 sage: br = disk((0.0,0.0), 1, (3*pi/2, 2*pi), rgbcolor=(0,0,0)) 1944 1960 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) 1946 1962 1947 1963 """ … … 1970 1986 A purple point from a single tuple or coordinates: 1971 1987 sage: p1 = point((0.5, 0.5), rgbcolor=hue(0.75)) 1988 sage: p1.save() 1972 1989 1973 1990 Here are some random larger red points, given as a list of tuples 1974 1991 sage: p2 = point(((0.5, 0.5), (1, 2), (0.5, 0.9), (-1, -1)), rgbcolor=hue(1), pointsize=30) 1992 sage: p2.save() 1975 1993 1976 1994 """ … … 2017 2035 sage: L = [[cos(pi*i/3),sin(pi*i/3)] for i in range(6)] 2018 2036 sage: p = polygon(L, rgbcolor=(1,0,1)) 2037 sage: p.save() 2019 2038 2020 2039 A green deltoid: … … 2022 2041 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)] 2023 2042 sage: p = polygon(L, rgbcolor=(1/8,3/4,1/2)) 2043 sage: p.save() 2024 2044 2025 2045 A blue hypotrochoid: … … 2027 2047 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)] 2028 2048 sage: p = polygon(L, rgbcolor=(1/8,1/4,1/2)) 2029 2049 sage: p.save() 2050 2030 2051 Another one: 2031 2052 … … 2033 2054 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)] 2034 2055 sage: p = polygon(L, rgbcolor=(1/8,1/4,3/4)) 2056 sage: p.save() 2035 2057 2036 2058 A purple epicycloid: … … 2039 2061 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)] 2040 2062 sage: p = polygon(L, rgbcolor=(7/8,1/4,3/4)) 2063 sage: p.save() 2041 2064 2042 2065 A brown astroid: … … 2044 2067 sage: L = [[cos(pi*i/100)^3,sin(pi*i/100)^3] for i in range(200)] 2045 2068 sage: p = polygon(L, rgbcolor=(3/4,1/4,1/4)) 2069 sage: p.save() 2046 2070 2047 2071 And, my favorite, a greenish blob: … … 2049 2073 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)] 2050 2074 sage: p = polygon(L, rgbcolor=(1/8, 3/4, 1/2)) 2075 sage: p.save() 2051 2076 2052 2077 This one is for my wife: … … 2054 2079 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)] 2055 2080 sage: p = polygon(L, rgbcolor=(1,1/4,1/2)) 2081 sage: p.save() 2056 2082 2057 2083 AUTHORS: … … 2146 2172 sage: len(P[0]) # how many points were computed 2147 2173 201 2174 sage: P.save() # render 2175 2148 2176 sage: P = plot(sin, 0,10, plot_points=10); P 2149 2177 Graphics object consisting of 1 graphics primitive 2150 sage: len(P[0]) # random output2178 sage: len(P[0]) # random output 2151 2179 80 2180 sage: P.save() # render 2152 2181 2153 2182 Use \code{show(plot(sin, 0,10))} or \code{plot(sin,0,10).show()} … … 2158 2187 sage: def h1(x): return abs(sqrt(x^3 - 1)) 2159 2188 sage: def h2(x): return -abs(sqrt(x^3 - 1)) 2160 sage: plot([h1, h2], 1,4) # slightly random output because of random sampling2189 sage: P = plot([h1, h2], 1,4) # slightly random output because of random sampling 2161 2190 Graphics object consisting of 2 graphics primitives 2191 sage: P.save() 2162 2192 2163 2193 We can also directly plot the elliptic curve: 2164 2194 sage: E = EllipticCurve([0,-1]) 2165 2195 sage: P = plot(E, 1, 4, rgbcolor=hue(0.6)) 2196 sage: P.save() 2166 2197 2167 2198 We can change the line style to one of '--' (dashed), '-.' (dash dot), … … 2241 2272 data.append((x, float(y))) 2242 2273 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 2244 2276 # adaptive refinement 2245 2277 i, j = 0, 0 … … 2307 2339 sage: t2 = text("World", (1,0.5), horizontal_alignment="left") 2308 2340 2341 sage: (t1+t2).save() 2342 2309 2343 """ 2310 2344 def _reset(self): … … 2343 2377 sage: f = lambda t: sin(t) 2344 2378 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 primitive2379 sage: G = parametric_plot((f,g),0,2*pi,rgbcolor=hue(0.6)) 2380 sage: G.save() 2347 2381 """ 2348 2382 if show is None: … … 2358 2392 Here is a blue 8-leaved petal: 2359 2393 sage: p1 = polar_plot(lambda x:sin(5*x)^2, 0, 2*pi, rgbcolor=hue(0.6)) 2394 sage: p1.save() 2360 2395 2361 2396 A red figure-8: 2362 2397 sage: p2 = polar_plot(lambda x:abs(sqrt(1 - sin(x)^2)), 0, 2*pi, rgbcolor=hue(1.0)) 2398 sage: p2.save() 2363 2399 2364 2400 A green limacon of Pascal: 2365 2401 sage: p3 = polar_plot(lambda x:2 + 2*cos(x), 0, 2*pi, rgbcolor=hue(0.3)) 2402 sage: p3.save() 2366 2403 2367 2404 """ … … 2382 2419 2383 2420 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: 2387 2425 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() 2392 2428 2393 2429 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 primitive2430 sage: L = list_plot(r, plotjoined=True, rgbcolor=(1,0,1)) 2431 sage: L.save() 2396 2432 """ 2397 2433 if show is None: … … 2440 2476 (0.0, 0.40000000000000036, 1.0) 2441 2477 2442 hue is an easy way of getting a broader2443 range of colors for graphics2478 hue is an easy way of getting a broader 2479 range of colors for graphics 2444 2480 2445 2481 sage: p = plot(sin, -2, 2, rgbcolor=hue(0.6)) 2482 sage: p.save() 2446 2483 2447 2484 """ … … 2618 2655 2619 2656 sage: ga = graphics_array(((p1,p2),(p3,p4))) 2657 sage: ga.save() 2620 2658 2621 2659 Here we give only one row: 2622 2660 sage: p1 = plot(sin,-4,4) 2623 2661 sage: p2 = plot(cos,-4,4) 2624 sage: g raphics_array([p1, p2])2662 sage: g = graphics_array([p1, p2]); g 2625 2663 Graphics Array of size 1 x 2 2664 sage: g.save() 2626 2665 2627 2666 """ … … 2633 2672 return GraphicsArray(array) 2634 2673 2674 """ 2675 Clean 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 223 223 self.save(filename, verbose=verbose, extra_opts=extra_opts) 224 224 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)) 226 228 227 229 -
sage/rings/complex_double.pyx
r3124 r3148 303 303 return real_double.RDF 304 304 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 305 316 def new_ComplexDoubleElement(): 306 317 cdef ComplexDoubleElement z -
sage/rings/integer_mod.pyx
r2817 r3154 95 95 True 96 96 """ 97 return isinstance(x, IntegerMod_abstract)97 return bool(isinstance(x, IntegerMod_abstract)) 98 98 99 99 def makeNativeIntStruct(sage.rings.integer.Integer z): -
sage/rings/mpfi.pxi
r2617 r3140 4 4 cdef extern from "mpfi.h": 5 5 ctypedef struct __mpfi_struct: 6 pass 6 __mpfr_struct left 7 __mpfr_struct right 7 8 #ctypedef __mpfi_struct mpfi_t[1] 8 9 ctypedef __mpfi_struct* mpfi_t -
sage/rings/mpfr.pxi
r2616 r3140 130 130 int mpfr_neg (mpfr_ptr rop, mpfr_srcptr op, mp_rnd_t rnd) 131 131 # 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) 133 134 int mpfr_cmp (mpfr_t op1, mpfr_t op2) -
sage/rings/rational_field.py
r2802 r3168 176 176 177 177 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 187 214 188 215 def complex_embedding(self, prec=53): -
sage/rings/real_double.pyx
r2869 r3148 209 209 210 210 EXAMPLES: 211 sage: R = RealField(100)212 211 sage: RDF.pi() 213 212 3.14159265359 -
sage/rings/real_mpfi.pyx
r2833 r3142 45 45 sage: a == 2 46 46 False 47 48 COMPARISONS: 49 50 Comparison operations (==,!=,<,<=,>,>=) return true if every value in 51 the first interval has the given relation to every value in the second 52 interval. The cmp(a, b) function works differently; it compares two 53 intervals lexicographically. (However, the behavior is not specified 54 if given a non-interval and an interval.) 55 56 This convention for comparison operators has good and bad points. The 57 good: 58 * Expected transitivity properties hold (if a > b and b == c, then a > c; 59 etc.) 60 * if a>b, then cmp(a, b) == 1; if a==b, then cmp(a,b) == 0; if a<b, then 61 cmp(a, b) == -1 62 * a==0 is true if the interval contains only the floating-point number 0; 63 similarly for a==1 64 * a>0 means something useful (that every value in the interval is greater 65 than 0) 66 67 The bad: 68 * Trichotomy fails to hold: there are values (a,b) such that none of a<b, 69 a==b, or a>b are true 70 * It is not the case that if cmp(a, b) == 0 then a==b, or that if 71 cmp(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 74 Note that intervals a and b overlap iff not(a != b). 75 76 EXAMPLES: 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 47 97 """ 48 98 … … 706 756 EXAMPLES: 707 757 sage: a = RIF(5,5.5) 708 sage: loads(dumps(a)) == a709 True758 sage: cmp(loads(dumps(a)), a) 759 0 710 760 sage: R = RealIntervalField(sci_not=1, prec=200) 711 761 sage: b = R('393.39203845902384098234098230948209384028340') 712 sage: loads(dumps(b)) == b713 True762 sage: cmp(loads(dumps(b)), b) 763 0 714 764 sage: b = R(1)/R(0); b 715 765 [+infinity ... +infinity] … … 722 772 sage: b = R('[2 ... 3]'); b 723 773 [2.0000000000000000000000000000000000000000000000000000000000000e0 ... 3.0000000000000000000000000000000000000000000000000000000000000e0] 724 sage: loads(dumps(b)) == b725 True774 sage: cmp(loads(dumps(b)), b) 775 0 726 776 """ 727 777 s = self.str(32, no_sci=False, e='@') … … 934 984 def relative_diameter(self): 935 985 """ 936 XXX This MPFI function is buggy!937 938 986 The relative diameter of this interval (for [a ... b], 939 987 this is (b-a)/((a+b)/2)), rounded upward, as a RealNumber. 940 988 941 989 EXAMPLES: 942 sage: RIF(1, pi).relative_diameter() # todo: not implemented 990 sage: RIF(1, pi).relative_diameter() 991 1.03418797197910 943 992 """ 944 993 cdef RealNumber x … … 949 998 def diameter(self): 950 999 """ 951 XXX This MPFI function is buggy!952 953 1000 If (0 in self), returns self.absolute_diameter(), 954 1001 otherwise self.relative_diameter(). … … 956 1003 EXAMPLES: 957 1004 sage: RIF(1, 2).diameter() 958 1.000000000000001005 0.666666666666666 959 1006 sage: RIF(1, 2).absolute_diameter() 960 1007 1.00000000000000 961 1008 sage: RIF(1, 2).relative_diameter() 962 1.000000000000001009 0.666666666666666 963 1010 sage: RIF(pi).diameter() 964 0.000000000000000 4440892098500621011 0.000000000000000141357985842822 965 1012 sage: RIF(pi).absolute_diameter() 966 1013 0.000000000000000444089209850062 967 1014 sage: RIF(pi).relative_diameter() 968 0.000000000000000 444089209850062969 sage: (RIF(pi) - RIF( pi).square().sqrt()).diameter()970 0. 00000000000000177635683940025971 sage: (RIF(pi) - RIF( pi).square().sqrt()).absolute_diameter()972 0. 00000000000000177635683940025973 sage: (RIF(pi) - RIF( pi).square().sqrt()).relative_diameter()974 +infinity1015 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 975 1022 """ 976 1023 cdef RealNumber x … … 994 1041 return x 995 1042 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 997 1059 998 1060 def center(self): … … 1442 1504 1443 1505 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(<.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(<.value.right, &rt.value.left)) \ 1671 and PyBool_FromLong(mpfr_lessequal_p(&rt.value.right, <.value.left)) 1672 elif op == 4: #> 1673 return PyBool_FromLong(mpfr_less_p(&rt.value.right, <.value.left)) 1674 elif op == 1: #<= 1675 return PyBool_FromLong(mpfr_lessequal_p(<.value.right, &rt.value.left)) 1676 elif op == 3: #!= 1677 return PyBool_FromLong(mpfr_less_p(<.value.right, &rt.value.left)) \ 1678 or PyBool_FromLong(mpfr_less_p(&rt.value.right, <.value.left)) 1679 elif op == 5: #>= 1680 return PyBool_FromLong(mpfr_lessequal_p(&rt.value.right, <.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) 1445 1709 1446 1710 cdef int _cmp_c_impl(left, Element right) except -2: 1447 1711 """ 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 1468 1718 1469 1719 cdef int i 1470 i = mpf i_cmp(self.value, x.value)1720 i = mpfr_cmp(<.value.left, &rt.value.left) 1471 1721 if i < 0: 1472 1722 return -1 1473 elif i == 0: 1474 return 0 1723 elif i > 0: 1724 return 1 1725 i = mpfr_cmp(<.value.right, &rt.value.right) 1726 if i < 0: 1727 return -1 1728 elif i > 0: 1729 return 1 1475 1730 else: 1476 return 1 1477 1731 return 0 1478 1732 1479 1733 def __contains__(self, other): … … 1511 1765 return False 1512 1766 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 1516 1795 1517 1796 def union(self, other): … … 1555 1834 def sqrt(self): 1556 1835 """ 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). 1563 1841 1564 1842 EXAMPLES: … … 1573 1851 [65.909028213136323 ... 65.909028213136339] 1574 1852 sage: r.sqrt()^2 == r 1853 False 1854 sage: r in r.sqrt()^2 1575 1855 True 1576 1856 sage: r.sqrt()^2 - r … … 1597 1877 """ 1598 1878 Return a square root of self. An interval will always be 1599 returned (though it will be NaN if self is n egative).1879 returned (though it will be NaN if self is nonpositive). 1600 1880 1601 1881 EXAMPLES: … … 1818 2098 sage: a.is_int() 1819 2099 (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() 1824 2105 b = (self.upper()).floor() 1825 2106 if a == b: 1826 1827 2107 return True, a 1828 2108 else: … … 1937 2217 sage: q2 = i.acos(); q2 1938 2218 [1.0471975511965974 ... 1.0471975511965981] 1939 sage: q2 == q 1940 True 2219 sage: q == q2 2220 False 2221 sage: q != q2 2222 False 1941 2223 sage: q2.lower() == q.lower() 1942 2224 False … … 1964 2246 sage: q2 = i.asin(); q2 1965 2247 [0.62831853071795851 ... 0.62831853071795885] 1966 sage: q2 == q 1967 True 2248 sage: q == q2 2249 False 2250 sage: q != q2 2251 False 1968 2252 sage: q2.lower() == q.lower() 1969 2253 False … … 1991 2275 sage: q2 = i.atan(); q2 1992 2276 [0.62831853071795851 ... 0.62831853071795885] 1993 sage: q2 == q 1994 True 2277 sage: q == q2 2278 False 2279 sage: q != q2 2280 False 1995 2281 sage: q2.lower() == q.lower() 1996 2282 False … … 2254 2540 2255 2541 def is_RealIntervalFieldElement(x): 2256 return PY_TYPE_CHECK(x, RealIntervalFieldElement Class)2542 return PY_TYPE_CHECK(x, RealIntervalFieldElement) 2257 2543 2258 2544 … … 2264 2550 def __create__RealIntervalFieldElement_version0(parent, x, base=10): 2265 2551 return RealIntervalFieldElement(parent, x, base=base) 2266 -
sage/server/notebook/cell.py
r3136 r3150 491 491 dir = self.directory() 492 492 D = os.listdir(dir) 493 D.sort() 493 494 if len(D) == 0: 494 495 return '' … … 547 548 r = '' 548 549 r += ' '*(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 = """ 560 562 <table class="cell_output_box"><tr> 561 563 <td class="cell_number" id="cell_number_%s" onClick="cycle_cell_output_type(%s);"> -
sage/server/notebook/css.py
r3126 r3145 923 923 color:#000000; 924 924 background-color: #e8e8e8; 925 border: 0px solid white; 926 /* border-left: 2px solid green; */ 925 border: 2px solid white; 927 926 font-family: courier, monospace; 928 927 font-size:12pt; 929 /* overflow:hidden; */930 928 overflow:auto; 931 929 padding-left:5px; 932 930 padding-top:3px; 933 931 padding-bottom:0px; 934 /* margin:0px; */935 932 width: 100%; 936 933 margin-bottom:0px; -
sage/server/notebook/js.py
r3126 r3153 761 761 e.className="cell_input_active"; 762 762 cell_input_resize(e); 763 set_class('evaluate_button_'+id, 'evaluate_button')763 /* set_class('evaluate_button_'+id, 'evaluate_button') */ 764 764 return true; 765 765 } … … 771 771 e.className="cell_input"; 772 772 cell_input_minimize_size(e); 773 setTimeout("set_class('evaluate_button_"+id+"', 'hidden')", 100);773 /* setTimeout("set_class('evaluate_button_"+id+"', 'hidden')", 100); */ 774 774 return true; 775 775 } … … 819 819 820 820 function cell_input_resize(cell_input) { 821 var rows = 2;822 //var rows = cell_input.value.split('\n').length - 1;823 821 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; 829 824 } 830 825 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... 832 827 } catch(e) {} 833 try{828 /* try{ 834 829 cell_input.rows = rows; 835 830 } catch(e) {} 831 */ 836 832 837 833 if(slide_hidden) { … … 861 857 862 858 cell_input.className = 'cell_input'; 863 var rows = v.split('\n').length ;859 var rows = v.split('\n').length + 1; 864 860 if (rows < 1) { 865 861 rows = 1; 866 862 } 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 */ 868 870 if (rows == 1) { 869 871 // hack because of bug in firefox with 1-row textarea -
sage/structure/element.pxd
r2866 r3141 12 12 cdef class Element(sage_object.SageObject): 13 13 cdef ParentWithBase _parent 14 cdef _richcmp_c_impl(left, Element right, int op) 14 15 cdef int _cmp_c_impl(left, Element right) except -2 15 16 cdef public _richcmp(self, right, int op) 17 cdef public _cmp(self, right) 16 18 cdef _set_parent_c(self, ParentWithBase parent) 17 19 cdef base_extend_c(self, ParentWithBase R) # do *NOT* override, but OK to call directly -
sage/structure/element.pyx
r3074 r3143 315 315 return PyBool_FromLong(self == self._parent(0)) 316 316 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. 323 323 """ 324 324 cdef int r … … 326 326 try: 327 327 _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) 329 332 except TypeError: 330 333 r = cmp(type(left), type(right)) 331 334 if r == 0: 332 335 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 333 359 else: 334 360 if HAS_DICTIONARY(left): # fast check 335 361 r = left.__cmp__(right) 336 362 else: 337 r = left._cmp_c_impl(right)363 return left._richcmp_c_impl(right, op) 338 364 339 365 return left._rich_to_bool(op, r) … … 357 383 # your subclasses, in order for it to take advantage of the 358 384 # 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). 360 391 # This is simply how Python works. 361 392 # … … 367 398 return (<Element>left)._richcmp(right, op) 368 399 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 369 414 cdef int _cmp_c_impl(left, Element right) except -2: 370 415 ### For derived SAGEX code, you *MUST* ALSO COPY the __richcmp__ above 371 416 ### into your class!!! For Python code just use __cmp__. 372 417 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) # default376 418 377 419 def is_ModuleElement(x):
Note: See TracChangeset
for help on using the changeset viewer.
