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

<channel>
	<title>Never Use This Font &#187; Math</title>
	<atom:link href="http://neverusethisfont.com/blog/topics/math/feed/" rel="self" type="application/rss+xml" />
	<link>http://neverusethisfont.com/blog</link>
	<description>Aaron Parecki is the co-founder of Geoloqi.com, and specializes in backend systems development.</description>
	<lastBuildDate>Mon, 11 Jul 2011 22:50:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Infinity Mathematicians Walk Into a Bar</title>
		<link>http://neverusethisfont.com/blog/2011/01/infinity-mathematicians-walk-into-a-bar/</link>
		<comments>http://neverusethisfont.com/blog/2011/01/infinity-mathematicians-walk-into-a-bar/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 19:31:34 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[beer]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[infinity]]></category>
		<category><![CDATA[joke]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=334</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div style="font-size: 200%">Infinity mathematicians walk into a bar. The first orders a beer. The second orders half a beer. The third orders a quarter beer, etc etc. How long until the bartender runs out of beer?</div>
<p>First person to answer correctly with a full explanation gets a free beer next time we meet.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2011/01/infinity-mathematicians-walk-into-a-bar/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Calculating Color Brightness</title>
		<link>http://neverusethisfont.com/blog/2006/11/calculating-color-brightness/</link>
		<comments>http://neverusethisfont.com/blog/2006/11/calculating-color-brightness/#comments</comments>
		<pubDate>Fri, 24 Nov 2006 09:25:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[color]]></category>

		<guid isPermaLink="false">http://blog.neverusethisfont.com/2006/11/calculating-color-brightness/</guid>
		<description><![CDATA[I was working on a website today, and I stumbled into a problem of needing to compute the brightness of a color, so that if it is a background color, I know whether to show white text or black text. My first thought was to simply add up the RGB components of the color and [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a website today, and I stumbled into a problem of needing to compute the brightness of a color, so that if it is a background color, I know whether to show white text or black text. My first thought was to simply add up the RGB components of the color and use that value. It turns out that is completely wrong, since pure green looks much brighter than pure blue:</p>
<div style="background-color:#00FF00;width:100px;height:30px;">Green</p>
<div style="color:white">Green</div>
</div>
<div style="background-color:#0000FF;width:100px;height:30px">Blue</p>
<div style="color:white">Blue</div>
</div>
<p>Obviously, you&#8217;d want to have white text against the blue background, but black text against the green background.</p>
<p>Now given, there is no way any sane person would use those specific colors as background colors. But the problem still applies to many other, more muted (read: useful), colors. So how do you find the apparent brightness of a color? It turns out to be much more difficult than I thought.</p>
<p>I knew that in Photoshop you can convert your picture from the RGB color space to the <a href="http://en.wikipedia.org/wiki/Lab_color_space">Lab color space</a>. Lab colors are described by two color components a and b, and a Lightness component. A good way to convert your photo to black and white is to convert it to Lab, and then get rid of the a and b channels, leaving just the Lightness channel.</p>
<p>So I needed some way to convert from RGB to Lab. Must be easy, right? No. it turns out that there is no absolute conversion between RGB and Lab, because of the nature of the design of the colorspaces. But you can do it if you use the intermediate CIE 1931 (also known as XYZ) color space, if you pick a reference white point to do the conversion. This means that you can get different XYZ colors for the same RGB color depending on what you decide &#8220;white&#8221; is.</p>
<p>Here is a <a href="http://www.easyrgb.com/calculator.php">color conversion calculator</a>. Enter your colors in any color space, pick a reference point, and it will give you the color in many color spaces.</p>
<p>They also give the <a href="http://www.easyrgb.com/math.html">algorithms used</a> to do the conversion on their site. Below is the algorithm to convert from RGB to XYZ:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">var_R <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> R <span style="color: #339933;">/</span> <span style="color: #CC0000;">255</span> <span style="color: #009900;">&#41;</span>        <span style="color: #006600; font-style: italic;">// scales var_R to between 0 and 1</span>
var_G <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> G <span style="color: #339933;">/</span> <span style="color: #CC0000;">255</span> <span style="color: #009900;">&#41;</span>
var_B <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> B <span style="color: #339933;">/</span> <span style="color: #CC0000;">255</span> <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> var_R <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #CC0000;">0.04045</span> <span style="color: #009900;">&#41;</span> var_R <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> var_R <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.055</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">1.055</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">^</span> <span style="color: #CC0000;">2.4</span>
<span style="color: #000066; font-weight: bold;">else</span>                   var_R <span style="color: #339933;">=</span> var_R <span style="color: #339933;">/</span> <span style="color: #CC0000;">12.92</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> var_G <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #CC0000;">0.04045</span> <span style="color: #009900;">&#41;</span> var_G <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> var_G <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.055</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">1.055</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">^</span> <span style="color: #CC0000;">2.4</span>
<span style="color: #000066; font-weight: bold;">else</span>                   var_G <span style="color: #339933;">=</span> var_G <span style="color: #339933;">/</span> <span style="color: #CC0000;">12.92</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> var_B <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #CC0000;">0.04045</span> <span style="color: #009900;">&#41;</span> var_B <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> var_B <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.055</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">1.055</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">^</span> <span style="color: #CC0000;">2.4</span>
<span style="color: #000066; font-weight: bold;">else</span>                   var_B <span style="color: #339933;">=</span> var_B <span style="color: #339933;">/</span> <span style="color: #CC0000;">12.92</span>
&nbsp;
var_R <span style="color: #339933;">=</span> var_R × <span style="color: #CC0000;">100</span>
var_G <span style="color: #339933;">=</span> var_G × <span style="color: #CC0000;">100</span>
var_B <span style="color: #339933;">=</span> var_B × <span style="color: #CC0000;">100</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Observer. = 2°, Illuminant = D65</span>
X <span style="color: #339933;">=</span> var_R × <span style="color: #CC0000;">0.4124</span> <span style="color: #339933;">+</span> var_G × <span style="color: #CC0000;">0.3576</span> <span style="color: #339933;">+</span> var_B × <span style="color: #CC0000;">0.1805</span>
Y <span style="color: #339933;">=</span> var_R × <span style="color: #CC0000;">0.2126</span> <span style="color: #339933;">+</span> var_G × <span style="color: #CC0000;">0.7152</span> <span style="color: #339933;">+</span> var_B × <span style="color: #CC0000;">0.0722</span>
Z <span style="color: #339933;">=</span> var_R × <span style="color: #CC0000;">0.0193</span> <span style="color: #339933;">+</span> var_G × <span style="color: #CC0000;">0.1192</span> <span style="color: #339933;">+</span> var_B × <span style="color: #CC0000;">0.9505</span></pre></div></div>

<p>The conversion from XYZ to Lab is more straightforward and doesn&#8217;t require vector math.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">var_X <span style="color: #339933;">=</span> X <span style="color: #339933;">/</span> ref_X          <span style="color: #006600; font-style: italic;">//ref_X =  95.047  Observer= 2°, Illuminant= D65</span>
var_Y <span style="color: #339933;">=</span> Y <span style="color: #339933;">/</span> ref_Y          <span style="color: #006600; font-style: italic;">//ref_Y = 100.000</span>
var_Z <span style="color: #339933;">=</span> Z <span style="color: #339933;">/</span> ref_Z          <span style="color: #006600; font-style: italic;">//ref_Z = 108.883</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> var_X <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #CC0000;">0.008856</span> <span style="color: #009900;">&#41;</span> var_X <span style="color: #339933;">=</span> var_X <span style="color: #339933;">^</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">/</span><span style="color: #CC0000;">3</span> <span style="color: #009900;">&#41;</span>
<span style="color: #000066; font-weight: bold;">else</span>                    var_X <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">7.787</span> × var_X <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">16</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">116</span> <span style="color: #009900;">&#41;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> var_Y <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #CC0000;">0.008856</span> <span style="color: #009900;">&#41;</span> var_Y <span style="color: #339933;">=</span> var_Y <span style="color: #339933;">^</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">/</span><span style="color: #CC0000;">3</span> <span style="color: #009900;">&#41;</span>
<span style="color: #000066; font-weight: bold;">else</span>                    var_Y <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">7.787</span> × var_Y <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">16</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">116</span> <span style="color: #009900;">&#41;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> var_Z <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #CC0000;">0.008856</span> <span style="color: #009900;">&#41;</span> var_Z <span style="color: #339933;">=</span> var_Z <span style="color: #339933;">^</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">/</span><span style="color: #CC0000;">3</span> <span style="color: #009900;">&#41;</span>
<span style="color: #000066; font-weight: bold;">else</span>                    var_Z <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">7.787</span> × var_Z <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">16</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">116</span> <span style="color: #009900;">&#41;</span>
&nbsp;
L <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">116</span> × var_Y <span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">16</span>
a <span style="color: #339933;">=</span> <span style="color: #CC0000;">500</span> × <span style="color: #009900;">&#40;</span> var_X <span style="color: #339933;">-</span> var_Y <span style="color: #009900;">&#41;</span>
b <span style="color: #339933;">=</span> <span style="color: #CC0000;">200</span> × <span style="color: #009900;">&#40;</span> var_Y <span style="color: #339933;">-</span> var_Z <span style="color: #009900;">&#41;</span></pre></div></div>

<p>Here are some sites I looked at while trying to figure out exactly what was going on in those functions.<br />
<a href="http://www.cs.rit.edu/~ncs/color/t_convert.html">Color Conversion Algorithms</a><br />
<a href="http://www.brucelindbloom.com/index.html?Math.html">Useful Color Equations</a></p>
<p>I wrote these two functions in PHP, and after running the output of one on the other, I was able to get the brightness value for the colors.</p>
<p>Here is the result of my programming. A <a href="http://aaronpk.net/color-brightness/">web palette of 216 colors in a table</a>, with their brightness values in each cell. The numbers are colored light if the background is dark, and dark if the background is light.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2006/11/calculating-color-brightness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reduce the number of multiplications required for the product of two polynomials</title>
		<link>http://neverusethisfont.com/blog/2006/04/reduce-the-number-of-multiplications-required-for-the-product-of-two-polynomials/</link>
		<comments>http://neverusethisfont.com/blog/2006/04/reduce-the-number-of-multiplications-required-for-the-product-of-two-polynomials/#comments</comments>
		<pubDate>Fri, 28 Apr 2006 07:26:09 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://blog.neverusethisfont.com/2006/04/reduce-the-number-of-multiplications-required-for-the-product-of-two-polynomials/</guid>
		<description><![CDATA[This was a problem done in my CIS 315 Algorithms class in Spring 2006. The product of two linear polynomials ax+b and cx+d [tex]\LARGE (ax+b)(cx+d)[/tex] is [tex]\LARGE acx^2 + (ad+bc)x + bd[/tex] Note that this requires 4 different multiplications of the coefficients: ac, ad, bc and bd. We want to find a way to determine [...]]]></description>
			<content:encoded><![CDATA[<p><i>This was a problem done in my CIS 315 Algorithms class in Spring 2006.</i></p>
<p>The product of two linear polynomials ax+b and cx+d</p>
<p>[tex]\LARGE (ax+b)(cx+d)[/tex]</p>
<p>     is</p>
<p>[tex]\LARGE acx^2 + (ad+bc)x + bd[/tex]</p>
<p>Note that this requires 4 different multiplications of the coefficients:<br />
ac, ad, bc and bd.</p>
<p>We want to find a way to determine this product with only 3 multiplications.</p>
<p>let:<br />
L = (a+b)(c+d)</p>
<p>note what happens when we FOIL L:<br />
L = ac + ad + bc + bd</p>
<p>We think that maybe we can combine the middle term (ad+bc) with only one multiplication. What we want is ad + bc, so subtract ac and bd from L:</p>
<p>J = ac<br />
K = bd</p>
<p>L &#8211; J &#8211; K = (ac + ad + bc + bd) &#8211; ac &#8211; bd</p>
<p>Note at this point we can rewrite the original FOILed product as:<br />
[tex]\LARGE Jx^2 + (L &#8211; J &#8211; K)x + K[/tex]</p>
<p>We now have solved the problem with only 3 multiplications. They are:<br />
J, K and L, or ac, bd, and (a+b)(c+d)</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2006/04/reduce-the-number-of-multiplications-required-for-the-product-of-two-polynomials/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

