︠556e420a-f306-460e-9a80-df3e5a5e1e0ai︠ %html

AMS Short Course: Computing with Elliptic Curves using Sage

January 2-3, 2012

Lecture 1: Introduction to Python and Sage

Kiran S. Kedlaya (MIT/UC San Diego)

This lecture is an introduction to using the computer algebra system Sage. In the process, we will also introduce the Python programming language, on which Sage is built; however, we'll keep the programming discussion to a minimum because it is easy to find Python tutorials and other documentation online. (For example, try the Beginner's Guide to Python.)

All of the lectures in this minicourse are meant to be interactive, so you are strongly encouraged to follow along on your own computer as we go along. To make this possible, we begin by explaining how to run Sage on your own computer. There are two natural ways to do this.

To simplify the exposition, I'm mostly going to stick to explaining the notebook interface. If you have questions about using the command line, ask during the Q&A session.

Getting started with the notebook

If you have successfully started a notebook session, you should see something that looks much like this window, except that instead of all of this text, you should just see an empty box like the one below. (That is, unless you followed my instructions to edit a copy of my worksheet. In that case, you should still have an empty box like the one below, but it will be surrounded by the other text that you see here!)

︡fcac7a32-e7d0-4f38-85eb-627982807998︡{"html": "

AMS Short Course: Computing with Elliptic Curves using Sage

\n

January 2-3, 2012

\n

Lecture 1: Introduction to Python and Sage

\n

Kiran S. Kedlaya (MIT/UC San Diego)

\n

This lecture is an introduction to using the computer algebra system Sage. In the process, we will also introduce the Python programming language, on which Sage is built; however, we'll keep the programming discussion to a minimum because it is easy to find Python tutorials and other documentation online. (For example, try the Beginner's Guide to Python.)

\n

All of the lectures in this minicourse are meant to be interactive, so you are strongly encouraged to follow along on your own computer as we go along. To make this possible, we begin by explaining how to run Sage on your own computer. There are two natural ways to do this.

\n\n

To simplify the exposition, I'm mostly going to stick to explaining the notebook interface. If you have questions about using the command line, ask during the Q&A session.

\n

Getting started with the notebook

\n

If you have successfully started a notebook session, you should see something that looks much like this window, except that instead of all of this text, you should just see an empty box like the one below. (That is, unless you followed my instructions to edit a copy of my worksheet. In that case, you should still have an empty box like the one below, but it will be surrounded by the other text that you see here!)

"}︡ ︠81f857d9-292b-44e7-af4d-198104261b9ci︠ %html

This box is called a cell, and can be used to evaluate any Sage command. For example, try clicking on the cell, typing 2+2, and clicking "evaluate". (A shortcut for "evaluate" is Shift+Enter.)

︡d6b95eb0-3069-43b7-914d-efe0bca40331︡{"html": "

This box is called a cell, and can be used to evaluate any Sage command. For example, try clicking on the cell, typing 2+2, and clicking \"evaluate\". (A shortcut for \"evaluate\" is Shift+Enter.)

"}︡ ︠38b77fb5-8b71-4834-af53-534619c10c45︠ 2+2 ︡61ae7fbc-5448-45a9-bf51-3b69374de04a︡{"stdout": "4"}︡ ︠5ed065f8-b08e-4728-a7cc-38a4d1940216i︠ %html

Note that the answer appears immediately below, and then a new cell is generated so that you can type another command. You can also go back and edit the previous cell, but the answer won't change until you evaluate again. You can even insert new cells between existing cells: if you click on the blue bar that shows up when you mouse between two existing cells, a new cell will pop up in between.

If you Shift-click instead, you get a text box like this, which supports some formatting and even basic TeX commands. This is one way to add annotations to a notebook; a more direct one is simply to insert comments in cells themselves. The # character denotes a comment, and forces everything to the end of the line to be ignored.

︡3b612f59-b647-46e6-830b-9d9bcb4e3a2d︡{"html": "

Note that the answer appears immediately below, and then a new cell is generated so that you can type another command. You can also go back and edit the previous cell, but the answer won't change until you evaluate again. You can even insert new cells between existing cells: if you click on the blue bar that shows up when you mouse between two existing cells, a new cell will pop up in between.

\n

If you Shift-click instead, you get a text box like this, which supports some formatting and even basic TeX commands. This is one way to add annotations to a notebook; a more direct one is simply to insert comments in cells themselves. The # character denotes a comment, and forces everything to the end of the line to be ignored.

"}︡ ︠9fdd1c3c-a883-4bec-96bd-586c19f1ec55︠ 2+2 # should equal 4 ︡32911de7-df00-41ae-852a-cce9818a7e4e︡{"stdout": "4"}︡ ︠d3e9f9ab-3c8e-4fa2-834e-8123a749d29fi︠ %html

Besides individual calculator-style expressions, a cell can contain a sequence of instructions; hit Enter to separate instructions. (This is why Shift-Enter is the shortcut for evaluation, not Enter.) The last expression is evaluated and printed; you can also add "print" commands to force additional printing.

︡7260ce18-e606-4885-b183-84d118ede5a7︡{"html": "

Besides individual calculator-style expressions, a cell can contain a sequence of instructions; hit Enter to separate instructions. (This is why Shift-Enter is the shortcut for evaluation, not Enter.) The last expression is evaluated and printed; you can also add \"print\" commands to force additional printing.

"}︡ ︠f66445f5-e8ab-4fd9-a7fd-673afd21124b︠ x = 5 y = 7 print x+y x*y ︡c37fba03-5873-4340-9588-6655983a9fe9︡{"stdout": "12\n35"}︡ ︠6dd405f0-fab1-4fbe-97fa-62a25c641395i︠ %html

Each cell evaluation remembers any definitions from cells that were evaluated previously, including variables and functions (more on which later).

︡d6a50725-509e-4b04-b94f-f71b868d1446︡{"html": "

Each cell evaluation remembers any definitions from cells that were evaluated previously, including variables and functions (more on which later).

"}︡ ︠43983678-2877-4844-bbdb-a33e82731bcb︠ x+y ︡e0b9745f-5ca2-43e5-b320-aaa635ba3355︡{"stdout": "12"}︡ ︠43abf641-4beb-4e53-ba19-a2a710858fcfi︠ %html

Warning: Sage will let you evaluate cells out of order. It is the order of evaluation that counts, not the order of appearance in the worksheet.

If you try to evaluate a cell which contains a mistake, such as trying to use a variable which is not yet defined, Sage will give you a (hopefully) useful error message. You can click on the output to see a more verbose error message, which may help you isolate the problem if it occurs in a large cell.

︡cf3cecd9-844d-4a8c-844f-d24ffdb262d8︡{"html": "

Warning: Sage will let you evaluate cells out of order. It is the order of evaluation that counts, not the order of appearance in the worksheet.

\n

If you try to evaluate a cell which contains a mistake, such as trying to use a variable which is not yet defined, Sage will give you a (hopefully) useful error message. You can click on the output to see a more verbose error message, which may help you isolate the problem if it occurs in a large cell.

"}︡ ︠bd684cea-9a71-4800-95b2-70525de9589e︠ z ︡4f8fc74a-674c-4f5e-9cdd-84b065e41efe︡{"stderr": "Traceback (most recent call last):\n File \"\", line 1, in \n File \"_sage_input_28.py\", line 10, in \n exec compile(u'open(\"___code___.py\",\"w\").write(\"# -*- coding: utf-8 -*-\\\\n\" + _support_.preparse_worksheet_cell(base64.b64decode(\"eg==\"),globals())+\"\\\\n\"); execfile(os.path.abspath(\"___code___.py\"))' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"/tmp/tmplJOMYe/___code___.py\", line 2, in \n exec compile(u'z' + '\\n', '', 'single')\n File \"\", line 1, in \n \nNameError: name 'z' is not defined"}︡ ︠228e5a8e-e5f2-401c-9eb8-d868460f8936i︠ %html

Basic Python/Sage objects

Let's get familiar with some basic types of Python/Sage objects. These will all be things that can be assigned to variables, which we have already seen how to do in the case of integers.

︡e516462e-8812-4e9e-ba46-8d5d1bd43812︡{"html": "

Basic Python/Sage objects

\n

Let's get familiar with some basic types of Python/Sage objects. These will all be things that can be assigned to variables, which we have already seen how to do in the case of integers.

"}︡ ︠24666e58-fddc-4ac3-9cd6-65ee7076e9e1︠ x = 2+2 print x ︡854a4dd7-38cd-47db-9b1d-e9f0bf4c0dd9︡{"stdout": "4"}︡ ︠f04960dc-58e0-4e99-abff-fad9b3cddbb4i︠ %html

Note that variables do not need to be declared before being used; in particular, there is no need to specify in advance what type of object is going to be assigned to a given variable.

So far our variable names have only been one character long. However, this is not required: you may use any sequence of letters, numbers, and the underscore _ as a variable name as long as it starts with a letter and does not coincide with a Python reserved wood (such as "print"). Considered choice of variable names may make your code easier for a human to understand.

︡cf0daa12-f423-434a-a153-cecaf051a8cb︡{"html": "

Note that variables do not need to be declared before being used; in particular, there is no need to specify in advance what type of object is going to be assigned to a given variable.

\n

So far our variable names have only been one character long. However, this is not required: you may use any sequence of letters, numbers, and the underscore _ as a variable name as long as it starts with a letter and does not coincide with a Python reserved wood (such as \"print\"). Considered choice of variable names may make your code easier for a human to understand.

"}︡ ︠fd69625d-f6ff-4ad6-a156-edcbdbd75287︠ square_root_of_2 = sqrt(2) print square_root_of_2^4 ︡6f58e57c-3cfe-4209-b042-2030a81c539e︡{"stdout": "4"}︡ ︠59da8340-63fd-4498-9296-4e7412bfd1aci︠ %html

Besides integers, some other basic types of objects include rational numbers, real numbers, and complex numbers (where capital I denotes the chosen square root of -1). These support the usual arithmetic operations.

︡ffac06ec-3907-42a1-95bf-c90be9beda20︡{"html": "

Besides integers, some other basic types of objects include rational numbers, real numbers, and complex numbers (where capital I denotes the chosen square root of -1). These support the usual arithmetic operations.

"}︡ ︠040fd784-0a09-4ef0-b661-41d576f5d10d︠ print 7 % 3 ## modular reduction print 7 // 3 ## integer division print 10/6 ## returns a rational number print exp(2.7) print (2+I)*(3+I) ︡b49200ed-9d9f-466a-b5de-f45e9caf2784︡{"stdout": "1\n2\n5/3\n14.8797317248728\n5*I + 5"}︡ ︠51c9e4d7-df58-4185-86ee-0e757039066di︠ %html

Another basic object type is strings, which are enclosed in either single or double quotes (there is a subtle distinction which is not relevant here). One common operation on strings is concatenation.

︡95940a56-d1d2-4133-9831-a08f62cfc9ec︡{"html": "

Another basic object type is strings, which are enclosed in either single or double quotes (there is a subtle distinction which is not relevant here). One common operation on strings is concatenation.

"}︡ ︠896dd52e-40f7-4cb9-99c5-156acb7d8529︠ '3' + '4' ︡fbb626db-4f41-4c6d-a362-832687b3ccba︡{"stdout": "'34'"}︡ ︠a1a093b6-1a94-432b-a2fb-c29c1c78e4ebi︠ %html

Arrays

Besides simple types like numbers and strings, one also has compound types like arrays. Arrays can be specified using square brackets (the entries need not be all of one type).

︡40ec4862-cbd8-4988-9945-c94f3bb7a935︡{"html": "

Arrays

\n

Besides simple types like numbers and strings, one also has compound types like arrays. Arrays can be specified using square brackets (the entries need not be all of one type).

"}︡ ︠2ef2f138-edc8-47ca-bcdf-66ddf57d2fd1︠ print [3, 4] + [5, 'six'] ## plus sign denotes composition ︡18be5287-cc89-48fa-932d-112d75b2d690︡{"stdout": "[3, 4, 5, 'six']"}︡ ︠5dbd4cd1-1996-4f0e-8fbe-434929ddd8cci︠ %html

One also uses square brackets to access the individual entries of an array, or even to assign them. Two important things to note:

  • Python indexes starting from 0, not 1.
  • You may also use negative indices: -n denotes the n-th term from the end.
︡02158ede-4dce-476b-a555-16965fd216c0︡{"html": "

One also uses square brackets to access the individual entries of an array, or even to assign them. Two important things to note:

\n
    \n
  • Python indexes starting from 0, not 1.
  • \n
  • You may also use negative indices: -n denotes the n-th term from the end.
  • \n
"}︡ ︠048a7c32-8633-4a31-8996-b616d8d0b461︠ u = [2, 3, 4] print u[0] ## first element print u[-1] ## last element u[1] = 1 ## modify an existing entry print u[-2] ## should equal u[1] u[3] = 5 ## this won't work ︡d8150c9c-7829-4c02-83d6-95e499265db4︡{"stdout": "2\n4\n1\n"}︡{"stderr": "Traceback (most recent call last):\n File \"\", line 1, in \n File \"_sage_input_34.py\", line 10, in \n exec compile(u'open(\"___code___.py\",\"w\").write(\"# -*- coding: utf-8 -*-\\\\n\" + _support_.preparse_worksheet_cell(base64.b64decode(\"dSA9IFsyLCAzLCA0XQpwcmludCB1WzBdICMjIGZpcnN0IGVsZW1lbnQKcHJpbnQgdVstMV0gIyMgbGFzdCBlbGVtZW50CnVbMV0gPSAxICMjIG1vZGlmeSBhbiBleGlzdGluZyBlbnRyeQpwcmludCB1Wy0yXSAjIyBzaG91bGQgZXF1YWwgdVsxXQp1WzNdID0gNSAjIyB0aGlzIHdvbid0IHdvcms=\"),globals())+\"\\\\n\"); execfile(os.path.abspath(\"___code___.py\"))' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"/tmp/tmpqPdTmN/___code___.py\", line 8, in \n exec compile(u\"u[_sage_const_3 ] = _sage_const_5 ## this won't work\" + '\\n', '', 'single')\n File \"\", line 1, in \n \nIndexError: list assignment index out of range"}︡ ︠19e03f6b-0752-48b5-9576-f7f8a00318eci︠ %html

Some other ways to construct arrays are the following.

  • One can concatenate existing arrays using the + operator (see above).
  • One can modify in place entries of an existing array (see above).
  • One can form slices of an existing array by picking out a range of values. This is the safest way to make a copy of an array (see below).
  • Some functions return arrays, such as the "range" function.
  • One can use list comprehensions to apply a function to each term of one array to make a new array. There is also the option to put in a conditional statement to pick out only some of the terms of the original array (using == for equality, rather than = which means assignment). This is a lot like how mathematicians make sets!
︡19fb0c0f-e0ef-43ee-97e1-d29a074c0eb4︡{"html": "

Some other ways to construct arrays are the following.

\n
    \n
  • One can concatenate existing arrays using the + operator (see above).
  • \n
  • One can modify in place entries of an existing array (see above).
  • \n
  • One can form slices of an existing array by picking out a range of values. This is the safest way to make a copy of an array (see below).
  • \n
  • Some functions return arrays, such as the \"range\" function.
  • \n
  • One can use list comprehensions to apply a function to each term of one array to make a new array. There is also the option to put in a conditional statement to pick out only some of the terms of the original array (using == for equality, rather than = which means assignment). This is a lot like how mathematicians make sets!
  • \n
"}︡ ︠f6f8fc01-cb8d-4542-adb0-4bc7a5d842fb︠ u = [2,3,4,5] print u[1:3] ## left index is included, right index is not print u[:4] ## left index defaults to 0 print u[1:] ## right index defaults to the length of the array print range(5) ## range(n) includes 0, excludes n print range(3,13) ## specify left and right endpoints as for slices print [x^2 for x in u if x%2==1] ︡524c7764-7478-478c-a897-2e5fec32668f︡{"stdout": "[3, 4]\n[2, 3, 4, 5]\n[3, 4, 5]\n[0, 1, 2, 3, 4]\n[3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\n[9, 25]"}︡ ︠442f20aa-bfe0-49d3-8391-34933f7c26a8i︠ %html

Warning: arrays are copied by reference, not by value. This is in fact true for all Python/Sage objects, but the fact that arrays can be modified after they are created (that is, they are mutable) creates a real danger.

︡127ef202-c042-44ef-b88a-55be21ef8e78︡{"html": "

Warning: arrays are copied by reference, not by value. This is in fact true for all Python/Sage objects, but the fact that arrays can be modified after they are created (that is, they are mutable) creates a real danger.

"}︡ ︠0f8e1abf-4cdc-48dd-bbc9-e13f1fa7ee90︠ a = [1,2,3] b = a ## does not create a new array! b[1] = -1 print "a = ", a ## has now been modified c = a[:] ## this does create a new array c[-1] = 4 print "a = ", a print "c = ", c ︡322a5350-e4ed-432c-a399-f7e9b08821f3︡{"stdout": "a = [1, -1, 3]\na = [1, -1, 3]\nc = [1, -1, 4]"}︡ ︠40c8d1cb-ec9f-42a1-a444-a5749903ddc2i︠ %html

Conditional evaluation

Like most programming languages, Python supports conditional evaluation via such mechanisms as for loops, while loops, and if-then-else constructions. Here is an example.

︡4e646ae9-02f7-458a-aac0-f4d5ea5c236d︡{"html": "

Conditional evaluation

\n

Like most programming languages, Python supports conditional evaluation via such mechanisms as for loops, while loops, and if-then-else constructions. Here is an example.

"}︡ ︠22e86c7b-5456-436e-92a2-a34019eabc28︠ for i in range(5): if i%2 == 0: print i, "is an even", else: print i, "is an odd", print "number" print "loop complete" ︡42a2a699-2a62-423d-8d37-6f815ff8d306︡{"stdout": "0 is an even number\n1 is an odd number\n2 is an even number\n3 is an odd number\n4 is an even number\nloop complete"}︡ ︠096b1c5a-e899-4441-9f05-e4d7c704e155i︠ %html

Let's step through this example in detail.

  • The first line creates the for loop. The range is created using the "range" function described above.
  • Everything within the for loop is indented. This is not optional! Python uses this indentation to figure out where the loop starts and ends. The notebook will help you: after you type the "for" line (ending with the colon), the next line will be indented appropriately.
  • The "if" command takes a Boolean expression. As we saw before,  == denotes equality, as opposed to a single = which denotes an assignment.
  • The "else" command is optional. Again, the indentation tells Python where the if and else clauses begin and end.
  • The "print" command can take multiple arguments, and adds a line break unless you end it with a comma.

Here is another example, this time of a while loop. Note the effect of the "continue" and "break" statements.

︡d8b87f3f-74cf-4367-b798-3f42e60e72ae︡{"html": "

Let's step through this example in detail.

\n
    \n
  • The first line creates the for loop. The range is created using the \"range\" function described above.
  • \n
  • Everything within the for loop is indented. This is not optional! Python uses this indentation to figure out where the loop starts and ends. The notebook will help you: after you type the \"for\" line (ending with the colon), the next line will be indented appropriately.
  • \n
  • The \"if\" command takes a Boolean expression. As we saw before,  == denotes equality, as opposed to a single = which denotes an assignment.
  • \n
  • The \"else\" command is optional. Again, the indentation tells Python where the if and else clauses begin and end.
  • \n
  • The \"print\" command can take multiple arguments, and adds a line break unless you end it with a comma.
  • \n
\n\n

Here is another example, this time of a while loop. Note the effect of the \"continue\" and \"break\" statements.

"}︡ ︠7245fbac-8ef9-4cb0-9e13-456ed9675b2d︠ t = 4 while t < 10: t += 1 ## has the same effect as t = t + 1 if t%2 == 0: continue ## jump to the next iteration of the loop print t if t > 8: break ## jump out of the loop ︡048e051e-c432-4ea0-b375-63c3b820453a︡{"stdout": "5\n7\n9"}︡ ︠716d2caf-ee30-4447-a445-7a2890e37510i︠ %html

Functions

By now, you have probably noticed that much Python functionality is provided via callable functions, such as "range". Sage extends this functionality by specifying many new advanced mathematical functions.

︡4b6a872f-b6a2-4dad-9ba2-45c189c6af31︡{"html": "

Functions

\n

By now, you have probably noticed that much Python functionality is provided via callable functions, such as \"range\". Sage extends this functionality by specifying many new advanced mathematical functions.

"}︡ ︠ca663194-27eb-4eca-ac2f-bc97a5a3f13b︠ prime_pi(1000) ## The number of primes up to 1000 ︡9ff40499-63e3-49f5-ad6b-920c6c4f835e︡{"stdout": "168"}︡ ︠feaeb6b8-6ec2-4367-a866-48854606a51di︠ %html

Sage includes a couple of handy techniques for inquiring about functions. One of these is tab completion: if you type part of the name of a function and hit Tab, Sage will attempt to complete the name of the function. On one hand, this can save a lot of typing.

︡bded953a-ddff-4182-aed2-eeda4f5db449︡{"html": "

Sage includes a couple of handy techniques for inquiring about functions. One of these is tab completion: if you type part of the name of a function and hit Tab, Sage will attempt to complete the name of the function. On one hand, this can save a lot of typing.

"}︡ ︠ad49274a-0d6e-4561-9f6b-10ea00b51cea︠ charac ︡14bb750d-c9cf-48aa-9ae4-00913fe51560︡{"stderr": "Traceback (most recent call last):\n File \"\", line 1, in \n File \"_sage_input_40.py\", line 10, in \n exec compile(u'open(\"___code___.py\",\"w\").write(\"# -*- coding: utf-8 -*-\\\\n\" + _support_.preparse_worksheet_cell(base64.b64decode(\"Y2hhcmFj\"),globals())+\"\\\\n\"); execfile(os.path.abspath(\"___code___.py\"))' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"/tmp/tmpgffKkR/___code___.py\", line 2, in \n exec compile(u'charac' + '\\n', '', 'single')\n File \"\", line 1, in \n \nNameError: name 'charac' is not defined"}︡ ︠5eef1942-1c3a-4fd4-9ae2-457afbf3b05ei︠ %html

Perhaps more usefully, if more than one completion is possible, Sage will show you all possible completions; this can be a useful way to find out about what is available in Sage. (This technique is even more possible when applied to object methods; see below.)

︡0fd97c61-da2e-4799-8d9f-aca27d78737b︡{"html": "

Perhaps more usefully, if more than one completion is possible, Sage will show you all possible completions; this can be a useful way to find out about what is available in Sage. (This technique is even more possible when applied to object methods; see below.)

"}︡ ︠a7582844-3572-4a94-82dd-3fc2ef4ea8ed︠ ran ︡4fa58cb4-7d45-4b58-be5e-5df538c5ed27︡{"stderr": "Traceback (most recent call last):\n File \"\", line 1, in \n File \"_sage_input_41.py\", line 10, in \n exec compile(u'open(\"___code___.py\",\"w\").write(\"# -*- coding: utf-8 -*-\\\\n\" + _support_.preparse_worksheet_cell(base64.b64decode(\"cmFu\"),globals())+\"\\\\n\"); execfile(os.path.abspath(\"___code___.py\"))' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"/tmp/tmp1l6IeV/___code___.py\", line 2, in \n exec compile(u'ran' + '\\n', '', 'single')\n File \"\", line 1, in \n \nNameError: name 'ran' is not defined"}︡ ︠e41fb803-55e3-4826-b3aa-15488954949bi︠ %html

Another important inquiry technique is introspection: if one evaluates the name of a function followed by a ?, Python will show you a bit of documentation about that function. For instance, if you have forgotten how to specify a range other than 0, ..., n-1, we can use introspection on the range function.

︡8bdf4a23-7ed6-4730-9c76-e41c9f583623︡{"html": "

Another important inquiry technique is introspection: if one evaluates the name of a function followed by a ?, Python will show you a bit of documentation about that function. For instance, if you have forgotten how to specify a range other than 0, ..., n-1, we can use introspection on the range function.

"}︡ ︠0516b1d8-96ec-468c-afea-432618e41220︠ range? ︡93f61ab8-a84d-4e20-a872-4237abd4bf1a︡{"html": "\n

Type: <type 'builtin_function_or_method'>

\n

Definition: range( [noargspec] )

\n

Docstring:

\n
\n\nrange([start,] stop[, step]) -> list of integers\n\nReturn a list containing an arithmetic progression of integers.\nrange(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\nWhen step is given, it specifies the increment (or decrement).\nFor example, range(4) returns [0, 1, 2, 3].  The end point is omitted!\nThese are exactly the valid indices for a list of 4 elements.
\n"}︡ ︠ce8bb40a-52bd-467c-a68d-be2abd658430i︠ %html

Python and Sage also allow for user-defined functions. As with variables, these may be defined in one cell and then used in later cell evaluations. (These will not admit introspection unless you do some extra work, except for source code viewing, but they will admit tab completion.)

︡d29e98db-b20b-43da-84d4-d24584df6adc︡{"html": "

Python and Sage also allow for user-defined functions. As with variables, these may be defined in one cell and then used in later cell evaluations. (These will not admit introspection unless you do some extra work, except for source code viewing, but they will admit tab completion.)

"}︡ ︠77204cf7-b6d6-4340-870a-5b1e6f47233d︠ def strange_sum(a, b): c = a+b return(a+b+c) ︡5565b003-d076-416c-80b5-91c09c8a0186︡︡ ︠a237baa7-e989-4e14-83f3-62a4d3df0c65︠ strange_sum(2, 3) ︡1960ef8e-5835-47bf-9c72-b8464df96f49︡{"stdout": "10"}︡ ︠cf04b360-94b5-47fd-85ea-a9e7ded43bd5︠ strange_sum? ︡80917e56-b680-4d27-b0bb-4bb5aa7e2b73︡{"html": "\n

File: /tmp/tmptnWB2h/___code___.py

\n

Type: <type 'function'>

\n

Definition: strange_sum(a, b)

\n

Docstring:

\n
\n\nx.__init__(...) initializes x; see x.__class__.__doc__ for signature
\n"}︡ ︠2c781561-e772-458b-89f2-d63730ef00e8︠ strange_sum?? ︡e6c55f19-cea5-45d0-9417-cc434ffef0a2︡{"html": "\n\n
\n \n

File: /tmp/tmptnWB2h/___code___.py

\n

Source Code (starting at line 2):

\n
def strange_sum(a, b):\n    c = a+b\n    return(a+b+c)\n
\n
\n\n\n
\n"}︡ ︠60a27f91-258d-47b3-b599-6dcf4cadb15bi︠ %html

Mathematical objects in Sage

One important difference between Python and some lower-level programming languages like C is that Python is object-oriented. That is, besides the variables and functions that one can define globally, one can also create objects with their own variables and functions attached to them. In Sage, this framework is used to implement the construction of mathematical objects in a rigorous fashion which corresponds pretty well to the way mathematicians are used to thinking about these objects. For example, one can create such objects as the ring of integers and the field of rational numbers.

︡c6d1345e-c558-458f-b395-4a2e5a2b75e6︡{"html": "

Mathematical objects in Sage

\n\n

One important difference between Python and some lower-level programming languages like C is that Python is object-oriented. That is, besides the variables and functions that one can define globally, one can also create objects with their own variables and functions attached to them. In Sage, this framework is used to implement the construction of mathematical objects in a rigorous fashion which corresponds pretty well to the way mathematicians are used to thinking about these objects. For example, one can create such objects as the ring of integers and the field of rational numbers.

"}︡ ︠5592ed67-db69-49a1-bee1-2d2f1442bb4c︠ Z = IntegerRing() Q = RationalField() ︡1efab56e-3d2c-41fa-9f6d-ade0e1c0439d︡︡ ︠6da4b3cc-9193-4eef-a350-3e71230b6935i︠ %html

One can then feed these into more complicated constructions, like the ring of polynomials in a single variable.

︡b6100a36-d73d-4ce3-ab5e-f0ac98bf5e2b︡{"html": "

One can then feed these into more complicated constructions, like the ring of polynomials in a single variable.

"}︡ ︠f100ec24-a87e-4d21-a70f-b415d1f1bbd6︠ R. = PolynomialRing(Q) ︡05b22de9-0bd8-4c00-a8d9-352dce80fafd︡︡ ︠1a1abbe3-dca6-441f-a79c-302097131e8ai︠ %html

In this example, we have created a polynomial ring over the rationals with a distinguished generator, to which we have assigned the name T. We can now generate elements of the ring R simply by writing down expressions in T.

 

︡2724b895-a18c-419f-87b8-3cf77f157d9f︡{"html": "

In this example, we have created a polynomial ring over the rationals with a distinguished generator, to which we have assigned the name T. We can now generate elements of the ring R simply by writing down expressions in T.

\n

 

"}︡ ︠347bb03d-e221-44bd-8fb4-07266fe72eea︠ poly = T^3 + 1 print poly.parent() print poly.parent() == R ︡c14a8c83-7330-4707-8206-de747c2de17d︡{"stdout": "Univariate Polynomial Ring in T over Rational Field\nTrue"}︡ ︠65fac4c0-f39c-4b3e-8ecb-61c9aa37f05bi︠ %html

The "parent" command here is an example of a method of the object poly.

Now that we can make polynomials over the rationals, what can we do with them? An excellent way to find out is to use tab completion: if one types "poly." and then hits Tab, one is presented a list of all of the methods associated to poly.

︡3aeb2869-f39d-4a70-827c-c0b9526c7fd4︡{"html": "

The \"parent\" command here is an example of a method of the object poly.

\n

Now that we can make polynomials over the rationals, what can we do with them? An excellent way to find out is to use tab completion: if one types \"poly.\" and then hits Tab, one is presented a list of all of the methods associated to poly.

"}︡ ︠07822e01-4fc3-4908-909a-81510bb5f3ee︠ poly.factor() ## can also be invoked as factor(poly) ︡695261ba-e2dd-4ac8-aa91-770eca396932︡{"stdout": "(T + 1) * (T^2 - T + 1)"}︡ ︠3941d337-9ed2-40c6-8006-3f87cdba4ee1i︠ %html

In the previous example, the "factor" method did not require any additional arguments. In other examples, one or more arguments may be required.

︡0de99f2c-8bc4-4b21-a284-1d8ceef6c237︡{"html": "

In the previous example, the \"factor\" method did not require any additional arguments. In other examples, one or more arguments may be required.

"}︡ ︠ed81d316-316c-4a0f-b95c-f3cdf6d2baaf︠ poly.xgcd(T-2) ## extended GCD; can also be invoked as xgcd(poly, T-2) ︡4f6950e0-3d4f-47a5-a924-6e21aedc77f3︡{"stdout": "(1, 1/9, -1/9*T^2 - 2/9*T - 4/9)"}︡ ︠1f703dfb-b863-4872-952a-5e694cad4ea7i︠ %html

This syntax might seem a bit strange: the extended GCD operation is essentially symmetric in its variables, so calling it in an asymmetric fashion may be counterintuitive. There is an extremely good reason for using the object-oriented syntax, namely tab completion. One can for instance type "poly." and his Tab to see the list of all of the methods associated to poly!

The ease of looking up the operations available on a given type of mathematical object is one of my favorite features of Sage. Even Magma, which has both object orientation and tab completion, fails on this point because functions are not viewed as object methods, but intsead all inhabit a single namespace.

︡f8f3ca30-a4c4-47dc-a77b-7d93439ac314︡{"html": "

This syntax might seem a bit strange: the extended GCD operation is essentially symmetric in its variables, so calling it in an asymmetric fashion may be counterintuitive. There is an extremely good reason for using the object-oriented syntax, namely tab completion. One can for instance type \"poly.\" and his Tab to see the list of all of the methods associated to poly!

\n

The ease of looking up the operations available on a given type of mathematical object is one of my favorite features of Sage. Even Magma, which has both object orientation and tab completion, fails on this point because functions are not viewed as object methods, but intsead all inhabit a single namespace.

"}︡ ︠6935a194-2d5d-4107-bb96-7726e7132924︠ poly. ︡7f41871a-a942-4809-b18f-28740049ec40︡{"stderr": "Traceback (most recent call last):\n File \"\", line 1, in \n File \"_sage_input_52.py\", line 10, in \n exec compile(u'open(\"___code___.py\",\"w\").write(\"# -*- coding: utf-8 -*-\\\\n\" + _support_.preparse_worksheet_cell(base64.b64decode(\"cG9seS4=\"),globals())+\"\\\\n\"); execfile(os.path.abspath(\"___code___.py\"))' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"/tmp/tmpzyGLH1/___code___.py\", line 2\n poly.\n ^\nSyntaxError: invalid syntax"}︡ ︠6d476d7a-f81e-4833-b8cb-52e1cddb03d3i︠ %html

As for bare functions, one can also type a few characters and get only the methods that start with the characters you type. For example, if you can't remember whether the method for factoring a polynomial is called "factor", "factorize", "factorise", "factorization", or "factorisation", you can check by doing a tab completion:

︡d1f7d0f9-93a1-4e42-8fcb-b2e1ca02f8d7︡{"html": "

As for bare functions, one can also type a few characters and get only the methods that start with the characters you type. For example, if you can't remember whether the method for factoring a polynomial is called \"factor\", \"factorize\", \"factorise\", \"factorization\", or \"factorisation\", you can check by doing a tab completion:

"}︡ ︠ef589df3-3ddf-4067-86af-e28469577a28︠ poly.factor ︡d4aa179b-628f-4986-aa2f-e70e5bc881b7︡{"stdout": ""}︡ ︠05da647c-6e82-4940-98bd-a2cadbe09f9di︠ %html

There can sometimes be some ambiguity about what the correct parent of a mathematical object should be. For instance, 3/4 is a rational number, but it can also be viewed as a polynomial over the rationals, e.g., when one wants to add or multiply it with another such polynomial. For the most part, Sage will take care of this for you automatically.

︡d21f697e-e9fe-4a1c-b4f6-18cc207b064a︡{"html": "

There can sometimes be some ambiguity about what the correct parent of a mathematical object should be. For instance, 3/4 is a rational number, but it can also be viewed as a polynomial over the rationals, e.g., when one wants to add or multiply it with another such polynomial. For the most part, Sage will take care of this for you automatically.

"}︡ ︠36c826d5-0802-4ea3-bdb1-d1cacd9bf527︠ poly2 = poly + 3/4 print poly2.parent() ︡a358decc-cd60-4ff6-961c-94646fa12674︡{"stdout": "Univariate Polynomial Ring in T over Rational Field"}︡ ︠aaf7e86b-edd6-4a81-9da1-c46546856824i︠ %html

Sometimes, however, one needs to make this change of parent explicit, e.g., in case one wants to call a method which exists for polynomials but not for rationals. For example, this fails:

︡867593ec-fb0c-4128-9b68-530e176d6e68︡{"html": "

Sometimes, however, one needs to make this change of parent explicit, e.g., in case one wants to call a method which exists for polynomials but not for rationals. For example, this fails:

"}︡ ︠ec6b90b5-2b33-4b0e-b8e9-d5bbbb0ef6d6︠ poly2 = 3/4 poly2.coefficients() ︡970d1799-a549-4790-8395-4ea77af70f50︡{"stderr": "Traceback (most recent call last):\n File \"\", line 1, in \n File \"_sage_input_55.py\", line 10, in \n exec compile(u'open(\"___code___.py\",\"w\").write(\"# -*- coding: utf-8 -*-\\\\n\" + _support_.preparse_worksheet_cell(base64.b64decode(\"cG9seTIgPSAzLzQKcG9seTIuY29lZmZpY2llbnRzKCk=\"),globals())+\"\\\\n\"); execfile(os.path.abspath(\"___code___.py\"))' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"/tmp/tmppWRlmg/___code___.py\", line 4, in \n exec compile(u'poly2.coefficients()' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"element.pyx\", line 331, in sage.structure.element.Element.__getattr__ (sage/structure/element.c:2868)\n File \"parent.pyx\", line 327, in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:3193)\nAttributeError: 'sage.rings.rational.Rational' object has no attribute 'coefficients'"}︡ ︠0f9e434d-f400-4e00-8030-2fd9a1a0a472i︠ %html

This change of parent (called coercion) is usually accomplished by the following syntax, which looks like plugging the element into the new parent viewed as a function.

︡d0036732-2034-41a2-8468-bb8624127ece︡{"html": "

This change of parent (called coercion) is usually accomplished by the following syntax, which looks like plugging the element into the new parent viewed as a function.

"}︡ ︠9baf4271-4364-4342-b737-1a50334afbb3︠ poly2 = R(3/4) poly2.coefficients() ︡bc0c0673-5030-4d33-96f9-8099e1218493︡{"stdout": "[3/4]"}︡ ︠36a24598-8cf1-4be2-874e-d41a7bf147fai︠ %html

Plotting

Sage has many more mathematical features than we can introduce here (but which are well-documented). One feature which will be used later is plotting of various kinds. (We only need 2D plotting her; there are also extremely cool 3D plotting capabilities, but you can discover those on your own.)

︡32801233-1b10-4e66-9f8a-dafc7758b9c9︡{"html": "

Plotting

\n

Sage has many more mathematical features than we can introduce here (but which are well-documented). One feature which will be used later is plotting of various kinds. (We only need 2D plotting her; there are also extremely cool 3D plotting capabilities, but you can discover those on your own.)

"}︡ ︠ce6dc591-c347-4669-b44b-f6e33767f154︠ plot(sin, 0, pi) ## Plotting a built-in function ︡ecefc21b-8713-4153-938e-c6262f29bebd︡{"html": ""}︡ ︠1c0d7289-d0b0-4c70-8a13-626c25b487eb︠ var('x') ## Define a symbolic variable named x plot(x, (x, 0, 1)) ## Plot a function specified in terms of a symbolic variable ︡853307ef-bf73-4181-9739-353a21d6240d︡{"html": ""}︡ ︠33d040bb-c1fa-4483-81ca-8a74af1af9dd︠ def f(x): return(x^2+1) plot(f, -1, 1) ## Plot a user-defined function ︡babf9af2-6611-49d5-a634-735d87dee4e2︡{"html": ""}︡ ︠1063aa42-1eba-43d4-ac65-75fea622b346︠ plot(lambda x: x^2+1, -1, 1) ## Same thing using an inline function ︡99f7b6b1-1e04-49f3-9e9b-ba03390f0031︡{"html": ""}︡ ︠78176e49-61ed-44bb-add9-5cc499e68f8e︠ plot([sin(x), cos(x)], (x, 0, pi/2)) ## Plot multiple functions on the same axes ︡4ea43990-ed0e-424c-8df8-d151b441b233︡{"html": ""}︡ ︠c9e11b36-fe8d-4f7d-a6ba-22540aa0e655︠ scatter_plot([(x^2,x^3) for x in range(-5,5)]) ## plot a collection of points ︡9bfda316-4fa4-454e-a6be-4a037ce0cfcb︡{"html": ""}︡ ︠2f2a2c50-3406-46f1-a7d9-d842c0870041i︠ %html

Use of other systems

In addition to its normal use as a Sage (and Python) interpreter, the Sage notebook can be used as an interface to numerous other packages. For example, Elkies's lecture in this Short Course uses gp, which is the direct interface to Pari. Although most of Pari's functionality is available in Python-wrapped form, one can also initiate a gp session and use its syntax directly, without leaving the notebook! (One way to tell that we're not using Sage syntax is that this example depends on gp being case-insensitive. Another is that the comment syntax in gp differs from that of Sage.)

︡cd72da37-6434-4e84-8cd6-ac673f7f9375︡{"html": "

Use of other systems

\n

In addition to its normal use as a Sage (and Python) interpreter, the Sage notebook can be used as an interface to numerous other packages. For example, Elkies's lecture in this Short Course uses gp, which is the direct interface to Pari. Although most of Pari's functionality is available in Python-wrapped form, one can also initiate a gp session and use its syntax directly, without leaving the notebook! (One way to tell that we're not using Sage syntax is that this example depends on gp being case-insensitive. Another is that the comment syntax in gp differs from that of Sage.)

"}︡ ︠0c9c53b9-5672-4af6-99c3-fd0a0dbf51c4︠ %gp \\ Ask gp what the function "ellinit" does ?ellinit \\ the elliptic curve with a1=a2=a3=0 and prescribed c4,c6 E1(c4, c6) = ellinit([0, 0, 0, -c4/48, -c6/864]) ︡bbc66ab0-9ec8-4e05-b419-d31203558288︡{"stdout": "ellinit(x,{flag=0}): x being the vector [a1,a2,a3,a4,a6] defining the curve Y^2 \n+ a1.XY + a3.Y = X^3 + a2.X^2 + a4.X + a6, gives the vector: \n[a1,a2,a3,a4,a6,b2,b4,b6,b8,c4,c6,disc,j,[e1,e2,e3],w1,w2,eta1,eta2,area]. If \nthe curve is defined over a p-adic field, the last six components are replaced \nby root,u^2,u,q,w,0. If optional flag is 1, omit them altogether. x can also be \na string, in this case the coefficients of the curve with matching name are \nlooked in the elldata database if available.\n\n(c4,c6)->ellinit([0,0,0,-c4/48,-c6/864])"}︡ ︠bd36e71f-ba36-4eb9-a57b-38df57ca6e49i︠ %html

Just like calls to Sage, external packages used from the Sage notebook remember their state from one cell evaluation to the next.

︡2313784b-308b-44a3-990a-9bbce5dac6e7︡{"html": "

Just like calls to Sage, external packages used from the Sage notebook remember their state from one cell evaluation to the next.

"}︡ ︠c109120a-3ab7-458a-bb94-b1a42d34dc39︠ %gp \\ here's the syntax for getting the discriminant and j-invariant E1(C4,C6).disc E1(C4,C6).j ︡df45c64a-de18-40de-b6a2-152459acb1d6︡{"stdout": "1728*C4^3/(C4^3 - C6^2)"}︡ ︠834fcb58-1271-4c92-8610-a284a616edcei︠ %html

By the way, one can also access external packages in the following way. Note that this is the same gp session as I had before; it remembers the assignments I made in the earlier cell!

︡5835f091-5633-4965-8c53-2de721425eaa︡{"html": "

By the way, one can also access external packages in the following way. Note that this is the same gp session as I had before; it remembers the assignments I made in the earlier cell!

"}︡ ︠1024e229-518c-414d-9f8f-5f4f16767831︠ print gp("E1") ︡7ac64269-e6eb-49e3-99c4-4afcb7b1fafc︡{"stdout": "(c4,c6)->ellinit([0,0,0,-c4/48,-c6/864])"}︡ ︠a9b7c118-5b22-4bcd-8a49-3fc2fb237445i︠ %html

Similar methods can be used to access packages not provided with Sage, as long as the server has access to them. For example, the machine on which I composed this notebook runs Magma, so the following works there. (One way to tell we're not using Sage syntax is that the Magma assignment operator is := rather than =.)

︡20b0b658-6c4e-427c-97a5-7e62e5e7a995︡{"html": "

Similar methods can be used to access packages not provided with Sage, as long as the server has access to them. For example, the machine on which I composed this notebook runs Magma, so the following works there. (One way to tell we're not using Sage syntax is that the Magma assignment operator is := rather than =.)

"}︡ ︠7afae815-6ae0-4416-844f-045f841e91c5︠ %magma Q := RationalField(); print(Q); /* Should print "Rational Field" if magma is available */ ︡e1ed0746-fbf8-4f47-9fb6-1d270bb96081︡{"stdout": "Rational Field"}︡ ︠43f76854-47fd-46e4-bbd9-20bf6cd826cei︠ %html

Exception handling

This last point is a bit technical, but it will arise in the later lectures. As we saw earlier, if you make a mistake, Sage normally interrupts the computation to return an error message explaining what went wrong.

︡b7196e0a-3065-4875-8809-4ea4c13eeda3︡{"html": "

Exception handling

\n

This last point is a bit technical, but it will arise in the later lectures. As we saw earlier, if you make a mistake, Sage normally interrupts the computation to return an error message explaining what went wrong.

"}︡ ︠c9ef5bbf-aba1-4758-b113-6fca77fbf3a4︠ print (3 / (1-1)) ︡64a94c3c-13a7-4de9-ab61-010add934653︡{"stderr": "Traceback (most recent call last):\n File \"\", line 1, in \n File \"_sage_input_67.py\", line 10, in \n exec compile(u'open(\"___code___.py\",\"w\").write(\"# -*- coding: utf-8 -*-\\\\n\" + _support_.preparse_worksheet_cell(base64.b64decode(\"cHJpbnQgKDMgLyAoMS0xKSk=\"),globals())+\"\\\\n\"); execfile(os.path.abspath(\"___code___.py\"))' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"/tmp/tmpG8iuaq/___code___.py\", line 3, in \n exec compile(u'print (_sage_const_3 / (_sage_const_1 -_sage_const_1 ))' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"element.pyx\", line 1558, in sage.structure.element.RingElement.__div__ (sage/structure/element.c:12852)\n File \"integer.pyx\", line 1705, in sage.rings.integer.Integer._div_ (sage/rings/integer.c:11921)\n File \"integer_ring.pyx\", line 286, in sage.rings.integer_ring.IntegerRing_class._div (sage/rings/integer_ring.c:5209)\nZeroDivisionError: Rational division by zero"}︡ ︠413acb01-3378-49c8-ac5f-0c51b7db1352i︠ %html

One can explicitly create these errors as a debugging tool.

︡224a6412-129e-4c6d-9be4-2f6471fb4fd6︡{"html": "

One can explicitly create these errors as a debugging tool.

"}︡ ︠ed8fc2e3-0fbf-4b6b-9b99-f0211fa3c795︠ def f(n): if n < 0: raise ValueError, "Argument of f must be nonnegative" return(sqrt(n)) print f(1) print f(-1) ︡77421bf3-1d9a-4909-81ee-8cb5d48e33aa︡{"stdout": "1\n"}︡{"stderr": "Traceback (most recent call last): print f(-1)\n File \"\", line 1, in \n \n File \"/tmp/tmpk4f3zr/___code___.py\", line 9, in \n exec compile(u'print f(-_sage_const_1 )' + '\\n', '', 'single')\n File \"\", line 1, in \n \n File \"/tmp/tmpk4f3zr/___code___.py\", line 5, in f\n raise ValueError, \"Argument of f must be nonnegative\"\nValueError: Argument of f must be nonnegative"}︡ ︠0e0582f4-a0b0-4077-a464-d8741cb17a1ei︠ %html

One can also catch these errors to a limited extent, using the try and except commands.

︡dcd359d0-c3f7-4f22-a060-d9f3e58bd8b7︡{"html": "

One can also catch these errors to a limited extent, using the try and except commands.

"}︡ ︠f3a80052-4033-4f88-a273-710e52443d7c︠ def f(x,y): try: n = 1/x print "inversion complete" return(n + y[0]) except ZeroDivisionError: return 0 print f(1, [2,3]) ## normal evaluation print f(0, [4,5]) ## exception encountered, skipping the internal print statement print f(2, []) ## this exception is not caught, so causes an error print f(3, [3, 4]) ## we never get this far ︡3b231e14-411c-4dcd-9f00-4b1e6e9a1a3b︡{"stdout": "inversion complete\n3\n0\ninversion complete\n"}︡{"stderr": "Traceback (most recent call last): return 0\n File \"\", line 1, in \n \n File \"/tmp/tmpDnVGyv/___code___.py\", line 13, in \n print f(_sage_const_2 , []) ## this exception is not caught, so causes an error\n File \"/tmp/tmpDnVGyv/___code___.py\", line 7, in f\n return(n + y[_sage_const_0 ])\nIndexError: list index out of range"}︡ ︠71ba0845-7614-4cdf-858e-06c0e368b4a5i︠ %html

Conclusion: what else can Sage do?

To conclude, we point out a few more advanced things that can be accomplished using Sage, just to give the flavor of what the possibilities are. These are mostly complementary to the advanced functionality for elliptic curves that will be highlighted in the subsequent lectures.

  • Communicate with other mathematical software. Sage itself ships with many well-regarded free software packages, such as Pari (number theory), Gap (group theory), Singular (commutative algebra), R (statistics), etc. Sage can also communicate with nonfree packages such as Mathematica, Maple, Matlab, and Magma if you have them installed. This means that you can access the power of many software packages while (mostly) only having to deal with one well-designed programming language!
  • Communicate with TeX at various levels. For instance, any Sage object has a method that returns its representation in TeX. An even more spectacular example is SageTeX, a TeX package that allows your TeX document to pass inputs to Sage and retrieve the answers!
  • Annotate notebooks by inserting formatted text and even TeX code between the cells, as in this presentation.
︡a8149aba-c494-4a35-89f7-6bb31990e03b︡{"html": "

Conclusion: what else can Sage do?

\n

To conclude, we point out a few more advanced things that can be accomplished using Sage, just to give the flavor of what the possibilities are. These are mostly complementary to the advanced functionality for elliptic curves that will be highlighted in the subsequent lectures.

\n
    \n
  • Communicate with other mathematical software. Sage itself ships with many well-regarded free software packages, such as Pari (number theory), Gap (group theory), Singular (commutative algebra), R (statistics), etc. Sage can also communicate with nonfree packages such as Mathematica, Maple, Matlab, and Magma if you have them installed. This means that you can access the power of many software packages while (mostly) only having to deal with one well-designed programming language!
  • \n
  • Communicate with TeX at various levels. For instance, any Sage object has a method that returns its representation in TeX. An even more spectacular example is SageTeX, a TeX package that allows your TeX document to pass inputs to Sage and retrieve the answers!
  • \n
  • Annotate notebooks by inserting formatted text and even TeX code between the cells, as in this presentation.
  • \n
"}︡