Skip to main content
Logo image

Section 1.5 Using Sage for Interactive Computation

This text is advertised as having interactive computation, but so far any computation has been your own. How does digital computation (interactive or not) fit in? We’ll skip ahead slightly here to see how this will work.
In the interactive version of this text, the areas below are called Sage cells, or cells for short. Assuming you’re connected to the internet, this very first cell will use SageMath 6  (usually just called Sage) to check whether a given fraction remains a fraction when reduced, or whether it reduces to an integer. Click “Evaluate” to try it out.
Again, if you’re viewing this online, go ahead and try changing the numbers, clicking the evaluate button again.
As we go through the text, you’ll see lots of opportunities to use Sage. Sometimes I’ll give you the opportunity to learn a little bit about how to use it in Sage notes, such as the following one.

Sage note 1.5.1. About Sage notes.

Sage notes will teach you useful things about basic programming, or more general facts about Sage and Python 7 , the computer language Sage is based on.
Let’s try another computational cell. We haven’t defined prime numbers yet (see Chapter 6), but I figure you know what they are. Here you can check whether an integer is prime.

Sage note 1.5.2. Using commands in Sage cells.

Assuming you are using this book online, you can put any legitimate Sage command in the cells above. (Try integrate(x^3,x) if you know some calculus.) Or you can use these commands in your own Sage worksheet at your local Sage server or with CoCalc, so that you can save your work!
If you are using an offline or hard copy version, I still highly recommend sifting through some of the code and commands; much of it will enlighten the reader. (Then try it out online or on your local computer!)
Finally, let’s test some conductor ideas using Sage. In the cell below, Sage will automatically list all the nonnegative numbers up to \(n\) that can be written as \(n=ax+by\) for nonnegative integers \(x\) and \(y\text{.}\) The default values are \(a=3,b=4\text{;}\) you can experiment by changing one or both of these values.
Notice that with the default values above we are definitely getting the same answers as expected from our ‘pencil and paper’ experiments.
Finally, notice that the algorithm I used in the code is very naive – I just listed all possible combinations under a certain size. It would be interesting to use this to try to verify patterns you may have noticed about the precise size of the conductor, and when it exists.
www.sagemath.org
www.python.org