Project MOSAIC M-Cast

2383 days ago by kcrisman

Project MOSAIC M-Cast:

The Notebook Interface to Sage Mathematics Software


Karl-Dieter Crisman, Gordon College (MA)


This introduction to Sage will be about the big picture: the range of functionality, what the notebook can do for collaboration and students, etc. I'll demonstrate some basic commands, show a few servers, and how we have used Sage pedagogically. I'll also show how to use R in the notebook and how to publish worksheets.



Thank you all for coming to today's M-Cast!  

This presentation is a little different than some of the other ones.  Rather than giving a mini-tutorial of how to use Sage, I'd like to give you a little of the big picture of how one might use Sage from the notebook.  Then you can explore later!

We'll do the following:

  • Show how to log in to Sage and start a worksheet
  • Demonstrate some of the basic commands and range of functionality in Sage
  • Show how to find documentation in the notebook, so you can find answers for yourself
  • Give some ideas about pedagogy of the notebook, including collaboration options

So let's get started.   First, let's see the very basics - how to log into a server, and how to create a worksheet.

There are many Sage servers out there, and some allow anyone to create an account.  

  • Two examples I like are the clemix server at Clemson U. and the Groundhog Day one at KAIST in Seoul.
  • Of course, there is the 'official' family of servers at the University of Washington, like
  • There are also many servers at individual colleges that allow only on-campus account creation

So let's see the basics:

  • Create an account and log in
  • Make a new worksheet
  • How to create and evaluate a mathematics cell


So what can you do with Sage?  Well... what do you want to do?


We can do various plots, as one would expect.


We can compute various standard things.   We can also put notes about them between computation cells of the worksheet.  Do you remember how to calculate $$\int \frac{1}{1+x^2}\, dx\; ?$$


There is lots of functionality in various topics.  The graph editor is nice.


But allows for more advanced usage!


We can also try to find fits for models of various types, using one of the many components of Sage - in this case, SciPy.

R = [[1,2],[3.45,4],[6,5],[4,3],[1.5,2.3]] var('a,b') model(x) = a*x+b find_fit(R,model) 

As another example of what can be done, let's see how to use R from the notebook.  All I have to do is insert '%r' at the beginning of a cell, and then everything is done in R.  (It's also possible to have a whole worksheet evaluate in a given system.)

Here, I'll first load the library from the MOSAIC project's R package.  (I've previously installed that package using the command 'install.packages("mosaic", repos="");', so don't try this at home without doing that!)

%r library(mosaic); 

We can use the functions from the package immediately.

%r do(5)*3 

Graphics work, too, if you create a graphics device.  Here, I'm using the D and fplot functions from the MOSAIC project's R package.

%r quartz() fplot(sin,xlim=c(-2*pi,2*pi)) fplot(D(sin),xlim=c(-2*pi,2*pi)) 

If you want to do a whole worksheet in R (or GAP, or Octave, or even Mathematica, if you own it) that is supported as well.


Okay, but what if I want to find help?

  • Basic notebook help - click 'Help' at the top of the page!
  • Tutorial and Reference Manual - click for that from the Help page


But this only helps if you know what you are looking for in the first place.  So there is contextual help in the notebook!

Contextual help means two things.

  1. Sage tries to find all possible commands that fit your needs.  Pressing the 'tab' key after the first few letters of a command, or after a previously created object, will give you lots of ideas.
  1. So press 'tab' for completion of your thoughts!
  2. Contextual help also means you get documentation with the '?', as in some other systems.

With these two help options,

  1. Tab-completion
  2. Contextual Documentation with '?'

you - and your students - are on the way to self-discovery.


Finally, how might one use Sage in terms of pedagogy?  Here, the answer is just as broad as your own interests.  Here are several ideas.

  • Basic 'cheat sheet' of functionality for checking answers or doing computations

For example, in a calculus class, just giving a worksheet to upload with prototypes of syntax could help a lot for routine problems.

derivative( sin(e^(-x^2)) , x); show(derivative( sin(e^(-x^2) ), x)) 
  • Interactive examples in class.  

I love doing this myself, and is the primary way I use Sage in the classroom.  Can you find the pattern?

@interact def _(p=(7,prime_range(100))): try: T = two_squares(p) html("The prime {0} can be written as ${1}^2+{2}^2$.".format(p,T[0],T[1])) except: html("Looks like the prime {0} can't be written as a sum of squares.".format(p)) 

Click to the left again to hide and once more to show the dynamic interactive window

  • Students working together on a project or lab can share their worksheets with each other and/or you, allowing for easy collaboration.  

Just click the 'Share' button at the top and fill in the usernames of the people who should share the worksheet!  Some people use this for turning in labs, for instance.

  • Publishing a worksheet so others can try it.

With this option, anyone on the server can look at your worksheet, and edit a copy for themselves.  This is especially effective when you want to post something for students to try out or use for homework, or to make easily available to colleagues elsewhere.

In fact, I'm going to publish THIS VERY WORKSHEET right now on one of these servers!  And then you can download it and try it yourself.


Well, I think that's all we have time for.  Please see for more discussion of download options for all platforms, places to try out Sage, and discussion forums.  We value your feedback!



var('x,y') plot3d(sin(x^2+y^2),(x,-3,3),(y,-3,3),plot_points=200)