A Beginning of Sage
Parts based on a worksheet by Mike May, S.J., 2010, licensed CC BYNCSA 3.0
The purpose of this worksheet is to learn just enough of Sage to be able to start using it in the course. Maybe soon you'll start making your own worksheets!
The first detail is to get an account. Look at the upper left corner of your browser window, where the red box is in this picture.
If you've already logged in, you'll see this. If you do not see the option to "Edit a copy", but instead to "Log in to edit a copy", you are not yet logged in, so select "Log in to edit a copy".
You should see a screen similar to this.
Then click on "Sign up for a new Sage Notebook account", and follow the instructions to do this.
Finally, log in with that account, and return to this page in your browser. People often skip this step and wonder why they can't try it out!
You should now see the option in the picture to "Edit a copy".
Select the "Edit" option; you will now have your own version of this worksheet you can use.
The rest of this worksheet introduces you to basic Sage stuff, at least somewhat systematically. If you are only interested in using commands from class, you can go straight to another published worksheet (see the link at the top) and click "Edit a copy" for those. In that case, good luck!
Otherwise, continue reading.

We now walk through how to actually do some mathematics!
The easiest operation is evaluating a cell that someone has already prepared for you. Notice the two math cells pictured below, which also appear beneath the text region.
The same cells are below.
11 11 
166153499473114484112975882535043072 166153499473114484112975882535043072 
When your cursor is in the math region, it becomes active. As the picture shows, an evaluate link appears, and the cell has a bluish border. You can evaluate the region by clicking the evaluate link.
When you do either, the cursor evaluates the contents of the cell, prints out the last result, and moves the cursor to the next math cell. Try this.
(If you get bored with clicking the "evaluate" link, you can also click inside the cell, and then press 'Shift' and 'Enter' at the same time to evaluate the cell. We call this "ShiftEnter".)
As you can see, we can use Sage to do easy calculations, or longer computations we would not want to do by hand. To see the output, always highlight the cell (with up/down arrows or by clicking) and then evaluate it.
Try evaluating the ones above, or be brave and try something new in the cell below!

One main thing you might want to do is to plot functions (for instance, if you didn't have a graphing calculator, or if you realized that they are very wimpy). The syntax is pretty simple, and you can reuse the same cell as often as you like.

There's a few things to note about this syntax.
You can think of it the whole syntax like a big function.
Try plotting $x^3+\frac{1}{x}$ between $x=1$ and $x=2$ in the next cell, which is currently empty.

You'll notice that Sage doesn't try to tell you how far you want to zoom, and (appropriately) shows the very high asymptotes. You can use some socalled "keywords" to try to see this closerup. Try typing in "plot(x^3+1/x,(x,1,2),ymin=10,ymax=10)" instead, to keep the vertical frame from $10$ to $10$.
Naturally, you won't always have nice spots to do things. You might want to put math in between other math, for instance.
As you can see in the picture, when you have the cursor just above a math cell, a thin blue line appears. Clicking while your cursor in in the blue line will cause another math cell to appear above the current cell.
Try this anywhere you want to on the worksheet, and calculate $2+4$ (or something more interesting, if you want).
Incidentally, if you want to put text in the page, look for the same blue line, but hold down "Shift" while you click (we call this "ShiftClick"). A nice fully featured editor will pop up. Or, take some existing text and doubleclick on it!
One of the most important things we can do in math is create new functions.
In the following cell, I've typed $f(x)=\sin(x^3)$, which assigns the name $f$ to that function. Then I plotted $f$ between $2$ and $5$.

Notice that I can just type $f$ in the plot command to do this.
There are lots of things I can do with this. One thing we often do in calculus, for instance, is to compare two related functions. If I wanted to compare this with $f(x2)$, I would just plot this, like below.

Or I might want to use different endpoints  it's up to you.
There are two interesting ways to compare the two plots. I can put both functions together, inside of square brackets $[f(x2),f]$:

Or I can add the plots themselves with the $+$ symbol. First, I'll assign them both to variables  to names in the computer program. In the second plot, I've added some cool options, so that they look different.

Now, to show them both, I just add them.

Well, there is lots more math to do. All we've really seen are how to plot basic functions and do some arithmetic and function evaluation. The rest of this worksheet is intended to help you find out more; it assumes that the rest of the worksheet is done in a classroom environment.
Now, there are lots of great references on the web.
But I want you to be able to help yourselves, right here, right now. So here is how it works.

/usr/local/sage/local/lib/python2.6/sitepackages/sage/misc/functional.p\ y:718: DeprecationWarning: Variable of integration should be specified explicitly. return x.integral(*args, **kwds) 1/12*((I*sqrt(3) + 1)*gamma(1/3, I*x^3) + (I*sqrt(3) + 1)*gamma(1/3, I*x^3))*x/(x^3)^(1/3) /usr/local/sage/local/lib/python2.6/sitepackages/sage/misc/functional.py:718: DeprecationWarning: Variable of integration should be specified explicitly. return x.integral(*args, **kwds) 1/12*((I*sqrt(3) + 1)*gamma(1/3, I*x^3) + (I*sqrt(3) + 1)*gamma(1/3, I*x^3))*x/(x^3)^(1/3) 
File: /usr/local/sage/local/lib/python2.6/sitepackages/sage/misc/functional.py Type: <type ‘function’> Definition: integrate(x, *args, **kwds) Docstring:
File: /usr/local/sage/local/lib/python2.6/sitepackages/sage/misc/functional.py Type: <type ‘function’> Definition: integrate(x, *args, **kwds) Docstring:

1/12*((I*sqrt(3) + 1)*gamma(1/3, I*x^3) + (I*sqrt(3) + 1)*gamma(1/3, I*x^3))*x/(x^3)^(1/3) 1/12*((I*sqrt(3) + 1)*gamma(1/3, I*x^3) + (I*sqrt(3) + 1)*gamma(1/3, I*x^3))*x/(x^3)^(1/3) 
verbose 0 (4101: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 58 points. verbose 0 (4101: plot.py, generate_plot_points) Last error message: 'unable to simplify to float approximation' verbose 0 (4101: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 58 points. verbose 0 (4101: plot.py, generate_plot_points) Last error message: 'unable to simplify to float approximation' 
By this point I hope you have realized that you are playing with fire!
The answers are out there! In this case, it's our fault, though  we tried to integrate a function which does not have an integral in terms of elementary functions.
And there's so much more...

Here, I assigned the value of a definite integral to $A$. What is its value?
0.493747393665062 0.493747393665062 
What's this? The syntax is really confusing. But here's all I did:
And  here's the kicker  I can use the same tab and ? to find out information about these!
1/6*gamma(1/3)  1/12*gamma(1/3, I*pi)  1/12*gamma(1/3, I*pi) 1/6*gamma(1/3)  1/12*gamma(1/3, I*pi)  1/12*gamma(1/3, I*pi) 
File: /usr/local/sage/devel/sage/sage/symbolic/expression.pyx Type: <type ‘builtin_function_or_method’> Definition: A.numerical_approx(prec=None, digits=None) Docstring:

Reading this tells me a way to get 50 digits of the area in the final plot here!
0.49374739366506238127138825017677521668593000673647 0.49374739366506238127138825017677521668593000673647 

