SageMath Lab

A practice space where NAMSSN UI students can use SageMath as a free, research-grade environment for algebra, number theory, combinatorics, determinants, and experiment-driven proofs.

How this lab fits together

SageMath is an open-source system built on top of Python. It glues together many powerful libraries — for algebra, number theory, geometry, combinatorics, and more — into a single language that feels close to mathematics.

In this lab, SageMath is treated as a thinking space: a place to test conjectures, search for patterns, compute determinants, and keep structured notes that look like early research notebooks.

  • • This page: a Sage learning roadmap, a live Sage cell, and a scratchpad.
  • • Subpages: slower, detailed walkthroughs for foundations, algebra & number theory, and projects.
  • • Goal: by the end, you can organise a Sage notebook that supports real course work or a small project.
🌱First contact in the browser 🔢Primes, congruences & sequences 📐Polynomials, determinants & matrices 🧠Experiment-driven proofs & patterns

A student who patiently works through the modules and uses SageMath on real UI problems will be able to open a fresh notebook and guide themselves through computations and experiments confidently.

SageMath Lab path
Choose a stage, study the detailed page, then use the scratchpad and live cell to try the ideas.

🌱 Foundations & interface

Accessing Sage in the browser or locally, running cells, understanding the notebook structure, and seeing your first plots and symbolic expressions.

Best place to start Open foundations

🔢 Algebra & number theory

Polynomials, fields, rings, modular arithmetic, primes, and integer sequences — all aligned with core algebra and number theory courses at UI.

For algebra & number theory Open algebra & NT

🧪 Experiments & projects

Graphs, combinatorial objects, linear algebra experiments, determinants, and mini projects that turn Sage computations into short, well-structured write-ups.

For confident users Open projects

Module 0 • First contact with SageMath Beginner

Start here if you have never used SageMath before. By the end of this module you should know how to open a notebook, run cells, and understand the basic idea of Sage objects.

0.1 Sage in the browser

The easiest first contact is through a browser: a Sage server, CoCalc, or a local Jupyter notebook. A typical first cell might be:

  • 2 + 3
  • 2^10
  • factor(2^16 - 1)

Goal: press “Run Sage” without fear and read the output calmly.

0.2 Sage integers and rationals

Sage distinguishes between plain Python integers and Sage integers. To work in the Sage world, you can write:

  • ZZ(5)   # an integer in Sage’s integer ring
  • QQ(1/3)   # an exact rational number
  • QQ(1) / 3
See detailed explanation

Module 1 • Polynomials & functions Beginner

Here you meet Sage’s polynomial rings and basic function plots. This is a direct companion to algebra and calculus courses.

1.1 Polynomial rings

In Sage, you explicitly create a polynomial ring and a variable:

  • R.<x> = QQ[]
  • f = x^4 - 5*x^2 + 4
  • factor(f)
Study polynomial theme
1.2 Plotting functions

Basic plotting is very close to mathematics notation:

  • var('x')
  • plot(sin(x)/x, (x, -10, 10))
  • plot([sin(x), cos(x)], (x, 0, 2*pi))
See more about plots

Module 2 • Number theory & discrete structures Intermediate

Now you use Sage as a genuine playground for primes, congruences, and combinatorial structures.

2.1 Modular arithmetic & primes

Sage has built-in support for modular arithmetic and prime-related functions:

  • Integers(17)
  • Mod(5, 17)^-1
  • [next_prime(n) for n in [10, 100, 1000]]
Explore modular theme
2.2 Simple graphs & combinatorics

You can construct graphs and measure simple invariants:

  • G = graphs.CompleteGraph(5)
  • G.degree_sequence()
  • G.plot()
Study graph & combinatorics track

Module 3 • Linear algebra, determinants & experiment-driven proofs Intermediate

In this module you treat Sage as a serious assistant: you explore matrices, determinants, eigenvalues, and search for examples and counterexamples to conjectures.

3.1 Matrices, determinants & eigenvalues

You can move quickly from a matrix definition to its key properties:

  • A = matrix([[1,2,3],[0,1,4],[0,0,1]])
  • A.det() (determinant)
  • A.eigenvalues() (eigenvalues)
See linear algebra ideas

This is the natural place to compute many determinants quickly and compare patterns with theoretical results.

3.2 Searching for patterns and counterexamples

Instead of guessing blindly, you can let Sage search through many small cases:

  • [n for n in range(2,200) if not is_prime(n^2 + 1)]
  • [A^k for k in range(2,10)] (checking behaviour of a matrix power)
Turn this into a mini project
Ambition for this lab: a NAMSSN UI student who completes Modules 0–3 and keeps using SageMath on real course problems should be able to use Sage as a natural extension of their own calculations and conjectures.

Live Sage cell (runs on SageCell)

This cell talks to the public SageCell server at sagecell.sagemath.org. Work in the scratchpad first, then use “Send to live cell” when you are ready to run the code and see the output.

Press Activate to turn on the live Sage cell. When you are done or want to reduce visual load, you can Deactivate it again — your browser will remember the cell.

Heads up: because the live cell uses an external Sage server, it may feel slow or briefly unavailable at times. That is usually the remote server, not your browser. In future, the same buttons here can point to a Sage server hosted at UI without students changing their habits.

Sage scratchpad

Draft Sage code here, then send it into the live cell or a full Sage notebook when ready.

This pad is a planning space; it does not execute Sage. It is useful for collecting commands, trying variations, and saving snippets.

Tip: keep one Sage notebook per course or project, and paste code there after drafting it here. Copied!

Habits for serious Sage work

  • Write each question in plain language before translating it to Sage code.
  • Store experiments in versioned notebooks (e.g. nt-2025-01.sage).
  • Compare Sage output with small hand calculations wherever possible.
  • Record interesting failures and counterexamples, not just “nice” cases.
  • When a pattern looks real, write a short text cell explaining a conjecture or proof sketch.