Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168696
Image: ubuntu2004

Sage is a computer algebra system written in python which allows you to do computations with a lot of different mathematical objects (see for example http://www.sagemath.org/doc/constructions/). This worksheet is intended to get you to be able to get to know how to work with elliptc curves in sage as quickly as possible. Since sage is written in python almost all pyhton syntax is also valid in sage.  If you want at a certain point to do more in sage you can find an introduction into python at: http://docs.python.org/tutorial/. A tutorial for sage can be found on http://www.sagemath.org/doc/tutorial/.

So lets first go to the most basic elements of every programming language. A function in python can be called as follows: (you can evaluate the code below by clicking on the code and the pres shift+Enter , after you did this the output should apear)

factor(507)

If your function needs more arguments then you just seperate them with a comma like:

gcd(350,45)

If you want to know what a function exactly does, you can just put a question mark behind the function and press shift+enter, try it

gcd?

of course in python you can use variables to store values, and do addition multiplication etc

a=3 b=4 a*b+a

you can make lists of things by putting them between braces [] and seperate them by comma's

c=[a,b,1] c

some functions take a list as input:

sum(c)

you can also retrieve elements from the list. the numbering starts at 0 so

c[0]
c[1]+c[2]

if you want to make a for loop in python, you cannot do it like in c++, but you first create a list, so you can iterate over all the elements in the list for example:

for i in c: a=i^2 print a

note that pyhon is indentation dependant, it uses the indentation to determine the end of the for loop. compare the following and the previous example

for i in c: a=i^2 print a

since "print a" is on the same indentation level as the for statement, it is considdered to be executed after the for loop. Now you might wonder how you have to iterate of the first few integers. Luckily python has a nice build-in command to generate a list of the integers ranging from a up to but not including b.

range(a,b)

or all even numbers from 0 to 20

range(0,22,2)

Excercise:

compute the sum of the squares of the odd numbers smaller then your age using the for loop

sage knows a lot of basic ring types. for this course Q\Bold{Q} and Fq\Bold{F}_q and polynomial rings over them will be the most important. they are shown below

QQ
GF(7)
R.<x>=PolynomialRing(QQ) R

The above command named the generator of the polynomial ring x and also made it available for future calculations


f=(x+10)^2 f

Excercise If you want to define a finite field which is not of prime order you have to specify a name for the generator, just as in the previous example with the polynomial ring. Just try it!

In sage, if you want to make a polynomial over F7\Bold F _7 of ff you first create the polynomial ring over F7\Bold F _7

R2.<x>=PolynomialRing(GF(7)) R2

And then simply use the polynomial ring as a function. This will cause sage to try and make an element of R2R2 out of ff 

R2(f)

note that this idea can be used for a lot more then polynomial rings. it of course also work in the much easier case F7\Bold F _7 itself. And as we wil see later even with elliptic curves.

F7=GF(7) a=F7(17); a,a^2

Now let us try to define our first elliptic curve

E=EllipticCurve([3,4]) E

To see what you can do with an object just put a dot behind it and press <tab>. Try it!

E.

For example sage can calculate the torsion points for you:

E.torsion_points()

And in some cases even the rank!

E.rank()

We can of course use coordinates to make points on the curve (remember that calling an object with something else tries to make an element of itself from the something else)

P=E([0,2]) P

Note that it shows the projective coordinates by default. We can also multiply this point by integers, just as we would expect.

P*3

Excercise : Add the previously found 2 torsion point to P

You can also define elliptic curves over finite fields

Ef7=EllipticCurve(F7,[3,4]) Ef7

We could also have obtained the previous curve by reducing E modulo 7

Emod7=E.reduction(7) Emod7

Excercise

can you make P in to a point on Emod7 an Ef7 and find it's order there?

In python you compare object for equality using the == operator (others are < for smaller then > greater then != for not equal and >= for greater then or equal etc)

4==4

Excercise

try to see if the Ef7 and Emod7 curves are really the same

(R(x)-5)*(R(x)-7)

Python of course also has an if statement and a while loop. They also depends on indentation just like the for loop to determine when to end. The following demonstrates how to combine them to investigate the 3n+1 problem

n=11 while n!=1: if is_even(n): n=n/2 else: n=3*n+1 print n

In python you can use for loops to iterate over almost all finite things (set, list, strings, etc). The same is True in sage. In particular finite fields are finite and elliptic cuves over them also. For example make a set containing all 3th powers in F7 

third_powers=set() # create empty set for i in F7: third_powers.add(i^3) print third_powers

Excercise find all points inf Ef7 of exact order 5

It's also usefull to know how to find functions in sage. There are multiple ways. One way is to use the command search_doc

search_doc("cyclotomic field")

Use the search function in the online reference manual at http://sagemath.org/doc/reference/

Or what I usually do is guess the first letters of the function and use tab completion (note that python is case sensitive so you might have to try both upper and lower case as the first letter). Try pressing tab using the input below

cy

Excercise Try to find the function which computes the Hilbert class polynomial.

Hopefully you now know enough to do basic things in sage with elliptic curves!