{"id":26,"date":"2016-09-22T19:15:50","date_gmt":"2016-09-22T19:15:50","guid":{"rendered":"http:\/\/keithmellinger.com\/magma\/?page_id=26"},"modified":"2016-11-17T01:58:40","modified_gmt":"2016-11-17T01:58:40","slug":"number-theory","status":"publish","type":"page","link":"https:\/\/keithmellinger.com\/magma\/number-theory\/","title":{"rendered":"Number Theory"},"content":{"rendered":"<p>Many courses in elementary number theory and cryptography teach both Fermat\u2019s Little Theorem and its generalization. Let\u2019s explore.<\/p>\n<p>Fermat\u2019s Little Theorem states that if <em>p<\/em> is prime and \u00a0then <em>a<\/em><sup><em>p<\/em><\/sup>\u00a0\u2261 <em>a<\/em> (mod <em>p<\/em>). In the case of gcd(<em>a<\/em>,<em>p<\/em>) = 1,\u00a0a<sup><em>p<\/em>-1<\/sup> \u2261\u00a01 (mod <em>p<\/em>). The result can be easily \u201cdiscovered\u201d via computation in <em>Magma<\/em>, and this is a great example of using loops. First, let\u2019s compute the powers of all the elements in Z<sub>5<\/sub>.<\/p>\n<p><code> &gt; Z5 := Integers(5); <\/code><br \/>\n<code> &gt; for x in Z5 do <\/code><br \/>\n<code> for&gt; x,x^2,x^3,x^4,x^5;<\/code><br \/>\n<code> for&gt; end for;<\/code><br \/>\n<code> 0 0 0 0 0<\/code><br \/>\n<code> 1 1 1 1 1<\/code><br \/>\n<code> 2 4 3 1 2<\/code><br \/>\n<code> 3 4 2 1 3<\/code><br \/>\n<code> 4 1 4 1 4<\/code><\/p>\n<p>The last column seems to illustrate the result. But let\u2019s use the power of <em>Magma<\/em> to check a larger example. The <code>forall<\/code> command will check that some statement is true for all elements in some set. For instance, Fermat\u2019s Little Theorem is not true when you don\u2019t use a prime:<\/p>\n<p><code> &gt; forall {x:x in Integers(24) | x^24 eq x }; <\/code><br \/>\n<code> false <\/code><\/p>\n<p>And, we can check that the statement is true only for a few special values in Z<sub>24<\/sub>:<\/p>\n<p><code> &gt; {x:x in Integers(24) | x^24 eq x }; <\/code><br \/>\n<code> { 0, 1, 16, 9 } <\/code><\/p>\n<p>But we can also check that it is indeed true when we use \u201clarge\u201d primes:<\/p>\n<p><code> &gt; IsPrime(9973);<\/code><br \/>\n<code> true<\/code><br \/>\n<code> &gt; forall {x:x in Integers(9973) | x^9973 eq x };<\/code><br \/>\n<code> true<\/code><\/p>\n<p>The Euler Phi function \u03c6\u00a0is defined as the number of integers <em>k<\/em> in the range 1 \u2264 <em>k<\/em> \u2264 <em>n<\/em> for which the greatest common divisor gcd(<em>n<\/em>, <em>k<\/em>) = 1. Euler\u2019s famous result states that if <em>a<\/em> and <em>n<\/em> are relatively prime, then <em>a<\/em><sup>\u03c6(n)<\/sup> \u2261 1 (<em>mod n<\/em>). \u00a0There are many things you can do to explore values of Euler Phi. For example, if <em>n<\/em> is the product of two distinct primes, there\u2019s a nice formula for computing the Euler Phi function. Let\u2019s look at some examples using a loop:<\/p>\n<p><code>for i in [1..10] do<\/code><br \/>\n<code>for&gt; for j in [1..10] do<\/code><br \/>\n<code>for|for&gt; if IsPrime(i) and IsPrime(j) and i ne j then<\/code><br \/>\n<code>for|for|if&gt; i,j, EulerPhi(i*j);<\/code><br \/>\n<code>for|for|if&gt; end if;<\/code><br \/>\n<code>for|for&gt; end for;<\/code><br \/>\n<code>for&gt; end for;<\/code><br \/>\n<code>2 3 2<\/code><br \/>\n<code>2 5 4<\/code><br \/>\n<code>2 7 6<\/code><br \/>\n<code>3 2 2<\/code><br \/>\n<code>3 5 8<\/code><br \/>\n<code>3 7 12<\/code><br \/>\n<code>5 2 4<\/code><br \/>\n<code>5 3 8<\/code><br \/>\n<code>5 7 24<\/code><br \/>\n<code>7 2 6<\/code><br \/>\n<code>7 3 12<\/code><br \/>\n<code>7 5 24<\/code><\/p>\n<p>Once you have the data above, you might look for a pattern. Given two primes <em>p<\/em> and <em>q<\/em>, can you conjecture a formula for\u00a0\u03c6(<em>pq<\/em>)? (Maybe\u00a0you already know this theorem. Ok, fine. Move along&#8230; nothing to see here&#8230;)<\/p>\n<p><strong><em>Exercise:<\/em><\/strong> We\u2019re trying to figure out which of the following \u201ctheorems\u201d is true?\u00a0 Use <em>Magma<\/em> to compute values and see what you can learn.<\/p>\n<ul>\n<li>If <em>a<\/em>|<em>b<\/em> then \u03c6(<em>a<\/em>) | \u03c6(<em>b<\/em>).<\/li>\n<li>If \u03c6(<em>a<\/em>) | \u03c6(<em>b<\/em>), then <em>a<\/em>|<em>b<\/em>.<\/li>\n<li>For any <em>n<\/em>\u00a0&gt; 1, 2|\u03c6(2<em><sup>n<\/sup><\/em>-1).<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Many courses in elementary number theory and cryptography teach both Fermat\u2019s Little Theorem and its generalization. Let\u2019s explore. Fermat\u2019s Little Theorem states that if p is prime and \u00a0then ap\u00a0\u2261 a (mod p). In the case of gcd(a,p) = 1,\u00a0ap-1 \u2261\u00a01 (mod p). The result can be easily \u201cdiscovered\u201d via computation in Magma, and this &hellip; <a href=\"https:\/\/keithmellinger.com\/magma\/number-theory\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Number Theory<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-26","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/keithmellinger.com\/magma\/wp-json\/wp\/v2\/pages\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/keithmellinger.com\/magma\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/keithmellinger.com\/magma\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/keithmellinger.com\/magma\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keithmellinger.com\/magma\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":5,"href":"https:\/\/keithmellinger.com\/magma\/wp-json\/wp\/v2\/pages\/26\/revisions"}],"predecessor-version":[{"id":65,"href":"https:\/\/keithmellinger.com\/magma\/wp-json\/wp\/v2\/pages\/26\/revisions\/65"}],"wp:attachment":[{"href":"https:\/\/keithmellinger.com\/magma\/wp-json\/wp\/v2\/media?parent=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}