<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Modulo Errors &#187; MAT-1-GTh</title>
	<atom:link href="http://maths.straylight.co.uk/archives/category/mat-1-gth/feed" rel="self" type="application/rss+xml" />
	<link>http://maths.straylight.co.uk</link>
	<description>for when the margin is too small</description>
	<lastBuildDate>Thu, 12 Jan 2012 16:36:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>The Extended Euclidean Algorithm</title>
		<link>http://maths.straylight.co.uk/archives/112</link>
		<comments>http://maths.straylight.co.uk/archives/112#comments</comments>
		<pubDate>Thu, 17 Jan 2008 22:45:40 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[MAT-1-GTh]]></category>
		<category><![CDATA[Number Theory]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=112</guid>
		<description><![CDATA[Some notes on Euclid's algorithm and its extension for solving linear Diophantine equations in two variables.]]></description>
			<content:encoded><![CDATA[<p><em>I promised some of my tutorial students a demonstration of how the &#8216;highschool&#8217; approach to Euclid&#8217;s algorithm can be reversed to give rise to the extended Euclidean algorithm &#8211; as opposed to the version in their lecture notes, which finds both gcd(a,b) and x,y such that ax+by=gcd(a,b)  in one pass, at the price of some notational complexity. To do so, it seemed worth recapping some of the properties of divisibility that make Euclid&#8217;s algorithm tick, and give an application for its extended form. That ended up taking four pages, so I figured I&#8217;d post it here as well&#8230; you can read it behind the cut, or download <a href="http://aleph.straylight.co.uk/eea.pdf">the LaTeX-formatted pdf version</a>.</em></p>
<p><span id="more-112"></span></p>
<h2>The Euclidean Algorithm</h2>
<p>Euclidâ€™s algorithm recovers the greatest common divisor of two numbers a and b- that is, the largest x with the property that x&#124;a and x&#124;b (we write<br />
x = gcd(a, b)). Thus, anything that is true of divisors of a and b in general is true of their g.c.d in particular.</p>
<p> To this end, recall that if x&#124;a and x&#124;b then x&#124;a &plusmn; b. Further, if x&#124;b then x&#124;&lambda;b for any integer &lambda;. Combining the two, we have that</p>
<p align=center>x&#124;a and x&#124;b &rArr; x&#124;(a &plusmn; &lambda;b) for all &lambda;   &nbsp;&nbsp;&nbsp;&nbsp;(1)</p>
<p>How does this help us? Since gcd(a, b) = gcd(b, a), we can assume w.l.o.g that a &ge; b. Then by the quotient-remainder theorem, we can write a as a = qb + r for some integers q, r with 0 &le; r &lt; b. Rearranging gives us r = a -qb, so by (1) we have</p>
<p align=center>x&#124;a and x&#124;b &rArr; x&#124;(a &#8211; qb) = r &nbsp;&nbsp;&nbsp;&nbsp;(2)</p>
<p>So in particular</p>
<p align=center>gcd(a, b)&#124;a and gcd(a, b)&#124;b &rArr; gcd(a, b)&#124;r &nbsp;&nbsp;&nbsp;&nbsp;(3)</p>
<p>So, to solve the question of finding gcd(a, b), we can instead solve the question of finding gcd(b, r). Notice that b &le; a and r &lt; b, so this second question is easier.</p>
<p>Repeating this process, the pairs of terms keep decreasing until eventually we have the question &#8220;find the g.c.d. of r and 0&#8243; for some r. But as anything divides 0, gcd(r, 0) = r. So there is always a final question; that question is easy to answer; and its answer is the same as the original g.c.d. we were looking for!</p>
<h3>Worked Example</h3>
<p>Suppose then that we want to find the g.c.d. of 51 and 36. We first appeal to the quotient-remainder theorem:</p>
<p align=center>51 = 36 + 15</p>
<p>Thus any divisor of 51 and 36 (including the greatest) is also a divisor of 15. So we turn our attention to the easier problem of the g.c.d. of 36 and 15. Again by quotient-remainder</p>
<p align=center>36 = 2 * 15 + 6</p>
<p>so it suffices to find gcd(15,6). Noting that</p>
<p align=center>15 = 2 * 6 + 3</p>
<p>we discover that this is the same as the g.c.d. of 6 and 3. But</p>
<p align=center>6 = 2 * 3 + 0</p>
<p>so thatâ€™s simply gcd(3,0)=3. Thus we have</p>
<p align=center>gcd(51, 36) = gcd(36, 15) = gcd(15, 6) = gcd(6, 3) = gcd(3, 0) = 3</p>
<h2>The Extended Euclidean Algorithm</h2>
<p>Typically, one tabulates their progress through the algorithm more compactly; using the previous example we have</p>
<blockquote><p>
51 = 36 + 15 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(4)<br />
<br />36 = 2 * 15 + 6 &nbsp;&nbsp;(5)<br />
<br />15 = 2 * 6 + 3 &nbsp;&nbsp;&nbsp;&nbsp;(6)<br />
<br />6&nbsp;&nbsp;&nbsp;= 2 * 3 + 0 &nbsp;&nbsp;&nbsp;&nbsp;(7)
</p></blockquote>
<p>With such a representation, we can now tackle a related problem &#8211; given a, b, finding x, y such that</p>
<p align=center>ax + by = gcd(a, b)</p>
<p>For our example, this means finding x, y with the property that 51x+36y = 3.</p>
<p>Notice that we do not have an identity in terms of 3, 36 and 51 anywhere in the table. But from (6), we do have an identity for 3 in terms of 15 and 6:</p>
<p align=center>3 = 15 &#8211; 2 * 6</p>
<p>Then (5) tells us that</p>
<p align=center>6 = 36 &#8211; 2 * 15</p>
<p>so we can rewrite our result for 3 in terms of 36 and 15 instead of 15 and 6, and so on.</p>
<p>In this way, we can chain upwards through the table to an identity for 3 ultimately in terms of 51 and 36- this process is known as the extended euclidean algorithm. Whereas the Euclidean algorithm works down from a and b, through simpler and simpler terms to the g.c.d., so the extended version works up from that g.c.d. through increasingly complicated terms to an expression in terms of a and b.</p>
<p>For our example, this works as follows:</p>
<blockquote><p>
3 = 15 &#8211; 2 * 6 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by (6)<br />
<br />&nbsp;&nbsp;&nbsp;= 15 &#8211; 2 * (36 &#8211; 2 * 15) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by (5)<br />
<br />&nbsp;&nbsp;&nbsp;= 5 * 15 &#8211; 2 * 36 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(simplifying)<br />
<br />&nbsp;&nbsp;&nbsp;= 5 * (51 &#8211; 36) &#8211; 2 * 36 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by (4)<br />
<br />&nbsp;&nbsp;&nbsp;= 5 * 51 &#8211; 7 * 36 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(simplifying)
</p></blockquote>
<h3>Linear Diophantine Equations</h3>
<p>Why is all this useful? In number theory, the study of Diophantine equations concerns finding integer solutions to equations, where possible. Typically we seek to classify such equations based on whether we can find infinitely many such solutions, only finitely many, or none at all. The general question as to whether solutions exist is actually undecidable, but in various special cases we can say something.</p>
<p>Armed with the extended euclidean algorithm, we can tackle the case of linear diophantine equations in two variables:</p>
<p align=center>For fixed integers a, b, c, do there exist integer solutions x, y of ax + by = c ?</p>
<h4>Existence</h4>
<p>Suppose c = &lambda;gcd(a, b) for some integer &lambda; . Then, by the extended Euclidean algorithm we have x&#8217;, y&#8217; with the property axâ€™+byâ€™=gcd(a, b). So x = &lambda;x&#8217;, y = &lambda;y&#8217; solve the linear diophantine equation, since</p>
<p align=center>ax + by = a&lambda;x&#8217; + b&lambda;y&#8217; = &lambda;(ax&#8217; + by&#8217;) = &lambda;gcd(a, b) = c</p>
<p>Conversely, suppose c is not a multiple of gcd(a, b). Then, if the equation had solutions x, y then weâ€™d have that gcd(a, b)&#124;a&#124;ax and gcd(a, b)&#124;b&#124;by so gcd(a, b)&#124;ax + by = c, which is a contradiction.</p>
<p>Hence, the linear diophantine equation in two variables ax + by = c has integer solutions if and only if c is a multiple of gcd(a, b).</p>
<h4>Number of Solutions</h4>
<p>Assuming solutions exist, how many are there? Although the g.c.d. is unique, suitable pairs (x, y) with ax+by = gcd(a, b) (and hence solutions to the linear diophantine equation) are not. To see this, consider one of the standard tricks of analysis, adding and subtracting the same thing:</p>
<p align=center>ax+by = &lambda;gcd(a, b) ) ax+by+ab-ab = &lambda;gcd(a, b) ) a(x+b)+b(y-a) = &lambda;gcd(a, b)</p>
<p>That is, if (x, y) satisfy the equation, so do (x + b, y &#8211; a). Which means we can apply the result again, giving (x+2b, y-2a). These will always be pairs of integer solutions, and so the existence of just one pair (x, y) gives us an infinite family (x + ib, y &#8211; ia) of solutions.</p>
<p>Hence we conclude that the linear diophantine equation in two variables ax+by = c has infinitely many integer solutions if c is a multiple of gcd(a, b), and none otherwise.</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/112/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On logic</title>
		<link>http://maths.straylight.co.uk/archives/87</link>
		<comments>http://maths.straylight.co.uk/archives/87#comments</comments>
		<pubDate>Thu, 24 May 2007 18:15:51 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
				<category><![CDATA[Logic]]></category>
		<category><![CDATA[MAT-1-GTh]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/archives/87</guid>
		<description><![CDATA[Worked solution to a first year undergraduate mathematics exam question on logic.]]></description>
			<content:encoded><![CDATA[<p>As part of my postgraduate life here in Edinburgh, I&#8217;m expected to tutor a couple of dozen first (of four) year undergraduate Mathematics students. Thus I was involved in the marking of their group theory exam last Friday. As the questions were being assigned to markers, there seemed to be a reluctance to take the logic question, probably because students manage to tie themselves in hard-to-follow knots with this material. However, I spent some of my previous year at Bath tutoring on set theory and logic to Physicists, so was prepared for the worst, and I&#8217;d also spotted that the question was multiple choice, so the actual marking shouldn&#8217;t be too taxing, so I took responsibility for that one.
</p>
<p>
Still, 207 scripts later I was somewhat worried by the general standard. There were quite a few attempts which received full marks, but many more received zero, including elsewhere high-scoring candidates. Whilst the emphasis of a group theory exam should be group theory, the pressure of an exam and lack of access to notes will always dampen performance, and I probably received a few scripts that were pure guesswork, that&#8217;s still a disappointment.  Whilst it pains me to say it, a student could become competent at first year undergraduate mathematics just by learning how to &#8216;turn the handle&#8217; of appropriate bits of mathematical machinery, and as this is pretty much all that they do at school, they may find that university-level mathematics isn&#8217;t really the subject they thought it was. To make the leap from computation to understanding,  it strikes me as vital to gain mastery of basic logical manipulation. Nor should this just be the domain of Mathematicians; if anything, a precise understanding of the structure of an argument (and its falsification) should be even more crucial to the Humanities.
</p>
<p>
So I&#8217;m going to reproduce the question here and then attempt to unravel it in a precise manner but without recourse to the more abstract approaches of formal logic, in the hope that everyone can follow. Here goes:
</p>
<blockquote>
<p>Consider the statements:<br />
<br />A. All people who can sing in tune are musical.<br />
<br />B. Some people who cannot sing in tune are musical.<br />
<br />C. Some unmusical people can sing in tune.<br />
<br />D. Some unmusical people cannot sing in tune.<br />
<br />E. No unmusical person can sing in tune.
</p>
<p>Mark with the number 1 any of the statements B,C,D,E that are logically equivalent to statement A, with 2 any that are (logically equivalent to) the negation of A, with 3 any that are (logically equivalent to) the converse of A, with 4 any that are (logically equivalent to) the negation of the converse of A and with 0 any which are in none of the above categories.</p>
</blockquote>
<p>
Solution is behind the cut, so if you want to try this yourself without spoilers, now&#8217;s the time!
</p>
<p><span id="more-87"></span></p>
<p>
It seems that the easiest way to proceed is to establish what an example of each number would look like, then match those to the statements given. To do so, of course, requires an understanding of the notions of negation and converse.
</p>
<h4>Negation</h4>
<p>Amongst the scripts which contained some reasoning (rather than just a final answer), the overwhelming majority of those that went wrong did so because of a misunderstanding of negation. To negate a statement is to make it false: <em>not</em> to find its complete opposite. For our statement </p>
<blockquote><p>all people who can sing in tune are musical</p></blockquote>
<p>negating is as simple as putting &#8220;not&#8221; in front:</p>
<blockquote><p>not all people who can sing in tune are musical</p></blockquote>
<p>But what I tended to see was the opposite of A:</p>
<blockquote><p><em>no</em> people who can sing in tune are musical</p></blockquote>
<p>Certainly, if no tuneful people were musical, then it would be the case that not all tuneful people are musical. But this over-reaches: all we need to negate the statement is one unmusical, tuneful person; not that every tuneful person be unmusical.</p>
<p>Put another way, statement A asserts that it is impossible to be an unmusical person who sings in tune. So if I tell you that Bob sings in tune, you know he&#8217;s musical. Its negation therefore asserts that it <em>is</em> possible to find such an individual; i.e., knowing that Bob sings in tune tells you nothing about his musical status. But the opposite is concerned with a different group of people: it means that if I tell you that Alice is a musical person,  you can conclude (oddly) that she can&#8217;t sing in tune.</p>
<h4>Converse</h4>
<p>
The converse of a statement is its reversal: that Y causes X, instead of X causing Y. This won&#8217;t, in general, have the same meaning, and often won&#8217;t even be talking about the same things. The converse of our statement A is as follows:</p>
<blockquote><p>All people who are musical can sing in tune</p></blockquote>
<p>
Now we know that given a musical person, we can count on them to sing in tune; but we no longer make any assertions about the musical nature of someone who can sing in tune. They could be musical, in which case our statement above doesn&#8217;t generate any contradiction (it verifies their ability to sing in tune); but if they&#8217;re not, since the statement says nothing about them, there is no problem.</p>
<p>More formally, we are dealing with statements of the form &#8220;P implies Q&#8221;, equivalently, &#8220;if P, then Q&#8221;. Sometimes, one has the situation of &#8220;P, if and only if Q&#8221; which is the combination of P implies Q and Q implies P. So we can speak of necessary and sufficient conditions: if you know one holds, you can be sure the other does (sufficient), and if you know one doesn&#8217;t, you also know the other doesn&#8217;t (necessary). This is the concept of logical equivalence which we also need for answering the question.</p>
<p>It&#8217;s vital to recognise that a statement needn&#8217;t be logically equivalent to its converse: that P can mean Q <em>without</em> Q meaning P. Whilst it&#8217;s necessary to drive at 20mph to hit 150mph (150 implies 20, if only briefly), no-one argues that driving at 20mph should be banned because all the 150mph drivers have done it, since it&#8217;s not inevitable (i.e., 20 doesn&#8217;t imply 150) that driving at slow speeds will lead to faster ones. Nonetheless, the same (invalid) argument arises for &#8220;gateway drugs&#8221;- even if it was the case that all class A drug users had used cannabis, that tells you nothing about a random cannabis user&#8217;s taste for stronger substances, since the (assumed) necessary condition (class A use implies cannabis use) doesn&#8217;t prove the converse, that cannabis use is sufficient to get you on the harder stuff. </p>
<h4>Negation of converse</h4>
<p>Since we know the converse, and know how to negate, this is easy:</p>
<blockquote><p>Not all people who are musical can sing in tune</p></blockquote>
<p>
That is, a musical person needn&#8217;t be able to sing in tune, so knowing about someone&#8217;s musical ability sheds no light on their singing under this assumption. </p>
<h4>Cases</h4>
<p>So we have</p>
<blockquote><p>1) All people who can sing in tune are musical<br />
<br />2) Not all people who can sing in tune are musical (negation)<br />
<br />3) All people who are musical can sing in tune (converse)<br />
<br />4) Not all people who are musical can sing in tune (negation of converse)<br />
<br />0) None of the above
</p></blockquote>
<p>Alternatively:</p>
<blockquote><p>1) Tuneful and unmusical is impossible<br />
<br />2) Tuneful and unmusical is possible (negation)<br />
<br />3) Musical and untuneful is impossible (converse)<br />
<br />4) Musical and untuneful is possible (negation of converse)
</p></blockquote>
<h4>The answer</h4>
<p>So we can compare to our given statements.<br />
<br /><strong>B</strong> says there are untuneful people who are nonetheless musical; this is the same as 4.<br />
<br /><strong>C</strong> says there are unmusical people who can sing in tune; this is the same as 2.<br />
<br /><strong>D</strong> says it&#8217;s possible to be an unmusical, untuneful person; none of our reformulations consider such individuals, so we have case 0.<br />
<br /><strong>E</strong> says that being unmusical prevents you from being someone who sings in tune, so it&#8217;s impossible to be both, that is, we have case 1, a rewording of A.
</p>
<p>That&#8217;s it! I&#8217;d be interested to know how people got on with this, whether you tried it &#8216;cold&#8217; or followed the explanation some of the way. I&#8217;m also bound to have mistyped something in a crucial way, so let me know if you spot an inconsistency.</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/87/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

