︠dfbe716f-209d-4ae5-aebb-ffcb963ebea5i︠ %html
Will Agnew-Svoboda
Math 356: Number Theory
Fall 2011, Willamette University
Sage Investigation 1: The Euler Phi Function and Modular Congruence
Using Sage, we can quickly investigate some patterns related to modular congruence. This worksheet is designed to help you explore the Euler phi function $\phi$, and to develop some conjectures regarding its value and its relation to modular congruence.
Assignment goals:
Task 0: Using this worksheet
To edit this worksheet, you need to open an account at http://www.sagenb.org/. You can create an account by clicking the 'log in to edit a copy' link in the left hand corner. Once you have an account, you can then 'edit a copy' of this worksheet and save it to your worksheets library. When you are done, turn in a print out of your sws file.
Here are a few basic facts about sage. To create a new calculation box move the cursor until a blue line appears and click. To creat a text box (in which to write down conjectures or notes), again move the cursor until a blue line appears, but hold down the shift key while clicking. You can double click on text to edit the text box, or click once on a calculation box to edit the code. After you have edited the code, click the evaluate link. You can enter LaTeX code in the text box. Exotic code requiring non-standard packages may not work, but your standard LaTeX code works fine. How cool is that?!? (Hypothetical question - it's clearly very cool!)
Task 1: Open a new text box at the very top of this worksheet and enter your name.
The Euler Phi Function $\phi$
Sage has a plethora of useful number theory functions. Today, we'll be exploring its Euler phi (or totient) function and its modular arithmetic features. The window below demonstrates how to calculate the Euler phi function of an integer n. Note: lines preceeded by a # sign are comments, not executed sage code.
︡5ba8ede0-f28b-4d8e-aa54-b674ea18430a︡{"html": "Will Agnew-Svoboda
\r\nMath 356: Number Theory
\r\nFall 2011, Willamette University
\r\nSage Investigation 1: The Euler Phi Function and Modular Congruence
\r\nUsing Sage, we can quickly investigate some patterns related to modular congruence. This worksheet is designed to help you explore the Euler phi function $\\phi$, and to develop some conjectures regarding its value and its relation to modular congruence. \ufeff
\r\nAssignment goals:
\r\nTask 0: Using this worksheet\ufeff
\r\nTo edit this worksheet, you need to open an account at http://www.sagenb.org/. You can create an account by clicking the 'log in to edit a copy' link in the left hand corner. Once you have an account, you can then 'edit a copy' of this worksheet and save it to your worksheets library. When you are done, turn in a print out of your sws file.
\r\n\r\n
Here are a few basic facts about sage. To create a new calculation box move the cursor until a blue line appears and click. To creat a text box (in which to write down conjectures or notes), again move the cursor until a blue line appears, but hold down the shift key while clicking. You can double click on text to edit the text box, or click once on a calculation box to edit the code. After you have edited the code, click the evaluate link. You can enter LaTeX code in the text box. Exotic code requiring non-standard packages may not work, but your standard LaTeX code works fine. How cool is that?!? (Hypothetical question - it's clearly very cool!)
\r\n\r\n
Task 1: Open a new text box at the very top of this worksheet and enter your name.
\r\n\r\n
The Euler Phi Function $\\phi$
\r\nSage has a plethora of useful number theory functions. Today, we'll be exploring its Euler phi (or totient) function and its modular arithmetic features. The window below demonstrates how to calculate the Euler phi function of an integer n. Note: lines preceeded by a # sign are comments, not executed sage code.\ufeff
"}︡ ︠dc9281ac-999c-40c2-83f7-68c926885b5c︠ # euler_phi(n) returns the number of integers (less than n and greater than zero) which are relatively prime to n. euler_phi(5) ︡fbf3a100-273c-4381-9716-17cee45c1a38︡{"stdout": "4"}︡ ︠4dfae1f5-da65-440a-8161-7fedf98f8890i︠ %htmlSo there are 4 integers less than 5 and greater than 0 which are relatively prime to five (namely 1, 2, 3, and 4).
Task 2: Fill in the following: For any prime $p$, $\phi(p)=$
What is $\phi(p^i)$ for any prime p? Below are a few calculations. Try some more until you feel you have established the formula for $\phi(p^i)$. Once you think you know the general formula, enter it into the Task 3 line below (double click on Task 3 to make changes).
︡47e5ea79-13d7-47cd-b5a0-33e85098ee4b︡{"html": "So there are 4 integers less than 5 and greater than 0 which are relatively prime to five (namely 1, 2, 3, and 4).
\r\nTask 2: Fill in the following: For any prime $p$, $\\phi(p)=$
\r\nWhat is $\\phi(p^i)$ for any prime p? Below are a few calculations. Try some more until you feel you have established the formula for $\\phi(p^i)$. Once you think you know the general formula, enter it into the Task 3 line below (double click on Task 3 to make changes).
"}︡ ︠6092581c-7d21-4044-884e-bcc58b55b1fc︠ (euler_phi(2^2), euler_phi(2^3), euler_phi(2^4), euler_phi(3^2), euler_phi(3^3), euler_phi(3^4), euler_phi(5^2), euler_phi(5^3), euler_phi(5^4)) ︡39ad3565-32d4-44be-8bc7-d3fe5247e883︡{"stdout": "(2, 4, 8, 6, 18, 54, 20, 100, 500)"}︡ ︠660a6a9c-62d9-4e27-9b6a-26b7d433326c︠ # calculating euler_phi(p^i) ︡459f36a9-d911-4bf6-8d62-8db8dc1fa4a5︡︡ ︠85c0bd9e-3bb0-4b65-b14c-3f86176f6d52i︠ %htmlTask 3: $\phi(p^i)=$
Optional Task 3b: Prove your general form for $\phi(p^i)$ is correct. We'll be going over this in class.
Now lets investigate $\phi(mn)$ for positive integers $m$ and $n$. Below are a few sample calculations. Try some more until you feel you have established the general formula.
︡3cba849b-d38f-4b48-a2f7-860160b97294︡{"html": "Task 3: $\\phi(p^i)=$
Optional Task 3b: Prove your general form for $\\phi(p^i)$ is correct. We'll be going over this in class.
Now lets investigate $\\phi(mn)$ for positive integers $m$ and $n$. Below are a few sample calculations. Try some more until you feel you have established the general formula.
"}︡ ︠0bf21274-74b2-4618-877e-4ac758aec27f︠ (euler_phi(6), euler_phi(14), euler_phi(6*14)) ︡fadb663b-41a6-440d-9007-df8446397466︡{"stdout": "(2, 6, 24)"}︡ ︠71e5b458-dae1-42bf-92e7-dcb6eb44fc70i︠ %htmlTask 4: $\phi(mn)=$
Modular Congruence Theorem
The Euler phi function is key to one of the most spectacular theorems regarding modular congruence. This theorem is important not only for its beauty, but for its sublime utility in modern cryptography. Use the following calculations, and more of your own if necessary, to deduce this remakable theorem.
First, let us go over a few useful modular arithmetic functions.
︡1fd9020d-2d93-4c28-a70c-ff99d76264ad︡{"html": "Task 4: $\\phi(mn)=$
\r\n\r\n
Modular Congruence Theorem
The Euler phi function is key to one of the most spectacular theorems regarding modular congruence. This theorem is important not only for its beauty, but for its sublime utility in modern cryptography. Use the following calculations, and more of your own if necessary, to deduce this remakable theorem.
\r\nFirst, let us go over a few useful modular arithmetic functions.
"}︡ ︠ebfd53b2-0e68-4523-9c81-89396af760f4︠ # Modular Arithmetic # gives 100 mod 34 Mod(100, 34) ︡7b06d7d4-826f-46f4-aa4d-fe79341dd1ba︡{"stdout": "32"}︡ ︠0f94b0f9-1dba-4ea3-b204-79a09de84387︠ # a^n mod m # 2^100 mod 10 = 6 power_mod(2, 100, 10) ︡8165dcea-5d73-434a-a5cb-f559128f6ca8︡{"stdout": "6"}︡ ︠c0a54ca2-e518-456b-9670-e269bc0e09cbi︠ %htmlNow let us examine the powers of [a] in Z/nZ
Let us start with Z/5Z.
Clearly $[1]^i=[1]$ and $[0]^i=[0]$ for all $i$ in Z. What about [2], [3], and [4]? And while we're at it, lets look at an example of using for loops in sage.
︡baf06480-76b4-4a09-8e0a-06a0567d5dc2︡{"html": "Now let us examine the powers of [a] in Z/nZ
\r\nLet us start with Z/5Z\ufeff.
\r\nClearly $[1]^i=[1]$ and $[0]^i=[0]$ for all $i$ in Z. What about [2], [3], and [4]? And while we're at it, lets look at an example of using for loops in sage.
"}︡ ︠8044ba60-2477-42bb-9381-82305ba5c4ec︠ # a2 will be the vector containing powers of [2], a3 the powers of [3], and a[4] the powers of [4] a2=[]; a3=[]; a4=[]; for i in range(1,5): a2.append(power_mod(2,i,5)) a3.append(power_mod(3,i,5)) a4.append(power_mod(4,i,5)) print "Powers of [2]=",a2 print "Powers of [3]=",a3 print "Powers of [4]=",a4 ︡928acb58-914f-4dd1-9346-5ab984878160︡{"stdout": "Powers of [2]= [2, 4, 3, 1]\nPowers of [3]= [3, 4, 2, 1]\nPowers of [4]= [4, 1, 4, 1]"}︡ ︠ccace76e-40d6-4db2-9764-4f790745ef1fi︠ %htmlInteresting! $[x]^4=[1]$ for all $[x]\not=[0]$ in Z/5Z. Lets look at the powers of $[x]$ in Z/9Z. Recall Z/9Z=$\{[0], [1], [2], [3], [4], [5], [6],[7], [8]\}$.
︡fa14222e-658e-4a3e-bf4e-480650591b7e︡{"html": "Interesting! $[x]^4=[1]$ for all $[x]\\not=[0]$ in Z/5Z. \ufeffLets look at the powers of $[x]$ in Z/9Z. Recall Z/9Z\ufeff=$\\{[0], [1], [2], [3], [4], [5], [6],[7], [8]\\}$.
"}︡ ︠ff210a8d-f346-47ec-a176-919c4f1e49d7︠ #Powers in Z/9Z a0=[]; a1=[]; a2=[]; a3=[]; a4=[]; a5=[]; a6=[]; a7=[]; a8=[]; for i in range(1,9): a0.append(power_mod(0,i,9)) a1.append(power_mod(1,i,9)) a2.append(power_mod(2,i,9)) a3.append(power_mod(3,i,9)) a4.append(power_mod(4,i,9)) a5.append(power_mod(5,i,9)) a6.append(power_mod(6,i,9)) a7.append(power_mod(7,i,9)) a8.append(power_mod(8,i,9)) print "Powers of [0]=",a0 print "Powers of [1]=",a1 print "Powers of [2]=",a2 print "Powers of [3]=",a3 print "Powers of [4]=",a4 print "Powers of [5]=",a5 print "Powers of [6]=",a6 print "Powers of [7]=",a7 print "Powers of [8]=",a8 ︡b4815ceb-8fd1-4119-9203-a82debb6ac15︡{"stdout": "Powers of [0]= [0, 0, 0, 0, 0, 0, 0, 0]\nPowers of [1]= [1, 1, 1, 1, 1, 1, 1, 1]\nPowers of [2]= [2, 4, 8, 7, 5, 1, 2, 4]\nPowers of [3]= [3, 0, 0, 0, 0, 0, 0, 0]\nPowers of [4]= [4, 7, 1, 4, 7, 1, 4, 7]\nPowers of [5]= [5, 7, 8, 4, 2, 1, 5, 7]\nPowers of [6]= [6, 0, 0, 0, 0, 0, 0, 0]\nPowers of [7]= [7, 4, 1, 7, 4, 1, 7, 4]\nPowers of [8]= [8, 1, 8, 1, 8, 1, 8, 1]"}︡ ︠9106fb5d-6799-41dd-ab38-1d2f9599e225i︠ %htmlHmm, hard to see a pattern yet. Are there any values of $i$ for which $[x]^i=[1]$ for all $[x]\not=[0]$ in Z/9Z? No, but the results for $[x]^6$ are interesting. We see they are all $[1]$ except for $[0]^6, [3]^6,$ and $[6]^6$.
Questions to ponder:
Task 5: Experiment more below, calculating the powers of the equivalence classes for Z/nZ for at least 2 more value of n.
I've included a few other sage functions in the appendix below related to concepts we've already covered in class. These may or may not be useful to you in your experimentation.
︡aa1c6903-d8fa-4b61-9130-c8f8612e3a10︡{"html": "Hmm, hard to see a pattern yet. Are there any values of $i$ for which $[x]^i=[1]$ for all $[x]\\not=[0]$ in Z/9Z? No, but the results for $[x]^6$ are interesting. We see they are all $[1]$ except for $[0]^6, [3]^6,$ and $[6]^6$.
\r\nQuestions to ponder:
\r\nTask 5: Experiment more below, calculating the powers of the equivalence classes for Z/nZ for at least 2 more value of n.
\r\nI've included a few other sage functions in the appendix below related to concepts we've already covered in class. These may or may not be useful to you in your experimentation.
"}︡ ︠363d8d1d-ef5a-4cab-b4fa-c43d9a59debf︠ #Powers in Z/nZ for n=?? ︡8a9f7379-3938-4bcc-b0eb-1244ee5f7e52︡︡ ︠36f04df5-5f6d-400f-aa87-42d7cf839bd9i︠ %htmlI think you're ready. Can you identify one of the most spectacular theorems regarding modular congruence? I'll give you a hint. It's of the form
Thm: $a^{?}\equiv 1\pmod{n}$ for all ???.
Task 6: Fill in the statement of the above theorem.
Appendix 1: Some Useful Sage Functions Related to Modular Equivalence, GCD, Primes, and Factorization
︡52b88119-1e79-42b5-a4b1-cd44336a1367︡{"html": "I think you're ready. Can you identify one of the most spectacular theorems regarding modular congruence? I'll give you a hint. It's of the form
\r\nThm: $a^{?}\\equiv 1\\pmod{n}$ for all ???.
\r\nTask 6: Fill in the statement of the above theorem.
\r\nAppendix 1: Some Useful Sage Functions Related to Modular Equivalence, GCD, Primes, and Factorization
"}︡ ︠b2657eb8-3868-4995-aa5b-c80fae94ee3c︠ # Greatest Common Divisors gcd(24, 12345) ︡b8c67026-8a3b-43da-a808-db30d99fd3ab︡{"stdout": "3"}︡ ︠eca802b3-fd0e-4c54-8711-9539cc81e8e5︠ # Extended GCD: This finds the GCD and the EA linear combination that produces it. # Example: 2 = (-5)*10 + 1*(52) xgcd(10, 52) ︡0a4a82fd-88ab-4db7-8cda-613b2afedb75︡{"stdout": "(2, -5, 1)"}︡ ︠e63ca750-76c5-4df1-96ab-9aaefbf8e690︠ # Multiplicative inverses # To find the inverse of 3 mod 100: # Note: we know 3 * 33 = 99 = -1 mod 100 # so 3 *(-33) = -99 = 1 mod 100 inverse_mod(3, 100) ︡96136cf4-fd6f-4101-b410-a9d3938463e2︡{"stdout": "67"}︡ ︠f9636bf4-179a-4ca0-b716-29b94f968261︠ # What if we try to find the inverse of 2 modulo 100? inverse_mod(2, 100) ︡99fb8afb-d6d7-45b3-8344-356b2bc04a80︡{"stderr": "Traceback (most recent call last):\n File \"