SD15 - MSR talk
system:sage

<p align="center"><img src="sage_logo_new.png" alt="" /></p>
<p>&nbsp;</p>
<h1 style="text-align: center;">What does Sage do?</h1>
<h2 style="text-align: center;">Craig Citro</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>

<table border="0" cellspacing="3" cellpadding="0">
<tbody>
<tr>
<td>&nbsp;</td>
<td colspan="3"><br />
<p style="text-align: center;"><span style="font-size: xx-large;"><strong><span style="font-family: courier new,courier;">http://www.sagemath.org/</span></strong></span></p>
<p style="text-align: center;"><span style="font-size: xx-large;"><strong><span style="font-family: courier new,courier;"><br /></span></strong></span></p>
<p><span style="font-size: large;"><strong>Sage</strong> is a free and open-source math software package that aims to be a viable alternative to Magma, Mathematica, Maple, and Matlab.</span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="10%">&nbsp;</td>
<td width="10%">&nbsp;</td>
<td width="60%">
<p><span style="font-size: large;">Sage: </span></p>
<ul>
<li>
<p><span style="font-size: large;">solves interesting problems quickly. </span></p>
</li>
<li>
<p><span style="font-size: large;">makes experimentation easy. </span></p>
</li>
<li>
<p><span style="font-size: large;">interfaces with everything under the sun. </span></p>
</li>
<li>
<p><span style="font-size: large;">makes creating and interacting with graphics simple. </span></p>
</li>
<li>
<p><span style="font-size: large;">makes sharing resources and collaborating natural. </span></p>
</li>
<li>
<p><span style="font-size: large;">shows you every line of source code. </span></p>
</li>
<li>
<p><span style="font-size: large;">local or on the Web &ndash; no difference. </span></p>
</li>
<li>
<p><span style="font-size: large;">is completely and totally FREE.</span></p>
</li>
</ul>
</td>
<td width="10%">&nbsp;</td>
<td width="10%">&nbsp;</td>
</tr>
</tbody>
</table>

{{{id=12|

///
}}}

<h1 style="text-align: center;">A Lightning-Fast Tour of Sage</h1>
<h2 style="text-align: center;">Some Basics ...<br /></h2>

{{{id=17|
2+2
///


4
}}}

{{{id=0|
factor(2009)
///


7^2 * 41
}}}

{{{id=19|
random_matrix(RDF,50).determinant()
///


9.18843347146e+17
Time: CPU 0.00 s, Wall: 0.00 s
}}}

{{{id=18|
f = x^7+1
roots = f.roots(ring=CDF)
roots
///


[(-1.0 + 2.22044604925e-16*I, 1), (-0.623489801859 - 0.781831482468*I, 1), (-0.623489801859 + 0.781831482468*I, 1), (0.222520933956 - 0.974927912182*I, 1), (0.222520933956 + 0.974927912182*I, 1), (0.900968867902 - 0.433883739118*I, 1), (0.900968867902 + 0.433883739118*I, 1)]
}}}

{{{id=22|
show(roots)
///


<html><div class="math">\begin{array}{l}[\left(-1.0 + 2.22044604925 \times 10^{-16}i, 
 1\right),\\
\left(-0.623489801859 - 0.781831482468i, 
 1\right),\\
\left(-0.623489801859 + 0.781831482468i, 
 1\right),\\
\left(0.222520933956 - 0.974927912182i, 
 1\right),\\
\left(0.222520933956 + 0.974927912182i, 
 1\right),\\
\left(0.900968867902 - 0.433883739118i, 
 1\right),\\
\left(0.900968867902 + 0.433883739118i, 
 1\right)]\end{array}</div></html>
}}}

{{{id=21|
show(taylor(e^x, x, 0, 20))
///


<html><div class="math">1 + x + \frac{{x}^{2} }{2} + \frac{{x}^{3} }{6} + \frac{{x}^{4} }{24} + \frac{{x}^{5} }{120} + \frac{{x}^{6} }{720} + \frac{{x}^{7} }{5040} + \frac{{x}^{8} }{40320} + \frac{{x}^{9} }{362880} + \frac{{x}^{10} }{3628800} + \frac{{x}^{11} }{39916800} + \frac{{x}^{12} }{479001600} + \frac{{x}^{13} }{6227020800} + \frac{{x}^{14} }{87178291200} + \frac{{x}^{15} }{1307674368000} + \frac{{x}^{16} }{20922789888000} + \frac{{x}^{17} }{355687428096000} + \frac{{x}^{18} }{6402373705728000} + \frac{{x}^{19} }{121645100408832000} + \frac{{x}^{20} }{2432902008176640000}</div></html>
}}}

{{{id=28|

///
}}}

<h2 style="text-align: center;">Graph Theory</h2>

{{{id=27|
G = Graph({1:[2,3], 2:[], 3:[1,2,4], 4:[]})
G
///


Graph on 4 vertices
}}}

{{{id=31|
show(G)
///


<html><font color='black'><img src='cell://sage0.png'></font></html>
}}}

{{{id=32|
show(graphs.PetersenGraph())
///


<html><font color='black'><img src='cell://sage0.png'></font></html>
}}}

{{{id=26|
HS = graphs.HoffmanSingletonGraph()
HS.plot()
///


<html><font color='black'><img src='cell://sage0.png'></font></html>
}}}

{{{id=25|
time HS.automorphism_group(order=True, return_group=False)
///


252000
Time: CPU 0.01 s, Wall: 0.01 s
}}}

{{{id=15|

///
}}}

<h2 style="text-align: center;">Elliptic Curves!</h2>

{{{id=3|
E = EllipticCurve([12,3,4,5,6])
E
///


Elliptic Curve defined by y^2 + 12*x*y + 4*y = x^3 + 3*x^2 + 5*x + 6 over Rational Field
}}}

{{{id=69|
# use tab completion and introspection!
///
}}}

{{{id=4|
show(plot(E, xmax=4))
///


<html><font color='black'><img src='cell://sage0.png'></font></html>
}}}

{{{id=5|
factor(E.conductor())
///


2^4 * 5 * 11 * 13 * 277
}}}

{{{id=6|
time E.rank()
///


2
Time: CPU 0.01 s, Wall: 0.37 s
}}}

{{{id=7|
time E.gens()
///


[(-6 : 66 : 1), (-2 : 20 : 1)]
Time: CPU 0.20 s, Wall: 0.96 s
}}}

{{{id=11|
S = SupersingularModule(37)
G = Graph(S.hecke_matrix(5))
G.girth()
///


1
}}}

{{{id=8|
show(G)
///


<html><font color='black'><img src='cell://sage0.png'></font></html>
}}}

{{{id=64|

///
}}}

<h2 style="text-align: center;">Experiment with Data Interactively ...</h2>

{{{id=63|
var('x')
x0   = 0
f(x) = sin(x)*e^(-x)
p    = plot(f,-1,5, thickness=2)
dot  = point((x0,f(x0)),pointsize=80,rgbcolor=(1,0,0))
@interact
def _(order=(1..12)):
  ft = f.taylor(x,x0,order)
  pt = plot(ft,-1, 5, color='green', thickness=2)
  html('$f(x)\;=\;%s$'%latex(f))
  html('$\hat{f}(x;%s)\;=\;%s+\mathcal{O}(x^{%s})$'%(x0,latex(ft),order+1))
  show(dot + p + pt, ymin = -.5, ymax = 1)
///
}}}

{{{id=61|
var('x y')
var('xx yy', ns=1)
G = sin(xx^2 + yy^2) * cos(yy) * exp(-0.5*(xx^2+yy^2))
def F(x,y):
    return G.subs(xx=x).subs(yy=y)
plotF = plot3d(F, (0.4, 2), (0.4, 2), adaptive=True, color='blue')
@interact
def _(x0=(0.5,1.5), y0=(0.5, 1.5),
      order=(1..10)):
    F0 = float(G.subs(xx=x0).subs(yy=y0))
    P = (x0, y0, F0)
    dot = point3d(P, size=15, color='red')
    plot = dot + plotF
    approx = F0
    for n in range(1, order+1):
        for i in range(n+1):
            if i == 0:
                deriv = G.diff(yy, n)
            elif i == n:
                deriv = G.diff(xx, n)
            else:
                deriv = G.diff(xx, i).diff(yy, n-i)
            deriv = float(deriv.subs(xx=x0).subs(yy=y0))
            coeff = binomial(n, i)/factorial(n)
            approx += coeff * deriv * (x-x0)^i * (y-y0)^(n-i)
    plot += plot3d(approx, (x, 0.4, 1.6), 
             (y, 0.4, 1.6), color='red', opacity=0.7)
    html('$F(x,y) = e^{-(x^2+y^2)/2} \\cos(y) \\sin(x^2+y^2)$')
    show(plot)
///
}}}

{{{id=59|

///
}}}

<h2 style="text-align: center;">Features Galore ...</h2>

{{{id=58|
# interfaces
(gp(2) + gap(5)) * singular(7)
///


49
}}}

{{{id=57|
%r

c(1:10)
d <- c(1:15)
mean(d)
///


 [1]  1  2  3  4  5  6  7  8  9 10

[1] 8
}}}

{{{id=79|

///
}}}

{{{id=76|
M = random_matrix(ZZ,50)
///
}}}

{{{id=77|
time M*M
///


50 x 50 dense matrix over Integer Ring
Time: CPU 0.01 s, Wall: 0.01 s
}}}

{{{id=78|
timeit('M*M')
///


125 loops, best of 3: 6.38 ms per loop
}}}

{{{id=80|

///
}}}

{{{id=56|
# easy naive parallelism ... no licenses required

ls = [2^n-1 for n in [190..200]]
time v = [ factor(x) for x in ls ]
///


Time: CPU 6.03 s, Wall: 6.61 s
}}}

{{{id=83|
@parallel(2)
def f_para(n):
    return factor(n)

time v = list(f_para(ls))
///
}}}

{{{id=82|

///
}}}

<p>The Sage Notebook is the web-based interface to Sage that I'm using to give this talk -- and that I used to write it. The Notebook has a number of important features, including:</p>
<ul>
<li>WYSIWYG HTML editor</li>
<li>easily usable over a network </li>
<li>jsMath integration</li>
<li>LaTeX integration</li>
</ul>

{{{id=54|
html('$$ \\textbf{Conjecture: } \\operatorname{Re}(s) > 0, \\zeta(s) = 0 \\longrightarrow \\operatorname{Re}(s) = \\frac{1}{2} $$')
///


<html><font color='black'><div class="math"> \textbf{Conjecture: } \operatorname{Re}(s) > 0, \zeta(s) = 0 \longrightarrow \operatorname{Re}(s) = \frac{1}{2} </div></font></html>
}}}

{{{id=72|

///
}}}

{{{id=53|
E
///


Elliptic Curve defined by y^2 + 12*x*y + 4*y = x^3 + 3*x^2 + 5*x + 6 over Rational Field
}}}

{{{id=74|
latex(E)
///


y^2 + 12xy + 4y = x^3 + 3x^2 + 5x + 6 
}}}

{{{id=52|
show(E)
///


<html><div class="math">y^2 + 12xy + 4y = x^3 + 3x^2 + 5x + 6 </div></html>
}}}

{{{id=51|
show(random_matrix(ZZ,4))
///


<html><div class="math">\left(\begin{array}{rrrr}
0 & 0 & -1 & 1 \\
13 & 7 & 0 & 9 \\
0 & 1 & 0 & 0 \\
-10 & -1 & 4 & 1
\end{array}\right)</div></html>
}}}

{{{id=50|

///
}}}

<h2 style="text-align: center;">Cython</h2>

{{{id=49|
%python
def mysum(N):
    s = int(0)
    for k in range(1,N):
        s += k
    return s
///
}}}

{{{id=75|
time mysum(10^6)
///


499999500000L
Time: CPU 0.26 s, Wall: 0.27 s
}}}

{{{id=48|
%cython
def mysum_cython(N):
    cdef int k
    cdef long long s = 0
    
    for k in range(N):
        s += k
    return s
///
}}}

{{{id=47|
time mysum_cython(10^6)
///


499999500000L
Time: CPU 0.00 s, Wall: 0.00 s
}}}

{{{id=46|

///
}}}

<p style="text-align: center;"><strong><span style="font-size: xx-large;">Questions?</span></strong></p>

{{{id=45|

///
}}}

{{{id=44|

///
}}}

{{{id=43|

///
}}}

{{{id=42|

///
}}}

{{{id=41|

///
}}}

{{{id=40|

///
}}}

{{{id=39|

///
}}}

{{{id=38|

///
}}}

{{{id=37|

///
}}}

{{{id=36|

///
}}}

{{{id=35|

///
}}}

{{{id=34|

///
}}}

{{{id=33|

///
}}}

{{{id=14|

///
}}}