20090210 -- Sun Sage Talk
system:sage
SAGE
Creating a viable free open source alternative to
Maple, Mathematica, Matlab and Magma
William Stein, Associate Professor, University of Washington

BTW: I really, REALLY like sage. I'm just surprised i haven't heard
of it before 5 days ago.
-- Clinton Bowen on the sage-support mailing list Mon, Feb 9, 2009 at 11:03 PM.
{{{id=2|
///
}}}
History
- I started Sage at Harvard in January 2005.
- Existing math software not good enough (free or commercial).
- Sage-1.0 released February 2006 at Sage Days 1 (San Diego).
- Sage Days Workshops 1, 2, ..., 11, at UCLA, UW, Cambridge, Bristol, Austin, France, San Diego, Seattle, etc.
- Sage won first prize in Trophees du Libre (November 2007)
- Funding from Microsoft, UW, NSF, DoD, Google, Sun, private donors, etc.
{{{id=117|
///
}}}
Sun's Interest in Sage
- Sage will very soon (weeks) fully support Solaris. This porting work was fully funded by the Department of Defense, and will continue.
- Sage is the only project whose goal is to create a viable open source alternative to Mathematica, Maple, and Magma. It is the analogue of Star Office or Firefox, as alternatives to Microsoft Office or Internet Explorer.
{{{id=160|
2 + 3
///
5
}}}
{{{id=80|
///
}}}
Sage is 100% Free
Active user community; 964 members of the sage-support mailing list.
Free webapp -- sagenb.org -- has about 3000 users (and there are other servers at universities around the world..)

sagemath.org


Sage Devel Headquarters: Four 24-core Sun X4450's with 128GB RAM each + 1 Sun X4540 with 24TB disk
sagenb.org

{{{id=161|
A. = QuaternionAlgebra(QQ, -1,-1)
A
///
Quaternion algebra with generators (i, j, k) over Rational Field
}}}
{{{id=162|
i*j + k
///
2*k
}}}
{{{id=62|
///
}}}
Some Advantages of Sage over the Ma*'s
- Python-- general purpose language at core of Sage; huge user base compared to Matlab, Mathematica, Maple and Magma
- Cython -- blazingly fast compiled code
- Integrated web server -- (twisted, etc.)
- Free and Open source
- Excellent Peer review of Code: "I do really and truly believe that the Sage refereeing model results in better code." -- John Cremona
{{{id=119|
email('wstein@gmail.com', 'The calculation finished!')
///
Child process 50883 is sending email to wstein@gmail.com...
}}}
{{{id=118|
///
}}}
So What is Sage?
- Well over 300,000 lines of new Python/Cython code
- A Distribution of mathematical software (over 60 third-party packages); builds from source without dependency (over 5 million lines of code)
- Nearly 150 developers: developer map
- Exact and numerical linear algebra, optimization (numpy, scipy, R, and gsl all included)
- Group theory, number theory, combinatorics, graph theory
- Symbolic calculus
- Coding theory, cryptography and cryptanalysis
- 2d and 3d plotting
- Statistics (Sage includes R)
- Overall range of functionality rivals that of Maple, Matlab, and Mathematica
Reference Manual (over 3000 pages, all new)
{{{id=96|
///
}}}
PART 2 -- Examples
The first example from the Python tutorial:
{{{id=22|
the_world_is_flat = 1
if the_world_is_flat:
print "Be careful not to fall off!"
///
Be careful not to fall off!
}}}
Symbolic expressions:
{{{id=23|
x, y = var('x,y')
type(x)
///
}}}
{{{id=19|
a = 1 + sqrt(2) + pi + 2/3 + x^y
a
///
x^y + pi + sqrt(2) + 5/3
}}}
{{{id=163|
show(a)
///
{x}^{y} + \pi + \sqrt{ 2 } + \frac{5}{3}
}}}
{{{id=20|
show(expand(a^3))
///
{x}^{{3 y}} + {{3 \pi} {x}^{{2 y}} } + {{3 \sqrt{ 2 }} {x}^{{2 y}} } + {5 {x}^{{2 y}} } + {{3 {\pi}^{2} } {x}^{y} } + {{{6 \sqrt{ 2 }} \pi} {x}^{y} } + {{10 \pi} {x}^{y} } + {{10 \sqrt{ 2 }} {x}^{y} } + \frac{{43 {x}^{y} }}{3} + {\pi}^{3} + {{3 \sqrt{ 2 }} {\pi}^{2} } + {5 {\pi}^{2} } + {{10 \sqrt{ 2 }} \pi} + \frac{{43 \pi}}{3} + \frac{{31 \sqrt{ 2 }}}{3} + \frac{395}{27}
}}}
Solve equations
{{{id=101|
var('a,b,c,x')
show(solve(x^3 + sqrt(17)*a*x + b == 0, x)[0])
///
x = {\left( \frac{{-\sqrt{ 3 } i}}{2} - \frac{1}{2} \right) {\left( \frac{\sqrt{ {27 {b}^{2} } + {{68 \sqrt{ 17 }} {a}^{3} } }}{{6 \sqrt{ 3 }}} - \frac{b}{2} \right)}^{\frac{1}{3}} } - \frac{{{\sqrt{ 17 } \left( \frac{{\sqrt{ 3 } i}}{2} - \frac{1}{2} \right)} a}}{{3 {\left( \frac{\sqrt{ {27 {b}^{2} } + {{68 \sqrt{ 17 }} {a}^{3} } }}{{6 \sqrt{ 3 }}} - \frac{b}{2} \right)}^{\frac{1}{3}} }}
}}}
{{{id=164|
# pynac
var('a,b,c,x',ns=1)
///
(a, b, c, x)
}}}
{{{id=165|
time f = expand((a+b+c)^20)
///
Time: CPU 0.01 s, Wall: 0.15 s
}}}
{{{id=166|
time f = expand((a+b+c)^20)
///
Time: CPU 0.07 s, Wall: 0.17 s
}}}
{{{id=3|
///
}}}
{{{id=32|
///
}}}
Example: A Huge Integer Determinant
{{{id=31|
a = random_matrix(ZZ,200,x=-2^127,y=2^127)
time d = a.determinant(); d
///
-320634583584115008653201266554496631838275153142722575173166280822720187527308117282992124804827890525933795477123152684989261229562711266703270264364168011363648992550474161262851188633927950372030798034197183243865866622885990260252243500331436289190024303391337022001821257555301927383116663134358804871669598500948669256725340804713694888599029931517155594443293572690801335284902718500512148361546712824674710831502127019676934661663495674291783760056700648741241772515101926397170958863966498401292132664292818213158359416168481100170654378731921455618924055879086251647652704418313178512967838588754650881840591963764442551022879587696258313433306224036415655238455750645106880662989211176709593373148541923044521416888030519567532565714877518914590783654234683498203626332032446139947982510466736172825569885764406915130851808886470881627061433742457110011421812257450352175437281302279258507121871593862085372565105481818481505682600687180603543490979347706855149052045025084868079546551494619891424113478609869832824855787166922323640652618297516361017450073300677281026838044528544554279998095656289380905630457604536870834834900284812808061289464420266611723285268299698074309550563399296284880874690845597940413330083950859666461942707649627281256418991674683575937043868911524818438766003999636450458323948565570507001964752813318300955902782781268310495204316531942268252746490258798563974532115911517199437745201650913286116237830549723932470262672851722997517357105637719389182258085693618314855192482071815787531730115442099101227560689786328059451067821662614446376266638527245830978589434204130333980588864002905661018946224065074267910451495471959778789908911680181104395896647730139038031471409311848273560595535718125098075841794606556295933674149438517112188450515366661369820070102796424147020505248343670307324928290570736947411487916389064111658651023449948620757150835635550435017518406032271960003325729431860331223148808546444715137217990036460852607530559513288227960117106094660703419606630699743643875103670683738222758577191393193071805020033858110403081928731601322128100935552748053122738228180657502904292923751186373621128569330066858020421286508640840842453310538035583250237067230409680394859125931989125688739989034657693879585724773282762024517441562242451278951007389848737670555505783826473504899549939875861522280407565961166151499902015179347673857796549281215310093335882931988910438472662705737492209984923520158050739834521380176795551576397658783017372422181359509565612394173754130801084456222229668272312461664487804836990463078058347403052301662201023172178048585815436992518271496824911693255232754745495242963372059148131120117664927546237056197938279492248604196415744576146173913698210037226940437778756425319593813478360244809990996964376706595880191229114400120832653748616075615460349969119578107499390626659543848668755286987534616291709748203185916705117744487688045057332736180533087089610674257154347089805266367619461697880043456120602107970550031446377790122245628781949859012385902554983232276082941837301368374770864368763374284821069509516842511407208001718316866142200206058152006956751394718907902882709900339771583373808756875608585321264337085405725878657689449094788044589646785402192158631867870584085854126923696711128819146494230259878008692152603990963098872889350646663876036534779299121810293817185156694338033819037616896698468193425972040847026564944481241940072506790107558410419004614032010777730289481062902243342938892697518305390795560385764471517866914729220258754890999080681327999607270482379212160849901606668619555707483480333172297553300129166684386851245491645839707535328928113925680521174203771986825574430673840602671502480503515312512104975045546248568741458171878578321063918948763326674599881301597915985045359977818556553656569846474967119416091994125086233776187405029854609669164784275874082758287400519112961351627811066707132147169366482095866658968232561633036730949081360300864746014288067056121323833419576465161885585649298820628724797970308386774516137426811900003107922927997787643100618882385129880890395430469670274792317248000484584395882934362572864493741175467122068051770430166319482177720871772178802496754415635912887236132208377345734263142315761703048974327582066521760296579378617843437272983887483064388930128086645611171216565817624308565295826397513605468746803794319666931642984970161209407555054608346288001887344786510664600917221719693706173473499515692887716285726272038339057597374325057008918953740657301457495004141887768238443077605321031235686796614768259626260789636611588177579697621705764710567033478446189966806595052574687762894506036749261031169713285601555357295283134185561664794732827009024016611930801321745951826845677757607159406560671445319153432700451034633219416873290979315401339879765298305053574999616252721520009537254628742124317191466094177211205590715478603782625365863521112560568495417166293244391229363868315410736138179544136331123390941781052805520007606066514022812512723519525579812557278525370978003618412888663584104101758165112654371993002475812914184195061619895461879183049650273598628254771030376523516095181193860826967307067407730451669110217865679910893336566009772772387343498139545867794753530179386927427160588593685958654659584676493615550088497555746287608712685480560016898072285994827170169465450511898183499239742697957578707714164753481763898469211647595157065791555552121533558263070659969786017185112181362029480027869926852624880884421281863838205183976044154397023369220084463161860580336806599407864784779234255912645787310454262170340296260768134108751231374291087167166934267988852505538892875199774024187686655299408775680083266860231088713135049055532449409020355371273284184106419861927922483860539770375477810226226626877530581129181224571679949089559618376216373896143942020541918493403357407841712680150951256816595064735111081129747334852263228891577356747161047533523989487279860350857459774101520916741477287029613338932312228489270348374737497284259885811284708043127463692150561369456502269927079068568060443502905925639439635175402802313424500478308777781148919838991205764104041181788885044147222712276280911863978207443301453420818427172967178033924359824759094494059006177048262360817458555930282232411689726478582689006486536712509121480054993508268239872632206590483505141347191169369054939114720112172031777762929627747782583408255744456538686299637835259611805831177094621663116623590118998403167494173024481755944613365007326326958890444817501539187944443398167483159926339627445247475684117826753910341367864230028651513842454032690687762047518710771649222661906959035493837424469471877116063889918460019092655213729411726066519579496467898264085920922805151998695583045301347005669272652508413777433894046828843204536321935941278311012497064540939987745316222508389264323861285652897344497508283666081937799058357920544080758133198341986048865342573071086197911203070411652994514347061945800738556799975121051476840923916493556897559945681468164606107264692079053187723553871390921326202344950057639586417816715000758007406551143393306009083948195165092546836212423082557379311962503323344370459757728176706081821007923507656078069989150482851568434963737412772913238083351086702338436968816648248807260995422057957815487026356191652193814618781301160190061003315790756912637413338427565084958632668555382884538818970376875815318336711774295376949250440491132627015541280607514711722635480048216501945015355854938068044645917255077287833962786830974541791301960788937017663939509821057033858540121272575770952075038054707891898562280759919337230325842442810391680321355248846209296002713057132613463109896337197908929348239063837780679221704361283348107408527914121219358732
Time: CPU 2.87 s, Wall: 3.28 s
}}}
We can also copy this matrix over to Maple and compute the same determinant there...
{{{id=167|
a[0,0]
///
5437434447110237200823494268835742396
}}}
{{{id=27|
maple.with_package('LinearAlgebra')
B = maple(a)
t = maple.cputime()
time c = B.Determinant() # new fast Determinant in maple (don't use "det"!)
maple.cputime(t)
///
21.969999999999999
}}}
{{{id=168|
c == d
///
True
}}}
{{{id=169|
R. = GF(389)[]
///
}}}
{{{id=170|
f = (x+y+z+1)^20
time g = f*(f+1)
///
Time: CPU 0.11 s, Wall: 0.11 s
}}}
{{{id=26|
len(str(g))
///
216557
}}}
We can copy to Magma also. This ability to copy objects around 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.36 s
10.69
}}}
{{{id=112|
///
}}}
IRC a few days ago...
22:41 < linuxgus> I can show people at work tomorrow
that they don't have to abandon Matlab [if they switch
to Sage]. Can Sage convert Matlab data types to
its own? That would be awesome!
{{{id=25|
///
}}}
Example: A Symbolic Expression
{{{id=50|
x = var('x')
f(x) = sin(3*x)*x+log(x) + 1/(x+1)^2
show(f)
///
x \ {\mapsto}\ {x \sin \left( {3 x} \right)} + \log \left( x \right) + \frac{1}{{\left( x + 1 \right)}^{2} }
}}}
Plotting functions has similar syntax to Mathematica:
{{{id=171|
show(f.integrate(x))
///
x \ {\mapsto}\ \frac{\sin \left( {3 x} \right) - {{3 x} \cos \left( {3 x} \right)}}{9} + {x \log \left( x \right)} - \frac{1}{x + 1} - x
}}}
{{{id=109|
plot(f,(0.01,2), thickness=4) + text("Mathematica-style plotting in Sage", (1,-2), rgbcolor='black')
///
}}}
Sage also has 2d plotting that is almost identical to MATLAB:
{{{id=159|
import pylab as p
p.figure()
t = p.arange(0.01, 2.0, 0.01)
s = p.sin(2 * p.pi * t)
s = p.array([float(f(x)) for x in t])
P = p.plot(t, s, linewidth=4)
p.xlabel('time (s)'); p.ylabel('voltage (mV)')
p.title('Matlab-style plotting in Sage')
p.grid(True)
p.savefig('sage.png')
///
}}}
{{{id=110|
///
}}}
{{{id=73|
///
}}}
_fast_float_ yields super-fast evaluation of Sage symbolic expressions -- e.g., here it is 10 times faster than native Python!
{{{id=105|
var('x')
show(f)
///
x \ {\mapsto}\ {x \sin \left( {3 x} \right)} + \log \left( x \right) + \frac{1}{{\left( x + 1 \right)}^{2} }
}}}
{{{id=172|
f(x,y,z) = x^3 * sin(x^2) + cos(x*y) - 1/(x+y+z)
///
}}}
{{{id=74|
g = f._fast_float_(x,y,z)
timeit('g(4.5r,3.2r,5.7r)')
///
625 loops, best of 3: 715 ns per loop
}}}
{{{id=75|
%python
# %python, so no preparsing so uses pure python
import math
def g(x): return math.sin(3*x)*x + log(x) + 1/(1+x)**2
///
}}}
{{{id=77|
timeit('g(4.5r)')
///
625 loops, best of 3: 6.88 µs per loop
}}}
{{{id=48|
///
}}}
{{{id=76|
///
}}}
Example: Compare Answers with Maple
{{{id=83|
var('x')
f = sin(3*x)*x+log(x) + 1/(x+1)^2
show(integrate(f))
///
\frac{\sin \left( {3 x} \right) - {{3 x} \cos \left( {3 x} \right)}}{9} + {x \log \left( x \right)} - \frac{1}{x + 1} - x
}}}
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)
///
}}}
{{{id=90|
m.parent()
///
Maple
}}}
{{{id=91|
m.parent().pid()
///
24038
}}}
{{{id=92|
os.system('ps ax |grep 24038')
///
24038 s007 Ss+ 0:00.01 /bin/sh /Users/wstein/bin/maple -t
24233 s015 S+ 0:00.00 sh -c ps ax |grep 24038
24235 s015 R+ 0:00.00 grep 24038
0
}}}
Use Maple objects via a Pythonic notation:
{{{id=88|
show(m.integrate('x'))
///
1/9\,\sin \left( 3\,x \right) -1/3\,\cos \left( 3\,x \right) x+\ln
\left( x \right) x-x- \left( x+1 \right) ^{-1}
}}}
{{{id=42|
mathematica(f).Integrate(x)
///
-x - (1 + x)^(-1) - (x*Cos[3*x])/3 + x*Log[x] + Sin[3*x]/9
}}}
{{{id=43|
///
}}}
Example: Interactive Image Compression
This illustrates pylab (matplotlib + numpy), Sage plotting, html output, and @interact.
{{{id=97|
# first just play
import pylab
A = pylab.imread(DATA + 'seattle.png')
graphics_array([matrix_plot(A^(-1)), matrix_plot(1-A[0:,0:,2])]).show(figsize=[10,4])
///
}}}
{{{id=174|
A[0,0,]
///
array([ 0.37254903, 0.42745098, 0.80784315, 1. ], dtype=float32)
}}}
{{{id=44|
import pylab
A_image = pylab.mean(pylab.imread(DATA + 'seattle.png'), 2)
@interact
def svd_image(i=(20,(1..100)), display_axes=True, m=matrix(ZZ,2,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('Compressed using %s eigenvalues
'%i)
///
}}}
{{{id=94|
///
}}}
{{{id=55|
///
}}}
Example: 3d Plots
{{{id=84|
var('x,y')
plot3d(sin(x*y) - cos(x^5), (x,-2,2), (y,-2,2))
///
}}}
{{{id=124|
show(sphere((0,0,0)) + sphere((0,1,0), color='red', opacity=0.5)
+ icosahedron((1,1,0), color='orange'), figsize=10)
///
}}}
{{{id=116|
L = []
@interact
def random_list(number_of_points=(10..50), dots=True):
n = normalvariate
global L
if len(L) != number_of_points:
L = [(n(0,1), n(0,1), n(0,1)) for i in range(number_of_points)]
G = list_plot3d(L,interpolation_type='nn', texture=Color('#ff7500'),num_points=120)
if dots: G += point3d(L)
G.show()
///
}}}
{{{id=54|
///
}}}
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|
///
}}}
Real World Example: Super Fast Code (using Cython)
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=7|
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.74 s, Wall: 0.86 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
}}}
While waiting to see if f_python(10^6) would finish, I decided to try the Cython compiler. I declared a few data types, put %cython at the top of the cell, and wham, it got over 200 times faster.
{{{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
print eind
for y in range(1,eind):
t = sqrtl( (3*y*y + 1))
if t * t == 3*y*y + 1:
uitkomst1.append((y, (2*t-1)/3))
t = sqrtl( (48*y*y + 1))
if t * t == 48*y*y + 1:
uitkomst2.append((y, (2*t+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=45|
time f(10^5)
///
28868
[(1L, 1L), (4L, 4L), (15L, 17L), (56L, 64L), (209L, 241L), (780L, 900L), (2911L, 3361L), (10864L, 12544L)]
[(1L, 5L), (14L, 65L), (195L, 901L), (2716L, 12545L)]
2
Time: CPU 0.00 s, Wall: 0.00 s
}}}
{{{id=4|
time f(10^6)
///
288675
[(1L, 1L), (4L, 4L), (15L, 17L), (56L, 64L), (209L, 241L), (780L, 900L), (2911L, 3361L), (10864L, 12544L), (40545L, 46817L), (151316L, 174724L)]
[(1L, 5L), (14L, 65L), (195L, 901L), (2716L, 12545L), (37829L, 174725L)]
2
Time: CPU 0.03 s, Wall: 0.03 s
}}}
{{{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|
7.14/0.03
///
238.000000000000
}}}
This is not a contrived example. This is a real world example that came up a this weekend. For C-style computations, Sage (via Cython) is as fast as C.
{{{id=151|
///
}}}
{{{id=148|
///
}}}
{{{id=149|
///
}}}
{{{id=144|
///
}}}
Example: Do some number theory
{{{id=128|
///
}}}
Plotting an elliptic curve over a finite field
{{{id=127|
p = 389
E = EllipticCurve(GF(p).random_element())
E.plot()
///
}}}
and finding its group structure...
{{{id=137|
E.abelian_group()
///
(Multiplicative Abelian Group isomorphic to C180 x C2, ((262 : 190 : 1), (228 : 0 : 1)))
}}}
Creating another random elliptic curve over a bigger finite field and compute its cardinality in seconds:
{{{id=129|
p = next_prime(10^60)
E = EllipticCurve(GF(p).random_element())
show(E)
///
y^2 = x^3 + 425356051223648747023108902736172620897278673931104973974164x + 920733503445411966314417165378315096439996780491982901461664
}}}
{{{id=130|
time E.cardinality()
///
1000000000000000000000000000000753054185359723724596110573310
Time: CPU 0.00 s, Wall: 5.66 s
}}}
Some weight 3 modular forms on $\Gamma_1(12)$:
{{{id=138|
show(ModularForms(Gamma1(12),3,prec=20).basis())
///
\begin{array}{l}[q - 6q^{4} - 3q^{5} + 6q^{6} + 5q^{7} + 12q^{8} - 9q^{9} - 6q^{11} - 6q^{12} + 14q^{13} - 24q^{14} + 3q^{15} + 15q^{17} - 31q^{19} + O(q^{20}),\\
q^{2} - 4q^{4} - q^{5} + 3q^{6} + 5q^{7} + 4q^{8} - 6q^{9} - 2q^{10} - 6q^{11} + 12q^{13} - 12q^{14} + 3q^{15} + 8q^{16} + 5q^{17} - 3q^{18} - 31q^{19} + O(q^{20}),\\
q^{3} - 2q^{4} - q^{5} + 2q^{6} + q^{7} + 4q^{8} - 6q^{9} - 2q^{11} - 2q^{12} + 12q^{13} - 8q^{14} + q^{15} + 5q^{17} - 19q^{19} + O(q^{20}),\\
1 + 528q^{10} - 960q^{11} + 572q^{12} - 1176q^{14} + 3200q^{15} - 420q^{16} - 4224q^{17} - 216q^{18} + 2496q^{19} + O(q^{20}),\\
q + \frac{32429}{72}q^{10} - \frac{7945}{9}q^{11} + \frac{96131}{216}q^{12} + 170q^{13} - \frac{70211}{72}q^{14} + \frac{67282}{27}q^{15} - \frac{23447}{72}q^{16} - \frac{30008}{9}q^{17} - \frac{637}{4}q^{18} + \frac{17615}{9}q^{19} + O(q^{20}),\\
q^{2} + \frac{2458}{9}q^{10} - \frac{4960}{9}q^{11} + \frac{8722}{27}q^{12} - \frac{5626}{9}q^{14} + \frac{49600}{27}q^{15} - \frac{2305}{9}q^{16} - \frac{21824}{9}q^{17} - 133q^{18} + \frac{12896}{9}q^{19} + O(q^{20}),\\
q^{3} + \frac{373}{3}q^{10} - \frac{760}{3}q^{11} + \frac{1435}{9}q^{12} - \frac{931}{3}q^{14} + \frac{7834}{9}q^{15} - \frac{355}{3}q^{16} - \frac{3344}{3}q^{17} - 70q^{18} + \frac{1976}{3}q^{19} + O(q^{20}),\\
q^{4} + \frac{88}{3}q^{10} - \frac{160}{3}q^{11} + \frac{331}{9}q^{12} - \frac{196}{3}q^{14} + \frac{1600}{9}q^{15} - \frac{31}{3}q^{16} - \frac{704}{3}q^{17} - 12q^{18} + \frac{416}{3}q^{19} + O(q^{20}),\\
q^{5} - \frac{1027}{72}q^{10} + \frac{350}{9}q^{11} - \frac{5005}{216}q^{12} + \frac{2989}{72}q^{14} - \frac{3032}{27}q^{15} + \frac{1225}{72}q^{16} + \frac{1450}{9}q^{17} + \frac{35}{4}q^{18} - \frac{793}{9}q^{19} + O(q^{20}),\\
q^{6} - \frac{70}{3}q^{10} + \frac{160}{3}q^{11} - \frac{286}{9}q^{12} + \frac{196}{3}q^{14} - \frac{1600}{9}q^{15} + \frac{79}{3}q^{16} + \frac{704}{3}q^{17} + 22q^{18} - \frac{416}{3}q^{19} + O(q^{20}),\\
q^{7} - \frac{1315}{72}q^{10} + \frac{350}{9}q^{11} - \frac{5005}{216}q^{12} + \frac{3277}{72}q^{14} - \frac{3275}{27}q^{15} + \frac{1225}{72}q^{16} + \frac{1441}{9}q^{17} + \frac{35}{4}q^{18} - \frac{784}{9}q^{19} + O(q^{20}),\\
q^{8} - \frac{88}{9}q^{10} + \frac{160}{9}q^{11} - \frac{250}{27}q^{12} + \frac{196}{9}q^{14} - \frac{1600}{27}q^{15} + \frac{70}{9}q^{16} + \frac{704}{9}q^{17} + 4q^{18} - \frac{416}{9}q^{19} + O(q^{20}),\\
q^{9} - \frac{31}{8}q^{10} + 5q^{11} - \frac{49}{24}q^{12} + \frac{49}{8}q^{14} - \frac{50}{3}q^{15} + \frac{13}{8}q^{16} + 22q^{17} + \frac{7}{4}q^{18} - 13q^{19} + O(q^{20})]\end{array}
}}}
{{{id=133|
///
}}}
{{{id=61|
///
}}}
Questions?
{{{id=175|
a = random_matrix(RDF,500)
///
}}}
{{{id=176|
matrix_plot(a)
///
}}}
{{{id=177|
time v = a.eigenvalues()
///
Time: CPU 0.77 s, Wall: 0.87 s
}}}
{{{id=60|
import scipy.special
///
}}}
{{{id=179|
import scipy.optimize
///
}}}
{{{id=180|
///
}}}
{{{id=59|
///
}}}
{{{id=52|
///
}}}
{{{id=107|
///
}}}
{{{id=106|
///
}}}
{{{id=108|
///
}}}