<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>The Endeavour</title>
	
	<link>http://www.johndcook.com/blog</link>
	<description>John D. Cook</description>
	<lastBuildDate>Thu, 23 May 2013 16:23:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TheEndeavour" /><feedburner:info uri="theendeavour" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>TheEndeavour</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Looking for small projects</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/3OhyeYnN8rI/</link>
		<comments>http://www.johndcook.com/blog/2013/05/22/looking-for-small-projects/#comments</comments>
		<pubDate>Wed, 22 May 2013 11:29:08 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Business]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13419</guid>
		<description><![CDATA[I&#8217;m looking for small consulting projects to fill the gaps between larger projects. I&#8217;m available for projects that would take up to a few days. I can&#8217;t take on another large project right now. However, if your company takes several<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/22/looking-for-small-projects/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m looking for small consulting projects to fill the gaps between larger projects. I&#8217;m available for projects that would take up to a few days.</p>
<p>I can&#8217;t take on another large project right now. However, if your company takes several weeks to initiate a project, we could start the process now and I may be available by the time the paperwork is done.</p>
<p>If you have a project you&#8217;d like to discuss, please <a href="http://www.johndcook.com/contact.html">let me know</a>.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/3OhyeYnN8rI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/22/looking-for-small-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/22/looking-for-small-projects/</feedburner:origLink></item>
		<item>
		<title>Never applied for a job</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/cpcCDJ5KZvw/</link>
		<comments>http://www.johndcook.com/blog/2013/05/21/never-applied-for-a-job/#comments</comments>
		<pubDate>Tue, 21 May 2013 18:44:41 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13436</guid>
		<description><![CDATA[John Conway explained in an interview that he&#8217;s never applied for an academic job. I am rather proud of the fact that, in some sense, I never applied for an academic position in my life. What happened: I was walking<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/21/never-applied-for-a-job/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>John Conway explained in an <a href="http://www.ams.org/notices/201305/rnoti-p567.pdf">interview</a> that he&#8217;s never applied for an academic job.</p>
<p style="padding-left: 30px;">I am rather proud of the fact that, in some sense, I never applied for an academic position in my life. What happened: I was walking down King&#8217;s Parade, the main street in Cambridge, after I received my Ph.D. The chairman of the mathematics department said, &#8220;Oh, Conway, what have you done about applying for jobs? And I said, &#8220;Nothing.&#8221; &#8220;I thought that might be the answer,&#8221; he said, &#8220;Well, we have a position in our department, and I think you should apply.&#8221; And I said, &#8220;How do I apply?&#8221; And he said, &#8220;You write a letter to me.&#8221; And I said, &#8220;What should I put in that letter?&#8221; Then he lost his patience, pulled out of his pocket a letter — which had been written on one side — turned it over, and scribbled &#8220;Dear Professor Cassels&#8221; — that was his name — &#8220;I wish to apply for dot-dot-dot.&#8221; He handed it to me, and I signed it. It would have been nice if I&#8217;d gotten the job. I didn&#8217;t that year, but I got the same job the next year with the same letter.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/cpcCDJ5KZvw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/21/never-applied-for-a-job/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/21/never-applied-for-a-job/</feedburner:origLink></item>
		<item>
		<title>The rise and fall of binomial coefficients</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/6YoMsua54yU/</link>
		<comments>http://www.johndcook.com/blog/2013/05/21/binomial-coefficients-log-concave/#comments</comments>
		<pubDate>Tue, 21 May 2013 12:00:20 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Convexity]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13331</guid>
		<description><![CDATA[When you expand (x + y)n, the coefficients increase then decrease. The largest coefficient is in the middle if n is even; it&#8217;s the two in the middle if n is odd. For example, the coefficients for (1 + x)4<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/21/binomial-coefficients-log-concave/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>When you expand (<em>x</em> + <em>y</em>)<em><sup>n</sup></em>, the coefficients increase then decrease. The largest coefficient is in the middle if <em>n</em> is even; it&#8217;s the two in the middle if <em>n</em> is odd. For example, the coefficients for (1 + <em>x</em>)<sup>4</sup> are 1, 4, 6, 4, 1 and the coefficients for (1 + <em>x</em>)<sup>5</sup> are 1, 5, 10, 10, 5, 1.</p>
<p>More generally, if <em>a</em> &gt; 0 and <em>b</em> &gt; 0, the coefficients of (<em>ax</em> + <em>by</em>)<em><sup>n</sup></em> can only have one maximum. They may increase, or decrease, or change direction once, but they cannot wiggle more than that. They can&#8217;t, for example, increase, decrease, then increase again.</p>
<p>Here&#8217;s a proof. The coefficients are</p>
<p style="text-align: center;"><img alt="{n \choose k} a^k b^{n-k}" src="http://www.johndcook.com/binomcoeff1.png" width="84" height="42" /></p>
<p>To show that the coefficients are unimodal as a function of <em>k</em>, we&#8217;ll show that their logarithms are unimodal. And we&#8217;ll do that by showing that they are samples from a concave function.</p>
<p>The log of the <em>k</em>th coefficient is</p>
<p style="padding-left: 30px;">log Γ(<em>n</em>+1) &#8211; log Γ(<em>k</em>+1) &#8211; log Γ(<em>n</em>-<em>k</em>+1) + <em>k</em> log <em>a</em> + (<em>n</em>-<em>k</em>) log <em>b</em>.</p>
<p>As a function of <em>k</em>, the terms</p>
<p style="padding-left: 30px;">log Γ(<em>n</em>+1) + <em>k</em> log <em>a</em> + (<em>n</em>-<em>k</em>) log <em>b</em></p>
<p>form an affine function. The function log Γ<em> </em>is convex, so -<em></em>log Γ<em> </em>is concave. The composition of a concave function with an affine function is concave, so &#8211; log Γ(<em>k</em>+1) and &#8211; log Γ(<em>n</em>-<em>k</em>+1) are concave functions of <em>k</em>. The sum of concave functions is concave. And the sum of a concave function with an affine function is concave. So binomial coefficients are <a href="http://www.johndcook.com/blog/2009/01/09/log-concave-functions/">log-concave</a> and they can only have one maximum.</p>
<p>(The fact log Γ(<em>z</em>) is a convex is the easy direction of the Bohr-Mollerup theorem. The harder direction is that Γ(<em>z</em>) is the <em>only</em> way to extend factorials to all reals that is log-convex.)</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/6YoMsua54yU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/21/binomial-coefficients-log-concave/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/21/binomial-coefficients-log-concave/</feedburner:origLink></item>
		<item>
		<title>Need a 12-digit prime?</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/lSzLO2b0Gdo/</link>
		<comments>http://www.johndcook.com/blog/2013/05/20/need-a-12-digit-prime/#comments</comments>
		<pubDate>Mon, 20 May 2013 11:50:29 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SymPy]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13426</guid>
		<description><![CDATA[You may have seen the joke &#8220;Enter any 12-digit prime number to continue.&#8221; I&#8217;ve seen it floating around as the punchline in several contexts. So what do you do if you need a 12-digit prime? Here&#8217;s how to find the<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/20/need-a-12-digit-prime/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>You may have seen the joke &#8220;Enter any 12-digit prime number to continue.&#8221; I&#8217;ve seen it floating around as the punchline in several contexts.</p>
<p>So what do you do if you need a 12-digit prime? Here&#8217;s how to find the smallest one using Python.</p>
<pre>&gt;&gt;&gt; from sympy import nextprime
&gt;&gt;&gt; nextprime(10**11)
100000000003L</pre>
<p>The function <code>nextprime</code> gives the smallest prime larger than its argument. (Note that the smallest 12-digit number is 10<sup>11</sup>, not 10<sup>12</sup>. Great opportunity for an off-by-one mistake.)</p>
<p>Optionally you can provide an addition argument to <code>nextprime</code> to get primes further down the list. For example, this gives the second prime larger than 10<sup>11</sup>.</p>
<pre>&gt;&gt;&gt; nextprime(10**11, 2)
100000000019L</pre>
<p>What if you wanted the largest 12-digit prime rather than the smallest?</p>
<pre>&gt;&gt;&gt; from sympy import prevprime
&gt;&gt;&gt; prevprime(10**12)
999999999989L</pre>
<p>Finally, suppose you want to know how many 12-digit primes there are. SymPy has a function <code>primepi</code> that returns the number of primes less than its argument. Unfortunately, it fails for large arguments. It works for arguments as big as <code>2**27</code> but throws a memory error for <code>2**28</code>.</p>
<p>The number of primes less than <em>n</em> is approximately <em>n</em> / log <em>n, </em> so there are about 32 billion primes between 10<sup>11</sup> and 10<sup>12</sup>. According to Wolfram Alpha, the exact number of 12-digit primes is 33,489,857,205. So if you try 12-digit numbers at random, your chances are about 1 in 30 of getting a prime. If you&#8217;re clever enough to just pick odd numbers, your chances go up to 1 in 15.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/lSzLO2b0Gdo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/20/need-a-12-digit-prime/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/20/need-a-12-digit-prime/</feedburner:origLink></item>
		<item>
		<title>Prove or disprove</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/jKDP5XAQKGE/</link>
		<comments>http://www.johndcook.com/blog/2013/05/19/prove-or-disprove/#comments</comments>
		<pubDate>Sun, 19 May 2013 17:56:10 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13373</guid>
		<description><![CDATA[From Concrete Mathematics: Incidentally, when we&#8217;re faced with a &#8220;prove or disprove,&#8221; we&#8217;re usually better off trying first to disprove with a counterexample, for two reasons: A disproof is potentially easier (we just need one counterexample); and nit-picking arouses our<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/19/prove-or-disprove/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>From <a href="http://www.amazon.com/gp/product/0201558025/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0201558025&amp;linkCode=as2&amp;tag=theende-20">Concrete Mathematics</a>:</p>
<blockquote><p>Incidentally, when we&#8217;re faced with a &#8220;prove or disprove,&#8221; we&#8217;re usually better off trying first to disprove with a counterexample, for two reasons: A disproof is potentially easier (we just need one counterexample); and nit-picking arouses our creative juices. Even if the given assertion is true, out search for a counterexample often leads us to a proof, as soon as we see why  a counterexample is impossible. Besides, it&#8217;s healthy to be skeptical.</p></blockquote>
<p><a href="http://www.amazon.com/gp/product/0201558025/ref=as_li_ss_il?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0201558025&amp;linkCode=as2&amp;tag=theende-20"><img alt="" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;ASIN=0201558025&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=US&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=theende-20" border="0" /></a><img style="border: none !important; margin: 0px !important;" alt="" src="http://www.assoc-amazon.com/e/ir?t=theende-20&amp;l=as2&amp;o=1&amp;a=0201558025" width="1" height="1" border="0" /></p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/jKDP5XAQKGE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/19/prove-or-disprove/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/19/prove-or-disprove/</feedburner:origLink></item>
		<item>
		<title>Extreme syntax</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/65S9_2v98Cs/</link>
		<comments>http://www.johndcook.com/blog/2013/05/16/extreme-syntax/#comments</comments>
		<pubDate>Thu, 16 May 2013 12:32:56 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13405</guid>
		<description><![CDATA[In his book Let Over Lambda, Doug Hoyte says Lisp is the result of taking syntax away, Perl is the result of taking syntax all the way. Lisp practically has no syntax. It simply has parenthesized expressions. This makes it<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/16/extreme-syntax/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>In his book <a href="http://www.amazon.com/gp/product/1435712757/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1435712757&amp;linkCode=as2&amp;tag=theende-20">Let Over Lambda</a>, Doug Hoyte says</p>
<blockquote><p>Lisp is the result of taking syntax away, Perl is the result of taking syntax all the way.</p></blockquote>
<p>Lisp practically has no syntax. It simply has parenthesized expressions. This makes it very easy to start using the language. And above all, it makes it easy to treat code as data. Lisp macros are very powerful, and these macros are made possible by the fact that the language is simple to parse.</p>
<p>Perl has complex syntax. Some people say it looks like line noise because its liberal use of non-alphanumeric characters as operators. Perl is not easy to parse — there&#8217;s a saying that only Perl can parse Perl — nor is it easy to start using. But the language was <a href="http://www.wall.org/~larry/natural.html">designed</a> for regular users, not beginners, because you spend more time using a language than learning it.</p>
<p>There are reasons I no longer use Perl, but I don&#8217;t object to the rich syntax. Saying Perl is hard to use because of its symbols is like saying Greek is hard to learn because it has a different alphabet. It takes years to master Greek, but you can learn the alphabet in a day. The alphabet is not the hard part.</p>
<p>Symbols can make text more expressive. If you&#8217;ve ever tried to read mathematics from the 18th or 19th century, you&#8217;ll see what I mean. Before the 20th century, math publications were very verbose. It might take a paragraph to say what would now be said in a single equation. In part this is because notation has developed and standardized over time. Also, it is now much easier to typeset the symbols someone would use in handwriting. Perl&#8217;s repertoire of symbols is parsimonious compared to mathematics.</p>
<p>I imagine that programming languages will gradually expand their range of symbols.</p>
<p>People joke about how unreadable Perl code is, but I think a page of well-written Perl is easier to read than a page of well-written Lisp.  At least the Perl is easier to scan: Lisp&#8217;s typographical monotony makes it hard to skim for landmarks. One might argue that a page of Lisp can accomplish more than a page of Perl, and that may be true, but that&#8217;s another topic.</p>
<p style="text-align: center;">***</p>
<p>Any discussion of symbols and programming languages must mention APL. This language introduced a large number of new symbols and never gained wide acceptance. I don&#8217;t know that much about APL, but I&#8217;ll give my impression of why I don&#8217;t think APL&#8217;s failure is not proof that programmers won&#8217;t use more symbols.</p>
<p>APL required a special keyboard to input. That would no longer be necessary. APL also introduced a new programming model; the language would have been hard to adopt even without the special symbols. Finally, APL&#8217;s symbols were completely unfamiliar and introduced all at once, unlike math notation that developed world-wide over centuries.</p>
<p style="text-align: center;">***</p>
<p>What if programming notation were more like music notation? Music notation is predominately non-verbal, but people learn to read it fluently with a little training. And it expresses concurrency very easily. Or maybe programs could look more like choral music, a mixture of symbols and prose.</p>
<p><a href="http://www.amazon.com/gp/product/1435712757/ref=as_li_ss_il?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1435712757&amp;linkCode=as2&amp;tag=theende-20"><img alt="" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;ASIN=1435712757&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=US&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=theende-20" border="0" /></a><img style="border: none !important; margin: 0px !important;" alt="" src="http://www.assoc-amazon.com/e/ir?t=theende-20&amp;l=as2&amp;o=1&amp;a=1435712757" width="1" height="1" border="0" /></p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/65S9_2v98Cs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/16/extreme-syntax/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/16/extreme-syntax/</feedburner:origLink></item>
		<item>
		<title>Wooden cash register</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/b6mPLk3Ccps/</link>
		<comments>http://www.johndcook.com/blog/2013/05/14/wooden-cash-register/#comments</comments>
		<pubDate>Tue, 14 May 2013 18:30:06 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13399</guid>
		<description><![CDATA[Cash register at Catalina Coffee: It&#8217;s a wooden frame for an iPad. The cashier flips the top over to let customers paying with a credit card to sign. Register frame created by Tinkering Monkey.]]></description>
				<content:encoded><![CDATA[<p>Cash register at <a href="http://catalinacoffeeshop.com/">Catalina Coffee</a>:</p>
<p><img class="alignnone" alt="" src="http://www.johndcook.com/cash_register1.jpg" width="420" height="343" /></p>
<p>It&#8217;s a wooden frame for an iPad. The cashier flips the top over to let customers paying with a credit card to sign.</p>
<p><img class="alignnone" alt="" src="http://www.johndcook.com/cash_register2.jpg" width="420" height="332" /></p>
<p>Register frame created by <a href="http://www.tinkeringmonkey.com/">Tinkering Monkey</a>.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/b6mPLk3Ccps" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/14/wooden-cash-register/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/14/wooden-cash-register/</feedburner:origLink></item>
		<item>
		<title>Synchronizing cicadas with Python</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/zgKOCLXW3jA/</link>
		<comments>http://www.johndcook.com/blog/2013/05/14/synchronizing-cicadas-with-python/#comments</comments>
		<pubDate>Tue, 14 May 2013 13:17:06 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Number theory]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13397</guid>
		<description><![CDATA[Suppose you want to know when your great-grandmother was born. You can&#8217;t find the year recorded anywhere. But you did discover an undated letter from her father that mentions her birth and one curious detail:  the 13-year and 17-year cicadas<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/14/synchronizing-cicadas-with-python/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Suppose you want to know when your great-grandmother was born. You can&#8217;t find the year recorded anywhere. But you did discover an undated letter from her father that mentions her birth and one curious detail:  the 13-year and 17-year cicadas were swarming.</p>
<p>You do a little research and find that the 13-year cicadas are supposed to come out next year, and that the 17-year cicadas came out last year. When was your great-grandmother born?</p>
<p>Since 13 and 17 are relatively prime, the 13-year and 17-year cicadas will synchronize their schedules every 13 × 17 = 221 years. Suppose your great-grandmother was born <em>n</em> years ago. The remainder when <em>n</em> is divided by 13 must be 12, and the remainder when <em>n</em> is divided by 17 must be 1. We have to solve the pair of congruences <em>n</em> = 12 mod 13 and <em>n</em> = 1 mod 17. The Chinese Remainder Theorem says that this pair of congruences has a solution, and the proof of the theorem suggests an algorithm for computing the solution.</p>
<p>The Python library SymPy has a function for solving linear congruences.</p>
<pre>&gt;&gt;&gt; from sympy.ntheory.modular import solve_congruence
&gt;&gt;&gt; solve_congruence( (12, 13), (1, 17) )
(103, 221)</pre>
<p>This says we&#8217;re 103 years into the joint cycle of the 13-year and 17-year cicadas. So your great-grandmother was born 103 years ago. (The solution 324 = 103 + 221 is also mathematically possible, but not biologically possible.)</p>
<p>You can use the same SymPy function to solve systems of more congruences. For example, when is the next year in which there will be summer Olympic games and the 13-year and and 17-year cicadas will swarm? Here are a couple ways to approach this. First, you could find the <em>last</em> time this happened, then find when it will happen next. You&#8217;d need to solve <em>n</em> = 1 mod 4 (since we had summer Olympics last year) and  <em>n</em> = 12 mod 13 and <em>n</em> = 1 mod 17.</p>
<pre>&gt;&gt;&gt; solve_congruence( (1, 4), (12, 13), (1, 17) )
(545, 884)</pre>
<p>So the cicadas and the summer Olympics were in sync 545 years ago. (Well, they would have been if the modern Olympics had existed in the middle ages.) This says they&#8217;ll be in sync again in 885 &#8211; 545 = 339 years.</p>
<p>Here&#8217;s a more direct approach. We want to know when the summer Olympics will be 3 years ahead of where they are now in the cycle, when the 13-year cicadas will be 1 year ahead, and the 17-year cicadas will be 16 years ahead.</p>
<pre>&gt;&gt;&gt; solve_congruence( (3, 4), (1, 13), (16, 17) )
(339, 884)</pre>
<p>By the way, you can use negative integers with the congruences, so you could have used (-1, 17) to say the 17-year cicadas will be 1 year back instead of 16 years ahead in their cycle.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/zgKOCLXW3jA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/14/synchronizing-cicadas-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/14/synchronizing-cicadas-with-python/</feedburner:origLink></item>
		<item>
		<title>Searching for Perrin pseudoprimes</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/LUszif5aD0k/</link>
		<comments>http://www.johndcook.com/blog/2013/05/14/searching-for-perrin-pseudoprimes/#comments</comments>
		<pubDate>Tue, 14 May 2013 11:02:31 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Number theory]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13394</guid>
		<description><![CDATA[A week ago I wrote about Perrin numbers, numbers Pn defined by a recurrence relation similar to Fibonacci numbers. If n is prime, Pn mod n = 0, and the converse is nearly always true. That is, if  Pn mod<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/14/searching-for-perrin-pseudoprimes/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.johndcook.com/blog/2013/05/07/almost-if-and-only-if/">A week ago</a> I wrote about Perrin numbers, numbers <em>P</em><sub><em>n</em></sub> defined by a recurrence relation similar to Fibonacci numbers. If <em>n</em> is prime, <em>P</em><sub><em>n</em></sub> mod <em>n</em> = 0, and the converse is nearly always true. That is, if  <em>P</em><sub><em>n</em></sub> mod <em>n</em> = 0, <em>n</em> is <strong>usually</strong> prime. The exceptions are called Perrin pseudoprimes.</p>
<p>Matt McIrvin wrote an excellent <a href="https://plus.google.com/u/0/100452847199780289157/posts/MGrzAkwtjdA">post</a> explaining how to compute Perrin pseudoprimes. Here I&#8217;m just going to elaborate on a couple points in his post.</p>
<p>Matt&#8217;s first point is that if you want to search for Perrin pseudoprimes, the most direct approach won&#8217;t get you very far. The obvious thing to do is compute <em>P</em><sub><em>n</em></sub> and then see whether it has remainder 0 when you divide by <em>n</em>. The problem is that <em>P</em><sub><em>n</em></sub> grows exponentially with n. In fact, <em>P</em><sub><em>n</em></sub> is approximately ρ<sup>n</sup> where ρ = 1.3247… is the <a href="http://en.wikipedia.org/wiki/Plastic_number">plastic number</a>. This means that <em>P</em><sub><em>n</em></sub> has about <em>n</em> log<sub>10</sub> ρ digits. So searching for pseudoprimes less than one billion would require working with numbers with over 100,000,000 digits. This can be done, but it&#8217;s slow and unnecessary.</p>
<p>Since the goal is to compute <em>P</em><sub><em>n</em></sub> mod <em>n</em> rather than <em>P</em><sub><em>n</em></sub> <em>per se</em>, we can carry out all calculations mod <em>n</em> and avoid extended precision arithmetic as long as <em>n</em> itself can fit in an ordinary precision integer. If we want to find pseudoprimes less than one billion, we calculate <em>P</em><sub><em>n</em></sub> mod <em>n</em> for each <em>n</em> up to <em>N</em> = 10<sup>9</sup>. This only requires ordinary arithmetic.</p>
<p>However, this approach takes O(<em>N</em><sup>2</sup>) time unless we&#8217;re clever. We have to compute <em>P</em><sub><em>n</em></sub> mod <em>n</em> separately for each <em>n</em>, and the most direct approach takes <em>n</em> steps. This leads to Matt&#8217;s second point: use matrix multiplication (mod <em>n</em>) to calculate <em>P</em><sub><em>n</em></sub> mod <em>n</em>. This requires calculating the <em>n</em>th power of a 3×3 matrix, which can be done in O(log <em>n</em>) time using <a href="http://www.johndcook.com/blog/2008/12/10/fast-exponentiation/">fast exponentiation</a>. This makes the search for pseudoprimes less than <em>N</em> require O(<em>N</em> log <em>N</em>) rather than O(<em>N</em><sup>2</sup>) time. This is enough to make the search for pseudoprimes less than a billion practical.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/LUszif5aD0k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/14/searching-for-perrin-pseudoprimes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/14/searching-for-perrin-pseudoprimes/</feedburner:origLink></item>
		<item>
		<title>Looking in both directions</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/FJx_we-9sc0/</link>
		<comments>http://www.johndcook.com/blog/2013/05/13/looking-in-both-direction/#comments</comments>
		<pubDate>Mon, 13 May 2013 19:32:42 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13389</guid>
		<description><![CDATA[From David Mumford&#8217;s May 2013 interview in SIAM News: The applied mathematician has the difficult job of looking at a problem in context with no explicit mathematics and trying to see what kinds of mathematical ideas are under the surface<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/13/looking-in-both-direction/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>From David Mumford&#8217;s May 2013 interview in SIAM News:</p>
<blockquote><p>The applied mathematician has the difficult job of looking at a problem in context with no explicit mathematics and trying to see what kinds of mathematical ideas are under the surface that could clarify the situation. I think the most successful applied mathematicians are those who <strong>look in both directions</strong>, at the science and the math.</p>
<p>You can&#8217;t become too attached to one way of looking at things. Applied math has always rejuvenated pure, and theorems in pure math can unexpectedly lead to new tools with vast applications.</p></blockquote>
<p>Emphasis added. I wish Mumford had said &#8220;at the <em>problem</em> and at the math&#8221; because not all applications of math are scientific.</p>
<p><strong>Related posts</strong>:</p>
<p><a href="http://www.johndcook.com/blog/2012/08/28/hard-analysis-soft-analysis/">Hard analysis, soft analysis</a><br />
<a href="http://www.johndcook.com/blog/2011/06/15/impure-math/">Impure math</a></p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/FJx_we-9sc0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/13/looking-in-both-direction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/13/looking-in-both-direction/</feedburner:origLink></item>
		<item>
		<title>Dogfooding</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/CtZSvRW1z1Q/</link>
		<comments>http://www.johndcook.com/blog/2013/05/13/dogfooding/#comments</comments>
		<pubDate>Mon, 13 May 2013 13:44:42 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quality]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13336</guid>
		<description><![CDATA[Dogfooding refers companies using their own software. According to Wikipedia, In 1988, Microsoft manager Paul Maritz sent Brian Valentine, test manager for Microsoft LAN Manager, an email titled &#8220;Eating our own Dogfood&#8221;, challenging him to increase internal usage of the<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/13/dogfooding/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Dogfooding refers companies using their own software. According to <a href="http://en.wikipedia.org/wiki/Eating_your_own_dog_food">Wikipedia</a>,</p>
<blockquote><p>In 1988, Microsoft manager Paul Maritz sent Brian Valentine, test manager for Microsoft LAN Manager, an email titled &#8220;Eating our own Dogfood&#8221;, challenging him to increase internal usage of the company&#8217;s product. From there, the usage of the term spread through the company.</p></blockquote>
<p>Dogfooding is a great idea, but it&#8217;s no substitute for usability testing. I get the impression that some products, if they&#8217;re tested at all, are tested by developers intimately familiar with how they&#8217;re intended to be used.</p>
<p>If your company is developing consumer software, it&#8217;s not dogfooding if just the developers use it. It&#8217;s dogfooding when people in sales and accounting use it. But that&#8217;s still no substitute for getting people outside the company to use it.</p>
<p>Dogfooding doesn&#8217;t just apply to software development. Whenever I buy something with inscrutable assembly instructions, I wonder why the manufacturer didn&#8217;t pay a couple people off the street to put the thing together on camera.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/CtZSvRW1z1Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/13/dogfooding/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/13/dogfooding/</feedburner:origLink></item>
		<item>
		<title>NYT Book of Mathematics</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/8xyMPolZ-JM/</link>
		<comments>http://www.johndcook.com/blog/2013/05/13/nyt-book-of-mathematics/#comments</comments>
		<pubDate>Mon, 13 May 2013 11:00:49 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13375</guid>
		<description><![CDATA[Today&#8217;s newspaper may be interesting because it reports new information. Newspapers from decades ago may be interesting for different reasons, not for the explicit content but for the implicit content. What were the contemporary reactions to what&#8217;s now well known?<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/13/nyt-book-of-mathematics/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Today&#8217;s newspaper may be interesting because it reports new information.</p>
<p>Newspapers from decades ago may be interesting for different reasons, not for the explicit content but for the implicit content. What were the contemporary reactions to what&#8217;s now well known? What were the readers expected to know and not know? To be impressed by?</p>
<p>But the newspapers in between are not so interesting. They&#8217;re not news and they&#8217;re not history.</p>
<p>The New York Times has just published their <a id="static_txt_preview" href="http://www.amazon.com/gp/product/1402793227/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1402793227&amp;linkCode=as2&amp;tag=theende-20" target="_blank">Book of Mathematics</a>, a collection of over 100 math articles written from 1892 to 2010. Most of the articles are toward the 2010 end of the timeline. I found most of the articles to be old news but not old enough to be historically interesting.</p>
<p>However, I&#8217;m a professional mathematician, and these articles were written for a popular audience. The intended audience for the original articles, as well as the new compilation, would probably enjoy the book more. On the other hand, these are newspaper articles: lots of text, no color, and few illustrations. People who read popular math books might have less patience for this book.</p>
<p>One of the articles I did enjoy was &#8220;The Electronic Digital Computer: How It Started, How It Works and What It Does&#8221; from 1967. It&#8217;s the longest article in the book at 20 pages, and goes into some depth. Of course parts of it are also quaint.</p>
<p>I also enjoyed &#8220;A Soviet Discovery Rocks World of Mathematics&#8221; from 1979. It&#8217;s jarring now to hear the adjective &#8220;Soviet&#8221; applied to a mathematical result, but I assume this was not remarkable at the time. The article is about Khachiyan&#8217;s discovery of the first polynomial time algorithm for solving linear programming problems. The algorithm was impractical but groundbreaking. It quickly led to new algorithms that were efficient in theory and in practice. The article has a hint of panic between the lines, something like the reaction to Sputnik but to a lesser degree.</p>
<p style="text-align: center;">***</p>
<p><a href="http://andrewgelman.com/2013/05/05/the-new-york-times-book-of-mathematics/">Andrew Gelman</a> wrote a short review of this book on his blog a few days ago. I put off reading his review until I had written my own above. His reaction was similar to mine:</p>
<blockquote><p>… Fun for the math content and historical/nostalgia value. … I have too much of a technical bent to be the ideal reader for this sort of book, but it seems like an excellent gift for a non-technical reader who nonetheless enjoys math. … My own preference would have been … more old stuff.</p></blockquote>
<p>&nbsp;</p>
<p><a href="http://www.amazon.com/gp/product/1402793227/ref=as_li_ss_il?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1402793227&amp;linkCode=as2&amp;tag=theende-20"><img alt="" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;ASIN=1402793227&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=US&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=theende-20" border="0" /></a><img style="border: none !important; margin: 0px !important;" alt="" src="http://www.assoc-amazon.com/e/ir?t=theende-20&amp;l=as2&amp;o=1&amp;a=1402793227" width="1" height="1" border="0" /></p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/8xyMPolZ-JM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/13/nyt-book-of-mathematics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/13/nyt-book-of-mathematics/</feedburner:origLink></item>
		<item>
		<title>Efficiency vs. Robustness</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/2WftNSdz4q0/</link>
		<comments>http://www.johndcook.com/blog/2013/05/10/efficiency-vs-robustness/#comments</comments>
		<pubDate>Fri, 10 May 2013 12:31:21 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13371</guid>
		<description><![CDATA[Something is efficient if it performs optimally under ideal circumstances. Something is robust if it performs pretty well under less than ideal circumstances. Life is full of trade-offs between efficiency and robustness. Over time, I&#8217;ve come to place more weight<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/10/efficiency-vs-robustness/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Something is <strong>efficient</strong> if it performs optimally under ideal circumstances.</p>
<p>Something is <strong>robust</strong> if it performs pretty well under less than ideal circumstances.</p>
<p>Life is full of trade-offs between efficiency and robustness. Over time, I&#8217;ve come to place more weight on the robustness side of the trade-off. I imagine that&#8217;s typical. With more experience, you become more willing to concede that you haven&#8217;t thought of everything that could happen. After a while, you notice that events with a &#8220;one in a million&#8221; chance of occurring happen much more often than predicted.</p>
<p><strong>Robust things are often more efficient than efficient things are robust</strong>. That is, robust strategies often do fairly well under ideal circumstances. You may not give up much efficiency for robustness. But efficient strategies can fail spectacularly when the assumptions they&#8217;re based on don&#8217;t hold.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/2WftNSdz4q0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/10/efficiency-vs-robustness/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/10/efficiency-vs-robustness/</feedburner:origLink></item>
		<item>
		<title>Asteroids can have moons</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/it1SNGHf5-M/</link>
		<comments>http://www.johndcook.com/blog/2013/05/09/asteroids-can-have-moons/#comments</comments>
		<pubDate>Fri, 10 May 2013 01:56:22 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13369</guid>
		<description><![CDATA[This afternoon my postman delivered a review copy of The Space Book by Jim Bell. This is the latest book in a series that includes Cliff Pickover&#8217;s math, physics, and medical books. Like the other books in the series, The<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/09/asteroids-can-have-moons/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>This afternoon my postman delivered a review copy of <a href="http://www.amazon.com/gp/product/1402780710/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1402780710&amp;linkCode=as2&amp;tag=theende-20">The Space Book</a> by Jim Bell. This is the latest book in a series that includes Cliff Pickover&#8217;s <a href="http://www.amazon.com/gp/product/1402788290/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1402788290&amp;linkCode=as2&amp;tag=theende-20">math</a>, <a href="http://www.amazon.com/gp/product/1402778619/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1402778619&amp;linkCode=as2&amp;tag=theende-20">physics</a>, and <a href="http://www.amazon.com/gp/product/1402785852/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1402785852&amp;linkCode=as2&amp;tag=theende-20">medical</a> books. Like the other books in the series, The Space Book alternates one-page articles and full-page color images.</p>
<p>Here&#8217;s something I learned while skimming through the book: Asteroids can have moons. (That&#8217;s the title of the article on page 414.) This has been known since the early 1990&#8242;s, but it&#8217;s news to me.</p>
<p>The first example discovered was a satellite now named Dactyl orbiting the asteroid 243 Ida. The Space Book says Dactyl was discovered in 1992. Wikipedia says Dactyl was photographed by the Galileo spacecraft in 1993 and discovered by examining the photos in February of 1994. Since that time, &#8220;more than 220 minor planet moons have been found.&#8221;</p>
<p><a href="http://www.amazon.com/gp/product/1402780710/ref=as_li_ss_il?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1402780710&amp;linkCode=as2&amp;tag=theende-20"><img alt="" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;ASIN=1402780710&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=US&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=theende-20" border="0" /></a><img style="border: none !important; margin: 0px !important;" alt="" src="http://www.assoc-amazon.com/e/ir?t=theende-20&amp;l=as2&amp;o=1&amp;a=1402780710" width="1" height="1" border="0" /></p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/it1SNGHf5-M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/09/asteroids-can-have-moons/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/09/asteroids-can-have-moons/</feedburner:origLink></item>
		<item>
		<title>Mutually odd functions</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/zWg7JUN8tbQ/</link>
		<comments>http://www.johndcook.com/blog/2013/05/09/mutually-odd-functions/#comments</comments>
		<pubDate>Fri, 10 May 2013 00:05:16 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13363</guid>
		<description><![CDATA[The floor of a real number x is the largest integer n ≤ x, written ⌊x⌋. The ceiling of a real number x is the smallest integer n ≥ x, written ⌈x⌉. The floor and ceiling have the following symmetric<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/09/mutually-odd-functions/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>The floor of a real number <em>x</em> is the largest integer <em>n ≤ x</em>, written ⌊x⌋.</p>
<p>The ceiling of a real number <em>x</em> is the smallest integer <em>n ≥ x</em>, written ⌈x⌉.</p>
<p>The floor and ceiling have the following symmetric relationship:</p>
<p style="padding-left: 30px;">⌊-<em>x</em>⌋ = -⌈<em>x</em>⌉<br />
⌈-<em>x</em>⌉ = -⌊<em>x</em>⌋</p>
<p>The floor and ceiling functions are not odd, but as a pair they satisfy a generalized parity condition:</p>
<p style="padding-left: 30px;"><em>f</em>(-<em>x</em>) = -<em>g</em>(<em>x</em>)<br />
<em>g</em>(-<em>x</em>) = -<em>f</em>(<em>x</em>)</p>
<p>If the functions f and g are equal, then each is an odd function. But in general f and g could be different, as with floor and ceiling.</p>
<p>Is there an established name for this sort of relation? I thought of &#8220;mutually odd&#8221; because it reminds me of mutual recursion.</p>
<p>Can you think of other examples of mutually odd functions?</p>
<p><strong>Related posts</strong>:</p>
<p><a href="http://www.johndcook.com/blog/2011/03/31/saved-by-symmetry/">Saved by symmetry</a><br />
<a href="http://www.johndcook.com/blog/2011/08/17/odd-numbers-in-odd-bases/">Odd numbers in odd bases</a><br />
<a href="http://www.johndcook.com/blog/2011/08/30/the-power-of-parity/">The power of parity</a></p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/zWg7JUN8tbQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/09/mutually-odd-functions/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/09/mutually-odd-functions/</feedburner:origLink></item>
		<item>
		<title>Almost if and only if</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/gH_lk2Lbug4/</link>
		<comments>http://www.johndcook.com/blog/2013/05/07/almost-if-and-only-if/#comments</comments>
		<pubDate>Tue, 07 May 2013 12:00:24 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Number theory]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13357</guid>
		<description><![CDATA[The Perrin numbers have a definition analogous to Fibonacci numbers. Define P0 = 3, P1 = 0, and P2 = 2. Then for n &#62; 2, define Pn+3 = Pn+1 + Pn+0. The Concrete Tetrahedron says It appears that n<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/07/almost-if-and-only-if/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>The Perrin numbers have a definition analogous to Fibonacci numbers. Define <em>P</em><sub>0</sub> = 3, <em>P</em><sub>1</sub> = 0, and <em>P</em><sub>2</sub> = 2. Then for <em>n</em> &gt; 2, define</p>
<p style="padding-left: 30px;"><em>P</em><sub><em>n</em>+3</sub> = <em>P</em><sub><em>n</em>+1</sub> + <em>P</em><sub><em>n</em>+0</sub>.</p>
<p><a href="http://www.amazon.com/gp/product/3709104440/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=3709104440&amp;linkCode=as2&amp;tag=theende-20">The Concrete Tetrahedron</a> says</p>
<blockquote><p>It appears that <em>n</em> is prime &#8220;almost if and only if&#8221; <em>P</em><sub><em>n</em></sub> mod <em>n</em> = 0.</p></blockquote>
<p>The &#8220;only if&#8221; condition is true without qualification: if <em>n</em> is prime, <em>P</em><sub><em>n</em></sub> mod <em>n</em> = 0. It&#8217;s the &#8220;if&#8221; part that&#8217;s almost true. When <em>P</em><sub><em>n</em></sub> mod <em>n</em> = 0, <em>n</em> is <strong>usually</strong> prime. Composite numbers that satisfy the Perrin condition <em>P</em><sub><em>n</em></sub> mod <em>n</em> = 0 are called Perrin pseudoprimes. The smallest Perrin pseudoprime is 271,441. The next is 904,631.</p>
<p>There are only 17 Perrin pseudoprimes less than a billion. By comparison, there are 50,847,534 primes less than a billion.</p>
<p>So if you used the Perrin condition to test whether numbers less than a billion are prime, you would correctly identify all 50,847,534 primes as primes. But out of the 949,152,466 composite numbers, you would falsely report 17 of these as prime.  In other words, you would be 100% accurate in identifying primes as primes, but only 99.999998% accurate in identifying composite numbers as composite.</p>
<p><strong>Related posts</strong>:</p>
<p><a href="http://www.johndcook.com/blog/2012/01/20/oscillating-fibonacci-ratios/">Oscillating Fibonacci ratios</a><br />
<a href="http://www.johndcook.com/blog/2010/10/06/probability-a-number-is-prime/">Probability that a number is prime</a></p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/gH_lk2Lbug4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/07/almost-if-and-only-if/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/07/almost-if-and-only-if/</feedburner:origLink></item>
		<item>
		<title>Ramanujan approximation for circumference of an ellipse</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/8g67MFSTzRE/</link>
		<comments>http://www.johndcook.com/blog/2013/05/05/ramanujan-circumference-ellipse/#comments</comments>
		<pubDate>Sun, 05 May 2013 17:21:12 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Ramanujan]]></category>
		<category><![CDATA[SciPy]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13340</guid>
		<description><![CDATA[There&#8217;s no elementary formula for the circumference of an ellipse, but there is an elementary approximation that is extremely accurate. An ellipse has equation (x/a)² + (y/b)² = 1. If a = b, the ellipse reduces to a circle and<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/05/05/ramanujan-circumference-ellipse/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>There&#8217;s no elementary formula for the circumference of an ellipse, but there is an elementary approximation that is extremely accurate.</p>
<p>An ellipse has equation (<em>x</em>/<em>a</em>)² + (<em>y</em>/<em>b</em>)² = 1. If <em>a</em> = <em>b</em>, the ellipse reduces to a circle and the circumference is simply 2π<em>a</em>. But the general formula for circumference requires the hypergeometric function <sub>2</sub><em>F</em><sub>1</sub>:</p>
<p style="text-align: center;"><img alt="\setlength\arraycolsep{1pt} \pi (a + b) \,  {}_2 F_1\left(\begin{matrix}-1/2&amp; &amp;-1/2 \\&amp;1&amp; \end{matrix}\middle;\lambda^2\right)" src="http://www.johndcook.com/hypergeometric_ellipse.png" width="227" height="42" /></p>
<p>where  λ = (<em>a</em> &#8211; <em>b</em>)/(<em>a</em> + <em>b</em>).</p>
<p>However, if the ellipse is anywhere near circular, the following approximation due to Ramanujan is extremely good:</p>
<p style="text-align: center;"><img alt="\pi (a + b) \left(1 + \frac{3\lambda^2}{10 + \sqrt{4 - 3\lambda^2}}\right)" src="http://www.johndcook.com/ramanujan_ellipse.png" width="222" height="44" /></p>
<p>To quantify what we mean by extremely good, the error is O(λ<sup>10</sup>). When an ellipse is roughly circular, λ is fairly small, and the error is on the order of λ to the 10th power.</p>
<p>To illustrate the accuracy of the approximation, I tried the formula out on some planets. The error increases with ellipticity, so I took the most most elliptical orbit of a planet or object formerly known as a planet. That distinction belongs to Pluto, in which case λ = 0.016. If Pluto&#8217;s orbit were exactly elliptical, you could use Ramanujan&#8217;s approximation to find the circumference of its orbit with an error less than one micrometer.</p>
<p>Next I tried it on something with a much more elliptical orbit: Halley&#8217;s comet. Its orbit is nearly four times longer than it is wide. For Halley&#8217;s comet, λ = 0.59 and Ramanujan&#8217;s approximation agrees with the exact result to seven significant figures. The exact result is 11,464,319,022 km and the approximation is 11,464,316,437 km.</p>
<p>Here&#8217;s a video showing how elliptical the comet&#8217;s orbit is.</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/L1SycRpYH3k?rel=0" frameborder="0" allowfullscreen></iframe></p>
<p>If you&#8217;d like to experiment with the approximation, here&#8217;s some Python code:</p>
<pre>
from scipy import pi, sqrt
from scipy.special import hyp2f1

def exact(a, b):
    t = ((a-b)/(a+b))**2
    return pi*(a+b)*hyp2f1(-0.5, -0.5, 1, t)

def approx(a, b):
    t = ((a-b)/(a+b))**2
    return pi*(a+b)*(1 + 3*t/(10 + sqrt(4 - 3*t)))

# Semimajor and semiminor axes for Halley's comet orbit
a = 2.667950e9 # km
b = 6.782819e8 # km

print exact(a, b)
print approx(a, b)
</pre>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/8g67MFSTzRE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/05/05/ramanujan-circumference-ellipse/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/05/05/ramanujan-circumference-ellipse/</feedburner:origLink></item>
		<item>
		<title>Recognizing numbers</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/FDq_zj9ihh0/</link>
		<comments>http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/#comments</comments>
		<pubDate>Wed, 01 May 2013 00:32:12 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SymPy]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13333</guid>
		<description><![CDATA[I was playing around with SymPy, a symbolic math package for Python, and ran across nsimplify. It takes a floating point number and tries to simplify it: as a fraction with a small denominator, square root of a small integer,<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I was playing around with SymPy, a symbolic math package for Python, and ran across <code>nsimplify</code>. It takes a floating point number and tries to simplify it: as a fraction with a small denominator, square root of a small integer, an expression involving famous constants, etc.</p>
<p>For example, suppose some calculation returned 4.242640687119286 and you suspect there&#8217;s something special about that number. Here&#8217;s how you might test where it came from.</p>
<pre>&gt;&gt;&gt; from sympy import *
&gt;&gt;&gt; nsimplify(4.242640687119286)
3*sqrt(2)</pre>
<p>Maybe you do a calculation numerically, find a simple expression for the result, and that suggests an analytical solution.</p>
<p>I think a more common application of <code>nsimplify</code> might be to help you remember half-forgotten formulas. For example, maybe you&#8217;re rusty on your trig identities, but you remember that cos(π/6) is something special.</p>
<pre>&gt;&gt;&gt; nsimplify(cos(pi/6))
sqrt(3)/2</pre>
<p>Or to take a more advanced example, suppose that you vaguely remember that the gamma function takes on recognizable values at half integer values, but you don&#8217;t quite remember how. Maybe something involving π or <em>e</em>. You can suggest that <code>nsimplify</code> include expressions with π and <em>e</em> in its search.</p>
<pre>&gt;&gt;&gt; nsimplify(gamma(3.5), constants=[pi, E])
15*sqrt(pi)/8</pre>
<p>You can also give <code>nsimplify</code> a tolerance, asking it to find a simple representation within a neighborhood of the number. For example, here&#8217;s a way to find approximations to π.</p>
<pre>&gt;&gt;&gt; nsimplify(pi, tolerance=1e-5)
355/113</pre>
<p>With a wider tolerance, it will return a simpler approximation.</p>
<pre>&gt;&gt;&gt; nsimplify(pi, tolerance=1e-2)
22/7</pre>
<p>Finally, here&#8217;s higher precision approximation to π that isn&#8217;t exactly simple:</p>
<pre>&gt;&gt;&gt; nsimplify(pi, tolerance=1e-7)
exp(141/895 + sqrt(780631)/895)</pre>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/FDq_zj9ihh0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/</feedburner:origLink></item>
		<item>
		<title>More sides or more dice?</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/XtfS3WJeQ3E/</link>
		<comments>http://www.johndcook.com/blog/2013/04/29/more-sides-or-more-dice/#comments</comments>
		<pubDate>Mon, 29 Apr 2013 16:22:28 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Probability and Statistics]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13327</guid>
		<description><![CDATA[My previous post looked at rolling 5 six-sided dice as an approximation of a normal distribution. If you wanted a better approximation, you could roll dice with more sides, or you could roll more dice. Which helps more? Whether you<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/29/more-sides-or-more-dice/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>My <a href="http://www.johndcook.com/blog/2013/04/29/rolling-dice-for-normal-samples-python-version/">previous post</a> looked at rolling 5 six-sided dice as an approximation of a normal distribution. If you wanted a better approximation, you could roll dice with more sides, or you could roll more dice. Which helps more?</p>
<p>Whether you double the number of sides per die or double the number of dice, you have the same total number of spots possible. But which approach helps more? Here&#8217;s a plot.</p>
<p style="text-align: center;"><img alt="" src="http://www.johndcook.com/sides_vs_dice.png" width="400" height="295" /></p>
<p>We start with 5 six-sided dice and either double the number of sides per die (the blue dots) or double the number of dice (the green triangles). When the number of sides <em>n</em> gets big, it&#8217;s easier to think of a spinner with <em>n</em> equally likely stopping points than an <em>n</em>-sided die.</p>
<p>At first, increasing the number of sides per die reduces the maximum error more than the same increase in the number of dice. But after doubling six times, i.e. increasing by a factor of 64, both approaches have the same error. But further increasing the number of sides per die makes little difference, while continuing to increase the number of dice decreases the error.</p>
<p>The long-term advantage goes to increasing the number of dice. By the central limit theorem, the error will approach zero as the number of dice increases. But with a fixed number of dice, increasing the number of sides only makes each die a better approximation to a uniform distribution. In the limit, your sum approximates a normal distribution no better or worse than the sum of five uniform distributions.</p>
<p>But in the near term, increasing the number of sides helps more than adding more dice. The central limit theorem may guide you to the right answer eventually, but it might mislead you at first.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/XtfS3WJeQ3E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/29/more-sides-or-more-dice/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/29/more-sides-or-more-dice/</feedburner:origLink></item>
		<item>
		<title>Rolling dice for normal samples: Python version</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/upvCMn0BXE4/</link>
		<comments>http://www.johndcook.com/blog/2013/04/29/rolling-dice-for-normal-samples-python-version/#comments</comments>
		<pubDate>Mon, 29 Apr 2013 13:17:49 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Probability and Statistics]]></category>
		<category><![CDATA[SciPy]]></category>
		<category><![CDATA[SymPy]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13309</guid>
		<description><![CDATA[A handful of dice can make a decent normal random number generator, good enough for classroom demonstrations. I wrote about this a while ago. My original post included Mathematica code for calculating how close to normal the distribution of the sum<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/29/rolling-dice-for-normal-samples-python-version/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>A handful of dice can make a decent normal random number generator, good enough for classroom demonstrations. I wrote about this <a href="http://www.johndcook.com/blog/2009/02/10/rolling-dice-for-normal-samples/">a while ago</a>.</p>
<p>My original post included Mathematica code for calculating how close to normal the distribution of the sum of the dice is. Here I&#8217;d like to redo the code in Python to show how to do the same calculations using SymPy. [<strong>Update</strong>: I'll also give a solution that does not use SymPy and that scales much better.]</p>
<p>If you roll five dice and add up the spots, the probability of getting a sum of <em>k</em> is the coefficient of x<sup>k</sup> in the expansion of</p>
<p style="padding-left: 30px;">(<em>x</em> + <em>x</em><sup>2</sup> + <em>x</em><sup>3</sup> + <em>x</em><sup>4</sup> + <em>x</em><sup>5</sup> + <em>x</em><sup>6</sup>)<sup>5</sup> / 6<sup>5</sup>.</p>
<p>Here&#8217;s code to find the probabilities by expanding the polynomial and taking coefficients.</p>
<pre>
from sympy import Symbol

sides = 6
dice = 5
rolls = range( dice*sides + 1 )

# Tell SymPy that we want to use x as a symbol, not a number
x = Symbol('x')

# p(x) = (x + x^2 + ... + x^m)^n
# where m = number of sides per die
# and n = number of dice
p = sum([x**i for i in range(1, sides + 1)])**dice

# Extract the coefficients of p(x) and divide by sides**dice
pmf = [sides**(-dice) * p.expand().coeff(x, i) for i in rolls]
</pre>
<p>If you&#8217;d like to compare the CDF of the dice sum to a normal CDF you could add this.</p>
<pre>
from scipy import array, sqrt
from scipy.stats import norm

cdf = array(pmf).cumsum()

# Normal CDF for comparison
mean = 0.5*(sides + 1)*dice
variance = dice*(sides**2 -1)/12.0
temp = [norm.cdf(i, mean, sqrt(variance)) for i in roles]
norm_cdf = array(temp)

diff = abs(cdf - norm_cdf)
# Print the maximum error and where it occurs
print diff.max(), diff.argmax()
</pre>
<p><strong>Question</strong>: Now suppose you want a better approximation to a normal distribution. Would it be better to increase the number of dice or the number of sides per dice? For example, would you be better off with 10 six-sided dice or 5 twelve-sided dice? Think about it before reading the <a href="http://www.johndcook.com/blog/2013/04/29/more-sides-or-more-dice/">solution</a>.</p>
<p><strong>Update</strong>: The SymPy code does not scale well. When I tried the code with 50 six-sided dice, it ran out of memory. Based on Andre&#8217;s <a href="http://www.johndcook.com/blog/2013/04/29/rolling-dice-for-normal-samples-python-version/comment-page-1/#comment-118236">comment</a>, I rewrote the code using <code>polypow</code>. SymPy offers much more symbolic calculation functionality than NumPy, but in this case NumPy contains all we need. It is much faster and it doesn&#8217;t run out of memory.</p>
<pre>
from numpy.polynomial.polynomial import polypow
from numpy import ones

sides = 6
dice = 100

# Create an array of polynomial coefficients for
# x + x^2 + ... + x^sides
p = ones(sides + 1)
p[0] = 0

# Extract the coefficients of p(x)**dice and divide by sides**dice
pmf = sides**(-dice) * polypow(p, dice)
cdf = pmf.cumsum()
</pre>
<p>That solution works for up to 398 dice. What&#8217;s up with that? With 399 dice, the largest polynomial coefficient overflows. If we divide by the number of dice <em>before</em> raising the polynomial to the power <code>dice</code>, the code becomes a little simpler and scales further.</p>
<pre>
p = ones(sides + 1)
p[0] = 0
p /= sides
pmf = polypow(p, dice)
cdf = pmf.cumsum()
</pre>
<p>I tried this last approach on 10,000 dice with no problem.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/upvCMn0BXE4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/29/rolling-dice-for-normal-samples-python-version/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/29/rolling-dice-for-normal-samples-python-version/</feedburner:origLink></item>
		<item>
		<title>2,000th post</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/lkOPSZOCi5o/</link>
		<comments>http://www.johndcook.com/blog/2013/04/25/2000th-post/#comments</comments>
		<pubDate>Thu, 25 Apr 2013 11:15:49 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13304</guid>
		<description><![CDATA[This is my 2,000th blog post. I&#8217;ve been blogging for a little over five years, writing around a post a day. Thank you all for reading, commenting, sharing, and generally being so encouraging. This post will just be a few<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/25/2000th-post/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>This is my 2,000th blog post. I&#8217;ve been blogging for a little over five years, writing around a post a day. Thank you all for reading, commenting, sharing, and generally being so encouraging. This post will just be a few brief updates.</p>
<h3>Blog upgrade</h3>
<p>I upgraded my blogging software and changed the theme a few weeks ago. The new theme is supposed to be more mobile-friendly. There were a few little problems with the upgrade. I think I&#8217;ve fixed everything by now, though I&#8217;d still like to make a few changes here and there. If you see any problems or have any suggestions, please let me know.</p>
<h3>Consulting</h3>
<p>Going out on my own has been a blast. I&#8217;ve got a few projects going on now and more on the horizon. Really interesting work. As you&#8217;d expect if you&#8217;ve read this blog for a while, the work has been a mixture of math, stats, computing, and writing. I may be hiring a couple people part-time to help me out.</p>
<h3>Google Reader</h3>
<p>If you&#8217;ve subscribed to this blog through Google Reader, remember that Google is going to turn it off July 1. There are many other RSS readers out there. I list a few options <a href="http://www.johndcook.com/blog/2013/03/14/rss-readers-on-linux/">here</a>. My impression is that a lot of the people are moving to <a href="http://www.feedly.com/">Feedly</a> or <a href="http://www.newsblur.com/">NewsBlur</a>.</p>
<h3>Travel</h3>
<p>I plan to visit Tuscaloosa, San Francisco, and Austin in the next few weeks. Let me know if you&#8217;re in one of these areas and would like to get together.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/lkOPSZOCi5o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/25/2000th-post/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/25/2000th-post/</feedburner:origLink></item>
		<item>
		<title>Hacking debt</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/qfDHkY6T85o/</link>
		<comments>http://www.johndcook.com/blog/2013/04/24/hacking-debt/#comments</comments>
		<pubDate>Wed, 24 Apr 2013 12:41:19 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13297</guid>
		<description><![CDATA[The term technical debt describes the accumulated effect of short term decisions in a software development process. In order to meet a deadline, for example, a project will take shortcuts, developing code in a way that&#8217;s not best for future<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/24/hacking-debt/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>The term <em>technical debt</em> describes the accumulated effect of short term decisions in a software development process. In order to meet a deadline, for example, a project will take shortcuts, developing code in a way that&#8217;s not best for future maintainability but that saves time immediately. Once the pressure is off, hopefully, the team goes back and repays the technical debt by refactoring.</p>
<p>I&#8217;d like to propose <em>hacking debt</em> to describe a person who has been focused on &#8220;real work&#8221; for so long that he or she hasn&#8217;t spent enough time playing around, making useless stuff for the fun of it. Some portion of a career should be devoted to hacking. Not 100%, but not 0% either. Without some time spent exploring and having fun, people become less effective and eventually burn out.</p>
<p><strong>Related posts</strong>:</p>
<p><a href="http://www.johndcook.com/blog/2010/03/03/just-in-case-versus-just-in-time/">Just-in-case versus just-in-time</a><br />
<a href="http://www.johndcook.com/blog/2012/08/01/bicycle-skills/">Bicycle skills</a><br />
<a href="http://www.johndcook.com/blog/2013/04/22/playful-and-purposeful-pure-and-applied/">Playful and purposeful, pure and applied</a></p>
<p>For hacking financial debt, see <a href="http://www.johndcook.com/blog/2010/11/02/snowball-strategy/">this</a>.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/qfDHkY6T85o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/24/hacking-debt/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/24/hacking-debt/</feedburner:origLink></item>
		<item>
		<title>Bad normal approximation</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/IdTopaB-rSg/</link>
		<comments>http://www.johndcook.com/blog/2013/04/23/bad-normal-approximation/#comments</comments>
		<pubDate>Tue, 23 Apr 2013 20:59:43 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Probability and Statistics]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13292</guid>
		<description><![CDATA[Sometimes you can approximate a binomial distribution with a normal distribution. Under the right conditions, a Binomial(n, p) has approximately the distribution of a normal with the same mean and variance, i.e. mean np and variance np(1-p). The approximation works<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/23/bad-normal-approximation/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Sometimes you can approximate a binomial distribution with a normal distribution. Under the right conditions, a Binomial(<em>n</em>, <em>p</em>) has approximately the distribution of a normal with the same mean and variance, i.e. mean <em>np</em> and variance <em>np</em>(1-<em>p</em>). The approximation works best when <em>n</em> is large and <em>p</em> is near 1/2.</p>
<p>This afternoon I was reading a paper that used a normal approximation to a binomial when <em>n</em> was around 10 and <em>p</em> around 0.001.  The relative error was enormous. The paper used the approximation to find an analytical expression for something else and the error propagated.</p>
<p><strong>A common rule of thumb</strong> is that the normal approximation works well when <em>np</em> &gt; 5 and <em>n</em>(1-<em>p</em>) &gt; 5.  This says that the closer <em>p</em> is to 0 or 1, the larger <em>n</em> needs to be. In this case <em>p</em> was very small, but <em>n</em> was not large enough to compensate since <em>np</em> was on the order of 0.01, far less than 5.</p>
<p><strong>Another rule of thumb</strong> is that normal approximations in general hold well near the center of the distribution but not in the tails. In particular the <em>relative</em> error in the tails can be unbounded. This paper was looking out toward the tails, and relative error mattered.</p>
<p>For more details, see these notes on the <a href="http://www.johndcook.com/normal_approx_to_binomial.html">normal approximation to the binomial</a>.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/IdTopaB-rSg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/23/bad-normal-approximation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/23/bad-normal-approximation/</feedburner:origLink></item>
		<item>
		<title>Why j for imaginary unit?</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/YjT1xQIWgQI/</link>
		<comments>http://www.johndcook.com/blog/2013/04/23/why-j-for-imaginary-unit/#comments</comments>
		<pubDate>Tue, 23 Apr 2013 11:56:54 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13286</guid>
		<description><![CDATA[Electrical engineers use j for the square root of -1 while nearly everyone else uses i. The usual explanation is that EE&#8217;s do this because they use i for current. But here&#8217;s one advantage to using j that has nothing<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/23/why-j-for-imaginary-unit/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Electrical engineers use <em>j</em> for the square root of -1 while nearly everyone else uses <em>i</em>. The usual explanation is that EE&#8217;s do this because they use <em>i</em> for current. But here&#8217;s one advantage to using <em>j</em> that has nothing to do with electrical engineering.</p>
<p>The symbols <strong>i</strong>, <strong>j</strong>, and <strong>k</strong> are used for unit vectors in the directions of the <em>x</em>, <em>y</em>, and <em>z</em> axes respectively. That means that &#8220;i&#8221; has two different meanings in the real plane, depending on whether you think of it as the vector space spanned by <strong>i</strong> and <strong>j</strong> or as complex numbers. But if you use <em>j</em> to represent the imaginary unit, its meaning does not change. Either way it points along the <em>y</em> axis.</p>
<p>Said another way, bold face <strong>i </strong>and italic <em>i</em> point in different directions But bold face <strong>j</strong> and italic <em>j</em> both point in the same direction.</p>
<p>Here&#8217;s what moving from vectors to complex numbers looks like in math notation:</p>
<p><img alt="" src="http://www.johndcook.com/mathvc.png" width="505" height="256" /></p>
<p>And here&#8217;s what it looks like in electrical engineering notation:</p>
<p><img itemprop="image" alt="" src="http://www.johndcook.com/eevc.png" width="533" height="256" /></p>
<p>I don&#8217;t expect math notation to change, nor would I want it to. I&#8217;m happy with <em>i</em>. But using <em>j</em> might make moving between vectors and complex numbers a little easier.</p>
<p style="text-align: center;">***</p>
<p>By the way, I use <em>j</em> on <a href="https://twitter.com/DSP_fact">@DSP_fact</a>. DSP came out of electrical engineering, so <em>j</em> is conventional there. I also use <em>j</em> in Python because that&#8217;s what the language requires.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/YjT1xQIWgQI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/23/why-j-for-imaginary-unit/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/23/why-j-for-imaginary-unit/</feedburner:origLink></item>
		<item>
		<title>Playful and purposeful, pure and applied</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/cm2HBz2DDi8/</link>
		<comments>http://www.johndcook.com/blog/2013/04/22/playful-and-purposeful-pure-and-applied/#comments</comments>
		<pubDate>Mon, 22 Apr 2013 18:56:17 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Creativity]]></category>
		<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13284</guid>
		<description><![CDATA[From Edwin Land, inventor of the Polaroid camera: &#8230; applied science, purposeful and determined, and pure science, playful and freely curious, continuously support and stimulate each other. The great nation of the future will be the one which protects the<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/22/playful-and-purposeful-pure-and-applied/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>From Edwin Land, inventor of the Polaroid camera:</p>
<blockquote><p>&#8230; applied science, purposeful and determined, and pure science, playful and freely curious, continuously support and stimulate each other. The great nation of the future will be the one which protects the freedom of pure science as much as it encourages applied science.</p></blockquote>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/cm2HBz2DDi8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/22/playful-and-purposeful-pure-and-applied/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/22/playful-and-purposeful-pure-and-applied/</feedburner:origLink></item>
		<item>
		<title>Quotation and endorsement</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/ijTMO3V-neI/</link>
		<comments>http://www.johndcook.com/blog/2013/04/21/quotation-and-endorsement/#comments</comments>
		<pubDate>Sun, 21 Apr 2013 17:15:41 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Quotes]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13282</guid>
		<description><![CDATA[I like sharing quotes on Twitter. Occasionally a quote will provoke an angry reaction, not to the content of the quote but to the source. Sometimes people will even acknowledge that they agree with the quote, but are dismayed that<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/21/quotation-and-endorsement/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I like sharing quotes on Twitter. Occasionally a quote will provoke an angry reaction, not to the content of the quote but to the source. Sometimes people will even acknowledge that they agree with the quote, but are dismayed that I would quote such a despicable person.</p>
<p>This morning I was reading <a href="http://www.amazon.com/gp/product/1592441548/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1592441548&amp;linkCode=as2&amp;tag=theende-20">Norman Geisler&#8217;s book on Thomas Aquinas</a> and these lines reminded me of the brouhaha over quotes and sources.</p>
<blockquote><p>No, I do not agree with everything he [Aquinas] ever wrote. On the other hand, neither do I agree with everything <em>I</em> ever wrote.</p></blockquote>
<p>I&#8217;d say along with Geisler that if I could only quote people I completely agreed with, I could not even quote myself.</p>
<p>Geisler goes on to say</p>
<blockquote><p>But seven hundred years from now no one will even recognize my name, while Aquinas&#8217; works will still be used with great profit.</p></blockquote>
<p>I feel the same way about many of the people I quote. I remember catching flak for quoting Martin Luther. I&#8217;ve already forgotten the critic&#8217;s name, and he&#8217;s probably forgotten mine, but people will still be reading Luther in another five hundred years.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/ijTMO3V-neI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/21/quotation-and-endorsement/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/21/quotation-and-endorsement/</feedburner:origLink></item>
		<item>
		<title>Moments of mixtures</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/_BsmKENbeTc/</link>
		<comments>http://www.johndcook.com/blog/2013/04/18/moments-of-mixtures-skewness-kurtosis/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 16:10:15 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Probability and Statistics]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13271</guid>
		<description><![CDATA[I needed to compute the higher moments of a mixture distribution for a project I&#8217;m working on. I&#8217;m writing up the code here in case anyone else finds this useful. (And in case I&#8217;ll find it useful in the future.)<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/18/moments-of-mixtures-skewness-kurtosis/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I needed to compute the higher moments of a mixture distribution for a project I&#8217;m working on. I&#8217;m writing up the code here in case anyone else finds this useful. (And in case I&#8217;ll find it useful in the future.) I&#8217;ll include the central moments first. From there it&#8217;s easy to compute skewness and kurtosis.</p>
<p>Suppose <em>X</em> is a mixture of <em>n</em> random variables <em>X</em><sub><em>i</em></sub> with weights <em>w</em><sub><em>i</em></sub>, non-negative numbers adding to 1. Then the <em>j</em>th central moment of <em>X</em> is given by</p>
<p style="text-align: center;"><img alt="E[(X - \mu)^j] = \sum_{i=1}^n \sum_{k=0}^j {j \choose k} (\mu_i - \mu)^{j-k} w_i E[(X_i- \mu_i)^k]" src="http://www.johndcook.com/mixture_moments.png" width="387" height="51" /></p>
<p>where μ<sub><em>i</em></sub> is the mean of <em>X</em><sub><em>i</em></sub>.</p>
<p>In my particular application, I&#8217;m interested in a mixture of normals and so the code below computes the moments for a mixture of normals. It could easily be modified for other distributions.</p>
<pre>
from scipy.misc import factorialk, comb

def mixture_central_moment(mixture, moment):

    '''Compute the higher moments of a mixture of normal rvs.
    mixture is a list of (mu, sigma, weight) triples.
    moment is the central moment to compute.'''

    mix_mean = sum( [w*m for (m, s, w) in mixture] )

    mixture_moment = 0.0
    for triple in mixture:
        mu, sigma, weight = triple
        for k in range(moment+1):
            prod = comb(moment, k) * (mu-mix_mean)**(moment-k)
            prod *= weight*normal_central_moment(sigma, k)
            mixture_moment += prod

    return mixture_moment


def normal_central_moment(sigma, moment):

    '''Central moments of a normal distribution'''

    if moment % 2 == 1:
        return 0.0
    else:
        # If Z is a std normal and n is even, E(Z^n) == (n-1)!!
        # So E (sigma Z)^n = sigma^n (n-1)!!
        return sigma**moment * factorialk(moment-1, 2)
</pre>
<p>Once we have code for central moments, it&#8217;s simple to add code for computing skewness and kurtosis.</p>
<pre>
def mixture_skew(mixture):

    variance = mixture_central_moment(mixture, 2)
    third = mixture_central_moment(mixture, 3)
    return third / variance**(1.5)

def mixture_kurtosis(mixture):

    variance = mixture_central_moment(mixture, 2)
    fourth = mixture_central_moment(mixture, 4)
    return fourth / variance**2 - 3.0
</pre>
<p>Here&#8217;s an example of how the code might be used.</p>
<pre>
# Test on a mixture of 30% Normal(-2, 1) and 70% Normal(1, 3)
mixture = [(-2, 1, 0.3), (1, 3, 0.7)]

print "Skewness = ", mixture_skew(mixture)
print "Kurtosis = ", mixture_kurtosis(mixture)
</pre>
<p><strong>Related post</strong>: <a href="http://www.johndcook.com/blog/2012/11/06/general-formula-for-normal-moments/">General formula for normal moments</a></p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/_BsmKENbeTc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/18/moments-of-mixtures-skewness-kurtosis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/18/moments-of-mixtures-skewness-kurtosis/</feedburner:origLink></item>
		<item>
		<title>New Twitter accounts for DSP and music theory</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/XouJWtTeQXs/</link>
		<comments>http://www.johndcook.com/blog/2013/04/16/new-twitter-accounts-for-dsp-and-music-theory/#comments</comments>
		<pubDate>Tue, 16 Apr 2013 13:16:56 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13267</guid>
		<description><![CDATA[I&#8217;ve started two new Twitter accounts this week: @DSP_fact and @MusicTheoryTip. DSP_fact is for DSP, digital signal processing: filters, Fourier analysis, convolution, sampling, wavelets, etc. MusicTheoryTip is for basic music theory with a little bias toward jazz. It&#8217;ll tweet about<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/16/new-twitter-accounts-for-dsp-and-music-theory/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve started two new Twitter accounts this week: <strong>@DSP_fact</strong> and <strong>@MusicTheoryTip</strong>.</p>
<p><a href="https://twitter.com/DSP_fact">DSP_fact</a> is for DSP, digital signal processing: filters, Fourier analysis, convolution, sampling, wavelets, etc.</p>
<p><a href="https://twitter.com/MusicTheoryTip">MusicTheoryTip</a> is for basic music theory with a little bias toward jazz. It&#8217;ll tweet about harmony, scales, tuning, notation, etc.</p>
<p>Here&#8217;s a full list of my <a href="http://www.johndcook.com/twitter/">15 daily tip twitter accounts</a>.</p>
<p>If you&#8217;re interested in one of these accounts but don&#8217;t use Twitter, you can <a href="http://www.johndcook.com/blog/2011/05/18/subscribe-twitter-rss/">subscribe to a Twitter account via RSS</a> just as you&#8217;d subscribe to a blog.</p>
<p>If you&#8217;re using Google Reader to subscribe to RSS feeds, you&#8217;ll need to switch to something else by July 1. Here are <a href="http://www.johndcook.com/blog/2013/03/14/rss-readers-on-linux/">18 alternatives</a>.</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/XouJWtTeQXs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/16/new-twitter-accounts-for-dsp-and-music-theory/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/16/new-twitter-accounts-for-dsp-and-music-theory/</feedburner:origLink></item>
		<item>
		<title>Social networks in fact and fiction</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/pJl4oQpOqfM/</link>
		<comments>http://www.johndcook.com/blog/2013/04/12/social-networks-in-fact-and-fiction/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 21:52:27 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[History]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13264</guid>
		<description><![CDATA[SIAM News arrived this afternoon and had an interesting story on the front page: Applying math to myth helps separate fact from fiction. In a nutshell, the authors hope to get some insight into whether a myth is based on<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/12/social-networks-in-fact-and-fiction/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>SIAM News arrived this afternoon and had an interesting story on the front page: <a href="http://www.siam.org/news/news.php?id=2058">Applying math to myth helps separate fact from fiction</a>.</p>
<p>In a nutshell, the authors hope to get some insight into whether a myth is based on fact by seeing whether the social network of characters in the myth looks more like a real social network or like the social network in a work of deliberate fiction. For instance, the social networks of the <a href="http://www.amazon.com/gp/product/0140275363/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0140275363&amp;linkCode=as2&amp;tag=theende-20">Iliad</a> and <a href="http://www.amazon.com/gp/product/0393320979/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0393320979&amp;linkCode=as2&amp;tag=theende-20">Beowulf</a> look more like actual social networks than does the social network of <a href="http://www.amazon.com/gp/product/0545596270/ref=as_li_ss_tl?ie=UTF8&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0545596270&amp;linkCode=as2&amp;tag=theende-20">Harry Potter</a>. Real social networks follow a power law distribution more closely than do social networks in works of fiction.</p>
<p>This could be interesting. For example, the article points out that some scholars believe Beowulf has a basis in historical events, though they don&#8217;t believe that Beowulf the character corresponds to a historical person. The network approach lends support to this position: the Beowulf social network looks more realistic when Beowulf himself is removed.</p>
<p>It seems however that an accurate historical account might have a suspicious social network, not because the events in it were made up but because they were filtered according to what the historian thought was important.</p>
<p>&nbsp;</p>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/pJl4oQpOqfM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/12/social-networks-in-fact-and-fiction/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/12/social-networks-in-fact-and-fiction/</feedburner:origLink></item>
		<item>
		<title>Which Unicode characters can you depend on?</title>
		<link>http://feedproxy.google.com/~r/TheEndeavour/~3/xxEjKyAZyIs/</link>
		<comments>http://www.johndcook.com/blog/2013/04/11/which-unicode-characters-can-you-depend-on/#comments</comments>
		<pubDate>Thu, 11 Apr 2013 19:19:37 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Typography]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=13253</guid>
		<description><![CDATA[Unicode is supported everywhere, but font support for Unicode characters is sparse. When you use any slightly uncommon character, you have no guarantee someone else will be able to see it. I&#8217;m starting a Twitter account @MusicTheoryTip and so I<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.johndcook.com/blog/2013/04/11/which-unicode-characters-can-you-depend-on/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Unicode is supported everywhere, but font support for Unicode characters is sparse. When you use any slightly uncommon character, you have no guarantee someone else will be able to see it.</p>
<p>I&#8217;m starting a Twitter account <a href="https://twitter.com/musictheorytip">@MusicTheoryTip</a> and so I wanted to know whether I could count on followers seeing music symbols. I asked whether people could see ♭ (flat, U+266D), ♮ (natural, U+266E), and ♯ (sharp, U+266F). Most people could see all three symbols, from desktop or phone, browser or Twitter app. However, several were unable to see the natural sign from an Android phone, whether using a browser or a Twitter app. One person said none of the symbols show up on his Blackberry.</p>
<p>I also asked <a href="https://twitter.com/diff_eq">@diff_eq</a> followers whether they could see the math symbols ∂ (partial, U+2202), Δ (Delta, U+0394), and ∇ (gradient, U+2207). One person said he couldn&#8217;t see the gradient symbol, but the rest of the feedback was positive.</p>
<p>So what characters can you count on nearly everyone being able to see? To answer this question, I looked at the characters in the intersection of several common fonts: Verdana, Georgia, Times New Roman, Arial, Courier New, and Droid Sans. My thought was that this would make a very conservative set of characters.</p>
<p>There are 585 characters supported by all the fonts listed above. Most of the characters with code points up to U+01FF are included. This range includes the code blocks for Basic Latin, Latin-1 Supplement, Latin Extended-A, and some of Latin Extended-B.</p>
<p>The rest of the characters in the intersection are Greek and Cyrillic letters and a few scattered symbols. Flat, natural, sharp, and gradient didn&#8217;t make the cut.</p>
<p>There are a dozen math symbols included:</p>
<pre>0x2202 ∂
0x2206 ∆
0x220F ∏
0x2211 ∑
0x2212 −
0x221A √
0x221E ∞
0x222B ∫
0x2248 ≈
0x2260 ≠
0x2264 ≤
0x2265 ≥</pre>
<p>Interestingly, even in such a conservative set of characters, there are a three characters included for semantic distinction: the minus sign (i.e. not a hyphen), the difference operator (i.e. not the Greek letter Delta), and the summation operator (i.e. not the Greek letter Sigma).</p>
<p>And in case you&#8217;re interested, here&#8217;s the complete list of the Unicode characters in the intersection of the fonts listed here. (<strong>Update</strong>: Added notes to indicate the start of a new code block and listed some of the isolated characters.)</p>
<pre>0x0009           Basic Latin
0x000d
0x0020 - 0x007e 
0x00a0 - 0x017f  Latin-1 supplement
0x0192	         
0x01fa - 0x01ff
0x0218 - 0x0219  
0x02c6 - 0x02c7  
0x02c9
0x02d8 - 0x02dd 
0x0300 - 0x0301 
0x0384 - 0x038a  Greek and Coptic
0x038c
0x038e - 0x03a1
0x03a3 - 0x03ce
0x0401 - 0x040c 
0x040e - 0x044f  Cyrillic
0x0451 - 0x045c
0x045e - 0x045f
0x0490 - 0x0491
0x1e80 - 0x1e85  Latin extended additional
0x1ef2 - 0x1ef3
0x200c - 0x200f  General punctuation
0x2013 - 0x2015
0x2017 - 0x201e
0x2020 - 0x2022
0x2026
0x2028 - 0x202e
0x2030
0x2032 - 0x2033
0x2039 - 0x203a
0x203c
0x2044
0x206a - 0x206f  
0x207f           
0x20a3 - 0x20a4  Currency symbols ₣ ₤
0x20a7           ₧
0x20ac           €
0x2105           Letterlike symbols ℅
0x2116           №
0x2122           ™
0x2126           Ω
0x212e           ℮
0x215b - 0x215e  ⅛ ⅜ ⅝ ⅞
0x2202 	         Mathematical operators ∂
0x2206           ∆
0x220f           ∏
0x2211 - 0x2212  ∑ −
0x221a           √
0x221e           ∞
0x222b           ∫
0x2248           ≈
0x2260           ≠
0x2264 - 0x2265  ≤ ≥
0x25ca           Box drawing ◊
0xfb01 - 0xfb02  Alphabetic presentation forms ﬁ ﬂ</pre>
<img src="http://feeds.feedburner.com/~r/TheEndeavour/~4/xxEjKyAZyIs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.johndcook.com/blog/2013/04/11/which-unicode-characters-can-you-depend-on/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		<feedburner:origLink>http://www.johndcook.com/blog/2013/04/11/which-unicode-characters-can-you-depend-on/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.580 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-05-25 22:33:32 -->
