Applied Math 106: Applied Algebra

Prof. Salil P. Vadhan


SAGE Instructions:

For some of your homework problems, we will be using an online platform for SAGE (see SageMath.org for full details on SAGE). The platform we will be using is hosted by CoCalc, which recommends using the latest version of Google Chrome to access the platform.

  1. You should have recevied an email from CoCalc inviting to join AM106 Fall 2018 and create an account if you don't already have one. If you haven't received one please let us know ASAP.

  2. Once you've created your new account, or logged in for the first time, you should arrive at a page titled "Projects."
  3. Directly under the "Files" tab, you'll find a place where you can input a "Filename," to the right of which you’ll find a "+Create" button.
  4. Familiarize yourself with the interface. E.g., try the following computations:
  5. Please annotate your notebook wth comments indicating which problem you are solving and the purpose of each step using "#" as follows: a=1 #Initialize at 2^0
    for i in range(10): a=Mod(2*a,7) #Find 2^10 mod 7 by successively multiplying by 2
    Mod(a+Mod(9,7),7) #Find (2^10+9) mod 7 as ((2^10 mod 7) + (9 mod 7)) mod 7


  6. You can save the notebook you're working on, convert it to a pdf, and download it, all within the window you're working in. To download, click on the button directly under the tab "Files," and choose the last option in the dropdown menue. You should always submit your annotated notebook as a pdf file on Canvas. To upload a file, go to the "Files" tab, and look for the "Upload" button at the top right part of the page.


PS2 Tips

When you enter a series of commands in SAGE, you do not need to hit shift+enter after each one. You can just hit shift+enter after the final one, after which all of the commands will execute in sequence. This can help make your notebook more readable.

You may find it useful to use the ``list'' data type in SAGE to keep track of sequences of numbers. The following sequence of commands will create and print a list consisting of the first 10 Fibonacci numbers.
fib=[0 for i in range(10)] # create an list of length 10 filled with 0's.
fib[0]=1 # set the 0th item in the list to 1. note that lists are indexed starting at 0
fib[1]=1 # set the 1st item in the list to 1.
for i in range(2,10): fib[i]=fib[i-2]+fib[i-1] #set the remaining 8 items in the list using the recurrence for Fibonacci numbers
fib # print the list


If you prefer not to use lists and loops, you can also achieve the same thing with a sequence of commands:
fib0=1 #initializing the first two elements of the sequence
fib1=1
fib2=fib0+fib1 #calculate the remaining 8 using the recurrence
fib3=fib1+fib2
fib4=fib2+fib3
fib5=fib3+fib4
fib6=fib4+fib5
fib7=fib5+fib6
fib8=fib6+fib7
fib9=fib7+fib8
fib10=fib8+fib9
fib0,fib1,fib2,fib3,fib4,fib5,fib6,fib7,fib8,fib9 #print all 10 numbers


PS3 Tips

To get the problem data g, q, a, b, and c, follow these instructions:


1) Download the files ps3data.csv (and optionally ps3read.sagews) from Canvas under Files.

2) Upload ps3data.csv  to your Cocalc workspace.

3) Run the following commands to get the data g, q, a, b, and c (also found in ps3read.sagews):


import sympy as sp

import pandas as pd

ABC = pd.read_csv("ps3data.csv",delimiter="\n",header=None).as_matrix()

data = sp.sympify(ABC[0][0])


g = Integer(int(data[0]));

p = Integer(int(data[1]));

a = Integer(int(data[2]));

b = [Integer(int(data[3][i])) for i in range(30)];

c = [Integer(int(data[4][i])) for i in range(30)];


4) You can access elements of the lists b and c as b[0],b[1],...,b[29],c[0],c[1],...,c[29].

5) In addition to the SAGE commands you have used on previous problem sets, you may now use power_mod(x,y,z) which calculates x^y mod z efficiently (using the same repeated squaring algorithm that was covered on problem set 1).   Note that the power_mod function expects all of its inputs to be integers.  If you take an even integer n and set m=n/2, SAGE will cast m as a rational number rather than as an integer and you won't be able to use it in power_mod. This can be avoided by using integer division instead: m=n//2.


PS4 Tips

Important: SAGE composes permutations from left to right, which is opposite from the convention in lecture and Gallian. That is, in SAGE, sigma*tau means performing permutation sigma then tau. For example, in SAGE, (1 2)*(2 3) = (1 3 2).

Here we will illustrate how you can use SAGE to answer questions about permutation groups. Specifically, suppose we want to study a subgroup of Sym({a,b,c,d,e,f}).

PS5 Tips

PS8 Tips

On this problem, you will see how to use SAGE to solve problems in polynomial rings. 

PS9 Tips


Download the files 
ps9data.csv  and ps9.sagews  from Canvas and upload them to CoCalc.  Open ps9.sagews, click 'Run,' and then you can continue your work at the bottom of the worksheet.  After doing that, several useful variables and functions that you will need will have been defined:

To make use of solve(M), the following functions for constructing matrices will be helpful.

Finally, if you want to play around with encoding messages on your own, corrupting them, and trying to decode them, you can use the following functions we have defined: