%% LyX 2.0.0 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{beamer}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{graphicx}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
 % this default might be overridden by plain title style
 \newcommand\makebeamertitle{\frame{\maketitle}}%
 \AtBeginDocument{
   \let\origtableofcontents=\tableofcontents
   \def\tableofcontents{\@ifnextchar[{\origtableofcontents}{\gobbletableofcontents}}
   \def\gobbletableofcontents#1{\origtableofcontents}
 }
 \long\def\lyxframe#1{\@lyxframe#1\@lyxframestop}%
 \def\@lyxframe{\@ifnextchar<{\@@lyxframe}{\@@lyxframe<*>}}%
 \def\@@lyxframe<#1>{\@ifnextchar[{\@@@lyxframe<#1>}{\@@@lyxframe<#1>[]}}
 \def\@@@lyxframe<#1>[{\@ifnextchar<{\@@@@@lyxframe<#1>[}{\@@@@lyxframe<#1>[<*>][}}
 \def\@@@@@lyxframe<#1>[#2]{\@ifnextchar[{\@@@@lyxframe<#1>[#2]}{\@@@@lyxframe<#1>[#2][]}}
 \long\def\@@@@lyxframe<#1>[#2][#3]#4\@lyxframestop#5\lyxframeend{%
   \frame<#1>[#2][#3]{\frametitle{#4}#5}}
 \def\lyxframeend{} % In case there is a superfluous frame end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.

\usepackage{appearance}\newcommand{\reals}{\mathbb R}

\makeatother

\usepackage{babel}
\begin{document}
%MODULE 1: Intro to SAGE


%USER DEFINED COMMANDS
\global\long\def\ds{{\displaystyle }}
 \global\long\def\nsp{\hspace{1em}*{9pt}}
 \global\long\def\lns{\rule{0pt}{11pt} }
 \global\long\def\xp{\mbox{\Large\sl e} }


%INPUT THE INSTRUCTIONS PAGE 


%BUILD  TITLE PAGE 



\title{An Introduction to SAGE}


\subtitle{Because SAGE is essential for this aspect of the course, this lesson
is designed to serve as an introduction to some basic constructions
of SAGE. }

\makebeamertitle

\lyxframeend{}\lyxframe{Why SAGE?}

These modules are aimed as a series of online, interactive lessons
and labs to help you learn Calculus. An essential component of the
modules is the use of the computer algebra package SAGE. SAGE is a
state-of-the-art, free computer algebra system that allows you to
do many different kinds of mathematics, from basic arithmetic to calculus
and beyond. Similar commercial systems include Maple and Mathematica.

Some of the lessons advise you to use SAGE. In some cases you will
use prebuilt applications we call SAGE applets; in other cases you
will start a blank worksheet and go from there. You are welcome to
use it on your own to try to answer your questions or explore your
ideas. The reason we include SAGE is because \emph{we want you to
experiment, even play with the mathematics.}


\lyxframeend{}\lyxframe{{Getting started}}

\noindent You have several options for obtaining and running SAGE.
All of them are free.
\begin{itemize}
\item Visit the department's SAGE server at \texttt{\ttcolor please insert
your own server's address here!} There you can login as guest (no
password), or create your own username. This can be slow if there
is a great deal of demand for the server, and the server might be
down sometimes. 
\item Obtain a copy of SAGE on a CD-ROM from the math department, and run
it on your own computer. 
\item Download SAGE from \texttt{\ttcolor http://www.sagemath.org/} and
run it on your own computer. 
\end{itemize}
You will sometimes need to use worksheets that the math department
has prepared for this course. You should be able to find these at
the same website where you find the modules, \texttt{\ttcolor http://www.math.usm.edu/sage/}

If you need help obtaining SAGE or the worksheets, your professor
should be able to help you. If not, s/he will tell you whom you can
contact.


\lyxframeend{}\lyxframe{{Start SAGE}}

\noindent At this point we assume that you have obtained SAGE and
have started it, either by navigating to the web address online or
by double-clicking an icon on your computer. You may receive some
security warnings; allow any certificates to pass. (The Firefox web
browser calls this {}``adding an exception.'') You should see a
welcome screen:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_login} 
\end{figure}


(Colors and some minor details may vary.)


\lyxframeend{}\lyxframe{{Log in to SAGE}}

\noindent SAGE's worksheet interface works best with the Firefox web
browser, which you can download (for free!) at \texttt{\ttcolor http://www.mozilla.com/}
It should also work with Internet Explorer, Safari, Opera, and any
web browser.

Go ahead and sign up for a new SAGE Notebook account. Then log in
to your account. You should see a screen like this:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_home} 
\end{figure}



\lyxframeend{}\lyxframe{{Your first SAGE worksheet}}

\noindent In the upper-left hand region of the window, you will see
a link for creating a new worksheet. Click on that, and you will see
something like the following.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_ws_highlighted_links} 
\end{figure}


Pay particular attention to the two circled objects.
\begin{itemize}
\item The one on the left is the title of your worksheet. You can change
it by clicking on it and typing a new name. Do that now; change the
title to \emph{My first SAGE worksheet!} 
\item The one on the right is a link to help. SAGE comes with a substantial
amount of documentation, and you may want to explore it from time
to time. However, we will try to include in this module everything
you need to know to make SAGE work. 
\end{itemize}

\lyxframeend{}\lyxframe{{Cells}}

\noindent When you want SAGE to do something, you type instructions
into a \emph{cell}. A cell looks like a rectangle; we have written
the word \textquotedbl{}CELL\textquotedbl{} in the screenshot below
to show you where it is.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_this_is_a_cell} 
\end{figure}


Click in the cell, and you will be ready to work with SAGE.


\lyxframeend{}\lyxframe{{Basic Arithmetic}}

\noindent SAGE will perform basic arithmetic like any calculator.
Type $\ec2+(-4)$ into the cell. To make SAGE perform an instruction,
hold the \texttt{\ttcolor \textless SHIFT\textgreater} key and
press \texttt{\ttcolor \textless RETURN\textgreater} (or \texttt{\ttcolor
\textless ENTER\textgreater}). You should see this:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_addition} 
\end{figure}


Personally, I find it highly reassuring that SAGE agrees with every
other calculator on this point.


\lyxframeend{}\lyxframe{{Symbolic calculator}}

\noindent SAGE is more than a calculator, however; it is a \emph{Computer
Algebra System}. Unlike ordinary calculators, SAGE can compute with
polynomials, matrices, and esoteric mathematical objects that you've
probably never heard of, such as Gr{ö}bner bases, modular forms,
elliptic curves, finite fields, and lots more.

Let's add two polynomials. We'll shoot for something that you should
be able to check yourself: $\ec\left(x^{2}-3x+2\right)+\left(4x^{3}-2x+3\right)$.
To type this in, use the caret (\^{}) to show exponentiation, and
a star ({*}) to show multiplication. Unlike written mathematics, you
will need to include the star for every multiplication.

We get this:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.4]{figures/sage_add_polys} 
\end{figure}



\lyxframeend{}\lyxframe{{Declaring variables}}

\noindent SAGE recognizes $\ec x$ as a variable. If you want your
functions to use variables other than $\ec x$, you will have to tell
this to SAGE. Otherwise you could get an error like the following.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.3]{figures/sage_pls_declare_vars} 
\end{figure}


To declare $\ec y$ as a variable to be used for functions, type {\ttcolor
var('y')}. After that you can manipulate it to your heart's content.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.3]{figures/sage_declare_y} 
\end{figure}


You can declare more than one variable by typing, for example, {\ttcolor
a, b, c = var('a b c')}.


\lyxframeend{}\lyxframe{{Simplifying expressions}}

\noindent You may have noticed in the previous slide that SAGE did
not expand the product $\ec(x+y)(x-y)$, but returned it to us in
the same form. If you want SAGE to expand the product, you can tell
it to do so explicitly.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_expand_product} 
\end{figure}


Likewise, if you want it to factor a polynomial, it will do so if
it can.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_factor_poly} 
\end{figure}


SAGE will also solve equations, but you have to use two equality signs
instead of one:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_solve} 
\end{figure}


SAGE has a large number of useful functions like these. We will introduce
the functions that you need when necessary.


\lyxframeend{}\lyxframe{{Multiple commands}}

\noindent You can enter multiple commands into a cell, separating
each one by pressing \texttt{\ttcolor \textless ENTER\textgreater}.
Do not hold the \texttt{\ttcolor \textless SHIFT\textgreater} key
when you want to enter multiple commands into a cell.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_multiple_commands} 
\end{figure}


Notice that SAGE only printed the result of the \emph{last} command
in the cell. To print the results of all the commands in a cell, surround
each command with the {\ttcolor print} function.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_print} 
\end{figure}



\lyxframeend{}\lyxframe{{Naming expressions}}

\noindent It can grow tiresome to retype the same expressions. Assigning
names to expressions makes this less burdensome. You can make an assignment
this way: 

\begin{center}
{\ec \textless name\textgreater\ =\ \textless expression\textgreater}
\par\end{center}

\noindent To illustrate, create two polynomials $\ec f$ and $\ec g$,
then perform a series of operations on them. Notice that SAGE does
not print the result of an assignment.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_assignments} 
\end{figure}



\lyxframeend{}\lyxframe{{Special names}}

\noindent SAGE reserves some names for mathematical expressions. The
ones that matter for Calculus are 
\begin{itemize}
\item {\ttcolor pi} for $\pi$ and 
\item {\ttcolor e} for $e$. 
\end{itemize}
\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.4]{figures/sage_pi_and_e} 
\end{figure}



\lyxframeend{}\lyxframe{{Plotting graphs}}

\noindent You can plot a graph using the commands {\ttcolor plot()}
and {\ttcolor show()}. To plot $\ec x^{2}-4$ on the interval $\ec\left[-3,3\right]$,
type 

\begin{center}
{\ttcolor plot(x\^{}2-4,-3,3)}
\par\end{center}

You can also assign the plot to a name such as {\ttcolor f\_plot}
and then type 

\begin{center}
{\ttcolor f\_plot.show()}
\par\end{center}

You would see something like this:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_plot} 
\end{figure}



\lyxframeend{}\lyxframe{{Combining the plots of graphs}}

\noindent You can also combine several plots into one. Assign the
plots of $\ec x^{2}-4$ and $\ec x+2$ over the interval $\ec\left[-3,3\right]$to
the names \texttt{\ttcolor f\_plot} and \texttt{\ttcolor g\_plot},
then type 

\begin{center}
\texttt{\ttcolor (f\_plot + g\_plot).show()}
\par\end{center}

You will see something like this:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_combine_plots} 
\end{figure}



\lyxframeend{}\lyxframe{{Colored plots}}

\noindent When combining plots, it can be hard to tell them apart
if they are all the same color. SAGE has an option for changing the
color of a plot. Type the following:

\texttt{\ttcolor f\_plot = plot(x\^{}2-4,-3,4,color=\textquotedbl{}red\textquotedbl{})}

\texttt{\ttcolor g\_plot = plot(x+2,-3,4,color=\textquotedbl{}blue\textquotedbl{})}

\texttt{\ttcolor (f\_plot + g\_plot).show()}

You will see this:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_colored_plots} 
\end{figure}



\lyxframeend{}\lyxframe{{Adjusting the aspect ratio}}

\noindent You may have noticed that the $x$-axis is a little longer
than the $y$-axis. The result is that the graphs are a little distorted;
a circle, for example, would look like an ellipse.

You can fix this by adding an option in the \texttt{\ttcolor show()}
command called \texttt{\ttcolor aspect\_ratio}. If you specify \texttt{\ttcolor
aspect\_ratio=1}, then the graph will look square. For example,

\begin{center}
\texttt{\ttcolor (f\_plot + g\_plot).show(aspect\_ratio=1)}
\par\end{center}

generates the following graph.

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_combine_plots_square} 
\end{figure}



\lyxframeend{}\lyxframe{{Adding, removing cells}}

\noindent If you want to insert a cell between two others, hover the
mouse slightly above an old cell. A line should appear:

\begin{figure}[h!]
 

\centering{}\includegraphics[scale=0.2]{figures/sage_create_cell} 
\end{figure}


If you click on that line, a new cell will appear.

To delete a cell, delete its contents, place the cursor inside the
cell, then press \texttt{\ttcolor \textless Backspace\textgreater}.


\lyxframeend{}\lyxframe{{Values of names}}

\noindent SAGE remembers the value of a name based on the order it
was executed, \emph{not} the order it appears in the worksheet. If
you insert a cell between two others and each of the three assigns
a value to the name $\ec f$, you could see something like this: 
\begin{figure}[h!]
 

\begin{centering}
\includegraphics[scale=0.3]{figures/sage_assignment_order} 
\par\end{centering}

\caption{ Why is $\ec a$ equal to $\ec8$ in the last cell?!? \label{fig:ooe}}
\end{figure}



\lyxframeend{}\lyxframe{Values of names}

\noindent Why does $\ec a$ have the value 8 in the last cell? Because
the second cell was executed \emph{after} the third one. This is not
something that we can show you in the slides, but you can try it yourself: 
\begin{itemize}
\item type what is written in the first three cells of \RefFig{fig:ooe}
and execute them (hold \texttt{\ttcolor \textless SHIFT\textgreater}
and press \texttt{\ttcolor \textless ENTER\textgreater}); 
\item execute the second cell again (click within the cell, hold \texttt{\ttcolor
\textless SHIFT\textgreater}, and press \texttt{\ttcolor \textless
ENTER\textgreater}; 
\item \emph{without executing the third cell again}, click within the fourth
cell, type what you see in \RefFig{fig:ooe}, and execute it. 
\end{itemize}
If calculations aren't working the way the worksheet suggests, it
is probably because something has been executed out of order. You
can fix this by executing the cells again in the proper order.


\lyxframeend{}\lyxframe{{Saving a worksheet}}

\noindent You can --- and should --- save your work frequently using
the \textbf{\color{blue}\textless Save\textgreater} button in the
upper right. If you want to work on a new worksheet, or just leave
SAGE, you have several options: 
\begin{itemize}
\item the \textbf{\color{blue}\textless Save and quit\textgreater} button; 
\item the \textbf{\color{blue}\textless Discard and quit\textgreater}
button; 
\item the \textbf{\color{blue}\textless New worksheet\textgreater} option
in the \textbf{\color{blue}\textless File\ldots{}\textgreater}
drop-down, and 
\item the \textbf{\color{blue}\textless Home\textgreater} link, 
\end{itemize}
For now choose the \textbf{\color{blue}\textless Save and quit\textgreater}
option. It will return you to the home screen, and you will find your
worksheet listed!


\lyxframeend{}\lyxframe{{Loading a worksheet}}
\begin{overlayarea}
{\textwidth}{6in}

\noindent For many of the modules you will have to load a SAGE worksheet
that contains a SAGE applet. We will describe three ways that you
can do this.


\pause{}
\begin{onlyenv}%{}
<2>

First, you can visit the SAGE homepage and download the module. 
\begin{itemize}
\item The SAGE homepage is \texttt{\ttcolor http://www.math.usm.edu/sage/}. 
\item Find the link to module worksheets, and click on it. 
\item Find the link to the worksheet that you want, and click on it. 
\item On the SAGE homepage, you will see a link named \textbf{\color{blue}\textless
Upload\textgreater} in the upper left, next to the \textbf{\color{blue}\textless
New worksheet\textgreater} link. 
\item Click on the \textbf{\color{blue}\textless Browse\ldots{}\textgreater}
button, and browse to the location where you saved the worksheet on
your computer. Select your worksheet. 
\item Press the \textbf{\color{blue}\textless Upload Worksheet\textgreater}
button. You will now return to the list of worksheets, and the worksheet
that you uploaded will be available. 
\end{itemize}
\end{onlyenv}%{}

\pause{}
\begin{onlyenv}%{}
<3>

Second, you can load it from a disk, such as a CD-ROM that your instructor
gave you. 
\begin{itemize}
\item On the SAGE homepage, you will see a link named \textbf{\color{blue}\textless
Upload\textgreater} in the upper left, next to the \textbf{\color{blue}\textless
New worksheet\textgreater} link. 
\item Click on the \textbf{\color{blue}\textless Browse\ldots{}\textgreater}
button, and browse to the location where the worksheet lies on the
CD-ROM. (Look for a directory called \texttt{\ttcolor Worksheets}.) 
\item Press the \textbf{\color{blue}\textless Upload Worksheet\textgreater}
button. You will now return to the list of worksheets, and the worksheet
that you uploaded will be available. 
\end{itemize}
\end{onlyenv}%{}

\pause{}
\begin{onlyenv}%{}
<4>

Third, you can load it directly from another website. In this case
your instructor may have created his own worksheet that he wants you
to use.
\begin{itemize}
\item On the SAGE homepage, you will see a link named \textbf{\color{blue}\textless
Upload\textgreater} in the upper left, next to the \textbf{\color{blue}\textless
New worksheet\textgreater} link. 
\item There is a box labeled, \emph{Or enter the url of a worksheet file
on the web:}. In this box, type the address that your instructor gave
you. 
\item Press the \textbf{\color{blue}\textless Upload Worksheet\textgreater}
button. You will now return to the list of worksheets, and the worksheet
that you uploaded will be available. 
\end{itemize}
\end{onlyenv}%{}
\end{overlayarea}

\lyxframeend{}\lyxframe{{Programming}}

\noindent One of the strengths of the SAGE computer algebra system
is that it relies on a computer programming language called Python.
You don't have to know any Python in order to complete the worksheets
for this course. However, you will learn a little bit about Python
programming indirectly, and if you do know how to program in Python
then you can do many powerful things in SAGE. 


\lyxframeend{}
\end{document}
