<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Lucky&#039;s Notes</title>
	<atom:link href="http://luckytoilet.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://luckytoilet.wordpress.com</link>
	<description>Notes on math, coding, and other stuff</description>
	<lastBuildDate>Sun, 19 May 2013 02:27:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='luckytoilet.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Lucky&#039;s Notes</title>
		<link>http://luckytoilet.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://luckytoilet.wordpress.com/osd.xml" title="Lucky&#039;s Notes" />
	<atom:link rel='hub' href='http://luckytoilet.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How to Write your own Minesweeper AI</title>
		<link>http://luckytoilet.wordpress.com/2012/12/23/2125/</link>
		<comments>http://luckytoilet.wordpress.com/2012/12/23/2125/#comments</comments>
		<pubDate>Sun, 23 Dec 2012 19:08:18 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[minesweeper]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2125</guid>
		<description><![CDATA[A while ago, I wrote a minesweeper AI. I intended to publish a writeup, but due to university and life and exams, I never got around to writing it. But having just finished my Fall term, I have some time to write a decent overview of what I did. Short 30 second video of the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2125&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>A while ago, I wrote a minesweeper AI. I intended to publish a writeup, but due to university and life and exams, I never got around to writing it. But having just finished my Fall term, I have some time to write a decent overview of what I did.</p>
<p>Short 30 second video of the AI in action here:</p>
<div class="embed-vimeo"><iframe src="http://player.vimeo.com/video/56183450" width="450" height="320" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>
<h3></h3>
<h3>How to Play Minesweeper</h3>
<p>If you’re an experienced minesweeper player, you can probably skip this section. Otherwise, I’ll just give a quick overview of some basic strategies that we can use to solve an easy minesweeper game.</p>
<p>We start with a 10&#215;10 Beginner’s grid, and click on a square in the middle:</p>
<p><a href="http://imgur.com/YBteZ"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/YBteZ.png" /></a></p>
<p>We can quickly identify some of the mines. When the number 1 has exactly one empty square around it, then we know there’s a mine there.</p>
<p>Let’s go ahead and mark the mines:</p>
<p><a href="http://imgur.com/7O3yj"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/7O3yj.png" /></a></p>
<p>Now the next strategy: if a 1 has a mine around it, then we know that all the other squares around the 1 <i>cannot</i> be mines.</p>
<p>So let’s go ahead and click on the squares that we know are not mines:</p>
<p><a href="http://imgur.com/17mM2"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/17mM2.png" /></a></p>
<p>Keep doing this. In this case, it turns out that these two simple strategies are enough to solve the Beginner’s grid:</p>
<p><a href="http://imgur.com/niNYH"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/niNYH.png" /></a></p>
<h3></h3>
<h3><b>Roadmap to an AI</b></h3>
<p>All this seems easy enough. Here’s what we’ll need to do:</p>
<ol>
<li><b>Read the board</b>. If we use a screenshot function, we can get a bitmap of all the pixels on the board. We just need to ‘read’ the numbers on the screen. Luckily for us, the numbers tend to have different colors: 1 is blue, 2 is green, 3 is red, and so on.</li>
<li><b>Compute</b>.  Run the calculations, figure out where the mines are. Enough said.</li>
<li><b>Click the board</b>. This step is easy. In Java, we can use the Robot class in the standard library to send mouse clicks to the screen.</li>
</ol>
<h3></h3>
<h3><b>Reading the Field</b></h3>
<p>There’s not a whole lot to this step, so I’m going to skim over it quickly.</p>
<p>At the beginning of the run, while we have a completely empty grid, we invoke a <b>calibration routine</b> – which takes a screenshot and looks for something that looks like a Minesweeper grid. Using heuristics, it determines the location of the grid, the size of a grid square, the dimensions of the board, and things like that.</p>
<p>Now that we know where the squares are, if we want to read a square, we crop a small section of the screenshot and pass it to a <b>detection routine</b>, which looks at a few pixels and figures out what’s in the square.</p>
<p>A few complications came up in the detection routine:</p>
<ul>
<li>The color for the number 1 is very close to the color of an unopened square: both are a dark-blue color. To separate them apart, I compared the ‘variance’ of the patch from the average color for the patch.</li>
<li>The color for 3 is identical to that for 7. Here, I used a simple edge-detection heuristic.</li>
</ul>
<h3></h3>
<h3><b>Straightforward Algorithm</b></h3>
<p>The trivially straightforward algorithm is actually good enough to solve the beginner and intermediate versions of the game a good percent of the time. Occasionally, if we’re lucky, it even manages to solve an advanced grid!</p>
<p>When humans play minesweeper, we compete for the <i>fastest</i> possible time to solve a grid of minesweeper. So it doesn’t matter if we lose 20 games for every game we win: only the wins count.</p>
<p>This is clearly a silly metric when we’re a robot that can click as fast as we want to. Instead, we’ll challenge ourselves with a more interesting metric:</p>
<p align="center"><b>Win as many games as possible.</b></p>
<p>Consider the following scenario:</p>
<p><a href="http://imgur.com/9zdIo"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/9zdIo.png" /></a></p>
<p>Using the straightforward method, we seem to be stuck.</p>
<p>Up until now, whenever we mark a square as having a mine or safe, we’ve only had to look at a single 3&#215;3 chunk at a time. This strategy fails us here: the trick is to employ a <b>multisquare</b> algorithm – look at multiple different squares at once.</p>
<p>From the lower 2, we know that one of the two circled squares has a mine, while the other doesn’t. We just don’t know which one has the mine:</p>
<p><a href="http://imgur.com/IOxCQ"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/IOxCQ.png" /></a></p>
<p>Although this doesn’t tell us anything right now, we can combine this information with the next 2: we can deduce that the two yellowed squares are empty:</p>
<p><a href="http://imgur.com/oTZ4o"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/oTZ4o.png" /></a></p>
<p>Let’s click them to be sure.</p>
<p><a href="http://imgur.com/hOwWz"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/hOwWz.png" /></a></p>
<p>And voilà. They’re empty. The rest of the puzzle can be solved easily, after we’ve made the deduction that those two squares were empty.</p>
<h3></h3>
<h3><b>The Tank Solver Algorithm</b></h3>
<p>It’s difficult to make the computer think deductively like we just did. But there is a way to achieve the same results, without deductive thinking.</p>
<p>The idea for the Tank algorithm is to <b>enumerate</b> <b>all possible</b> configurations of mines for a position, and see what’s in common between these configurations.</p>
<p>In the example, there are two possible configurations:</p>
<p><a href="http://imgur.com/y1MH4"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/y1MH4.png" /></a></p>
<p>You can check for yourself that no other configuration could work here. We’ve deduced that the one square with a cross <i>must</i> contain a mine, and the three squares shaded white below <i>must not</i> contain a mine:</p>
<p><a href="http://imgur.com/QvFFZ"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/QvFFZ.png" /></a></p>
<p>This works even better than human deduction!</p>
<p>We always try to apply the simple algorithm first, and only if that gets us stuck, then we bring in the Tank algorithm.</p>
<p>To implement the Tank algorithm, we first make a list of <b>border tiles</b>: all the tiles we aren’t sure about but have some partial information.</p>
<p>Now we have a list of <img src='http://s0.wp.com/latex.php?latex=T&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='T' title='T' class='latex' />  border tiles. If we’re considering every possible configuration, there are <img src='http://s0.wp.com/latex.php?latex=2%5ET&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='2^T' title='2^T' class='latex' /> of them. With backtracking, this number is cut down enough for this algorithm to be practical, but we can make one important optimization.</p>
<p>The optimization is <b>segregating</b> the border tiles into several disjoint regions:</p>
<p><a href="http://imgur.com/TlLM1"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/TlLM1.png" /></a></p>
<p>If you look carefully, whatever happens in the green area has no effect on what happens in the pink area – we can effectively consider them separately.</p>
<p>How much of a speedup do we get? In this case, the green region has 10 tiles, the pink has 7. Taken together, we need to search through <img src='http://s0.wp.com/latex.php?latex=2%5E%7B17%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='2^{17}' title='2^{17}' class='latex' /> combinations. With segregation, we only have <img src='http://s0.wp.com/latex.php?latex=2%5E%7B10%7D+%2B+2%5E7&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='2^{10} + 2^7' title='2^{10} + 2^7' class='latex' />: about a 100x speedup.</p>
<p>Practically, the optimization brought the algorithm from stopping for several seconds (sometimes minutes) to think, to giving the solution instantly.</p>
<h3><b>Probability: Making the Best Guess</b></h3>
<p>Are we done now? Can our AI dutifully solve any minesweeper grid we throw at it, with 100% accuracy?</p>
<p>Unsurprisingly, no:</p>
<p><a href="http://imgur.com/AUhXq"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/AUhXq.png" /></a></p>
<p>One of the two squares has a mine. It could be in either, with equal probability. No matter how cleverly we program our AI, we can’t do better than a 50-50 guess. Sorry.</p>
<p>The Tank solver fails here, no surprise. Under exactly what circumstances does the Tank algorithm fail?</p>
<p>If it failed, it means that for <b>every</b> border tile, there exists <b>some</b> configuration that this tile has a mine, and <b>some</b> configuration that this tile is empty. Otherwise the Tank solver would have ‘solved’ this particular tile.</p>
<p>In other words, if it failed, we are forced to guess. But before we put in a random guess, we can do some more analysis, just to make sure that we’re making the <b>best guess</b> we could make.</p>
<p>Try this. What do we do here:</p>
<p><a href="http://imgur.com/nFMPE"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/nFMPE.png" /></a></p>
<p>From the 3 in the middle, we know that three of them are mines, as marked. But marking mines doesn’t give us any <i>new information</i> about the grid: in order to gain information, we have to uncover some square. Out of the 13 possible squares to uncover, it’s not at all clear which one is the best.</p>
<p>The Tank solver finds 11 possible configurations. Here they are:</p>
<p><a href="http://imgur.com/sPnKm"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/sPnKm.png" /></a></p>
<p>Each of these 11 configurations should be equally likely to be the actual position – so we can assign each square a <b>probability</b> that it contains a mine, by counting how many (of the 11) configurations does it contain a mine:</p>
<p><a href="http://imgur.com/41QOe"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/41QOe.png" /></a></p>
<p>Our best guess would be to click on any of the squares marked ‘2’: in all these cases, we stand an 82% chance of being correct!</p>
<h3><b>Two Endgame Tactics</b></h3>
<p>Up until now, we haven’t utilized this guy:</p>
<p><a href="http://imgur.com/Atrcz"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/Atrcz.png" /></a></p>
<p>The mine counter. Normally, this information isn’t of too much use for us, but in many endgame cases it saves us from guessing.</p>
<p>For example:</p>
<p><a href="http://imgur.com/FeakY"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/FeakY.png" /></a></p>
<p>Here, we would have a 50-50 guess, where two possibilities are equally likely.</p>
<p>But what if the mine counter reads 1? The 2-mine configuration is eliminated, leaving just one possibility left. We can safely open the three tiles on the perimeter.</p>
<p>Now on to our final tactic.</p>
<p>So far we have assumed that we only have information on a tile if there’s a number next to it. For the most part, that’s true. If you pick a tile in some distant unexplored corner, who knows if there’s a mine there?</p>
<p>Exceptions can arise in the endgame:</p>
<p><a href="http://imgur.com/xAQaZ"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/xAQaZ.png" /></a></p>
<p>The mine counter reads 2. Each of the two circled regions gives us a 50-50 chance – and the Tank algorithm stops here.</p>
<p>Of course, the middle square is safe!</p>
<p>To modify the algorithm to solve these cases, when there aren’t that many tiles left, do the recursion on <i>all</i> the remaining tiles, not just the border tiles.</p>
<p>The two tricks here have the shared property that they rely on the mine counter. Reading the mine counter, however, is a non-trivial task that I won’t attempt; instead, the program is coded in with the total number of mines in the grid, and keeps track of the mines left internally.</p>
<h3><b>Conclusion, Results, and Source Code</b></h3>
<p>At this point, I’m convinced that there isn’t much more we could do to improve the win rate. The algorithm uses every last piece of information available, and only fails when it’s provably certain that guessing is needed.</p>
<p>How well does it work? We’ll use the success rate for the advanced grid as a benchmark.</p>
<ul>
<li>The naïve algorithm could not solve it, unless we get very lucky.</li>
<li>Tank Solver with probabilistic guessing solves it about 20% of the time.</li>
<li>Adding the two endgame tricks bumps it up to a 50% success rate.</li>
</ul>
<p>Here’s proof:</p>
<p><a href="http://imgur.com/h1L95"><img class="aligncenter" title="Hosted by imgur.com" alt="" src="http://i.imgur.com/h1L95.png" /></a></p>
<p>I’m done for now; the source code for the project is available on Github if anyone is inclined to look at it / tinker with it:</p>
<p align="center"><a href="https://github.com/luckytoilet/MSolver">https://github.com/luckytoilet/MSolver</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2125&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2012/12/23/2125/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/YBteZ.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/7O3yj.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/17mM2.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/niNYH.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/9zdIo.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/IOxCQ.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/oTZ4o.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/hOwWz.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/y1MH4.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/QvFFZ.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/TlLM1.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/AUhXq.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/nFMPE.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/sPnKm.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/41QOe.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/Atrcz.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/FeakY.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/xAQaZ.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/h1L95.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Notes on the partial fraction decomposition: why it always works</title>
		<link>http://luckytoilet.wordpress.com/2012/06/13/notes-on-the-partial-fraction-decomposition-why-it-always-works/</link>
		<comments>http://luckytoilet.wordpress.com/2012/06/13/notes-on-the-partial-fraction-decomposition-why-it-always-works/#comments</comments>
		<pubDate>Thu, 14 Jun 2012 03:52:33 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[algebra]]></category>
		<category><![CDATA[calculus]]></category>
		<category><![CDATA[complex numbers]]></category>
		<category><![CDATA[theorem proof]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2096</guid>
		<description><![CDATA[If you&#8217;ve taken any intro to Calculus class, you&#8217;re probably familiar with partial fraction decomposition. In case you&#8217;re not, the idea is that you&#8217;re given some rational function with an awful denominator that you want to integrate, like: And you break it up into smaller, simpler fractions: This is the idea. If we get into [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2096&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;ve taken any intro to Calculus class, you&#8217;re probably familiar with partial fraction decomposition.</p>
<p>In case you&#8217;re not, the idea is that you&#8217;re given some rational function with an awful denominator that you want to integrate, like:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7B4x-2%7D%7B%28x-2%29%28x%2B4%29%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{4x-2}{(x-2)(x+4)} ' title='&#92;frac{4x-2}{(x-2)(x+4)} ' class='latex' /></p>
<p style="text-align:left;">And you break it up into smaller, simpler fractions:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7Bx-2%7D+%2B%5Cfrac%7B3%7D%7Bx%2B4%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{1}{x-2} +&#92;frac{3}{x+4} ' title='&#92;frac{1}{x-2} +&#92;frac{3}{x+4} ' class='latex' /></p>
<p style="text-align:left;">This is the idea. If we get into the details, it gets fairly ugly &#8212; in a typical calculus textbook, you&#8217;ll find a plethora of rules regarding what to do in all sorts of cases: what to do when there are repeated linear factors, quadratic factors, repeated quadratic factors, and so on.</p>
<p style="text-align:left;">Since the textbooks generously cover this for us, we&#8217;ll assume that we know what to do with a rational polynomial with some polynomial as the numerator, and some number of linear or quadratic factors in the denominator. We can do partial fraction decomposition on this. If we like, we could integrate it too. I&#8217;m talking about anything of this form:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7BP%28x%29%7D%7B%28%28ax%2Bb%29%28cx%2Bd%29+%5Ccdots%29%28%28ex%5E2%2Bfx%2Bg%29%28hx%5E2%2Bix%2Bj%29+%5Ccdots%29%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{P(x)}{((ax+b)(cx+d) &#92;cdots)((ex^2+fx+g)(hx^2+ix+j) &#92;cdots)} ' title='&#92;frac{P(x)}{((ax+b)(cx+d) &#92;cdots)((ex^2+fx+g)(hx^2+ix+j) &#92;cdots)} ' class='latex' /></p>
<p style="text-align:left;">Although we won&#8217;t prove this, this seems fairly believable. We&#8217;ll assume that once we get a fraction into this form, we&#8217;re done and we can let existing partial fraction methods take care of the rest.</p>
<h3 style="text-align:left;">Can Partial Fractions Fail?</h3>
<p>What if we have a polynomial greater than a quadratic in the denominator? So let&#8217;s say:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7Bx%5E3%2B1%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{1}{x^3+1} ' title='&#92;frac{1}{x^3+1} ' class='latex' /></p>
<p>Fortunately, here the denominator can be factored, giving us a form we can deal with:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B%28x%2B1%29%28x%5E2-x%2B1%29%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{1}{(x+1)(x^2-x+1)} ' title='&#92;frac{1}{(x+1)(x^2-x+1)} ' class='latex' /></p>
<p style="text-align:left;">But we were lucky that time. After all, not all polynomials can be factored, right? What if we have this:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7Bx%5E3%2B5%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{1}{x^3+5} ' title='&#92;frac{1}{x^3+5} ' class='latex' /></p>
<p style="text-align:left;">We can&#8217;t factor this. What can we do?</p>
<p style="text-align:left;">It turns out that this isn&#8217;t a huge problem. We never required the coefficients of the factors to be integers! Although the factorization is awkward, it can still be factored:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7B1%7D%7B%28x+%2B+5%5E%7B1%2F3%7D%29%28x%5E2-5%5E%7B1%2F3%7Dx%2B5%5E%7B2%2F3%7D%29%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{1}{(x + 5^{1/3})(x^2-5^{1/3}x+5^{2/3})} ' title='&#92;frac{1}{(x + 5^{1/3})(x^2-5^{1/3}x+5^{2/3})} ' class='latex' /></p>
<p style="text-align:left;">Other than making the next step somewhat algebraically tedious, this decomposition is perfectly valid. The coefficients need not be integers, or even be expressed with radicals. As long as every coefficient is real, partial fraction decomposition will work fine.</p>
<h3 style="text-align:left;">Universality of Partial Fractions</h3>
<p>The logical next question would be, can all radical functions be written in the previous partial fraction decomposition-suitable form? Looking through my calculus textbooks, none seemed to provide a proof of this &#8212; and failing to find a proof on the internet, I&#8217;ll give the proof here.</p>
<p>We need to prove that any polynomial that might appear in the denominator of a rational function, say <img src='http://s0.wp.com/latex.php?latex=Q%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='Q(x)' title='Q(x)' class='latex' />, can be broken down into linear or quadratic factors with real coefficients.</p>
<p>In order to prove this, we&#8217;ll need the following two theorems:</p>
<ul>
<li><strong>Fundamental Theorem of Algebra</strong> &#8212; any polynomial of degree n can be written as a product of n linear complex factors: <img src='http://s0.wp.com/latex.php?latex=Q%28x%29+%3D+%28x-z_1%29+%28x-z_2%29+%5Ccdots+%28x-z_n%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='Q(x) = (x-z_1) (x-z_2) &#92;cdots (x-z_n)' title='Q(x) = (x-z_1) (x-z_2) &#92;cdots (x-z_n)' class='latex' /></li>
<li><a href="http://en.wikipedia.org/wiki/Complex_conjugate_root_theorem"><strong>Complex Conjugate Root Theorem</strong></a> &#8212; if some complex number <img src='http://s0.wp.com/latex.php?latex=a+%2B+bi&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a + bi' title='a + bi' class='latex' /> is a root of some polynomial with real coefficients, then its conjugate <img src='http://s0.wp.com/latex.php?latex=a-bi&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a-bi' title='a-bi' class='latex' /> is also a root.</li>
</ul>
<p>Starting with the denominator polynomial <img src='http://s0.wp.com/latex.php?latex=Q%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='Q(x)' title='Q(x)' class='latex' />, we break it down using the Fundamental Theorem of Algebra into complex factors. Of these factors, some will be real, while others will be complex.</p>
<p>Consider the complex factors of <img src='http://s0.wp.com/latex.php?latex=Q%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='Q(x)' title='Q(x)' class='latex' />. By the complex conjugate root theorem, for every complex factor we have, its conjugate is also a factor. Hence we can take all of the complex factors and pair them up with their conjugates. Why? If we multiply a complex root by its complex conjugate root: <img src='http://s0.wp.com/latex.php?latex=%28x-z%29%28x-%5Cbar%7Bz%7D%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='(x-z)(x-&#92;bar{z})' title='(x-z)(x-&#92;bar{z})' class='latex' /> &#8212; we always end up with a quadratic with real coefficients. (you can check this for yourself if you want)</p>
<p>Before, we were left with real linear factors and pairs of complex factors. The pairs of complex factors multiply to form quadratic polynomials with real coefficients, so we are done.</p>
<p>At least in theory &#8212; partial fraction decomposition always works. The problem is just that we relied on the Fundamental Theorem of Algebra to hand us the roots of our polynomial. Often, these roots aren&#8217;t simple integers or radicals &#8212; often they can&#8217;t really be expressed exactly at all. So we should say &#8212; partial fraction decomposition always works, if you&#8217;re fine with having infinitely long decimals in the decomposed product.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2096/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2096/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2096&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2012/06/13/notes-on-the-partial-fraction-decomposition-why-it-always-works/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>
	</item>
		<item>
		<title>Minimum quadrilateral inscribed in a square</title>
		<link>http://luckytoilet.wordpress.com/2012/05/06/minimum-quadrilateral-inscribed-in-a-square/</link>
		<comments>http://luckytoilet.wordpress.com/2012/05/06/minimum-quadrilateral-inscribed-in-a-square/#comments</comments>
		<pubDate>Sun, 06 May 2012 23:18:38 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[quadrilateral]]></category>
		<category><![CDATA[square]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2081</guid>
		<description><![CDATA[A problem that I&#8217;ve seen lately reduces to the following problem: We have a square, and we put a point on each side of the square. Then we connect the four points to create a quadrilateral. How can we make this quadrilateral have the smallest possible perimeter? Intuitively, you may believe that this natural, obvious [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2081&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>A problem that I&#8217;ve seen lately reduces to the following problem:</p>
<p>We have a square, and we put a point on each side of the square. Then we connect the four points to create a quadrilateral. How can we make this quadrilateral have the smallest possible perimeter?</p>
<p><a href="http://imgur.com/uD33a"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/uD33a.png" alt="" /></a></p>
<p>Intuitively, you may believe that this natural, obvious configuration should produce the least perimeter:</p>
<p><a href="http://imgur.com/k86QK"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/k86QK.png" alt="" /></a></p>
<h3>Attempt with Calculus</h3>
<p>How can we prove that this indeed gives us the smallest possible perimeter?</p>
<p>A first attempt might be to give variables to the side lengths, and somehow find the minimum perimeter using algebra and calculus tools. So there are four independent points &#8212; let&#8217;s parameterize them with four variables, and assume the side length of the square is 1:</p>
<p><a href="http://imgur.com/TWAuX"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/TWAuX.png" alt="" /></a></p>
<p>Then we want to minimize this expression:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7Ba%5E2%2B%281-d%29%5E2%7D+%2B+%5Csqrt%7Bb%5E2%2B%281-a%29%5E2%7D%2B+%5Csqrt%7Bc%5E2%2B%281-b%29%5E2%7D%2B+%5Csqrt%7Bd%5E2%2B%281-c%29%5E2%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=-2' alt='&#92;sqrt{a^2+(1-d)^2} + &#92;sqrt{b^2+(1-a)^2}+ &#92;sqrt{c^2+(1-b)^2}+ &#92;sqrt{d^2+(1-c)^2} ' title='&#92;sqrt{a^2+(1-d)^2} + &#92;sqrt{b^2+(1-a)^2}+ &#92;sqrt{c^2+(1-b)^2}+ &#92;sqrt{d^2+(1-c)^2} ' class='latex' /></p>
<p style="text-align:left;">At this point, it isn&#8217;t clear how to proceed &#8212; there doesn&#8217;t seem to be any way to minimize this expression of four variables.</p>
<h3 style="text-align:left;">Proof by Net</h3>
<p style="text-align:left;">We&#8217;ll have to try something different. It&#8217;s hard to make sense of anything when there are four independent variables. Instead, if we expand things out a bit, things start to become more manageable:</p>
<p><a href="http://imgur.com/o00sK"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/o00sK.png" alt="" /></a></p>
<p>What we did was reflect the square three times, and each time the square is reflected, the inscribed quadrilateral goes with it. By taking only the relevant parts of the quadrilateral, we get the green path.</p>
<p>Now we might have a solution. If we had a different green path, can we reverse the steps and get the original quadrilateral back? Basically, the following requirements have to be met:</p>
<ul>
<li>The path has to cross all three of the internal lines BC, BA, and DA.</li>
<li>The path&#8217;s position on the bottom-most line, DC must be the same when reflected onto the top-most line DC.</li>
</ul>
<p>With these requirements in mind, the shortest green path that satisfies these requirements is a straight line connecting a point on the bottom left to its reflected point on the top right:</p>
<p><a href="http://imgur.com/rIjht"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/rIjht.png" alt="" /></a></p>
<p>Our intuition at the start was well-founded.</p>
<p>Now notice that this isn&#8217;t the only possible shortest path. If we move the entire green line to the left or right, we get a different path of the same length!</p>
<p>For instance, the degenerate &#8216;quadrilateral&#8217; formed by connecting two opposite corners has the same perimeter as the one we get by connecting the midpoints. Neat, huh?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2081/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2081/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2081&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2012/05/06/minimum-quadrilateral-inscribed-in-a-square/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/uD33a.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/k86QK.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/TWAuX.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/o00sK.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/rIjht.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>
	</item>
		<item>
		<title>A CMOQR Problem and why not to Trust Brute Force</title>
		<link>http://luckytoilet.wordpress.com/2012/03/06/a-cmoqr-problem-and-why-not-to-trust-brute-force/</link>
		<comments>http://luckytoilet.wordpress.com/2012/03/06/a-cmoqr-problem-and-why-not-to-trust-brute-force/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 20:42:15 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[cmoqr]]></category>
		<category><![CDATA[combinatorics]]></category>
		<category><![CDATA[solved problem]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2064</guid>
		<description><![CDATA[Recently I was invited to compete in the CMOQR &#8211; a qualifier contest for the Canadian Math Olympiad. The contest consisted of eight problems, and contestants were allowed about a week&#8217;s time to submit written solutions via email. After a few days, I was able to solve all of the problems except one &#8212; the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2064&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Recently I was invited to compete in the <a href="http://math.ca/Competitions/REP/2012CMOQR.pdf">CMOQR </a>&#8211; a qualifier contest for the Canadian Math Olympiad. The contest consisted of eight problems, and contestants were allowed about a week&#8217;s time to submit written solutions via email.</p>
<p>After a few days, I was able to solve all of the problems except one &#8212; the second part of the seventh problem:</p>
<blockquote><p>Seven people participate in a tournament, in which each pair of players play one game, and one player is declared the winner and the other the loser. A triplet ABC is considered <em>cyclic</em> if A beats B, B beats C, and C beats A.</p>
<p>Can you always separate the seven players into two rooms, so that neither room contains a cyclic triplet?</p></blockquote>
<p>(Note: the first half of the problem asked the same question for six people &#8212; and it&#8217;s not too difficult to prove that no matter what, we can put them into two rooms so that neither the first nor the second room contains a cyclic triplet.)</p>
<p>But what happens when we add another person? Can we still put four people in one room, and three people in the other, so that neither rooms contain a cyclic triplet?</p>
<p>There are two possibilities here:</p>
<ul>
<li><strong>One, it&#8217;s always possible</strong>. No matter what combinations of wins and losses have occurred, we can always separate them into two rooms in such a way. To prove this, we&#8217;ll need to systematically consider all possible combinations, and one by one, verify that the statement is possible for each of the cases.</li>
<li><strong>Two, it&#8217;s not always possible</strong>. Then there is some counterexample &#8212; some combination of wins and losses so that no matter how we separate them, one of the rooms has a cyclic triplet. This is easier to prove: provided that we have the counterexample, we just have to verify that indeed, this case is a counterexample to the statement.</li>
</ul>
<p>But there&#8217;s a problem. Which of the cases does the solution fall into? That is, should we look for a quick solution by counterexample, or look for some mathematical invariant that no counterexample can exist?</p>
<h3>Brute Force?</h3>
<p>It would be really helpful if we knew the counterexample, or knew for sure what the counterexample was. What if we wrote a computer program to check all the cases? After all, there are only 7 people in the problem, and 7 choose 2 or 21 games played. Then since each game is either won by one player or the other, there are only 2^21 combinations overall (although that does count some duplicates). And 2^21 is slightly over two million cases to check &#8212; completely within the bounds of brute force.</p>
<p>So I coded up a possibility-checker. Generate all 2^21 possible arrangements, then for each one, check all possible ways to separate them into two rooms. If it turns out that no matter how we arrange them, a cyclic triplet persists, then display the counterexample. Simple.</p>
<p>I ran the program. It quickly cycled through every possible arrangement, three seconds later exiting without producing a counterexample.</p>
<p>Alright. So there&#8217;s no counterexample. I would have to find some nice mathematical invariant, showing that no matter what, there is always some way to group the players so that neither room has a cyclic triplet.</p>
<p>But no such invariant came. I tried several things, but in each attempt couldn&#8217;t quite show that the statement held for every case. I knew that there was no counterexample, but I couldn&#8217;t prove it. But why? There must be some tricky way to show that no counterexample existed; whatever it was, I couldn&#8217;t find it.</p>
<h3>Brute Force poorly implemented</h3>
<p>Reluctantly, as the deadline came and passed, I submitted my set of solutions without solving the problem. When the solutions came out a week later, the solution to this problem did not contain any tricky way to disprove the counterexample. Instead, what I found was this:</p>
<blockquote><p>Let <img src='http://s0.wp.com/latex.php?latex=A_0+%5Cldots+A_6&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A_0 &#92;ldots A_6' title='A_0 &#92;ldots A_6' class='latex' /> be seven players. Let <img src='http://s0.wp.com/latex.php?latex=A_i&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A_i' title='A_i' class='latex' /> beat <img src='http://s0.wp.com/latex.php?latex=A_j&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A_j' title='A_j' class='latex' /> when the difference <img src='http://s0.wp.com/latex.php?latex=i-j+%5Cequiv+1%2C2%2C4+%5Cmod+7&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='i-j &#92;equiv 1,2,4 &#92;mod 7' title='i-j &#92;equiv 1,2,4 &#92;mod 7' class='latex' />.</p></blockquote>
<p>Huh? A counterexample, really? Let&#8217;s look at it.</p>
<p>Everything is symmetric &#8212; we can &#8216;cycle&#8217; the players around without changing anything. Also, if we take four players, two of them are consecutive. Let them be <img src='http://s0.wp.com/latex.php?latex=A_0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A_0' title='A_0' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=A_1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A_1' title='A_1' class='latex' />.</p>
<p>At this point everything falls into place: in any subset of four players, three of them are cyclic.</p>
<p>But wait &#8230; my program had not found any counterexamples! And right here is a counterexample! The culprit was obvious (the reader may have foreseen this by now) &#8212; of course, there had to be a problem with my program.</p>
<p>Running my code through a debugger, I found a logic error in the routine converting binary numbers to array configurations, meaning that not all possible configurations were tried. As a result, the counterexample slipped through the hole.</p>
<p>After fixing the code, the program found not one, but a total of 7520 (although not necessarily distinct) counterexamples. Most of them had no elegant structure, but the solution&#8217;s configuration was among them.</p>
<p>For the interested, <a href="http://ideone.com/HCV6e">here is the fixed code</a>.</p>
<h3>When to Start Over?</h3>
<p>It is true that the program could have been better written, better debugged. But how could you know whether a counterexample existed and your program didn&#8217;t find it, or if no counterexample existed at all?</p>
<p>In hindsight, it seems that writing the brute force program made me worse off than if I hadn&#8217;t written it at all. After the program ran without finding a single counterexample, I was confident that no counterexample existed, and set out about proving that, instead of looking for counterexamples or symmetry.</p>
<p>When you are stuck on such a math problem &#8212; that is, after making a bit of progress you get stuck &#8212; it might be profitable to start over. More often than I would like, I prove a series of neat things, without being able to prove the desired result. Then a look at the solutions manual reveals that a very short solution &#8212; one or two steps &#8212; lay in the opposite direction.</p>
<p>I&#8217;ll put an end to my philosophical musings of the day. Fortunately, the cutoff for the CMOQR was low enough that even without solving every single problem, I was still able to meet the cutoff.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2064/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2064/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2064&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2012/03/06/a-cmoqr-problem-and-why-not-to-trust-brute-force/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>
	</item>
		<item>
		<title>A trivial inequality, and how to express its solution in the most cryptic way imaginable</title>
		<link>http://luckytoilet.wordpress.com/2012/02/19/a-simple-inequality-and-how/</link>
		<comments>http://luckytoilet.wordpress.com/2012/02/19/a-simple-inequality-and-how/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 04:01:41 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[inequalities]]></category>
		<category><![CDATA[olympiad]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2049</guid>
		<description><![CDATA[Solutions to olympiad problems are seldom written with clarity in mind &#8212; just look at forum posts in the Art of Problem Solving. The author makes jumps and skips a bunch of steps, expecting the reader to fill in the gaps. Usually this is not much of a problem &#8212; the missing steps become obvious [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2049&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Solutions to olympiad problems are seldom written with clarity in mind &#8212; just look at forum posts in the Art of Problem Solving. The author makes jumps and skips a bunch of steps, expecting the reader to fill in the gaps.</p>
<p>Usually this is not much of a problem &#8212; the missing steps become obvious when you sit down and think about what&#8217;s going on with a pencil and some paper. But sometimes, this is not the case.</p>
<h3>The problem</h3>
<p>One of the worst examples I&#8217;ve seen comes in the book <em><a href="http://www.amazon.com/Inequalities-Mathematical-Radmila-Bulajich-Manfrino/dp/3034600496/">Inequalities, A Mathematical Olympiad Approach</a></em>. By all means, this is an excellent book. Anyways, here&#8217;s one of its easier problems &#8212; and you&#8217;re expected to solve it using the triangle inequality:</p>
<blockquote><p>Prove that for all real numbers a and b,</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%7C%7Ca%7C-%7Cb%7C%7C+%5Cleq+%7Ca-b%7C+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='||a|-|b|| &#92;leq |a-b| ' title='||a|-|b|| &#92;leq |a-b| ' class='latex' /></p>
</blockquote>
<h3 style="text-align:left;">Attempt 1: Intuitive solution</h3>
<p style="text-align:left;">It isn&#8217;t clear how the triangle inequality fits. If I weren&#8217;t required to use the triangle inequality, I might be tempted to do an intuitive, case-by-case argument.</p>
<p style="text-align:left;">Let&#8217;s visualize the absolute value of <img src='http://s0.wp.com/latex.php?latex=a-b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a-b' title='a-b' class='latex' /> as the difference between the two numbers on a number line. Now we compare this distance <img src='http://s0.wp.com/latex.php?latex=%7Ca-b%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|a-b|' title='|a-b|' class='latex' /> with the distance after you take the absolute value of both of them, <img src='http://s0.wp.com/latex.php?latex=%7C%7Ca%7C-%7Cb%7C%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='||a|-|b||' title='||a|-|b||' class='latex' />. If one of the numbers is positive and the other negative, we clearly have a smaller distance if we &#8216;reflect&#8217; the negative one over. Of course, if they&#8217;re both positive, or they&#8217;re both negative, then nothing happens and the distances remain equal.</p>
<p style="text-align:left;">There, a simple, fairly clear argument. Now let&#8217;s see what the book says.</p>
<h3 style="text-align:left;">The book&#8217;s solution</h3>
<p>Flip to the end of the book, and find</p>
<blockquote><p>Consider <img src='http://s0.wp.com/latex.php?latex=%7Ca%7C%3D%7Ca-b%2Bb%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|a|=|a-b+b|' title='|a|=|a-b+b|' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%7Cb%7C%3D%7Cb-a%2Ba%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|b|=|b-a+a|' title='|b|=|b-a+a|' class='latex' />, and apply the triangle inequality.</p></blockquote>
<p>Huh. Perhaps if you are better versed than I am in the art of solving inequalities, you&#8217;ll understand what this solution is saying. But I, of course, had no idea.</p>
<p>Maybe try the substitution they suggest. I only see one place to possibly substitute <img src='http://s0.wp.com/latex.php?latex=%7Ca%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|a|' title='|a|' class='latex' /> for anything &#8212; and substituting gives <img src='http://s0.wp.com/latex.php?latex=%7C%7Ca-b%2Bb%7C-%7Cb-a%2Ba%7C%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='||a-b+b|-|b-a+a||' title='||a-b+b|-|b-a+a||' class='latex' />. Now what? I don&#8217;t think I did it right &#8212; this doesn&#8217;t make any sense.</p>
<p>To be fair, I cheated a little bit in the first attempt: I didn&#8217;t use the triangle inequality. Fair enough &#8212; let&#8217;s solve it with the triangle inequality then and come back to see if the solution makes any sense now.</p>
<h3>Attempt 2: Triangle inequality solution</h3>
<p>A standard corollary to the triangle inequality of two variables is the following:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%7Ca%7C-%7Cb%7C+%5Cleq+%7Ca-b%7C+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='|a|-|b| &#92;leq |a-b| ' title='|a|-|b| &#92;leq |a-b| ' class='latex' /></p>
<p style="text-align:left;">Combine this with the two variables switched around:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%7Cb%7C-%7Ca%7C+%5Cleq+%7Cb-a%7C+%3D+%7Ca-b%7C+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='|b|-|a| &#92;leq |b-a| = |a-b| ' title='|b|-|a| &#92;leq |b-a| = |a-b| ' class='latex' /></p>
<p style="text-align:left;">Combine the two inequalities and we get the desired</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%7C%7Ca%7C-%7Cb%7C%7C+%5Cleq+%7Ca-b%7C+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='||a|-|b|| &#92;leq |a-b| ' title='||a|-|b|| &#92;leq |a-b| ' class='latex' /></p>
<p style="text-align:left;">Now let&#8217;s look at the solution again. Does it make sense? No, at no point here  did we do any <img src='http://s0.wp.com/latex.php?latex=%7Ca-b%2Bb%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|a-b+b|' title='|a-b+b|' class='latex' /> substitution. Clearly the authors were thinking of a different solution that happened to also use the triangle inequality. Whatever it was, I had no idea what the solution meant.</p>
<h3 style="text-align:left;">The book&#8217;s solution, decrypted</h3>
<p>Out of ideas and hardly apt to let the issue rest, I consulted help online at a math forum. And look &#8212; it turns out that <em>my solution was without a doubt the same solution</em> as the book&#8217;s intended solution!</p>
<p>What the author meant was this: considering that <img src='http://s0.wp.com/latex.php?latex=%7Ca%7C+%3D+%7Ca-b%2Bb%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|a| = |a-b+b|' title='|a| = |a-b+b|' class='latex' />, we have <img src='http://s0.wp.com/latex.php?latex=%7Ca%7C+%5Cleq+%7Ca-b%7C%2B%7Cb%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|a| &#92;leq |a-b|+|b|' title='|a| &#92;leq |a-b|+|b|' class='latex' /> from the triangle inequality. Then, moving the <img src='http://s0.wp.com/latex.php?latex=%7Cb%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|b|' title='|b|' class='latex' /> over we get <img src='http://s0.wp.com/latex.php?latex=%7Ca%7C-%7Cb%7C+%5Cleq+%7Ca-b%7C&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|a|-|b| &#92;leq |a-b|' title='|a|-|b| &#92;leq |a-b|' class='latex' />.</p>
<p>After that, the steps I took above are left to the reader.</p>
<p>Perhaps I&#8217;m a bit thick-headed, but your solution can&#8217;t <em>possibly</em> be very clear if a reader has the exact <em>same</em> solution yet can&#8217;t even <em>recognize</em> your solution as the same solution. Come to think of it, if I couldn&#8217;t even recognize the solution, what chance is there of anybody being able to <em>follow</em> the solution &#8212; especially if they&#8217;re new to inequalities?</p>
<p>Almost <em>every</em> one of the one-sentence phrasings of this solution I could think of would be clearer and less puzzling than the solution the book gives me.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2049/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2049/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2049&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2012/02/19/a-simple-inequality-and-how/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>
	</item>
		<item>
		<title>Fix for Digsby&#8217;s Facebook authentication error and broken Facebook support</title>
		<link>http://luckytoilet.wordpress.com/2012/01/26/fix-for-digsbys-broken-facebook-support/</link>
		<comments>http://luckytoilet.wordpress.com/2012/01/26/fix-for-digsbys-broken-facebook-support/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 19:01:32 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[digsby]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2042</guid>
		<description><![CDATA[To all Digsby users (ignore this post if you don&#8217;t use Digsby): If you use Digsby with Facebook, you might have noticed that things behave strangely &#8212; the program pops up a window looking like this when it tries to connect to Facebook: Then after you give it your credentials, Digsby still thinks you&#8217;re not [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2042&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>To all <a href="http://www.digsby.com/">Digsby </a>users (ignore this post if you don&#8217;t use Digsby):</p>
<p>If you use Digsby with Facebook, you might have noticed that things behave strangely &#8212; the program pops up a window looking like this when it tries to connect to Facebook:</p>
<p><a href="http://imgur.com/QrmvP"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/QrmvP.png" alt="" /></a></p>
<p>Then after you give it your credentials, Digsby still thinks you&#8217;re not logged in, and so on.</p>
<p>If you found this page via a google search, there&#8217;s a simple hack / workaround you can use to patch up this problem. Basically, instead of using the Facebook protocol to connect, we let Digsby use the Jabber protocol as a &#8216;proxy&#8217; to connect to Facebook:</p>
<ol>
<li>Go to <strong>Digsby</strong> -&gt; <strong>My Accounts</strong> and in the Add Accounts section at the top, select the <strong>Jabber</strong> icon.</li>
<li>You should get a window that looks like this:<br />
<a href="http://imgur.com/OEy21"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/OEy21.png" alt="" /></a></li>
<li>In the <strong>Jabber ID</strong> box, put <strong><em>your.id</em>@chat.facebook.com</strong>, and in the password field, put your <strong>facebook password</strong>. For example, if your facebook page is at <em>facebook.com/yourname</em>, your Jabber id is <em>yourname@chat.facebook.com</em>.</li>
<li>Remove the facebook account from Digsby</li>
</ol>
<p>At this point, you&#8217;re done: Digsby should give you no more problems about Facebook.</p>
<p><strong>Warning: the following is unnecessary and experimental! It might screw up the entire Digsby installation, forcing you to reinstall!</strong></p>
<p>However, you can replace the Jabber icon with the Facebook one (this is for purely cosmetic purposes):</p>
<ol>
<li>Go to <strong>C:\Program Files (x86)\Digsby\res\skins\default\serviceicons</strong> (that&#8217;s the default installation path on my machine, yours may be different)</li>
<li>Delete <strong>jabber.png</strong>, duplicate <strong>facebook.png</strong>, and rename it <strong>jabber.png</strong></li>
<li>Restart Digsby</li>
</ol>
<p>There you have it &#8212; hack accomplished:</p>
<p><a href="http://imgur.com/yrhAH"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/yrhAH.png" alt="" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2042/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2042/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2042&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2012/01/26/fix-for-digsbys-broken-facebook-support/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/QrmvP.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/OEy21.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/yrhAH.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding Harmonic Conjugates (sort of)</title>
		<link>http://luckytoilet.wordpress.com/2012/01/07/understanding-harmonic-conjugates-sort-of/</link>
		<comments>http://luckytoilet.wordpress.com/2012/01/07/understanding-harmonic-conjugates-sort-of/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 07:06:38 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[apollonius]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[harmonic conjugates]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2027</guid>
		<description><![CDATA[For many people (for me at least), the Harmonic Conjugate is a difficult concept to understand. I didn&#8217;t really get it the first time I saw it, at Mathcamp. Let&#8217;s take the definition of the harmonic conjugate: AB and CD are harmonic conjugates if this equation holds: If you&#8217;re like me, you&#8217;re thinking along the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2027&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>For many people (for me at least), the <a href="http://en.wikipedia.org/wiki/Projective_harmonic_conjugate">Harmonic Conjugate</a> is a difficult concept to understand. I didn&#8217;t really get it the first time I saw it, at Mathcamp. Let&#8217;s take the definition of the harmonic conjugate:</p>
<p><a href="http://imgur.com/z1G8I"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/z1G8I.png" alt="" /></a></p>
<blockquote><p>AB and CD are harmonic conjugates if this equation holds:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7BAC%7D%7BBC%7D+%3D+%5Cfrac%7BAD%7D%7BBD%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=3' alt='&#92;frac{AC}{BC} = &#92;frac{AD}{BD} ' title='&#92;frac{AC}{BC} = &#92;frac{AD}{BD} ' class='latex' /></p>
</blockquote>
<p style="text-align:left;">If you&#8217;re like me, you&#8217;re thinking along the lines of<em> &#8220;But why? Why is this defined this way? Why would we spend so much time proving things about this weird concept? What&#8217;s the point, what&#8217;s the use?&#8221;</em></p>
<p style="text-align:left;">Even now, I can&#8217;t really give you an <em>intuitive</em> explanation of why this equality is so important. On the other hand, I could certainly come up with a few problems in which the concept of the harmonic conjugate turns to be <em>useful</em>.</p>
<h3 style="text-align:left;">Apollonius and Fleeing Ships</h3>
<p>Apollonius&#8217;s problem was this: you are in control of a ship (point A on diagram), and you are in pursuit of another ship (point B). The other ship is fleeing in a straight line in some direction:</p>
<p><a href="http://imgur.com/JV1ct"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/JV1ct.png" alt="" /></a></p>
<p>Your speed is (obviously) faster than the speed of the other ship: say they&#8217;re going at 30 km/h and you&#8217;re going at 50 km/h. Additionally, your ship is required to go in a straight line.</p>
<p>In which direction should you set off in order to intercept the fleeing ship?</p>
<h3>Solution with Harmonic Conjugates</h3>
<p>The first step of the solution is to construct harmonic conjugates CD so that their ratio is the ratio of your speed to the other ship&#8217;s speed (we&#8217;ll prove later that this is actually possible; assume we can do this for now):</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7BAC%7D%7BBC%7D+%3D+%5Cfrac%7BAD%7D%7BBD%7D+%3D+%5Cfrac%7B5%7D%7B3%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{AC}{BC} = &#92;frac{AD}{BD} = &#92;frac{5}{3} ' title='&#92;frac{AC}{BC} = &#92;frac{AD}{BD} = &#92;frac{5}{3} ' class='latex' /></p>
<p style="text-align:left;">Next, draw a circle with diameter CD:</p>
<p><a href="http://imgur.com/YUMee"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/YUMee.png" alt="" /></a></p>
<p>There is a point where the ray from B (their ship) intersects this circle. Now go to this point immediately, in a straight line: the ship will be there.</p>
<h3>The Proof</h3>
<p>In order to prove that this works, we&#8217;ll need to take a step back and look at how we constructed the points C and D. The solution turns out to be evident directly from the construction of the harmonic conjugates.</p>
<p>Again, let&#8217;s assume our desired ratio is 5/3. Starting with the points A and B, the first step is constructing some point P so that:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7BAP%7D%7BBP%7D+%3D+%5Cfrac%7B5%7D%7B3%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{AP}{BP} = &#92;frac{5}{3} ' title='&#92;frac{AP}{BP} = &#92;frac{5}{3} ' class='latex' /></p>
<p style="text-align:left;">This is fairly easy to do. Draw a circle of radius 5 around A, and draw a circle of radius 3 around B &#8212; the intersection P of these two circles forms the correct ratio. (if the circles don&#8217;t intersect, just scale everything up and try again)</p>
<p style="text-align:left;">Next, dropping the internal and external <em>angle bisectors</em> of the new triangle gives the harmonic conjugates C and D:</p>
<p><a href="http://imgur.com/f2CZ1"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/f2CZ1.png" alt="" /></a></p>
<p>Why angle bisectors? From the angle bisector theorems (which I won&#8217;t prove here):</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7BAP%7D%7BBP%7D+%3D+%5Cfrac%7BAC%7D%7BBC%7D+%3D+%5Cfrac%7B5%7D%7B3%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{AP}{BP} = &#92;frac{AC}{BC} = &#92;frac{5}{3} ' title='&#92;frac{AP}{BP} = &#92;frac{AC}{BC} = &#92;frac{5}{3} ' class='latex' /></p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7BAP%7D%7BBP%7D+%3D+%5Cfrac%7BAD%7D%7BBD%7D+%3D+%5Cfrac%7B5%7D%7B3%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;frac{AP}{BP} = &#92;frac{AD}{BD} = &#92;frac{5}{3} ' title='&#92;frac{AP}{BP} = &#92;frac{AD}{BD} = &#92;frac{5}{3} ' class='latex' /></p>
<p style="text-align:left;">Combining the two proves that C and D are indeed harmonic conjugates to AB.</p>
<p style="text-align:left;">As a corollary, notice that because of angle bisecting, the angle CPD is always a right angle &#8212; hence, the <em>locus</em> of all points P forms a circle with diameter CD.</p>
<p style="text-align:left;">Returning to the ship problem, since each point P is <em>defined</em> as a point so that <img src='http://s0.wp.com/latex.php?latex=%5Cfrac%7BAP%7D%7BBP%7D+%3D+%5Cfrac%7B5%7D%7B3%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;frac{AP}{BP} = &#92;frac{5}{3} ' title='&#92;frac{AP}{BP} = &#92;frac{5}{3} ' class='latex' />, it follows that when both ships travel to such a point P, they will meet at the same time.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2027/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2027&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2012/01/07/understanding-harmonic-conjugates-sort-of/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/z1G8I.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/JV1ct.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/YUMee.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/f2CZ1.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>
	</item>
		<item>
		<title>My attempt at a Conquest AI</title>
		<link>http://luckytoilet.wordpress.com/2011/12/09/my-attempt-at-a-conquest-ai/</link>
		<comments>http://luckytoilet.wordpress.com/2011/12/09/my-attempt-at-a-conquest-ai/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 01:19:49 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[conquest]]></category>
		<category><![CDATA[monte carlo]]></category>
		<category><![CDATA[runescape]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2020</guid>
		<description><![CDATA[Before I move on, let me introduce Conquest &#8211; a chesslike minigame in Runescape. This isn&#8217;t a detailed description of the rules, just an overview to kind of get to know how the game works, if you haven&#8217;t seen it before. You have a 20&#215;20 board and some pieces (which you choose yourself and get [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2020&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Before I move on, let me introduce <a href="http://services.runescape.com/m=rswiki/en/Conquest">Conquest </a>&#8211; a chesslike minigame in Runescape. This isn&#8217;t a detailed description of the rules, just an overview to kind of get to know how the game works, if you haven&#8217;t seen it before.</p>
<p>You have a 20&#215;20 board and some pieces (which you choose yourself and get to set up wherever you want, with some restrictions). You&#8217;re trying to kill all of your opponent&#8217;s pieces, which you have to do in order to win.</p>
<p><a href="http://imgur.com/RsKep"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/RsKep.jpg" alt="" /></a></p>
<p>Each piece has a certain move <strong>radius</strong> &#8212; so it can move to any square within that radius (diagonals only counting as a distance of one). Then, once it has moved, it is allowed to attack an enemy within its <strong>range</strong> &#8212; again varying from piece to piece.</p>
<p>That&#8217;s the gist of the game. Oh yes, at certain times you can also use some silly <strong>special attacks</strong> <em>in addition</em> to moving and attacking &#8212; for instance, freeze an enemy piece for one move or temporarily boost the attack of one of your own pieces. And these special moves can be used on any pieces during your move, and in any combination.</p>
<h3>A Conquest AI&#8230; or not</h3>
<p>So some months ago, I was playing Conquest. I was a decent player, but after a string of losses, I thought: maybe I can write an AI to play this game for me &#8212; perhaps better than a human can? Perhaps the same way you would write a chess AI?</p>
<p>Well, I scribbled some back of the envelope calculations, but I quickly realized that the number of possible moves at each position was far too large.</p>
<p>How large? A player has maybe 5 pieces, and if a piece&#8217;s average move radius is 4, then we already have 5*9*9 (remember 4 is the radius, not diameter) which is over 400. And that&#8217;s if we never attack or use special moves. If we take special moves into account, since special moves can be stacked on top of each other, assuming 5 valid targets per special move and 3 special moves we would multiply the 400 again by 5*5*5. For one move, we would need to consider 50000 possibilities.</p>
<p>In comparison, from any position in chess there are typically 30 or 40 legal moves. So the standard minimax algorithm would probably be no good, at least not without an incredible amount of heuristics. I had to try something different for this to work.</p>
<h3>Random has a chance</h3>
<p>It turns out that there exists a very different strategy that worked quite well for Go-playing AIs. Instead of constructing and evaluating a huge search tree to find the best move, we simulate thousands <em>random</em> games, with random moves from each side. The move that gives us the best win percentage is played. All else being equal, a position that gives you a 90% chance of winning given random play from that point on is usually better than one with only a 30% chance of winning.</p>
<p>Here&#8217;s a screenshot of a <a href="http://beej.us/blog/2010/01/monte-carlo-method-for-game-ai/">connect-4 AI</a> using this technique:</p>
<p><a href="http://imgur.com/FnAVd"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/FnAVd.png" alt="" /></a></p>
<p>The <strong>Monte Carlo</strong> approach, as that&#8217;s what it&#8217;s called, seems absurd &#8212; there&#8217;s no way playing random moves can beat a good minimax! Indeed, Monte Carlo is never used to play chess, and I could sometimes beat the above AI. But where Monte Carlo really shines is when standard minimax is impractical &#8212; my scenario.</p>
<p>After finding and reading a few papers describing the method in detail, I was ready to start coding. However, there is still one more catch: to make it practical to set up the AI against other players over Runescape (and where the time limit for each move is usually 30 seconds), I would have to find a way to integrate the back end &#8212; the part that does the computations &#8212; with a front end that relayed the moves back and forth to the Runescape game client.</p>
<p>All is not lost, however: there were several freely available hacked clients for botting purposes: <a href="http://www.powerbot.org/">Powerbot </a>allowed for users to write java scripts that automated tedious ingame actions.</p>
<p>That was about as far as I got though, unfortunately. Coding the game logic proved trickier than expected. A month or so after I started my account was banned for botting; later, Jagex (the company behind the game) made an update that rendered Powerbot (as well as every other similar hacked client) unusable. Without a game account nor a practical front-end, I called it quits.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2020/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2020/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2020&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2011/12/09/my-attempt-at-a-conquest-ai/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/RsKep.jpg" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/FnAVd.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Solving the AB Game by Brute Force</title>
		<link>http://luckytoilet.wordpress.com/2011/11/07/solving-the-ab-game-by-brute-force/</link>
		<comments>http://luckytoilet.wordpress.com/2011/11/07/solving-the-ab-game-by-brute-force/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 03:18:32 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ab]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[guess]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mastermind]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=2013</guid>
		<description><![CDATA[The AB game, a variant of Mastermind, is played with pencil and paper and with two people. One person chooses a four digit number in which no digit is repeated, say X, and the other person tries to guess it in as few moves as possible. After the guesser guesses some number, say Y, the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2013&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The AB game, a variant of Mastermind, is played with pencil and paper and with two people. One person chooses a four digit number in which no digit is repeated, say X, and the other person tries to guess it in as few moves as possible. After the guesser guesses some number, say Y, the other person gives information on how closely Y matched with X:</p>
<ul>
<li>If some digit in Y coincides with a digit in X (in the same position), then the guesser scores an A.</li>
<li>If some digit in Y exists in X but is in the wrong place, then the guesser scores a B.</li>
</ul>
<p>For instance, if X is 1234 and we guess 2674, we get an A and a B, because the 4 is in the right place, and the 2 is one of the right numbers but isn&#8217;t in the right place.</p>
<p>This proceeds until the guesser gets the exact number.</p>
<p>When humans (or at least beginners) play the AB game, they usually do some form of uncoordinated trial and error, which gets the right answer after some large number of moves. This takes anywhere from about 8 to possibly 30 guesses. When I played this game with a friend, I didn&#8217;t have a very systematic strategy, but I wondered if a computer program could solve the game, always entering the optimal guess.</p>
<h3>A Bruteforce Solver</h3>
<p>My first approach happened to work fairly well. Simply, the computer keeps track of a list of all possible numbers that the answer can be. At random, the computer guesses one of the numbers, and upon receiving feedback, eliminates every number in its list that doesn&#8217;t match that feedback. Quickly it eliminates whole swaths of combinations and arrives at the answer.</p>
<p>A typical session might go like this:</p>
<pre class="brush: plain; title: ; notranslate">
Guess 1: 6297. Score: 5040
b
Guess 2: 8512. Score: 1440
abb
Guess 3: 2315. Score: 83
bb
Guess 4: 5842. Score: 29
bb
Guess 5: 9581. Score: 13
ab
Guess 6: 8021. Score: 1
</pre>
<p>It took only 5 guesses for the computer to narrow down the choices to the only possible answer (8021).</p>
<p>A variant that is usually much harder for humans to solve is to allow the number chosen to have repeats. Although significantly trickier for humans to guess by trial and error, brute force doesn&#8217;t seem to be affected too much by it:</p>
<pre class="brush: plain; title: ; notranslate">
Guess 1: 1796. Score: 10000
b
Guess 2: 5881. Score: 3048
a
Guess 3: 0131. Score: 531
abb
Guess 4: 3311. Score: 15
aa
Guess 5: 3201. Score: 9
abb
Guess 6: 2011. Score: 1
</pre>
<p>The computer&#8217;s average of five or six is much better than a human can normally do! (although I haven&#8217;t researched possible human algorithms).</p>
<h3>Optimal or Not?</h3>
<p>At this point you may begin to wonder if this strategy is the optimal one. Unfortunately, it is not &#8212; and I only need one counterexample to demonstrate that.</p>
<p>Suppose that instead of four numbers, you were allowed to choose 4 letters from A to Z. You choose the combination ABCW. Now suppose that the computer &#8216;knows&#8217; that the first three letters are ABC &#8212; that is, it has eliminated all other combinations except for ABCD, ABCE, &#8230;, ABCZ.</p>
<p>By the random guessing algorithm, the computer is forced to guess ABCJ, ABCP, etc, until it eventually hits on ABCW at random. This may take a very high number of guesses.</p>
<p>A smarter strategy would be to guess combinations of four unknown letters, say DEFG, then HIJK, etc. Instead of eliminating one letter, you eliminate four letters at a time. Although some guesses have no chance of being correct, the number of guesses required is fewer in the long run.</p>
<h3>Source Code</h3>
<p>I&#8217;ll put my somewhat unwieldy java code here for all to see:</p>
<pre class="brush: java; title: ; wrap-lines: false; notranslate">


import java.util.*;

public class ABSolver{
  
  // Does cc1 and cc2 together match the pattern?
  // If repeats are allowed, cc2 is matched against cc1.
  static boolean fits(char[] cc1, char[] cc2, int A, int B){

    int a = 0;
    int b = 0;
    for(int i=0; i&lt;4; i++){
      if(cc1[i] == cc2[i]) a++;
      else{
        for(int j=0; j&lt;4; j++){
          if(i != j &amp;&amp; cc1[j] == cc2[i] &amp;&amp; cc1[j]!=cc2[j]){
            b++;
            break;
          }
        }
      }
    }

    return a==A &amp;&amp; b==B;
  }

  public static void main(String[] args){
    
    Random rand = new Random();
    Scanner scan = new Scanner(System.in);

    // Combinations that haven't been eliminated yet
    List&lt;char[]&gt; ok = new ArrayList&lt;char[]&gt;(10000);

    // Generate all possible combinations
    for(int i = 0; i &lt;= 9999; i++){
      
      String i_s = Integer.toString(i);
      while(i_s.length() != 4) i_s = &quot;0&quot; + i_s;

      // Check for sameness
      char a = i_s.charAt(0);
      char b = i_s.charAt(1);
      char c = i_s.charAt(2);
      char d = i_s.charAt(3);
      boolean same = a==b || a==c || a==d || b==c || b==d || c==d;

      // Comment this line out if we're allowing repeats
      if(same) continue;

      char[] i_ia = i_s.toCharArray();
      ok.add(i_ia);

    }

    // Pick the first guess randomly
    char[] firstg = ok.get(rand.nextInt(ok.size()));
    char[] guess = null;

    int nguesses = 1;

    // Question answer cycle until we get it right
    while(true){

      // Ask for user response
      if(nguesses &gt; 1){
        String ans = scan.nextLine();
        int A = 0;
        int B = 0;
        for(char cc : ans.toCharArray()){
          if(cc == 'a') A++;
          if(cc == 'b') B++;
        }

        if(A==4) return;

        // For each one check to see if it still fits
        List&lt;char[]&gt; ok_ = new ArrayList&lt;char[]&gt;(ok.size());
        for(char[] zhe : ok){
          if(fits(zhe, guess, A, B))
            ok_.add(zhe);
        }
        ok = ok_;
      }

      char[] nextguess = null;
      if(nguesses == 1)
        nextguess = firstg;
      else nextguess = ok.get(rand.nextInt(ok.size()));

      System.out.println(&quot;Guess &quot; + nguesses + &quot;: &quot; + new String(nextguess)
                       + &quot;. Score: &quot; + ok.size());
      
      // we win!
      if(ok.size() == 1)
        return;

      guess = nextguess;
      nguesses++;
    }
    
  }
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/2013/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/2013/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=2013&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2011/11/07/solving-the-ab-game-by-brute-force/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>
	</item>
		<item>
		<title>Calculating the Plane Angles of Platonic Solids</title>
		<link>http://luckytoilet.wordpress.com/2011/10/11/calculating-the-plane-angles-of-platonic-solids/</link>
		<comments>http://luckytoilet.wordpress.com/2011/10/11/calculating-the-plane-angles-of-platonic-solids/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 03:44:04 +0000</pubDate>
		<dc:creator>luckytoilet</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[dodecahedron]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[isosahedron]]></category>
		<category><![CDATA[platonic solids]]></category>
		<category><![CDATA[tetrahedron]]></category>
		<category><![CDATA[vector geometry]]></category>

		<guid isPermaLink="false">http://luckytoilet.wordpress.com/?p=1979</guid>
		<description><![CDATA[What is the angle between two planes of a tetrahedron? The angle between any two edges of the tetrahedron is , so it&#8217;s easy to (falsely) conclude that the angle between two faces must also be . But this isn&#8217;t the case: the plane angle is defined as the angle between two lines on the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=1979&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>What is the angle between two planes of a tetrahedron?<br />
<a href="http://imgur.com/d2ncO"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/d2ncO.gif" alt="" /></a></p>
<p>The angle between any two edges of the tetrahedron is <img src='http://s0.wp.com/latex.php?latex=60%5E%5Ccirc&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='60^&#92;circ' title='60^&#92;circ' class='latex' />, so it&#8217;s easy to (falsely) conclude that the angle between two faces must also be <img src='http://s0.wp.com/latex.php?latex=60%5E%5Ccirc&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='60^&#92;circ' title='60^&#92;circ' class='latex' />.</p>
<p>But this isn&#8217;t the case: the plane angle is defined as the angle between two lines on the two planes that are both perpendicular to the edge. None of the edges in a tetrahedron is perpendicular to any other, so the answer of <img src='http://s0.wp.com/latex.php?latex=60%5E%5Ccirc&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='60^&#92;circ' title='60^&#92;circ' class='latex' /> is invalid.</p>
<p>We can try to compute the angle using regular Euclidean solid geometry, but things tend to get messy. A different way to approach the problem is by using vector geometry: using vector methods we can easily calculate the plane angle of the tetrahedron (as well as the icosahedron and the dodecahedron).</p>
<p>Assume symmetry. We represent three concurrent edges of the polyhedron as three vectors beginning at the same point: <img src='http://s0.wp.com/latex.php?latex=%5Cvec+a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec a' title='&#92;vec a' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=%5Cvec+b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec b' title='&#92;vec b' class='latex' />, and <img src='http://s0.wp.com/latex.php?latex=%5Cvec+c&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec c' title='&#92;vec c' class='latex' />; let <img src='http://s0.wp.com/latex.php?latex=%5Calpha&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;alpha' title='&#92;alpha' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Cbeta&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;beta' title='&#92;beta' class='latex' /> be the angles between the vectors (by symmetry we&#8217;re assuming that the two alpha&#8217;s are equal):<br />
<a href="http://imgur.com/jDUcg"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/jDUcg.png" alt="" /></a>(in case my poor drawing skills does not make this apparent, vectors a and b form one face of the polyhedron and c and b form another face)</p>
<p>For simplicity, let&#8217;s also say the lengths of each of the three vectors is 1.</p>
<p>We want to compute the angle between the plane formed by <img src='http://s0.wp.com/latex.php?latex=%5Cvec+a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec a' title='&#92;vec a' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Cvec+c&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec c' title='&#92;vec c' class='latex' />, and the plane formed by <img src='http://s0.wp.com/latex.php?latex=%5Cvec+b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec b' title='&#92;vec b' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Cvec+c&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec c' title='&#92;vec c' class='latex' />. Hence let <img src='http://s0.wp.com/latex.php?latex=%5Cvec+x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec x' title='&#92;vec x' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Cvec+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec y' title='&#92;vec y' class='latex' /> be the perpendiculars to <img src='http://s0.wp.com/latex.php?latex=%5Cvec+a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec a' title='&#92;vec a' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Cvec+b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec b' title='&#92;vec b' class='latex' /> respectively each ending at the same point as their respective vectors:</p>
<p><a href="http://imgur.com/3OGkO"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/3OGkO.png" alt="" /></a>For any two vectors, the dot product is defined <img src='http://s0.wp.com/latex.php?latex=%5Cvec+a+%5Ccdot+%5Cvec+b+%3D+%7C%5Cvec+a%7C+%7C%5Cvec+b%7C+%5Ccos+%5Ctheta&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec a &#92;cdot &#92;vec b = |&#92;vec a| |&#92;vec b| &#92;cos &#92;theta' title='&#92;vec a &#92;cdot &#92;vec b = |&#92;vec a| |&#92;vec b| &#92;cos &#92;theta' class='latex' /> with <img src='http://s0.wp.com/latex.php?latex=%5Ctheta&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;theta' title='&#92;theta' class='latex' /> being the angle between the vectors. Given that the lengths of the vectors are all 1, we have:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cvec+a+%5Ccdot+%5Cvec+c+%3D+%5Cvec+b+%5Ccdot+%5Cvec+c+%3D+%5Ccos+%5Calpha+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;vec a &#92;cdot &#92;vec c = &#92;vec b &#92;cdot &#92;vec c = &#92;cos &#92;alpha ' title='&#92;vec a &#92;cdot &#92;vec c = &#92;vec b &#92;cdot &#92;vec c = &#92;cos &#92;alpha ' class='latex' /></p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cvec+a+%5Ccdot+%5Cvec+b+%3D+%5Ccos+%5Cbeta+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;vec a &#92;cdot &#92;vec b = &#92;cos &#92;beta ' title='&#92;vec a &#92;cdot &#92;vec b = &#92;cos &#92;beta ' class='latex' /></p>
<p style="text-align:left;">Also, by vector addition:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cvec+c+%5Ccos+%5Calpha+%2B+%5Cvec+x+%3D+%5Cvec+a+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;vec c &#92;cos &#92;alpha + &#92;vec x = &#92;vec a ' title='&#92;vec c &#92;cos &#92;alpha + &#92;vec x = &#92;vec a ' class='latex' /></p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cvec+c+%5Ccos+%5Calpha+%2B+%5Cvec+y+%3D+%5Cvec+b+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;vec c &#92;cos &#92;alpha + &#92;vec y = &#92;vec b ' title='&#92;vec c &#92;cos &#92;alpha + &#92;vec y = &#92;vec b ' class='latex' /></p>
<p style="text-align:left;">Hence <img src='http://s0.wp.com/latex.php?latex=%5Cvec+x+%3D+%5Cvec+a+-+%5Cvec+c+%5Ccos+%5Calpha&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec x = &#92;vec a - &#92;vec c &#92;cos &#92;alpha' title='&#92;vec x = &#92;vec a - &#92;vec c &#92;cos &#92;alpha' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Cvec+y+%3D+%5Cvec+b+-+%5Cvec+c+%5Ccos+%5Calpha&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec y = &#92;vec b - &#92;vec c &#92;cos &#92;alpha' title='&#92;vec y = &#92;vec b - &#92;vec c &#92;cos &#92;alpha' class='latex' />.</p>
<p style="text-align:left;">We want to find the angle between <img src='http://s0.wp.com/latex.php?latex=%5Cvec+x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec x' title='&#92;vec x' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Cvec+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;vec y' title='&#92;vec y' class='latex' /> &#8212; call this angle <img src='http://s0.wp.com/latex.php?latex=%5Ctheta&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;theta' title='&#92;theta' class='latex' />. Then</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cvec+x+%5Ccdot+%5Cvec+y+%3D+%7C%5Cvec+x%7C+%7C%5Cvec+y%7C+%5Ccos+%5Ctheta+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;vec x &#92;cdot &#92;vec y = |&#92;vec x| |&#92;vec y| &#92;cos &#92;theta ' title='&#92;vec x &#92;cdot &#92;vec y = |&#92;vec x| |&#92;vec y| &#92;cos &#92;theta ' class='latex' /></p>
<p style="text-align:left;">The dot product of vectors x and y is simply:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cbegin%7Barray%7D%7Bl%7D+%28%5Cvec+a+-+%5Cvec+c+%5Ccos+%5Calpha%29+%5Ccdot+%28%5Cvec+b+-+%5Cvec+c+%5Ccos+%5Calpha%29+%5C%5C+%3D+%28%5Cvec+a+-+%5Cvec+c+%28%5Cvec+a+%5Ccdot+%5Cvec+c%29%29+%5Ccdot+%28%5Cvec+b+-+%5Cvec+c+%28%5Cvec+b+%5Ccdot+%5Cvec+c%29%29+%5C%5C+%3D+%5Cvec+a+%5Ccdot+%5Cvec+b+-+%28%5Cvec+a+%5Ccdot+%5Cvec+c%29+%28%5Cvec+b+%5Ccdot+%5Cvec+c%29+%5C%5C+%3D+%5Ccos+%5Cbeta+-+%5Ccos%5E2+%5Calpha+%5Cend%7Barray%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;begin{array}{l} (&#92;vec a - &#92;vec c &#92;cos &#92;alpha) &#92;cdot (&#92;vec b - &#92;vec c &#92;cos &#92;alpha) &#92;&#92; = (&#92;vec a - &#92;vec c (&#92;vec a &#92;cdot &#92;vec c)) &#92;cdot (&#92;vec b - &#92;vec c (&#92;vec b &#92;cdot &#92;vec c)) &#92;&#92; = &#92;vec a &#92;cdot &#92;vec b - (&#92;vec a &#92;cdot &#92;vec c) (&#92;vec b &#92;cdot &#92;vec c) &#92;&#92; = &#92;cos &#92;beta - &#92;cos^2 &#92;alpha &#92;end{array} ' title='&#92;begin{array}{l} (&#92;vec a - &#92;vec c &#92;cos &#92;alpha) &#92;cdot (&#92;vec b - &#92;vec c &#92;cos &#92;alpha) &#92;&#92; = (&#92;vec a - &#92;vec c (&#92;vec a &#92;cdot &#92;vec c)) &#92;cdot (&#92;vec b - &#92;vec c (&#92;vec b &#92;cdot &#92;vec c)) &#92;&#92; = &#92;vec a &#92;cdot &#92;vec b - (&#92;vec a &#92;cdot &#92;vec c) (&#92;vec b &#92;cdot &#92;vec c) &#92;&#92; = &#92;cos &#92;beta - &#92;cos^2 &#92;alpha &#92;end{array} ' class='latex' /></p>
<p style="text-align:left;">Additionally <img src='http://s0.wp.com/latex.php?latex=%7C%5Cvec+x%7C+%3D+%7C%5Cvec+y%7C+%3D+%5Csin+%5Calpha&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='|&#92;vec x| = |&#92;vec y| = &#92;sin &#92;alpha' title='|&#92;vec x| = |&#92;vec y| = &#92;sin &#92;alpha' class='latex' />. Hence the cosine of the angle is:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Ccos+%5Ctheta+%3D+%5Cfrac%7B%5Cvec+x+%5Ccdot+%5Cvec+y%7D%7B%7C%5Cvec+x%7C+%7C%5Cvec+y%7C%7D+%3D+%5Cfrac%7B%5Ccos+%5Cbeta+-+%5Ccos%5E2+%5Calpha%7D%7B%5Csin%5E2+%5Calpha%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=2' alt='&#92;cos &#92;theta = &#92;frac{&#92;vec x &#92;cdot &#92;vec y}{|&#92;vec x| |&#92;vec y|} = &#92;frac{&#92;cos &#92;beta - &#92;cos^2 &#92;alpha}{&#92;sin^2 &#92;alpha} ' title='&#92;cos &#92;theta = &#92;frac{&#92;vec x &#92;cdot &#92;vec y}{|&#92;vec x| |&#92;vec y|} = &#92;frac{&#92;cos &#92;beta - &#92;cos^2 &#92;alpha}{&#92;sin^2 &#92;alpha} ' class='latex' /></p>
<p style="text-align:left;">We can now use this newly derived formula to calculate plane angles! For example&#8230;</p>
<h3 style="text-align:left;">Tetrahedron</h3>
<p>In the tetrahedron, both <img src='http://s0.wp.com/latex.php?latex=%5Calpha&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;alpha' title='&#92;alpha' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Cbeta&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;beta' title='&#92;beta' class='latex' /> are 60:<br />
<a href="http://imgur.com/DzLh0"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/DzLh0.png" alt="" /></a>So <img src='http://s0.wp.com/latex.php?latex=%5Ccos+%5Ctheta+%3D+%5Cfrac%7B%5Ccos+60+-+%5Ccos%5E2+60%7D%7B%5Csin%5E2+60%7D+%3D+%5Cfrac%7B1%7D%7B2%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;cos &#92;theta = &#92;frac{&#92;cos 60 - &#92;cos^2 60}{&#92;sin^2 60} = &#92;frac{1}{2} ' title='&#92;cos &#92;theta = &#92;frac{&#92;cos 60 - &#92;cos^2 60}{&#92;sin^2 60} = &#92;frac{1}{2} ' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Ctheta+%3D+%5Carccos+%5Cfrac%7B1%7D%7B3%7D+%3D+70.8%5E%5Ccirc&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;theta = &#92;arccos &#92;frac{1}{3} = 70.8^&#92;circ' title='&#92;theta = &#92;arccos &#92;frac{1}{3} = 70.8^&#92;circ' class='latex' />.</p>
<p><span class="Apple-style-span" style="font-size:15px;font-weight:bold;">Icosahedron</span></p>
<p>In the icosahedron, <img src='http://s0.wp.com/latex.php?latex=%5Calpha+%3D+60&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;alpha = 60' title='&#92;alpha = 60' class='latex' /> but <img src='http://s0.wp.com/latex.php?latex=%5Cbeta+%3D+108&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;beta = 108' title='&#92;beta = 108' class='latex' />:<br />
<a href="http://imgur.com/qD7ev"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/qD7ev.png" alt="" /></a>The top &#8216;cap&#8217; is a regular pentagon, which has a vertex angle of 108; each side of the pentagon constitutes a side of an equilateral triangle. Since <img src='http://s0.wp.com/latex.php?latex=%5Ccos+108+%3D+%5Cfrac%7B1%7D%7B4%7D+%281-%5Csqrt%7B5%7D%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;cos 108 = &#92;frac{1}{4} (1-&#92;sqrt{5})' title='&#92;cos 108 = &#92;frac{1}{4} (1-&#92;sqrt{5})' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=%5Ccos+%5Ctheta+%3D+%5Cfrac%7B%5Ccos+108+-+%5Ccos%5E2+60%7D%7B%5Csin%5E2+60%7D+%3D+-%5Cfrac%7B%5Csqrt%7B5%7D%7D%7B3%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;cos &#92;theta = &#92;frac{&#92;cos 108 - &#92;cos^2 60}{&#92;sin^2 60} = -&#92;frac{&#92;sqrt{5}}{3} ' title='&#92;cos &#92;theta = &#92;frac{&#92;cos 108 - &#92;cos^2 60}{&#92;sin^2 60} = -&#92;frac{&#92;sqrt{5}}{3} ' class='latex' />, and <img src='http://s0.wp.com/latex.php?latex=%5Ctheta+%3D+%5Carccos+%28-%5Cfrac%7B%5Csqrt%7B5%7D%7D%7B3%7D%29+%3D+138.2%5E%5Ccirc&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;theta = &#92;arccos (-&#92;frac{&#92;sqrt{5}}{3}) = 138.2^&#92;circ' title='&#92;theta = &#92;arccos (-&#92;frac{&#92;sqrt{5}}{3}) = 138.2^&#92;circ' class='latex' />.</p>
<h3>Dodecahedron</h3>
<p>Computing angles for the dodecahedron works a bit differently from the tetrahedron and icosahedron. Instead of using existing edges as vectors, we construct an equilateral triangle by connecting three vertices:</p>
<p><a href="http://imgur.com/uFIXJ"><img class="aligncenter" title="Hosted by imgur.com" src="http://i.imgur.com/uFIXJ.png" alt="" /></a>So <img src='http://s0.wp.com/latex.php?latex=%5Calpha+%3D+36&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;alpha = 36' title='&#92;alpha = 36' class='latex' /> (since it&#8217;s part of a regular pentagon) and <img src='http://s0.wp.com/latex.php?latex=%5Cbeta+%3D+60&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;beta = 60' title='&#92;beta = 60' class='latex' />. Then <img src='http://s0.wp.com/latex.php?latex=%5Ccos+%5Ctheta+%3D+%5Cfrac%7B%5Ccos%5E2+60+-+%5Ccos%5E2+36%7D%7B%5Csin%5E2+36%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=1' alt='&#92;cos &#92;theta = &#92;frac{&#92;cos^2 60 - &#92;cos^2 36}{&#92;sin^2 36} ' title='&#92;cos &#92;theta = &#92;frac{&#92;cos^2 60 - &#92;cos^2 36}{&#92;sin^2 36} ' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Ctheta+%3D+116.6%5E%5Ccirc&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;theta = 116.6^&#92;circ' title='&#92;theta = 116.6^&#92;circ' class='latex' />.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/luckytoilet.wordpress.com/1979/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/luckytoilet.wordpress.com/1979/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=luckytoilet.wordpress.com&#038;blog=12001659&#038;post=1979&#038;subd=luckytoilet&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://luckytoilet.wordpress.com/2011/10/11/calculating-the-plane-angles-of-platonic-solids/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1f915fbd3fb60671d7171db4b8e3fda1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">luckytoilet</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/d2ncO.gif" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/jDUcg.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/3OGkO.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/DzLh0.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/qD7ev.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>

		<media:content url="http://i.imgur.com/uFIXJ.png" medium="image">
			<media:title type="html">Hosted by imgur.com</media:title>
		</media:content>
	</item>
	</channel>
</rss>
