Introduction to SageMath

by Luca De Feo

ECC summer school

September 23-25, 2015. Bordeaux.

What is SageMath?

SageMath (formerly Sage) is a free open-source mathematics software system licensed under the GPL.

  • It builds on top of many existing open-source packages: NumPy, SciPy, matplotlib, Sympy, Maxima, Pari/GP, GAP, FLINT, R and many more.
  • Accesses their combined power through a common Python-based language, or directly via interfaces or wrappers.

Official downloads, docs, etc.: http://www.sagemath.org/

Mission statement

Creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab.

Facts and numbers

  • Started in 2004 by William Stein;
  • Developed by researchers, students and engineers for researchers and students (and engineers?);
  • A community of >500 developers
  • A company SageMath, Inc., established in 2015;
  • 19K tickets in the issue tracker, 39K commits, 1.8M LOCs (native code);
  • ~70 community meetings (Sage Days) in 10 years.

No, seriously, what is it?

  • A distribution of mathematical software (NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, R,…),
  • A common Python-based interface, including interfaces to proprietary software (Magma, Mathematica, …),
  • Native Python/Cython code implenting more functionality,
  • Two web-based notebook interfaces developed in house + Jupyter integration,
  • SageMathCloud, a spinoff project hosting collaborative math projects (Jupyter, Sage, LaTeX, …) in the cloud.

SageMath’s development model

You can contribute too!

Using SageMath

On your own computer

  • Download from http://sagemath.org

  • install,

  • Run one of these:

    sage
    sage --notebook
    sage --notebook ipython
    

In the cloud

  • Create an account on https://cloud.sagemath.com,
  • Create a new project, then
    • Create a new terminal and type sage, or
    • Create a new SageMath Worksheet, or
    • Create a new Jupyter Notebook.

SageMath interfaces

Batch execution

  • Write .sage or .py files in your favorite editor,
  • Link to SageMath library,
  • Execute from the command line.

REPL (Based on IPython)

user@host:~$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath Version 6.8, Release Date: 2015-07-26                     │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: 1+1
2
sage: _

SageMath interfaces

SageMath worksheet

  • Web-based notebook format,
  • If you know SageMath, you probably know this one,
  • Not supported anymore, bound to disappear.

SageMath worksheet (SageMathCloud)

  • New notebook application for collaborative writing,
  • Exclusive to SMC,
  • Destiny uncertain.

Jupyter notebook

  • Spinoff project of IPython
  • Notebook webapp for generic scientific computing,
  • Supports many different languages: Python, Julia, R, Haskell, Sage, …

Using subsystems from SageMath

In the REPL or SageMath worksheet

sage: %gp

  --> Switching to PARI/GP interpreter <--

pari: 1+1
2
pari: ffinit(13,2)
Mod(1, 13)*x^2 + Mod(1, 13)*x + Mod(12, 13)

In Jupyter

Not sure… upcoming?

Hands on!

If you have SageMath on your laptop

Check your version, 6.8 is best

user@host:~$ sage --version
SageMath Version 6.8, Release Date: 2015-07-26

launch

sage --notebook ipython

you might need to point your browser to http://localhost:8080.

If you have a SageMathCloud account

Simply open a new Jupyter Notebook.

Go to the demo!

Fork me on GitHub