<?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"
	>

<channel>
	<title>Modulo Errors</title>
	<atom:link href="http://maths.straylight.co.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://maths.straylight.co.uk</link>
	<description>for when the margin is too small</description>
	<pubDate>Thu, 12 Jun 2008 15:24:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Maximal Cyclotomic Matrices from Q(sqrt(-7))</title>
		<link>http://maths.straylight.co.uk/archives/121</link>
		<comments>http://maths.straylight.co.uk/archives/121#comments</comments>
		<pubDate>Thu, 12 Jun 2008 15:22:46 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Graph Theory]]></category>

		<category><![CDATA[Number Theory]]></category>

		<category><![CDATA[PhD]]></category>

		<category><![CDATA[cyclotomic]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=121</guid>
		<description><![CDATA[As a companion to my previous post, here&#8217;s the list of valid forms of a connected maximal cyclotomic graph with an entry from the ring of integers of Q(&#8730; -7):
Uncharged Lines:

Uncharged Squares:

Uncharged Hexagons:

Uncharged Cubes:

T_2k Variants (Infinite Family):
A chain of the form

for any integer k.
Charged Triangles:

Charged Squares:

or
C_2k Variants (Infinite Family):
A chain of the form

for any integer [...]]]></description>
			<content:encoded><![CDATA[<p>As a companion to my previous post, here&#8217;s the list of valid forms of a connected maximal cyclotomic graph with an entry from the ring of integers of Q(&radic; -7):</p>
<h4>Uncharged Lines:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2g.png" alt="maximal lines" /></p>
<h4>Uncharged Squares:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2h.png" alt="maximal squares" /></p>
<h4>Uncharged Hexagons:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2i.png" alt="maximal hexagons" /></p>
<h4>Uncharged Cubes:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2b.png" alt="maximal cubes" /></p>
<h4>T_2k Variants (Infinite Family):</h4>
<p>A chain of the form<br />
<img src="http://aleph.straylight.co.uk/cyclotomic/neg2c.png" alt="maximal T_2k variants" /><br />
for any integer k.</p>
<h4>Charged Triangles:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2d.png" alt="maximal charged triangles" /></p>
<h4>Charged Squares:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2e.png" alt="maximal charged squares" /></p>
<p><em>or</em></p>
<h4>C_2k Variants (Infinite Family):</h4>
<p>A chain of the form<br />
<img src="http://aleph.straylight.co.uk/cyclotomic/neg2f.png" alt="maximal C_2k variants" /><br />
for any integer k.</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/121/feed</wfw:commentRss>
		</item>
		<item>
		<title>Maximal Cyclotomic Matrices from Q(sqrt(-2))</title>
		<link>http://maths.straylight.co.uk/archives/120</link>
		<comments>http://maths.straylight.co.uk/archives/120#comments</comments>
		<pubDate>Sun, 08 Jun 2008 16:52:55 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Graph Theory]]></category>

		<category><![CDATA[Number Theory]]></category>

		<category><![CDATA[PhD]]></category>

		<category><![CDATA[cyclotomic]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=120</guid>
		<description><![CDATA[To recap: I&#8217;ve been trying to completely classify the possible matrices/graphs subject to a constraint on their eigenvalues we&#8217;re describing as cyclotomicity. This is a problem that can be posed in the ring of integers of any imaginary quadratic extension field, but for all but finitely many of them reduces to the problem in the [...]]]></description>
			<content:encoded><![CDATA[<p>To recap: I&#8217;ve been trying to completely classify the possible matrices/graphs subject to a constraint on their eigenvalues we&#8217;re describing as cyclotomicity. This is a problem that can be posed in the ring of integers of any imaginary quadratic extension field, but for all but finitely many of them reduces to the problem in the rational-integer case which has been solved in a paper by my supervisor. </p>
<p>For a couple of the remaining fields, the problem is easy: there&#8217;s only a finite supply of graphs featuring a non-rational integer label, which can be found simply by running a growing process to termination. But once you move to fields with norm 2 integers, there&#8217;s enough freedom for things to get interesting: I&#8217;ve been working in the rings of integers of Q(&radic; -2) and Q(&radic; -7), where I can demonstrate an infinite family of such graphs and so the growing algorithm can never terminate. Nonetheless, in the simpler, &#8216;uncharged&#8217; version of the problem, I have (proven) a complete classification in both of these fields. With a bit more work I&#8217;ve now settled the general case in Q(&radic; -2) and expect the logic of the argument (although not the precise results) to carry over to Q(&radic; -7).</p>
<p>That argument is essentially a lengthy case analysis; rather than get into the details I thought I&#8217;d just present the &#8216;zoo&#8217; of possible graphs. The forms presented are necessary conditions (any cyclotomic graph will take one of these forms) but not sufficient (there may be non-cyclotomic graphs satisfying the form). However, no form contains no cyclotomic graphs - for a given form, including any instance of the infinite ones, I can exhibit at least one class of cyclotomic graphs. </p>
<p>After applying a numbering, the visual styling of an edge between two nodes i&lt;j indicates the norm of the edge label (entry [i,j] of the matrix; take the conjugate for entry [j,i]); uncharged nodes are indicated by a point whilst [C] denotes a charged node (value of &plusmn;1 for entry [i.i] if node i is charged, otherwise zero). The precise choice of labels and charges requires some care over signs to ensure that the matrix has minimal polynomial x<sup>2</sup>-4; working with forms saves tracking such details, choosing equivalence class representatives, etc. </p>
<p>Then for the ring of integers of Q(&radic; -2) any connected maximal cyclotomic graph with a non-rational integer label must take one of the following forms:</p>
<h4>Uncharged Squares:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2a.png" alt="maximal squares" /></p>
<h4>Uncharged Cubes:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2b.png" alt="maximal cubes" /></p>
<h4>T_2k Variants (Infinite Family):</h4>
<p>A chain of the form<br />
<img src="http://aleph.straylight.co.uk/cyclotomic/neg2c.png" alt="maximal T_2k variants" /><br />
for any integer k.</p>
<h4>Charged Triangles:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2d.png" alt="maximal charged triangles" /></p>
<h4>Charged Squares:</h4>
<p><img src="http://aleph.straylight.co.uk/cyclotomic/neg2e.png" alt="maximal charged squares" /></p>
<p><em>or</em></p>
<h4>C_2k Variants (Infinite Family):</h4>
<p>A chain of the form<br />
<img src="http://aleph.straylight.co.uk/cyclotomic/neg2f.png" alt="maximal C_2k variants" /><br />
for any integer k.</p>
<p>As I said, I expect this to easily generalise to Q(&radic;-7); the remaining fields Q(&radic;-1) and Q(&radic;-3) present more of a computational challenge, but meeting that challenge will hopefully be rewarded with more interesting behaviour!</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/120/feed</wfw:commentRss>
		</item>
		<item>
		<title>Geometry Club Talk: Computational aspects of ECDLP</title>
		<link>http://maths.straylight.co.uk/archives/118</link>
		<comments>http://maths.straylight.co.uk/archives/118#comments</comments>
		<pubDate>Wed, 23 Apr 2008 09:05:35 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Algebraic Geometry]]></category>

		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[Complexity]]></category>

		<category><![CDATA[Cryptology]]></category>

		<category><![CDATA[Group Theory]]></category>

		<category><![CDATA[PhD]]></category>

		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=118</guid>
		<description><![CDATA[Notes from my geometry club talk given April 18th, 2008.]]></description>
			<content:encoded><![CDATA[<p>On Friday I gave a <a href="http://www.maths.ed.ac.uk/~s0198576/gc/">geometry club</a> seminar, speaking about some of the computational aspects of discrete-logarithm cryptography in general and as implemented for elliptic curves.  <a href="http://www.maths.ed.ac.uk/~s0677951/gc_apr_08.pdf">My notes</a> supplement rather than completely describe the talk, being heavier on the formalities and lighter on the narrative. </p>
<p>The topics covered are: Diffie-Hellman and one-way functions for key exchange; the generic Discrete Logarithm Problem and BSGS algorithm; scalar multiplication- addition chains, fast exponentiation, m-ary methods and windowing; group law implementations, Side-channel attacks and the Edwards form. </p>
<p>I&#8217;ve discussed several of these ideas elsewhere on this blog, as well as the cryptanalysis ideas I mentioned on the day but which are not in the notes. I also refered to a recent real-world example of a side-channel attack; see <a href="http://www.theregister.co.uk/2008/04/03/keeloq_master_key_found/">this</a> story from The Register for details.</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/118/feed</wfw:commentRss>
		</item>
		<item>
		<title>Greedy Pig</title>
		<link>http://maths.straylight.co.uk/archives/117</link>
		<comments>http://maths.straylight.co.uk/archives/117#comments</comments>
		<pubDate>Sun, 06 Apr 2008 12:17:11 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Game Theory]]></category>

		<category><![CDATA[Pop.Maths]]></category>

		<category><![CDATA[Probability]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=117</guid>
		<description><![CDATA[A simple maths game about probability.]]></description>
			<content:encoded><![CDATA[<p><em><small>This entry <a href="http://everything2.com/index.pl?node_id=1936051">first appeared</a> as a writeup for Everything2.</small></em></p>
<p>Greedy pig is a simple maths game for groups that serves as an introduction to probability. I used it recently as a warm-up activity for a maths hour with local primary school children (around 11 years old), where it was well-received. For older students, it could provide the starting point for a discussion of topics such as the gambler&#8217;s fallacy or for a statistical investigation.</p>
<h2>How to Play</h2>
<p>A pair of dice are thrown, and their total recorded as a starting score for all participants. Play then proceeds in rounds. Before each round, players decide whether to stick with their current score, or continue playing. To play a round, roll a die; each player who is still in adds that many points to their score- unless a two is thrown, in which case they lose all their points. Play proceeds until all participants have decided to keep their score, or a two eliminates all remaining players. The winners of the game are the players with the highest score; it&#8217;s worth playing around three games and taking a combined total.</p>
<h3>Practical issues when running the game</h3>
<p>
Keeping track of who&#8217;s in or out is most easily done by having students stand up if they wish to gamble or sit down if they wish to stick with their score. Apart from making it easy to spot when a player is trying to sneak back into the game, this is also good as it gives the students an idea of how confident their peers are to continue, and you&#8217;ll get lots of them wavering up and down as they try to decide!
</p>
<p>
Recording scores of players as they drop out is harder, but vital- children may try to cheat, or accuse each other of doing so, when it comes to declaring their final total. It&#8217;s definitely worth keeping a running tally of throws and totals on the blackboard -with the students doing the adding up! For smaller groups, you might be able to give out tokens or numbered cards as players save their score, but with larger groups (we had around 30 students per session) this would probably slow things down a lot. Perhaps give each student a piece of paper and a pen to write their score on (nice and large!) to hold up once they&#8217;ve sat down.
</p>
<p>
Some children are very risk adverse, and sit down almost immediately; others just stay standing until they get knocked out by a two. To make sure this isn&#8217;t due to misunderstanding the game, it&#8217;s worth doing a practice run first. It&#8217;s interesting to watch how strategies adapt as the players get more experience- particularly if the two is thrown surprisingly early or late in a game (we hit a total in the 70s for one session, which skewed things somewhat!)
</p>
<h2>Strategy</h2>
<p>
Can we say anything mathematically about when a player should sit down? That is, should we gamble a given total or not? You might want to think about this yourself before reading on.</p>
<p>
To model this game, we can consider the expectation of a round- that is, the average outcome in the long run. Suppose then we have a total of N. Obviously, it&#8217;s only worth playing if our expected increase in the total offsets the risk of losing it all. One sixth of the time, a one will be thrown in the next round, leading to a gain of 1; with equal probability we might gain 3,4,5, or 6. So five sixths of the time, we gain some amount. But the remaining sixth of the time, we&#8217;ll hit a two and lose everything; this can be thought of as a &#8216;gain&#8217; of minus N. So our expected gain by staying in is:</p>
<p align=center>(1/6)*1+(1/6)*(-N)+(1/6)*3+(1/6)*4+(1/6)*5+(1/6)*6 = (1/6)*(1+3+4+5+6-N) = (19-N)/6.</p>
<p>
Hence, for a play to be worthwhile, we need (19-N)/6 (and thus 19-N) to be positive. That is, we should be willing to gamble on a total of 19 or less, but a total of 20 or above should be banked.
</p>
<h3>Game Theory</h3>
<p>
However, as is always the case with expectation theory, this analysis depends on playing a large number of games and considering the total (or average) score across them. Playing just a few games tends to encourage an &#8216;all or nothing&#8217; approach wherein players are more interested in winning in absolute terms (that is, being best in class) than the score attained in the progress.
</p>
<p>
Of course, the ideal time to bank is just before the two is thrown, thus leaving you with the maximum possible score (anyone who sat out earlier has less; anyone who stayed in scores zero). The problem is that by banking a score in a given round with the hope of winning <em>that particular game</em>, you are effectively gambling on it being the next throw being a two, and you&#8217;ll only be right one sixth of the time. The remaining five sixths of the time, you&#8217;ll be wrong and the others get a higher score- in a group situation, any of them could now retire with a better score than you, and in a 1-on-1 duel your opponent can bank immediately to guarantee the win.
</p>
<p>
But then, if everyone adopts this brinksmanship strategy of always staying in, then eventually they will all go over the brink and score zero. Depending on how the payoffs are modelled (which is of course crucial!) this two-player version of a round of Greedy Pig can be interpreted in game-theoretic terms as follows. If neither player has an advantage over the other, either by ending the game with a tied score, or by proceeding to another round, then assign them a score of 1, unless both players tied with zero, in which case score 0. Else, if one player wins the game this round and the other loses, the winner scores 2 and the loser 0. Mixing in the probabilities of winning or losing depending on a play of stick or gamble, we get a payoff bimatrix:</p>
<p><center><br />
<table border=1>
<tr>
<td></td>
<td>Gamble</td>
<td>Stick</td>
</tr>
<tr>
<td>Gamble</td>
<td>5/6,5/6</td>
<td>10/6,2/6</td>
</tr>
<tr>
<td>Stick</td>
<td>2/6,10/6</td>
<td>1,1</td>
</tr>
</table>
<p></center></p>
<p>Notice that for player 1 the &#8216;gamble&#8217; row dominates the &#8217;stick&#8217; row (and equivalently for player 2 in columns), and thus each player must gamble despite the fact that they each prefer the outcome of both sticking (score 1) to both gambling (score 5/6). Thinking of sticking as cooperating, and gambling as defecting, this is precisely the famous prisoner&#8217;s dilemma!
</p>
<h2>Variations</h2>
<p>
More advanced versions of Greedy Pig, and the resulting changes in optimal strategy, can be explored. For instance, you could cap the number of rounds to be played. A pair of dice could be used, scoring by either adding the total of both or taking their difference; this also allows for a range of elimination conditions: ending the game on a double, when either die is a 2, for a particular total etc. You could also vary the frequency with which players choose to gamble, such as commiting them to two throws of the die each round. But, particularly for younger children, beware of making the game too complicated at the expense of fun!</p>
<hr />
<p>
<small>Based on my experiences running primary school workshops as part of the <em>Science Communcation in Action</em> scheme at the University of Edinburgh. Unfortunately, I do not know who deserves the original credit for this game.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/117/feed</wfw:commentRss>
		</item>
		<item>
		<title>Conference Season 08</title>
		<link>http://maths.straylight.co.uk/archives/115</link>
		<comments>http://maths.straylight.co.uk/archives/115#comments</comments>
		<pubDate>Sun, 30 Mar 2008 15:45:25 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Conferences]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=115</guid>
		<description><![CDATA[This May, I&#8217;ll be travelling all the way to Canada for ANTS-VIII, the Eighth Algorithmic Number Theory Symposium; I&#8217;m tacking a couple of days holiday on the front as well, so should be good!
]]></description>
			<content:encoded><![CDATA[<p>This May, I&#8217;ll be travelling all the way to Canada for <a href="http://ants.math.ucalgary.ca/">ANTS-VIII</a>, the Eighth Algorithmic Number Theory Symposium; I&#8217;m tacking a couple of days holiday on the front as well, so should be good!</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/115/feed</wfw:commentRss>
		</item>
		<item>
		<title>What I&#8217;m working on&#8230;</title>
		<link>http://maths.straylight.co.uk/archives/114</link>
		<comments>http://maths.straylight.co.uk/archives/114#comments</comments>
		<pubDate>Sun, 30 Mar 2008 15:42:13 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Graph Theory]]></category>

		<category><![CDATA[Number Theory]]></category>

		<category><![CDATA[PhD]]></category>

		<category><![CDATA[SAGE]]></category>

		<category><![CDATA[cyclotomic]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=114</guid>
		<description><![CDATA[Brief, fairly technical overview of what I've been working on these last few months.]]></description>
			<content:encoded><![CDATA[<p>So it&#8217;s been over two months since a post; more attentive readers will have noticed that there was one, but now there isn&#8217;t. I&#8217;ve moved away from thinking about cryptography to generalising some number/graph theoretic results of my supervisor, concerning matrices with constrained eigenvalues. However, this creates a problem: unless I &#8216;blog every up and down of the research process (which could be interesting, but would slow me down!) information on here becomes decreasingly accurate or relevant as I revise my thinking on the topic. Certainly it would be premature to present firm results at the moment.</p>
<p>But I can at least set the stage for more technically-minded readers (a friendlier explanation/illustration will hopefully follow once I truly understand all this!). Chris has characterised all symmetric integer matrices with the property that their eigenvalues are at most 2 in modulus; under a suitable transformation of their characteristic polynomials, these give cyclotomic polynomials and thus are referred to as cyclotomic matrices. Conveniently, any submatrix of a cyclotomic matrix is itself cyclotomic, so it suffices to find maximal examples. Although there are infinite families of these matrices, there are only a few &#8216;types&#8217; possible. </p>
<p>These types are best understood by considering not the matrix, but an associated graph, where values in the matrix determine the weights on edges and nodes of the graph. This introduces a notion of equivalence, since many matrices will correspond to the same graph or certain well-defined variations on it. Further, we can adjoin nodes and edges to the corresponding graph to try and &#8216;grow&#8217; towards maximal examples.</p>
<p>The motivation comes from finding polynomials of small Mahler measure- whilst a cyclotomic polynomial has measure 1, all others seem to be pushed away, with the smallest known value being 1.176&#8230; The question is how to generate small examples, and these matrices provide a way: by adjoining a single extra node to a maximal cyclotomic graph, a non-cyclotomic graph/matrix is obtained and thus a non-cyclotomic polynomial. The minimal graphs with this property (non-cyclotomic, but all subgraphs cyclotomic) often correspond to polynomials with some of the smallest known Mahler measures.</p>
<p>But some examples are not generated in this way, which is where I&#8217;ve stepped in. There is no reason to restrict attention to integer matrices, and I&#8217;ve established which imaginary quadratic extensions of the rationals give rise to rings of integers over which suitable matrices can be found. For a couple of fields, there are very few new (non rational-integer) cyclotomic matrices, and I have a complete description of them, but in others there are again infinite families as well as occasional examples that don&#8217;t generalise. </p>
<p>So I explore this behaviour by growing graphs/matrices, and try to spot patterns as they emerge from the fragments. I use the university&#8217;s parallel computing cluster <i>Eddie</i> for brute force work in SAGE, but such is the nature of the combinatorial explosion that even this doesn&#8217;t suffice without some mathematical insight along the way, as I try to refine my growing algorithms and capture equivalence as early as possible. I&#8217;m hopefully nearing the point where all examples fit into known families, at which point I&#8217;ll need to switch into serious mathematician mode and try and prove why this should be so. But for now I need to make sure that nothing unexpected tumbles out of each batch of calculations! </p>
<p>On a completely unrelated note, I&#8217;ve dragged <i>modulo errors</i> up to date with wordpress 2.5 and switched themes; please shout if you find I&#8217;ve broken something along the way.</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/114/feed</wfw:commentRss>
		</item>
		<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 - 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 - 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 - 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 - 2 * 6</p>
<p>Then (5) tells us that</p>
<p align=center>6 = 36 - 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 - 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 - 2 * (36 - 2 * 15) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by (5)<br />
<br />&nbsp;&nbsp;&nbsp;= 5 * 15 - 2 * 36 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(simplifying)<br />
<br />&nbsp;&nbsp;&nbsp;= 5 * (51 - 36) - 2 * 36 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by (4)<br />
<br />&nbsp;&nbsp;&nbsp;= 5 * 51 - 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 - 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 - 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>
		</item>
		<item>
		<title>Tate pairing computation in SAGE III</title>
		<link>http://maths.straylight.co.uk/archives/111</link>
		<comments>http://maths.straylight.co.uk/archives/111#comments</comments>
		<pubDate>Thu, 10 Jan 2008 13:49:00 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Algebraic Geometry]]></category>

		<category><![CDATA[Cryptology]]></category>

		<category><![CDATA[PhD]]></category>

		<category><![CDATA[SAGE]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=111</guid>
		<description><![CDATA[Optimised SAGE object for pairing computation.]]></description>
			<content:encoded><![CDATA[<p>The latest version of my <tt>ellnet</tt> class is <a href="http://www.maths.ed.ac.uk/~s0677951/ellnet2d_lowmem.spyx">ellnet2d_lowmem.spyx</a>. It combines all the tricks I know of:</p>
<ul>
<li>The use of precomputed inverses for all steps, and precomputed squares/products for each step, as described by Stange,</li>
<li>computation with a local vector to avoid overhead from function calls to keep the dictionary up-to-date,</li>
<li>mixed block lengths as described in the previous post,</li>
<li>and compilation to pyrex.</li>
</ul>
<p>Thus it&#8217;s the fastest implementation I currently have for finding Tate pairings in SAGE (about twice as fast as accessing Stange&#8217;s PARI script from SAGE). Attach it in the normal way;  example calculations are <a href="http://maths.straylight.co.uk/archives/104">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/111/feed</wfw:commentRss>
		</item>
		<item>
		<title>A variable block length algorithm for Elliptic Nets</title>
		<link>http://maths.straylight.co.uk/archives/110</link>
		<comments>http://maths.straylight.co.uk/archives/110#comments</comments>
		<pubDate>Wed, 09 Jan 2008 11:08:42 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

		<category><![CDATA[PhD]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=110</guid>
		<description><![CDATA[Describes generation of long blocks from short, and presents an algorithm to exploit the advantages of each for computation of terms in elliptic nets.]]></description>
			<content:encoded><![CDATA[<p><em>(updated 10/i/08)</em></p>
<p>In <a href="http://maths.straylight.co.uk/archives/102">an earlier post</a> I described Stange&#8217;s algorithm for efficiently finding terms in elliptic nets (with a view to pairing computation). I also made the observation that a shorter block structure could be used for doubling- but once employed, it was not possible to perform a double-and-add. This meant that unless the desired term had a higher power of two as a factor then savings would be minor.</p>
<p>However, for a cost it is possible to &#8216;upgrade&#8217; these short blocks to long blocks, since they contain enough information to recover the missing (k+4,0) term: </p>
<p align=center><img src="http://straylight.co.uk/cgi-bin/mimetex.cgi?(k+4,0)=\frac{(2,0)^2\times(k+3,0)\times(k+1,0)-(3,0)\times{(k+2,0)}^2}{(k,0)}"/></p>
<p>Better still, this only introduces an additional two multiplications and one inversion, since some of the terms feature in the precomputation (and assuming (2,0)<sup>2</sup> is computed once and stored for subsequent use):</p>
<p align=center><img src="http://straylight.co.uk/cgi-bin/mimetex.cgi?(k+4,0)=\frac{(2,0)^2B(k+2)-(3,0)A(k+2)}{(k,0)}"/></p>
<p>Thus, given a short block centred at k, we can obtain the short block centred at 2k+1 (that is, perform a <b>shortDoubleAdd</b>). The dependencies are as follows:</p>
<p><img src="http://aleph.straylight.co.uk/doubleAddShortFromShort.png"/></p>
<p>Notice that a <b>shortDoubleAdd</b> is more expensive than <b>DoubleAdd</b>, even though it gives a short rather than long block! Thus a purely short-block algorithm would perform worse than the standard algorithm for binary strings with a high Hamming weight, since for each Double-and-add an inversion is introduced in place of a multiplication. However, when the Hamming weight is low, then the occasional cost of an inversion is balanced by the savings accrued during short doublings. To exploit this, whilst guarding against too many inversions, we introduce an algorithm that uses a mixture of standard (‘long’) and short blocks. Since only a single inversion is required to switch to long blocks, doing so allows us to more efficiently compute long runs of 1s in the binary representation by spreading the cost across several DoubleAdds. </p>
<p>We consider the generation of long or short blocks with centre 2k (double) or 2k + 1 (double-and-add) from long or short blocks of centre k. The cheapest such operation is the generation of the short block with centre 2k from a short or long block with centre k, at a cost of 31 multiplications, 6 squarings and no inversions. Using this as a base line, each procedure introduces the following additional operations: </p>
<p><center><br />
<table>
<tr>
<th>Procedure</th>
<th> M</th>
<th> S</th>
<th> I </th>
</tr>
<tr>
<td>DoubleShortFromShort</td>
<td> 0</td>
<td> 0</td>
<td> 0 </td>
</tr>
<tr>
<td>DoubleLongFromShort</td>
<td> 6</td>
<td> 1</td>
<td> 1 </td>
</tr>
<tr>
<td>DoubleAddShortFromShort</td>
<td> 4</td>
<td> 1</td>
<td> 1 </td>
</tr>
<tr>
<td>DoubleAddLongFromShort</td>
<td> 6</td>
<td> 1</td>
<td> 1 </td>
</tr>
<tr>
<td>DoubleShortFromLong</td>
<td> 0</td>
<td> 0</td>
<td> 0 </td>
</tr>
<tr>
<td>DoubleLongFromLong</td>
<td> 4</td>
<td> 1</td>
<td> 0 </td>
</tr>
<tr>
<td>DoubleAddShortFromLong</td>
<td> 2</td>
<td> 1</td>
<td> 0 </td>
</tr>
<tr>
<td>DoubleAddLongFromLong</td>
<td> 4</td>
<td> 1</td>
<td> 0</td>
</tr>
</table>
<p></center></p>
<p>We adopt a windowing approach with two-bit windows: that is, bit b<sub>i</sub> informs whether we are to double or double-and-add, but b<sub>i-1</sub> is also examined to determine whether we should generate a long or short block. </p>
<ul>
<li>For <em>b<sub>i</sub>b<sub>i-1</sub>=00</em>, the short block approach clearly minimises the cost through these two bits.</li>
<li>For <em>b<sub>i</sub>b<sub>i-1</sub>=11</em>, one should stay with long blocks if these are already in use, to avoid inversion. If short, adopting the long block immediately will mean only a single inversion is required for the following run of 1s. </li>
<li>For <em>b<sub>i</sub>b<sub>i-1</sub>=10</em>, if short, then an inversion is required whether you go long or not: since being long is not necessary for the following double, we keep the multiplication count down by 2 by staying short. Similarly for long: no inversion is required to perform the Double-and-add for either length, but as the next operation will be a double, we go short to avoid the unnecessary 2 multiplications.</li>
<li>For <em>b<sub>i</sub>b<sub>i-1</sub>=01</em>, then it is always worth staying short if you already are, defering the inversion until it is strictly required for <em>b<sub>i-1</sub>=1</em> (possibly choosing to go long then based on <em>b<sub>i-2</sub></em>). If currently long, going short will save 4 multiplications and a squaring (approximately 5 multiplications).  Even if it proves necessary to upgrade to long for the very next bit, that will only cost around 3.6 multiplications (based on 1I=1.6M, see performance section). Thus even a single zero bit is worth going short for.</li>
</ul>
<p>Hence the approach is to always go to (or stay with, if already the case) short blocks, unless <em>b<sub>i</sub>b<sub>i-1</sub>=11</em> in which case one should go to (or stay with) long blocks. Thus a 2-bit window is sufficient to determine appropriate block length, leading to the following algorithm.</p>
<h3>2-Bit Window Algorithm</h3>
<p><b>Double-and-add Mixed-blocks Algorithm</b></p>
<p><b>INPUT</b>: Integer <em>n</em> and long block centred at 1.</p>
<p><b>OUTPUT</b>: Block centred at <em>n</em>.</p>
<ol>
<li> Compute binary digits <em>d<sub>i</sub></em> of <em>n</em> such that <em>n=(d<sub>k</sub>d<sub>k-1</sub>&#8230;d<sub>1</sub>)<sub>2</sub></em> with <em>d<sub>k</sub>=1</em>.</li>
<li> Set c=1 (centre), Set status=&#8217;long&#8217;</li>
<li> For i=k-1 down to 2 do:
<ul>
<li> If status=&#8217;long&#8217;
<ul>
<li> If d_i=1
<ul>
<li> If d_{i-1}=1 Compute block with centre 2c+1 via <b>DoubleAddLongFromLong</b>; Set c to 2c+1.</li>
<li> Else Compute short block with centre 2c+1 via  <b>DoubleAddShortFromLong</b>; Set c to 2c+1; Set status=&#8217;short&#8217;.</li>
</ul>
</li>
<li> Else <br /> Compute short block with centre 2c via <b>DoubleShortFromLong</b>; Set c to 2c; Set status=&#8217;short&#8217;.</li>
</ul>
</li>
<li> Else
<ul>
<li> If d_i=1
<ul>
<li>If d_{i-1}=1 Compute block with centre 2c+1 via <b>DoubleAddLongFromShort</b>; Set c to 2c+1; Set status=&#8217;long&#8217;.</li>
<li>Else Compute block with centre 2c+1 via <b>DoubleAddShortFromShort</b>; Set c to 2c+1.</li>
</ul>
</li>
<li> Else<br /> Compute short block with centre 2c via <b>DoubleShortFromShort</b>; Set c to 2c.</li>
</ul>
</li>
</ul>
</li>
<li>
<ul>
<li> If d_1=1
<ul>
<li>If status=&#8217;short&#8217; Compute block with centre 2c+1 via <b>DoubleAddShortFromShort</b>.</li>
<li>Else Compute block with centre 2c+1 via <b>DoubleAddShortFromLong</b>.</li>
</ul>
</li>
<li> Else Compute short block with centre 2c via <b>DoubleShortFromShort</b>.</li>
</ul>
</li>
<li> Return final block.</li>
</ol>
<h3>Performance</h3>
<p>As described before, the maximum possible gain is when n is a power of two, in which case the algorithm proceeds entirely by short doubles. In this case, there is a 12 percent reduction in the number of multiplications/squarings performed, with no inversions required.</p>
<p>Brute-force analysis of all possible 16-bit strings gives an average reduction of around 9 percent in the number of multiplications/squarings performed. Costing each inversion at 1.6 multiplications (based on average performance in SAGE for a 256-bit prime field), this leads to an average reduction of around 5 percent in the number of multiplications required for such strings. Testing several hundred 256-bit strings gives a similar figure.</p>
<p>Clearly, inversion is not viable if it will lead to a division-by-zero error. However, since the first zero along <em>(i,0)</em> will arise at <em>(m,0)</em>, no such error will occur when performing Tate pairing computations.</p>
<hr />
<p>A summary of this post and the earlier one on Stange&#8217;s algorithm is <a href="http://aleph.straylight.co.uk/ellnet.pdf">available</a> as pdf, containing (hopefully) clearer copies of the dependency graphs.</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/110/feed</wfw:commentRss>
		</item>
		<item>
		<title>Topics in Algebra, Analysis and Geometry.</title>
		<link>http://maths.straylight.co.uk/archives/109</link>
		<comments>http://maths.straylight.co.uk/archives/109#comments</comments>
		<pubDate>Sun, 06 Jan 2008 15:02:59 +0000</pubDate>
		<dc:creator>Graeme</dc:creator>
		
		<category><![CDATA[Analysis]]></category>

		<category><![CDATA[Conferences]]></category>

		<guid isPermaLink="false">http://maths.straylight.co.uk/?p=109</guid>
		<description><![CDATA[Details of this year's Utrecht Summerschool in Mathematics.]]></description>
			<content:encoded><![CDATA[<p>Last summer I spent two weeks at the very rewarding Utrecht Summerschool in Mathematics, so I thought I&#8217;d spread the word about this year&#8217;s course. It&#8217;s entitled <em>Topics in Algebra, Analysis and Geometry</em>; analysis is a new inclusion this year (in place of number theory) and will be the main emphasis. Abstracts for the three courses are not yet available, but the titles are  <em>QRT and elliptic surfaces, Distributions,</em>and  <em>Lie algebras and Integrable Systems.  </em></p>
<p>As last year, the course runs for two weeks in August, with a fairly intensive schedule of lectures and problem classes; when I attended, the students also spent a couple of days preparing a presentation for the final day. The pace is reasonably demanding, and the ideal audience would be students just finishing undergrad and about to enter study for an MSc or PhD (although I went after a year of postgrad study).</p>
<p>There are also social activities organised by both the department and the university - there are fifty courses scheduled across the summer in a wide range of subjects, so you&#8217;ll have the opportunity to mix with students from outside of mathematics too. Utrecht itself is a beautiful city - night canoeing through the canals is highly recommended! - and daytrips further afield are also offered.</p>
<p>For further details on the summerschool programme, see <a href="http://www.utrechtsummerschool.nl/">here</a>; specifics for the mathematics course are being made available on the <a href="http://www.math.uu.nl/Main/Master/Summerschool/">department pages</a>.  I also took <a href="http://gallery.straylight.co.uk/USMS">some photos</a> during my stay. Feel free to leave any questions you have in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://maths.straylight.co.uk/archives/109/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
