Sage Days 14 Talk system:sage
{{{id=215| /// }}} {{{id=2| /// }}}
![]() ![]() ![]() ![]() ![]() |
{{{id=117| /// }}} {{{id=214| /// }}}
Each day about 1500-2000 different real human visitors each day.
Sage Devel Headquarters: Four 24-core Sun X4450's with 128GB RAM each + 1 Sun X4540 with 24TB disk
Symbolic expressions:
{{{id=23| x, y = var('x,y') type(x) ///We can also copy this matrix over to Maple and compute the same determinant there...
{{{id=167| a[0,0] /// -57511480170851074417469190457182575086 }}} {{{id=27| maple.with_package('LinearAlgebra') B = maple(a) t = maple.cputime() time c = B.Determinant() maple.cputime(t) /// Time: CPU 0.00 s, Wall: 23.42 s 21.962 }}} {{{id=168| c == d /// True }}}This ability to easily move objects between math software is unique to Sage.
{{{id=82| B = magma(a) t = magma.cputime() time e = B.Determinant() magma.cputime(t) /// Time: CPU 0.00 s, Wall: 11.01 s 10.75 }}} {{{id=208| e == d /// True }}} {{{id=261| import scipy.stats /// }}} {{{id=262| /// }}} {{{id=260| [ZZ.random_element(-5,5) for _ in [1..1000]] /// [-3, -3, 3, -3, 2, 1, 4, -1, -2, -5, -4, -3, 3, -1, -1, 0, -1, 0, 2, -2, 2, 1, 4, 4, 3, 4, 0, -1, -2, -1, -2, 0, 1, 3, -4, 4, 0, -3, -3, 3, -4, -1, 1, 0, 3, 0, -1, -3, 2, 4, -5, -3, -5, -2, -3, -1, 4, 2, 0, -1, -4, 0, -4, -5, 0, 1, 2, 2, 1, 1, -5, 3, 1, -3, -1, 2, 0, -3, 4, 1, 3, 2, -1, -1, 2, -2, -2, 2, 2, 4, -5, 2, -1, -3, 2, 3, -5, 3, -4, -2, -2, -3, 0, -5, -3, 0, 4, 4, 0, -5, -3, -3, 3, -5, 4, -3, -5, 1, 4, -3, 1, -1, 2, 2, 2, -1, 3, 3, -4, 1, -5, 3, 0, -1, -1, -4, -3, 3, 1, -5, -5, -2, -2, 1, -4, -2, 4, -3, 1, -3, 1, 2, -3, -4, -4, 0, -5, -4, -1, 2, -2, 2, 2, 4, 3, -3, -5, 0, -1, 2, 1, -4, 1, 4, 4, -5, 4, 3, -1, -5, -3, -5, 2, 4, 3, -4, 1, -3, -3, -4, 3, -2, -4, 4, 2, 1, 0, -1, 1, 4, -5, -5, -2, -3, 1, -5, -5, -3, -2, 1, -1, 4, 4, -5, -4, -5, 4, -4, 1, 4, 4, -4, -5, 2, -1, -3, -1, 4, 0, 0, -4, -5, 0, 1, 0, -5, 4, 0, -1, 2, 1, -1, -5, -2, 2, -5, 1, 0, -4, 3, 0, -5, 4, 3, -2, 4, 4, 0, -3, 1, 1, 1, -2, 0, -3, -4, -3, -4, -5, 1, 0, 2, 3, 3, 3, -2, 3, 0, -2, 2, 3, 4, -5, 1, 3, -5, 1, -4, -2, 4, -3, 4, -1, 1, 1, 3, -2, 1, 4, 3, 2, 4, -5, -2, -3, 4, 1, -4, 3, 3, 4, -5, -4, 0, -4, -4, 1, 4, -2, 0, 0, -4, -4, 0, -5, -2, -3, -2, -1, -5, 2, -5, 4, -5, -4, 0, -3, 0, 3, 4, 0, -2, -2, 2, 4, -4, -3, 3, 2, 3, 0, -4, 1, -3, -1, -3, -4, -1, -5, 0, -3, 0, -5, 2, -3, -4, -3, 3, -1, -3, 0, 0, -4, -1, -2, -2, 2, -4, 1, -5, 1, -2, 0, 2, -5, 2, -5, -3, -3, -2, 2, 4, 3, 3, -4, 0, 2, -3, -1, 1, -3, 0, 1, 4, -2, 3, 2, 2, 4, -3, 2, 3, 0, 1, -3, -4, -3, 0, -4, 0, -3, -1, -3, -5, -2, 4, 4, 3, -3, 0, 3, 2, -2, -3, 2, -4, -2, -5, -5, -2, -3, -5, -4, -2, 0, 2, -5, 1, -3, -4, -4, -2, -5, 3, 1, 3, 2, 4, 3, 3, 2, 2, -5, 1, 4, -5, -1, 4, -2, -2, -3, 3, -3, 1, -5, 3, 0, 2, 1, -1, 3, 4, 4, -5, 3, -3, -3, 3, -2, -4, -2, 1, -3, -3, -4, 4, -4, 4, -1, -5, 0, 3, -5, 3, 3, -3, -2, -5, -3, -3, 3, 1, -4, -1, 0, -2, -4, -2, -2, 1, 1, -2, -1, -2, -3, -5, 4, 2, -2, 0, 3, 2, -5, -2, -4, 0, -3, -3, 4, 0, -3, -1, -4, -4, -1, -2, -2, 2, 2, -3, -1, -4, 2, 1, 2, 4, 3, -3, -2, 2, -5, -3, 4, 1, 4, 2, 4, 4, 4, 2, -2, 1, -2, -1, 3, -4, 3, -4, -2, -4, 1, -5, -2, -5, -5, 1, -4, 0, 4, -5, 0, -3, 4, -3, 0, -4, -2, -3, -1, -4, 0, 2, -4, -3, -3, -4, 1, 2, 3, 0, 2, -4, -1, 2, 2, 4, -1, -4, -2, -2, 1, 3, 1, -3, -4, 1, -2, 0, -5, 2, 3, -1, -3, -1, 2, 3, 1, -2, -4, -1, 0, -5, -4, 4, 4, 2, -2, -4, -5, 4, -3, -1, 4, -4, 4, 3, 1, 1, -4, 4, -1, 4, 1, -4, 4, -2, 3, 3, 2, -1, -1, 4, 4, 2, 0, -1, 2, -3, 2, 2, -2, -2, 3, 0, 2, 2, 0, 4, -3, 2, 4, -4, 3, 3, 0, 0, 1, -5, -1, -3, 0, 3, 2, -1, 3, -4, -3, -5, -4, -4, 4, -2, 3, 3, 0, -3, -4, 0, 2, -1, 0, 0, 4, 3, 4, 2, 2, -1, -2, -4, 4, 2, -3, -2, -5, -1, -4, 2, 2, 1, -2, -1, -3, 3, 0, -1, -1, 2, 4, 4, 3, 4, -1, -1, 3, 4, 0, 1, 3, 1, 0, -3, 1, -3, 1, 0, -1, -3, -3, 1, -4, -2, -1, 0, 3, 3, -5, 4, -1, -4, 0, 2, 0, -4, 1, -5, 1, -2, 4, 4, 3, -2, 1, 4, 2, 2, -4, 0, 2, -5, 3, 1, 2, -4, -3, 4, 2, 4, 4, 0, 4, 4, -5, -1, -4, -5, -2, 2, -1, -4, -4, 0, 1, 1, -2, 4, -3, 0, 4, 4, 2, -3, -3, -3, -5, 3, -4, -1, -2, -1, 0, -1, -1, -2, 1, 2, -2, -4, 3, 1, -5, 2, -3, 4, -4, -2, 0, 2, -4, 1, -4, 3, 3, -3, 2, -5, -1, 1, -2, -2, -3, 4, 4, 3, -4, -1, 0, 2, 4, 2, -2, 4, -5, -4, 4, -2, -3, -1, 3, 0, 3, -2, -3, -5, 2, -4, 4, 3, -3, -2, -2, -5, -4, 2, -5, -2, 4, -2, -5, 0, 2, 4, 1, -5, -5, 0, -1, 0, -1, 0, 2, 0, 4, -4, 2, 0, -3, -4, -3, -1, -2, 1, -1, 3, -1, 3, 1, 0, 0, 3, 3, 4, -4, -2, -4, 2, 3, 4, 4, 2, -4, -3, 2, -2, 4, -2, -3, -3, -2, 0, 0, -3, -3, 4, -3, -5, 0, -2, -5, -3, 4, 1, -5, 2, 3, -5, -3, -4, -2, -5, -3, 0, -2, -3, 4, 3, -5, 0, 1, -5, -1, -4, 2, -1, -2, -3, -3, -2, -2, -5] }}} {{{id=259| QQ.random_element?? /// }}} {{{id=25| /// }}}Plotting functions has similar syntax to Mathematica:
{{{id=109| plot(f,(0.01,2), thickness=4) + text("Mathematica-style plotting in Sage", (1,-2), rgbcolor='black') /// }}}NOTE: Sage also has 2d plotting that is almost identical to MATLAB's 2d plotting:
The command maple(...) fires up Maple (if you have it!), and creates a reference to a live object:
{{{id=0| m = maple(f); m /// sin(3*x)*x+ln(x)+1/(x+1)^2 }}} {{{id=89| type(m) ///Use Maple objects via a Pythonic notation:
{{{id=88| show(m.integrate('x')) ///This illustrates pylab (matplotlib + numpy), Sage plotting, html output, and @interact.
{{{id=97| # first just play import pylab A = pylab.imread(DATA + 'simons.png') graphics_array([matrix_plot(A), matrix_plot(A[0:,0:,1]*A[0:,0:,1])]).show(figsize=[10,4]) /// }}} {{{id=174| A[0,0,] /// array([ 0.03529412, 0.04705882, 0.01960784, 1. ], dtype=float32) }}} {{{id=44| import pylab A_image = pylab.mean(pylab.imread(DATA + 'simons.png'), 2) @interact def svd_image(i=(20,(1..100)), j=[1..30], display_axes=True, m=matrix(QQ,2,2), color=Color('red'), f=sin(x^2)): u,s,v = pylab.linalg.svd(A_image) A = sum(s[j]*pylab.outer(u[0:,j], v[j,0:]) for j in range(i)) g = graphics_array([matrix_plot(A),matrix_plot(A_image)]) show(g, axes=display_axes, figsize=(8,3)) html('
|
|
3d plotting (using jmol) is fast even though it does not use Java3d or OpenGL or require any special signed code or drivers.
{{{id=53| # Yoda! -- over 50,000 triangles. from scipy import io X = io.loadmat(DATA + 'yodapose.mat') from sage.plot.plot3d.index_face_set import IndexFaceSet V = X['V']; F3=X['F3']-1; F4=X['F4']-1 Y = IndexFaceSet(F3,V,color='green') + IndexFaceSet(F4,V,color='green') Y = Y.rotateX(-1) Y.show(aspect_ratio=[1,1,1], frame=False, figsize=4) html('"Use the source, Luke..."') /// "Use the source, Luke..." }}} {{{id=145| /// }}}
to sage-support date Sat, Jan 31, 2009 at 11:15 AM Hi, I received first a MemoryError, and later on Sage reported: uitkomst1=[] uitkomst2=[] eind=int((10^9+2)/(2*sqrt(3))) print eind for y in srange(1,eind): test1=is_square(3*y^2+1,True) test2=is_square(48*y^2+1,True) if test1[0] and test1[1]%3==2: uitkomst1.append((y,(2*test1[1]-1)/3)) if test2[0] and test2[1]%3==1: uitkomst2.append((y,(2*test2[1]+1)/3)) print uitkomst1 een=sum([3*x-1 for (y,x) in uitkomst1 if 3*x-1<10^9]) print uitkomst2 twee=sum([3*x+1 for (y,x) in uitkomst2 if 3*x+1<10^9]) print een+twee If you replace 10^9 with 10^6, the above listing works properly. Maybe I made a mistake? Rolandb
I rewrote Roland's code slightly so it wouldn't waste memory by constructing big lists... but the result was slow.
{{{id=150| def f_python(n): uitkomst1=[] uitkomst2=[] eind=int((n+2)/(2*sqrt(3))) print eind for y in (1..eind): test1=is_square(3*y^2+1,True) test2=is_square(48*y^2+1,True) if test1[0] and test1[1]%3==2: uitkomst1.append((y,(2*test1[1]-1)/3)) if test2[0] and test2[1]%3==1: uitkomst2.append((y,(2*test2[1]+1)/3)) print uitkomst1 een=sum(3*x-1 for (y,x) in uitkomst1 if 3*x-1<10^9) print uitkomst2 twee=sum(3*x+1 for (y,x) in uitkomst2 if 3*x+1<10^9) print een+twee /// }}} {{{id=182| time f_python(10^5) /// 28868 [(1, 1), (15, 17), (209, 241), (2911, 3361)] [(1, 5), (14, 65), (195, 901), (2716, 12545)] 51408 Time: CPU 0.72 s, Wall: 0.77 s }}} {{{id=8| time f_python(10^6) /// 288675 [(1, 1), (15, 17), (209, 241), (2911, 3361), (40545, 46817)] [(1, 5), (14, 65), (195, 901), (2716, 12545), (37829, 174725)] 716034 Time: CPU 7.14 s, Wall: 7.65 s }}}Rewrite using CYTHON
{{{id=1| %cython from sage.all import is_square cdef extern from "math.h": long double sqrtl(long double) def f(n): uitkomst1=[] uitkomst2=[] cdef long long eind=int((n+2)/(2*sqrt(3))) cdef long long y, t for y in range(1,eind): t =A speedup by a factor of 238!!
{{{id=255| 7.14/0.03 /// 238.000000000000 }}} {{{id=5| time f(10^9) /// 288675135 [(1L, 1L), (4L, 4L), (15L, 17L), (56L, 64L), (209L, 241L), (780L, 900L), (2911L, 3361L), (10864L, 12544L), (40545L, 46817L), (151316L, 174724L), (564719L, 652081L), (2107560L, 2433600L), (7865521L, 9082321L), (29354524L, 33895684L), (109552575L, 126500417L)] [(1L, 5L), (14L, 65L), (195L, 901L), (2716L, 12545L), (37829L, 174725L), (526890L, 2433601L), (7338631L, 33895685L), (102213944L, 472105985L)] 2 Time: CPU 25.60 s, Wall: 26.50 s }}} {{{id=6| /// }}} {{{id=242| /// }}} {{{id=243| /// }}}NOTE: Sage includes Singular and is very tightly integrated with it.
{{{id=229| sage.rings.ideal.Katsura(P,3).groebner_basis('singular:std') /// [a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c] }}} {{{id=230| sage.rings.ideal.Katsura(P,3).groebner_basis('singular:slimgb') /// [a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c] }}}NOTE: You must have Macaulay 2 installed for this to work...
{{{id=231| sage.rings.ideal.Katsura(P,3).groebner_basis('macaulay2') /// [a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c] }}} {{{id=232| sage.rings.ideal.Katsura(P,3).groebner_basis('magma') /// [a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c] }}}