This repository contains the course materials from Math 157: Intro to Mathematical Software.
Creative Commons BY-SA 4.0 license.
License: OTHER
Math 157: Intro to Mathematical Software
UC San Diego, winter 2018
January 22, 2018: SageMath (part 1 of 3)
Administrivia:
You should have a solution key for HW 1 in the folder
solutions/2018-01-19
. We will continue to provide solution keys throughout the course.Homework 2 is now available; it is due Friday, January 26 at 8pm. If you do not have it, contact course staff immediately.
We are continuing to monitor the course waitlist. If you are on it and still want to join the course, please continue to keep up with lectures and homework, and watch your email for further instructions.
SageMath in Jupyter
As I mentioned in the initial discussion of Jupyter notebook, the backend computing is provided by a piece of software called a kernel. The Python interpreter is an example of a kernel; Sage, also called SageMath to distinguish it from this accounting software, is another example.
To switch kernels, go to the Kernel menu to select a new kernel; this will reset the state of the kernel, so at that point you will have no variables or functions declared. For this lecture, please make sure that you have "SageMath 8.1" as the chosen kernel: you should see this image at the top right of your window (below the CoCalc tab bar):
What is Sage?
From the SageMath home page:
SageMath is a free open-source mathematics software system licensed under the GPL.
Note the distinction between free and open-source. Here free means that there is no cost to use the software, while open-source means that anyone can see the source code, modify it, and distribute the results. The only restriction is that any modified version must be distributed under the same conditions; in order to enforce this, the software is not released into the public domain (without any copyright protection), but under a suitable license (in this case the GNU Public License) which enshrines both the protection of open access and the rules for redistribution.
A consequence of these design choices is that SageMath does not have a cadre of full-time programmers developing the software. Most of the code base has been contributed by math researchers in order to extend Sage for their own purposes. This includes me!
It builds on top of many existing open-source packages: NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, R and many more.
One key feature of the open-source model is that it is very easy to incorporate existing software into new software. In particular, in lieu of developing many basic features from scratch, the SageMath developers have incorporated other mature, well-written software to accomplish these tasks. In most cases, these packages are themselves under active development; updates from "upstream" are periodically imported into Sage.
Access their combined power through a common, Python-based language or directly via interfaces or wrappers.
The underlying language of Sage is Python (with some minor modifications). Some of the underlying packages can also be accessed more directly; this is sometimes important for high-performance computations, but we will not deal with such subtleties in this course.
Mission: Creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab.
The creator and lead developer of Sage is William Stein. Stein is also the creator of CoCalc, but these are different projects (albeit closely related).
Getting started
Since the underlying language of Sage is adapted from Python (currently Python 2, although this may change someday), most simple Python code will run unchanged in Sage. However, behind the scenes there are some subtle changes.
Symbolic calculus
Some resources for this material:
Sage calculus tutorial: http://www.sagemath.org/calctut/
Sage reference manual: http://doc.sagemath.org/html/en/reference/calculus/index.html
Sage calculus "thematic tutorial": http://doc.sagemath.org/html/en/prep/Calculus.html
Preview of this section:
defining symbolic variables
defining symbolic functions
plot
differente
integrate
finding zeros
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/all_cmdline.pyc in <module>()
----> 1 y + theta
NameError: name 'y' is not defined
Note that these are symbolic variables rather than Python variables.
In addition to Python functions, Sage also has symbolic functions.
Resources for further study
Since Sage has been around for some time, a number of resources exist for new users.
The SageMath home page includes a tutorial as well as extensive documentation.
There is also a Q&A site in the style of StackExchange or MathOverflow.
Gregory Bard's book Sage for Undergraduates is available online (as well as in print).
A more advanced book is Mathematical Computation with Sage by Paul Zimmermann et al.