Sage Lab 4

## instructions

This lab should be completed in groups of 1—4. You do not need to be in the same group as your presentation partner. I recommend keeping this window open as a tab in your browser.

First, one member of your group will need to log into the Sage Notebook server. Go to http://sagenb.org (Sage recommends that you use Firefox). Once you are logged into the Sage Notebook server, you will be in your "Home" directory. Click on "New Worksheet" towards the top left. A small window will pop up asking you what you want to call the worksheet. Name your worksheet

MA4140 Lab 4 (name-1, name-2, etc.)

where you should replace name-1, name-2, etc. with the appropriate first names of your group members separated by commas. You will be presented with a blank Sage worksheet.

Before you actually do anything with this worksheet, I want you to share it with me and the other members of your group. Click "Save & Quit" in the upper right hand corner. This will return you to your "Home" directory. Now, click on "Share now" in the middle column for your newly created worksheet. As you did on the last lab, type in the Sage usernames of the members of your group (separated by commas). If you do not know the usernames of your group members, you can get them here. You should also share the worksheet with me (my Sage username is dcernst). Once you have typed in the appropriate usernames, click "Invite Collaborators".

Now, open the worksheet back up. The goal of this lab is to explore the group of units $U(n)$ (under mulitplication) of $\mathbb{Z}_n$, learn a little bit about making nested lists in Sage, and reinforce some ideas about cyclic groups.

In a Sage cell, type

G=Integers(40)


and evaluate the cell. It may look like nothing happened, but you just told Sage that you want to let $G$ denote the group $\mathbb{Z}_{40}$. In the next empty Sage cell, employ the .list() function to $G$ to get a list of the elements in $\mathbb{Z}_{40}$.

Recall that $\mathbb{Z}_40$ is a group under addition mod 40. However, $U(40)$, which is the set of elements in $\mathbb{Z}_{40}$ relatively prime to 40, is a group under multiplication mod 40. We'd like to deal with $U(40)$. In the next empty Sage cell, type

G.list_of_elements_of_multiplicative_group()


and evaluate the cell. This will list all of the elements in $U(40)$. Of course, you can count how many elements just appeared, but for really big groups this would be impractical. In the next empty Sage cell, type

G.unit_group_order()


and evaluate the cell. This will output the order of $U(40)$ (which happens to be 16). We can create elements of this group with syntax like

a = G(7)


Enter this now in an empty Sage cell and evaluate it. This will tell Sage that you want to view 7 as an element of $G$ subject to the corresponding operations, rather than the integer 7. To see what I mean evaluate the following in two different Sage cells:

7^2

a^2


We can use Sage to easily compute all of the elements generated by 7 in $U(40)$. In an empty Sage cell, type

for j in (1..16):
print a^j


and evaluate the cell. Warning: You need to have the tab intent on the second line; if you type this in manually, this will happen automatically for you. Sage just computed $a^1, a^2, \ldots, a^{16}$. Note that (1..16) is Sage's shorthand for the set $\{1,2,3,\ldots,16\}$. By the way, we are using 16 because this is the order of $U(40)$. Below the output you just got, Shift+click on a purple line to open the mini text editor and answer the following questions about the output you just got:

(1) What are the elements generated by 7 in $U(40)$?

(2) What is the order of 7 in $U(40)$?

We could repeat this process for all 16 elements in $U(40)$, but if there were thousands of elements in a group, it would certainly be tedious to type all the commands in one at a time. Thankfully, we can exploit the power of Sage and do them all in one shot. In an empty Sage cell, type

units40=[n for n in G if gcd(n,40)==1]


and evaluate the cell. What we just did was create a row matrix called units40 (which I made up) consisting of the elements in $U(40)$ that are relatively prime to 40. To see what this matrix looks like, type

print units40


and evaluate the cell. Next, type the following in an empty Sage cell and evaluate:

for k in units40:
for j in (1..16):
print k^j,


This will output a lengthy list of numbers that in its current form is very difficult to interpret. Here's what happened. For each $k\in U(40)$, Sage computed $k^1, k^2, \ldots, k^{16}$. Sage just tossed all of these in a big list. The first 16 elements in this list correspond to $1^1, 1^2, \ldots, 1^{16}$ (which of course are all equal to 1). The next 16 elements correspond to $3^1, 3^2, \ldots, 3^{16}$ (in $U(40)$), and so on.

Without going into too much detail, we can tell Sage to put this list of computations in a nicely formatted table. In the next empty Sage cell, type

html.table([(1..16)]+[[k^j for j in (1..16)] for k in units40],header=true)


and evaluate the cell. The top green row of the table that you just got is telling you the power that is being used. The first column corresponds to the elements of $U(40)$. Using only the information in this table, answer the following question (Shift+click on a purple line to open the mini text editor):

(3) Is $U(40)$ cyclic? Explain your answer.

It turns out that $U(49)$ is cyclic (notice I said 49 now, and not 40). Using the techniques introduced above, produce a nicely formatted table that computes all of the powers of the elements from $U(49)$ from 1 to the order of $U(49)$. Of course, you'll need to know the order of $U(49)$ to do this. Also, you'll have to modify parts of the line above that starts html.table. Now, using your table answer the following questions (Shift+click on a purple line to open the mini text editor):

(4) What information in the table tells us that $U(49)$ is cyclic? Explain your answer.

Now, consider $U(35)$. Again, using the techniques introduced above, produce a nicely formatted table that computes all of the powers of the elements from $U(35)$ from 1 to the order of $U(35)$. Now, using your table answer the following questions (Shift+click on a purple line to open the mini text editor):

(5) Is $U(35)$ cyclic? Explain your answer.

## getting help

If you need help, you can always contact me, or even better, post a question in the forum. In addition, there are some useful links on the Sage help page.

## due date

This lab is due by 5PM on Friday, April 9.

page revision: 6, last edited: 06 Apr 2010 03:00