Mini Sage Introduction

Math 304: Number Theory - Spring 2026

Getting Started with SageMath

This page provides interactive examples to help you get started with SageMath. Click the "Run" button below each code cell to execute the code.

Arithmetic in SageMath

SageMath can perform basic arithmetic operations:

You can assign values to variables for later use:

You can recall and print variables that you've defined:

SageMath can factor integers into their prime factorization:

SageMath can do a whole bunch more, but this is enough for now...

Basics of Lists

Lists are a fundamental data structure in SageMath/Python:

Creating a list:

Accessing elements (indexing starts at 0):

Finding the length of a list:

Adding elements to a list:

List slicing is a very useful operation:

Here is an example of how we can easily use SageMath to find the sum of the first 10 cubes: