REU

3118 days ago by jimlb

This worksheet just gives a very short introduction to SAGE.  The first thing to note is that one nice thing about SAGE is that you can type latex directly into it and read it!  For example, we have the equation $E: y^2 = x^3 + 1$.  You can also select the typeset condition above and it will display the answers in latex as well.  Finally, you can copy the latex from SAGE directly into your latex file so you don't have to retype horrible messy answers.

2+2 
       
f(x) = x^2 
       
type(f(x)) 
       
f(2) 
       
E1; 
       

SAGE is based on the programming language python, so if you are familiar with python SAGE is very easy to use.  You definitely don't have to know anything about python to use SAGE.  One very nice feature is that once you define an object, say a polynomial $f \in \mathbb{Q}[x]$, one can get the possible commands by typing $f$. tab.  We need to declare a variable first.

var('x'); R = QQ[x];R 
       

f = x^3 + 1;f 
       
f.derivative(x) 
       
f.factor() 
       
P=plot(f,(0,10)); 
       
Q=plot(800,(0,10), color='red'); 
       
P+Q 
       
var('x,y,z') 
       
R=QQ[x,y,z];R 
       
I = (x^2 *y, x*(y+z), y^5 * (x-z))*R;I 
       
I.groebner_basis() 
       

As far as I can tell there are no algorithms for SAGBI bases implemented in SAGE, so if you work on that project it might be a good idea to put that on your list of things to do.

I know very little graph theory, so Kirsti will help you more with this (or force me to learn it.) 

D = Graph( { 0: [1], 1: [2], 2: [0]} ) 
       
D.show() 
       
g=graphs.CompleteGraph(5) 
       
g.show() 
       
g.adjacency_matrix() 
       
g=graphs.CompleteBipartiteGraph(2, 3) 
       
g.show() 
       
g.bipartite_color() 
       
D = DiGraph( { 0: [1], 1: [2], 2: [0], 3:[2]} ) 
       
D.show() 
       

There are a lot of commands related to elliptic curves implemented in SAGE.

E1=EllipticCurve([0,1]);E1 
       
E1.plot() 
       
E1.torsion_subgroup() 
       
E1.torsion_polynomial(5) 
       
E2=EllipticCurve([0,3]);E2 
       
E2.rank() 
       
L=E2.lseries() 
       
L(1) 
       
rho=E1.galois_representation() 
       
rho.image_type(2); 
       
rho.image_type(6); 
       
Traceback (click to the left of this block for traceback)
...
TypeError: p (=6) must be prime.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_51.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cmhvLmltYWdlX3R5cGUoNik7"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpCKXrkU/___code___.py", line 3, in <module>
    exec compile(u'rho.image_type(_sage_const_6 );
  File "", line 1, in <module>
    
  File "/usr/local/sage-5.8/local/lib/python2.7/site-packages/sage/schemes/elliptic_curves/gal_reps.py", line 902, in image_type
    raise TypeError, "p (=%s) must be prime."%p
TypeError: p (=6) must be prime.
K.<i>=NumberField(x^2+1);K 
       
i^2 
       
b=i^3 + 1; 
       
b.parent() 
       
i^2 + 1 
       
E=EllipticCurve([3*i,-5*i]);E 
       
E.torsion_subgroup() 
       
E.rank() 
       

Programming is done as it is in python.  The thing to remember is indexing starts at 0, not 1!

for i in [1..10]: i^2 
       









for p in primes(10): p 
       



E1; 
       
for p in primes(20): E1.ap(p) 
       







for n in [2..10]: E1.an(n) 
       








E2; 
       
E2.rank() 
       
E2.torsion_subgroup() 
       
E2.rational_points(bound=20); 
       
T=E2.gens();T 
       
P=T[0] 
       
for j in [25..35]: j*P 
       










Suppose you needed $5P$ for your write-up.  You can copy it directly from SAGE into latex!

5*P 
       

We can also define our own functions in SAGE.

def eucl_dist((a1,b1),(a2,b2)): return N(sqrt((a1-a2)^2 + (b1-b2)^2)) 
       
eucl_dist((1,0),(0,0)) 
       
eucl_dist((1,1),(0,0)) 
       
def eucl_dist((a1,b1,c1),(a2,b2,c2)): return N(sqrt((a1-a2)^2 + (b1-b2)^2 + (c1-c2)^2)) 
       

One last fancy example. You can also define an environment where you can interact with the output.

@interact def f(t=(1/4,(1/16,1/8,..,1))): t0 = t x,y,t=var('x,y,t') show([x==(1-t^2)/(1+t^2), y==2*t/(1+t^2)]) t = t0 (x,y) = ((1-t^2)/(1+t^2), 2*t/(1+t^2)) a = 1/3 G = circle((0,0), 1, color='blue', thickness=3) G += arrow((-1-a,-t*a), (x+a,y+t*a), head=2, color='red') G += point((0,t), pointsize=150, color='black', zorder=100) G += point((-1,0), pointsize=150, color='black', zorder=100) G += point((x,y), pointsize=190, color='lightgreen', zorder=100) G += text("$(0, %s)$"%t, (-.3, t+.2), fontsize=16, color='black', zorder=200) G += text(r"$(%s,\,%s)$"%(x,y), (x+.35, y+.25), fontsize=16, color='black', zorder=200) G.show(aspect_ratio=1, ymin=-1.1, ymax=1.6, xmax=2, xmin=-1.3, fontsize=0, figsize=6) 
       

Click to the left again to hide and once more to show the dynamic interactive window