<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Rod Carvalho</title>
	<atom:link href="http://stochastix.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://stochastix.wordpress.com</link>
	<description></description>
	<lastBuildDate>Fri, 24 May 2013 14:01:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='stochastix.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/b0e76faf2071260b9a9604a2923d3591?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Rod Carvalho</title>
		<link>http://stochastix.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://stochastix.wordpress.com/osd.xml" title="Rod Carvalho" />
	<atom:link rel='hub' href='http://stochastix.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Interview with László Lovász</title>
		<link>http://stochastix.wordpress.com/2013/05/11/interview-with-laszlo-lovasz/</link>
		<comments>http://stochastix.wordpress.com/2013/05/11/interview-with-laszlo-lovasz/#comments</comments>
		<pubDate>Sat, 11 May 2013 19:36:41 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Graph Theory]]></category>
		<category><![CDATA[Mathematicians]]></category>
		<category><![CDATA[Paul Erdős]]></category>
		<category><![CDATA[Alfred Tarski]]></category>
		<category><![CDATA[History of Mathematics]]></category>
		<category><![CDATA[P vs NP]]></category>
		<category><![CDATA[László Lovász]]></category>
		<category><![CDATA[Avi Wigderson]]></category>
		<category><![CDATA[Hungarian Mathematicians]]></category>
		<category><![CDATA[Hungarian Mathematics]]></category>
		<category><![CDATA[Biographies]]></category>
		<category><![CDATA[Interviews]]></category>
		<category><![CDATA[Regularity Lemma]]></category>
		<category><![CDATA[Approximation Algorithms]]></category>
		<category><![CDATA[Sociology of Mathematics]]></category>
		<category><![CDATA[Mathematics Education]]></category>
		<category><![CDATA[Mathematics Competitions]]></category>
		<category><![CDATA[SDP Relaxations]]></category>
		<category><![CDATA[Extremal Graph Theory]]></category>
		<category><![CDATA[Parenting]]></category>
		<category><![CDATA[Graph Limit Theory]]></category>
		<category><![CDATA[International Mathematical Union]]></category>
		<category><![CDATA[Channel Capacity]]></category>
		<category><![CDATA[Open Problems]]></category>
		<category><![CDATA[Simons Foundation]]></category>
		<category><![CDATA[Lenstra–Lenstra–Lovász Algorithm]]></category>
		<category><![CDATA[Academic Politics]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=9257</guid>
		<description><![CDATA[On November 28, 2011, Avi Wigderson interviewed László Lovász. A total of 27 short videos can be watched at the Simons Foundation website. I particularly liked the discussion on the LLL algorithm, and also on semidefinite relaxations. __________ Related: The social construction of Hungarian genius Filed under: Combinatorics, Computer Science, Graph Theory, Mathematics Tagged: Academic [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9257&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>On November 28, 2011, <a href="http://en.wikipedia.org/wiki/Avi_Wigderson" target="_blank">Avi Wigderson</a> interviewed <a href="http://en.wikipedia.org/wiki/L%C3%A1szl%C3%B3_Lov%C3%A1sz" target="_blank">László Lovász</a>. A total of 27 short videos can be watched at the <a href="http://simonsfoundation.org/science_lives_video/laszlo-lovasz/" target="_blank">Simons Foundation</a> website. I particularly liked the discussion on the <a href="http://en.wikipedia.org/wiki/Lenstra%E2%80%93Lenstra%E2%80%93Lov%C3%A1sz_lattice_basis_reduction_algorithm" target="_blank">LLL algorithm</a>, and also on semidefinite relaxations.</p>
<p style="text-align:center;"><a href="http://stochastix.files.wordpress.com/2013/05/lc3a1szlc3b3-lovc3a1sz.jpg"><img class="size-full wp-image-9260 aligncenter" style="border:1px solid black;" title="László Lovász" alt="László Lovász / Laszlo Lovasz" src="http://stochastix.files.wordpress.com/2013/05/lc3a1szlc3b3-lovc3a1sz.jpg?w=450"   /></a></p>
<p style="text-align:center;">__________</p>
<p>Related:</p>
<ul>
<li><a href="http://stochastix.wordpress.com/2011/04/24/the-social-construction-of-hungarian-genius/" target="_blank">The social construction of Hungarian genius</a></li>
</ul>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/mathematics/combinatorics/'>Combinatorics</a>, <a href='http://stochastix.wordpress.com/category/computer-science/'>Computer Science</a>, <a href='http://stochastix.wordpress.com/category/mathematics/graph-theory/'>Graph Theory</a>, <a href='http://stochastix.wordpress.com/category/mathematics/'>Mathematics</a> Tagged: <a href='http://stochastix.wordpress.com/tag/academic-politics/'>Academic Politics</a>, <a href='http://stochastix.wordpress.com/tag/alfred-tarski/'>Alfred Tarski</a>, <a href='http://stochastix.wordpress.com/tag/approximation-algorithms/'>Approximation Algorithms</a>, <a href='http://stochastix.wordpress.com/tag/avi-wigderson/'>Avi Wigderson</a>, <a href='http://stochastix.wordpress.com/tag/biographies/'>Biographies</a>, <a href='http://stochastix.wordpress.com/tag/channel-capacity/'>Channel Capacity</a>, <a href='http://stochastix.wordpress.com/tag/combinatorics/'>Combinatorics</a>, <a href='http://stochastix.wordpress.com/tag/extremal-graph-theory/'>Extremal Graph Theory</a>, <a href='http://stochastix.wordpress.com/tag/graph-limit-theory/'>Graph Limit Theory</a>, <a href='http://stochastix.wordpress.com/tag/graph-theory/'>Graph Theory</a>, <a href='http://stochastix.wordpress.com/tag/history-of-mathematics/'>History of Mathematics</a>, <a href='http://stochastix.wordpress.com/tag/hungarian-mathematicians/'>Hungarian Mathematicians</a>, <a href='http://stochastix.wordpress.com/tag/hungarian-mathematics/'>Hungarian Mathematics</a>, <a href='http://stochastix.wordpress.com/tag/international-mathematical-union/'>International Mathematical Union</a>, <a href='http://stochastix.wordpress.com/tag/interviews/'>Interviews</a>, <a href='http://stochastix.wordpress.com/tag/laszlo-lovasz/'>László Lovász</a>, <a href='http://stochastix.wordpress.com/tag/lenstra-lenstra-lovasz-algorithm/'>Lenstra–Lenstra–Lovász Algorithm</a>, <a href='http://stochastix.wordpress.com/tag/mathematicians/'>Mathematicians</a>, <a href='http://stochastix.wordpress.com/tag/mathematics-competitions/'>Mathematics Competitions</a>, <a href='http://stochastix.wordpress.com/tag/mathematics-education/'>Mathematics Education</a>, <a href='http://stochastix.wordpress.com/tag/open-problems/'>Open Problems</a>, <a href='http://stochastix.wordpress.com/tag/p-vs-np/'>P vs NP</a>, <a href='http://stochastix.wordpress.com/tag/parenting/'>Parenting</a>, <a href='http://stochastix.wordpress.com/tag/paul-erdos/'>Paul Erdős</a>, <a href='http://stochastix.wordpress.com/tag/regularity-lemma/'>Regularity Lemma</a>, <a href='http://stochastix.wordpress.com/tag/sdp-relaxations/'>SDP Relaxations</a>, <a href='http://stochastix.wordpress.com/tag/simons-foundation/'>Simons Foundation</a>, <a href='http://stochastix.wordpress.com/tag/sociology-of-mathematics/'>Sociology of Mathematics</a>, <a href='http://stochastix.wordpress.com/tag/videos/'>Videos</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/9257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/9257/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9257&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2013/05/11/interview-with-laszlo-lovasz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>

		<media:content url="http://stochastix.files.wordpress.com/2013/05/lc3a1szlc3b3-lovc3a1sz.jpg" medium="image">
			<media:title type="html">László Lovász</media:title>
		</media:content>
	</item>
		<item>
		<title>Der Wanderer über dem Nebelmeer</title>
		<link>http://stochastix.wordpress.com/2013/05/11/der-wanderer-uber-dem-nebelmeer/</link>
		<comments>http://stochastix.wordpress.com/2013/05/11/der-wanderer-uber-dem-nebelmeer/#comments</comments>
		<pubDate>Sat, 11 May 2013 18:30:55 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Art]]></category>
		<category><![CDATA[Caspar David Friedrich]]></category>
		<category><![CDATA[Paintings]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=9251</guid>
		<description><![CDATA[I love Der Wanderer über dem Nebelmeer (1818), by Caspar David Friedrich (1774-1840): [ source ] Filed under: Art Tagged: Art, Caspar David Friedrich, Paintings<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9251&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I love <em><a href="http://en.wikipedia.org/wiki/Wanderer_above_the_Sea_of_Fog" target="_blank">Der Wanderer über dem Nebelmeer</a></em> (1818), by <a href="http://en.wikipedia.org/wiki/Caspar_David_Friedrich" target="_blank">Caspar David Friedrich</a> (1774-1840):</p>
<p><a href="http://stochastix.files.wordpress.com/2013/05/der-wanderer-c3bcber-dem-nebelmeer.jpg"><img class="alignnone size-full wp-image-9252" style="border:1px solid black;" title="&quot;Das Nebelmeer wirkt wie die Wiedergabe eines Traums oder als ob man in die Seele des Bergsteigers blicken könnte. Es ist als wenn der Mann träumt, philosophiert oder etwas sucht. Der Nebel verdeckt und umhüllt das Tal. Die Berge, die wie Inseln aus dem Meer ragen sind unerreichbar für ihn. Jedoch gibt einem der Himmel Hoffnung. Er ist unendlich und weit. Der grobe Felsen bringt einen in die Wirklichkeit zurück. Er ist hart, unvergänglich und für ewig.&quot;" alt="Der Wanderer über dem Nebelmeer" src="http://stochastix.files.wordpress.com/2013/05/der-wanderer-c3bcber-dem-nebelmeer.jpg?w=450&#038;h=575" width="450" height="575" /></a></p>
<p style="text-align:center;">[ <a href="http://commons.wikimedia.org/wiki/File:Caspar_David_Friedrich_032_%28The_wanderer_above_the_sea_of_fog%29.jpg" target="_blank">source</a> ]</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/art/'>Art</a> Tagged: <a href='http://stochastix.wordpress.com/tag/art/'>Art</a>, <a href='http://stochastix.wordpress.com/tag/caspar-david-friedrich/'>Caspar David Friedrich</a>, <a href='http://stochastix.wordpress.com/tag/paintings/'>Paintings</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/9251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/9251/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9251&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2013/05/11/der-wanderer-uber-dem-nebelmeer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>

		<media:content url="http://stochastix.files.wordpress.com/2013/05/der-wanderer-c3bcber-dem-nebelmeer.jpg" medium="image">
			<media:title type="html">&#34;Das Nebelmeer wirkt wie die Wiedergabe eines Traums oder als ob man in die Seele des Bergsteigers blicken könnte. Es ist als wenn der Mann träumt, philosophiert oder etwas sucht. Der Nebel verdeckt und umhüllt das Tal. Die Berge, die wie Inseln aus dem Meer ragen sind unerreichbar für ihn. Jedoch gibt einem der Himmel Hoffnung. Er ist unendlich und weit. Der grobe Felsen bringt einen in die Wirklichkeit zurück. Er ist hart, unvergänglich und für ewig.&#34;</media:title>
		</media:content>
	</item>
		<item>
		<title>Sipser on P versus NP</title>
		<link>http://stochastix.wordpress.com/2012/12/22/sipser-on-p-versus-np/</link>
		<comments>http://stochastix.wordpress.com/2012/12/22/sipser-on-p-versus-np/#comments</comments>
		<pubDate>Sun, 23 Dec 2012 02:18:00 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Computational Complexity]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Michael Sipser]]></category>
		<category><![CDATA[P vs NP]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=9215</guid>
		<description><![CDATA[On October 3, 2006 Michael Sipser was at Harvard to give the following lecture on the P versus NP problem: This talk is arguably the very best introduction to computational complexity I have ever come across. I highly recommend it. Filed under: Computational Complexity, Computer Science Tagged: Computational Complexity, Michael Sipser, P vs NP, Talks<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9215&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>On October 3, 2006 <a href="http://en.wikipedia.org/wiki/Michael_Sipser" target="_blank">Michael Sipser</a> was at Harvard to give the following lecture on the <a href="http://en.wikipedia.org/wiki/P_versus_NP_problem" target="_blank">P versus NP problem</a>:</p>
<span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='450' height='284' src='http://www.youtube.com/embed/msp2y_Y5MLE?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span>
<p>This talk is arguably the very best introduction to <a href="http://en.wikipedia.org/wiki/Computational_complexity_theory" target="_blank">computational complexity</a> I have ever come across. I highly recommend it.</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/computer-science/computational-complexity-computer-science/'>Computational Complexity</a>, <a href='http://stochastix.wordpress.com/category/computer-science/'>Computer Science</a> Tagged: <a href='http://stochastix.wordpress.com/tag/computational-complexity/'>Computational Complexity</a>, <a href='http://stochastix.wordpress.com/tag/michael-sipser/'>Michael Sipser</a>, <a href='http://stochastix.wordpress.com/tag/p-vs-np/'>P vs NP</a>, <a href='http://stochastix.wordpress.com/tag/talks/'>Talks</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/9215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/9215/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9215&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2012/12/22/sipser-on-p-versus-np/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>
	</item>
		<item>
		<title>Luttwak on Kissinger</title>
		<link>http://stochastix.wordpress.com/2012/12/10/luttwak-on-kissinger/</link>
		<comments>http://stochastix.wordpress.com/2012/12/10/luttwak-on-kissinger/#comments</comments>
		<pubDate>Tue, 11 Dec 2012 03:14:01 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Edward Luttwak]]></category>
		<category><![CDATA[Henry Kissinger]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=9153</guid>
		<description><![CDATA[Edward Luttwak on Henry Kissinger: Kissinger at 88 is writing brochures for Kissinger Associates. His last book on China is one such work written by the staff at Kissinger Associates. It is designed to curry favor with the Chinese authorities and nothing else. I know him personally very well, but he is such a deceptive [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9153&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Edward_Luttwak" target="_blank">Edward Luttwak</a> on <a href="http://en.wikipedia.org/wiki/Henry_kissinger" target="_blank">Henry Kissinger</a>:</p>
<p style="padding-left:30px;"><em>Kissinger at 88 is writing brochures for <a href="http://en.wikipedia.org/wiki/Kissinger_Associates" target="_blank">Kissinger Associates</a>. His last book <a href="http://en.wikipedia.org/wiki/On_China" target="_blank">on China</a> is one such work written by the staff at <em><a href="http://en.wikipedia.org/wiki/Kissinger_Associates" target="_blank">Kissinger Associates</a></em>. It is designed to curry favor with the Chinese authorities and nothing else.</em></p>
<p style="padding-left:30px;"><em>I know him personally very well, but he is such a deceptive person; he’s a habitual liar and dissembler. Although I’ve spent a lot of time talking to him, I have no insight on him at all. His book ends with a paean to U.S.-Chinese friendship and how every other country has to fit in. I have to review it for the TLS, but I’ve been delaying it by weeks because I don’t know whether it is a case of senility or utter corruption.</em></p>
<p>I wonder if Kissinger would consider this a compliment. Anyone can be transparent, but obfuscation requires <a href="http://stochastix.wordpress.com/2012/01/16/communicating-with-half-words/" target="_blank">sophistication</a>.</p>
<p style="text-align:center;">__________</p>
<p>Source:</p>
<p style="padding-left:30px;">David Samuels, <em><a href="http://www.tabletmag.com/jewish-news-and-politics/76739/qa-edward-luttwak" target="_blank">Q&amp;A: Edward Luttwak</a></em>, Tablet Magazine, Sept. 6, 2011.</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/thoughts/'>Thoughts</a> Tagged: <a href='http://stochastix.wordpress.com/tag/edward-luttwak/'>Edward Luttwak</a>, <a href='http://stochastix.wordpress.com/tag/henry-kissinger/'>Henry Kissinger</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/9153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/9153/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9153&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2012/12/10/luttwak-on-kissinger/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>
	</item>
		<item>
		<title>Function composition via folding</title>
		<link>http://stochastix.wordpress.com/2012/12/02/function-composition-via-folding/</link>
		<comments>http://stochastix.wordpress.com/2012/12/02/function-composition-via-folding/#comments</comments>
		<pubDate>Sun, 02 Dec 2012 23:43:22 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Folding]]></category>
		<category><![CDATA[Function Composition]]></category>
		<category><![CDATA[Higher-Order Functions]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=9102</guid>
		<description><![CDATA[Let us suppose that we are given a list of functions. We would like to compose the functions in this list (if they are composable, of course) in the order in which they are arranged in the list, i.e., we would like to create a higher-order function compose such that Here is one of many [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9102&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Let us suppose that we are given a list of functions. We would like to compose the functions in this list (if they are composable, of course) in the order in which they are arranged in the list, i.e., we would like to create a <a href="http://en.wikipedia.org/wiki/Higher-order_function" target="_blank">higher-order function</a> <code>compose</code> such that</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7Bcompose%7D+%5C%2C%5C%2C+%5Bf_0%2C+f_1%2C+%5Cdots%2C+f_%7Bn-1%7D%5D+%3D+f_0+%5Ccirc+f_1+%5Ccirc+%5Cdots+%5Ccirc+f_%7Bn-1%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;text{compose} &#92;,&#92;, [f_0, f_1, &#92;dots, f_{n-1}] = f_0 &#92;circ f_1 &#92;circ &#92;dots &#92;circ f_{n-1}' title='&#92;text{compose} &#92;,&#92;, [f_0, f_1, &#92;dots, f_{n-1}] = f_0 &#92;circ f_1 &#92;circ &#92;dots &#92;circ f_{n-1}' class='latex' /></p>
<p>Here is one of many possible implementations in <a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" target="_blank">Haskell</a>:</p>
<pre style="padding-left:30px;background:#EEEEEE;">compose :: [(a -&gt; a)] -&gt; (a -&gt; a)
compose = foldr (.) (\x -&gt; x)</pre>
<p>where we use a right-<a href="http://en.wikipedia.org/wiki/Fold_%28higher-order_function%29">fold</a> to compute the composition. Note that the <a href="http://en.wikipedia.org/wiki/Identity_function" target="_blank">identity function</a> is defined <a href="http://www.haskell.org/haskellwiki/Anonymous_function" target="_blank">anonymously</a>. What happens if we apply <code>compose</code> to the empty list? We should obtain the identity function. Let us see if this is the case:</p>
<pre style="padding-left:30px;background:#FFFFFF;">compose [] = foldr (.) (\x -&gt; x) [] = (\x -&gt; x)</pre>
<p>Indeed, it is the case: if we apply <code>compose</code> to the empty list, we obtain the identity function. What is the type of this identity function? We load the two-line script above into <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> and experiment a bit:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main&gt; let id = compose []
*Main&gt; :t id
id :: a -&gt; a
*Main&gt; map id [0..9]
[0,1,2,3,4,5,6,7,8,9]
*Main&gt; map id ['a'..'z']
"abcdefghijklmnopqrstuvwxyz"</pre>
<p>We thus obtain a <a href="http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29" target="_blank">polymorphic</a> identity function that merely outputs its input, regardless of the type of the input. So far, so good. What happens if we apply <code>compose</code> to a non-empty list? Here is some more <a href="http://www.haskell.org/haskellwiki/Equational_reasoning_examples" target="_blank">equational reasoning</a>:</p>
<pre style="padding-left:30px;background:#FFFFFF;">compose [f0,f1,f2] = foldr (.) (\x -&gt; x) [f0,f1,f2]
                   = foldr (.) (\x -&gt; x) (f0 : f1 : f2 : [])
                   = f0 . (f1 . (f2 . (\x -&gt; x)))</pre>
<p>A couple of days ago, we saw how to <a href="http://stochastix.wordpress.com/2012/11/30/composing-an-endofunction-with-itself/" target="_blank">compose a function with itself</a> <img src='http://s0.wp.com/latex.php?latex=n&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n' title='n' class='latex' /> times. This is a special case of composing a list of functions, of course. Using function <a href="http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Prelude.html#v%3Areplicate" target="_blank">replicate</a>, we can compose a function <code>f</code> with itself <img src='http://s0.wp.com/latex.php?latex=n&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n' title='n' class='latex' /> times in the following manner:</p>
<pre style="padding-left:30px;background:#FFFFFF;">compose (replicate n f) = foldr (.) (\x -&gt; x) (replicate n f)</pre>
<p>as <a href="http://stackoverflow.com/questions/3911060/library-function-to-compose-a-function-with-itself-n-times/3911161#3911161" target="_blank">suggested</a> by Reid Barton. Let us now repeat the <a href="http://stochastix.wordpress.com/2012/11/30/composing-an-endofunction-with-itself/">experiment</a> we did perform a couple of days ago, but using the new <code>compose</code>:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main&gt; let f =  (\n -&gt; (n+1) `mod` 64)
*Main&gt; let h = compose (replicate 64 f)
*Main&gt; map h [0..63]
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63]</pre>
<p>In the next posts, we will do some interesting things with this <code>compose</code>.</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/programming/haskell/'>Haskell</a> Tagged: <a href='http://stochastix.wordpress.com/tag/folding/'>Folding</a>, <a href='http://stochastix.wordpress.com/tag/function-composition/'>Function Composition</a>, <a href='http://stochastix.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://stochastix.wordpress.com/tag/higher-order-functions/'>Higher-Order Functions</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/9102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/9102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9102&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2012/12/02/function-composition-via-folding/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>
	</item>
		<item>
		<title>Composing an endofunction with itself</title>
		<link>http://stochastix.wordpress.com/2012/11/30/composing-an-endofunction-with-itself/</link>
		<comments>http://stochastix.wordpress.com/2012/11/30/composing-an-endofunction-with-itself/#comments</comments>
		<pubDate>Sat, 01 Dec 2012 05:57:21 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Function Composition]]></category>
		<category><![CDATA[Higher-Order Functions]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=9070</guid>
		<description><![CDATA[Suppose we are given an endofunction . Let us introduce a new function , where , which we define recursively as follows where is the identity function on , i.e., for all . In Haskell, it is easy to create a higher-order function compose that composes an endofunction with itself times: compose :: (a -&#62; a) [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9070&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Suppose we are given an <a href="http://en.wikipedia.org/wiki/Endomorphism" target="_blank">endofunction</a> <img src='http://s0.wp.com/latex.php?latex=f+%3A+%5Cmathcal%7BX%7D+%5Cto+%5Cmathcal%7BX%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f : &#92;mathcal{X} &#92;to &#92;mathcal{X}' title='f : &#92;mathcal{X} &#92;to &#92;mathcal{X}' class='latex' />. Let us introduce a new function <img src='http://s0.wp.com/latex.php?latex=f%5E%7B%28n%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f^{(n)}' title='f^{(n)}' class='latex' />, where <img src='http://s0.wp.com/latex.php?latex=n+%5Cgeq+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n &#92;geq 0' title='n &#92;geq 0' class='latex' />, which we define recursively as follows</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=f%5E%7B%28k%29%7D+%3D+f+%5Ccirc+f%5E%7B%28k-1%29%7D%2C+%5Cqquad%7B%7D+f%5E%7B%280%29%7D+%3D+%5Ctext%7Bid%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f^{(k)} = f &#92;circ f^{(k-1)}, &#92;qquad{} f^{(0)} = &#92;text{id}' title='f^{(k)} = f &#92;circ f^{(k-1)}, &#92;qquad{} f^{(0)} = &#92;text{id}' class='latex' /></p>
<p>where <img src='http://s0.wp.com/latex.php?latex=%5Ctext%7Bid%7D+%3A+%5Cmathcal%7BX%7D+%5Cto+%5Cmathcal%7BX%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;text{id} : &#92;mathcal{X} &#92;to &#92;mathcal{X}' title='&#92;text{id} : &#92;mathcal{X} &#92;to &#92;mathcal{X}' class='latex' /> is the <a href="http://en.wikipedia.org/wiki/Identity_function" target="_blank">identity function</a> on <img src='http://s0.wp.com/latex.php?latex=%5Cmathcal%7BX%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;mathcal{X}' title='&#92;mathcal{X}' class='latex' />, i.e., <img src='http://s0.wp.com/latex.php?latex=%5Ctext%7Bid%7D+%28x%29+%3D+x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;text{id} (x) = x' title='&#92;text{id} (x) = x' class='latex' /> for all <img src='http://s0.wp.com/latex.php?latex=x+%5Cin+%5Cmathcal%7BX%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x &#92;in &#92;mathcal{X}' title='x &#92;in &#92;mathcal{X}' class='latex' />. In <a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" target="_blank">Haskell</a>, it is easy to create a <a href="http://en.wikipedia.org/wiki/Higher-order_function" target="_blank">higher-order function</a> <code>compose</code> that <a href="http://en.wikipedia.org/wiki/Function_composition" target="_blank">composes</a> an <a href="http://en.wikipedia.org/wiki/Endomorphism" target="_blank">endofunction</a> <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f' title='f' class='latex' /> with itself <img src='http://s0.wp.com/latex.php?latex=n&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n' title='n' class='latex' /> times:</p>
<pre style="padding-left:30px;background:#EEEEEE;">compose :: (a -&gt; a) -&gt; Integer -&gt; (a -&gt; a)
compose f 0 = (\x -&gt; x)
compose f k = f . (compose f (k-1))</pre>
<p>where the identity function is defined <a href="http://www.haskell.org/haskellwiki/Anonymous_function" target="_blank">anonymously</a>. If you happen to dislike anonymity in your functions, here is another implementation:</p>
<pre style="padding-left:30px;background:#EEEEEE;">compose :: (a -&gt; a) -&gt; Integer -&gt; (a -&gt; a)
compose f 0 = identity
compose f k = f . (compose f (k-1))

identity :: a -&gt; a
identity x = x</pre>
<p>There are many other alternatives. Take a look at this <a href="http://stackoverflow.com/questions/3911060/library-function-to-compose-a-function-with-itself-n-times" target="_blank">Stack Overflow thread</a>. I particularly liked <a href="http://en.wikipedia.org/wiki/Reid_Barton" target="_blank">Reid Barton</a>&#8216;s elegant <a href="http://stackoverflow.com/a/3911161/582416" target="_blank">solution</a> using a right-<a href="http://en.wikipedia.org/wiki/Fold_%28higher-order_function%29" target="_blank">fold</a>:</p>
<pre style="padding-left:30px;background:#EEEEEE;">compose f n = foldr (.) id (replicate n f)</pre>
<p>where <code>id = (\x -&gt; x)</code>. Beautiful, isn&#8217;t it? If this one-liner does not convert you to <a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" target="_blank">Haskell</a>, then nothing will.</p>
<p style="text-align:center;">__________</p>
<p><strong>Example</strong></p>
<p>Let <img src='http://s0.wp.com/latex.php?latex=%5Cmathbb%7BZ%7D_%7B64%7D+%3A%3D+%5C%7B0%2C+1%2C%5Cdots%2C63%5C%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;mathbb{Z}_{64} := &#92;{0, 1,&#92;dots,63&#92;}' title='&#92;mathbb{Z}_{64} := &#92;{0, 1,&#92;dots,63&#92;}' class='latex' />, and let function <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f' title='f' class='latex' /> be defined by</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cbegin%7Barray%7D%7Brl%7D+f+%3A+%5Cmathbb%7BZ%7D_%7B64%7D+%26%5Cto+%5Cmathbb%7BZ%7D_%7B64%7D%5C%5C+n+%26%5Cmapsto+n%2B1+%5Cpmod%7B64%7D%5Cend%7Barray%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;begin{array}{rl} f : &#92;mathbb{Z}_{64} &amp;&#92;to &#92;mathbb{Z}_{64}&#92;&#92; n &amp;&#92;mapsto n+1 &#92;pmod{64}&#92;end{array}' title='&#92;begin{array}{rl} f : &#92;mathbb{Z}_{64} &amp;&#92;to &#92;mathbb{Z}_{64}&#92;&#92; n &amp;&#92;mapsto n+1 &#92;pmod{64}&#92;end{array}' class='latex' /></p>
<p>This function corresponds to a cyclic shift. Therefore, we expect to have <img src='http://s0.wp.com/latex.php?latex=f%5E%7B%2864%29%7D+%3D+%5Ctext%7Bid%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f^{(64)} = &#92;text{id}' title='f^{(64)} = &#92;text{id}' class='latex' />. Let <img src='http://s0.wp.com/latex.php?latex=g+%3A%3D+f%5E%7B%2832%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='g := f^{(32)}' title='g := f^{(32)}' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=h+%3A%3D+f%5E%7B%2864%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='h := f^{(64)}' title='h := f^{(64)}' class='latex' />. We load the script above into <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a>, and <em>voilà</em>, we have the session:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main&gt; let ns = [0..63]
*Main&gt; let f =  (\n -&gt; (n+1) `mod` 64)
*Main&gt; map f ns
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,0]</pre>
<p>So far, so good! Let us take a look at <img src='http://s0.wp.com/latex.php?latex=g&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='g' title='g' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=h&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='h' title='h' class='latex' />:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main&gt; let g = compose f 32
*Main&gt; let h = compose f 64
*Main&gt; map g ns
[32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
*Main&gt; map h ns
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63]</pre>
<p>Indeed, as we expected, we have <img src='http://s0.wp.com/latex.php?latex=f%5E%7B%2864%29%7D+%3D+%5Ctext%7Bid%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f^{(64)} = &#92;text{id}' title='f^{(64)} = &#92;text{id}' class='latex' />.</p>
<p style="text-align:center;">__________</p>
<p>Everything in this post is elementary. But now that the elements are solid, we can dare to attempt more sophisticated things. Like what? Like composing lists of (distinct) functions. I am thinking of <a href="http://en.wikipedia.org/wiki/Permutation" target="_blank">permutations</a>. I am thinking of <a href="http://stochastix.wordpress.com/2012/04/17/perfect-shuffles-in-haskell/" target="_blank">perfect shuffles</a>.</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/programming/haskell/'>Haskell</a>, <a href='http://stochastix.wordpress.com/category/mathematics/'>Mathematics</a> Tagged: <a href='http://stochastix.wordpress.com/tag/function-composition/'>Function Composition</a>, <a href='http://stochastix.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://stochastix.wordpress.com/tag/higher-order-functions/'>Higher-Order Functions</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/9070/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/9070/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9070&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2012/11/30/composing-an-endofunction-with-itself/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>
	</item>
		<item>
		<title>Zawinski on venture capitalists</title>
		<link>http://stochastix.wordpress.com/2012/11/29/zawinski-on-venture-capitalists/</link>
		<comments>http://stochastix.wordpress.com/2012/11/29/zawinski-on-venture-capitalists/#comments</comments>
		<pubDate>Thu, 29 Nov 2012 17:54:30 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[HIWTYL]]></category>
		<category><![CDATA[Jamie Zawinski]]></category>
		<category><![CDATA[Silicon Valley]]></category>
		<category><![CDATA[Silly Con Valley]]></category>
		<category><![CDATA[Software Industry]]></category>
		<category><![CDATA[Useful Idiots]]></category>
		<category><![CDATA[Venture Capitalists]]></category>
		<category><![CDATA[Vulture Capitalists]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=9058</guid>
		<description><![CDATA[Approximately one year ago, über-hacker Jamie Zawinski wrote the following on venture capitalists: Normally I just ignore navel-gazing tech-industry articles like this, but people keep sending it to me, so I guess this guy is famous or something. Michael Arrington posted this article, &#8220;Startups Are Hard. So Work More, Cry Less, And Quit All The [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9058&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Approximately one year ago, <em>über</em>-hacker <a href="http://en.wikipedia.org/wiki/Jamie_Zawinski" target="_blank">Jamie Zawinski</a> wrote the following on venture capitalists:</p>
<p style="padding-left:30px;"><em>Normally I just ignore navel-gazing tech-industry articles like this, but people keep sending it to me, so I guess this guy is famous or something. Michael Arrington posted this article, &#8220;<a href="http://uncrunched.com/2011/11/27/startups-are-hard-so-work-more-cry-less-and-quit-all-the-whining/" target="_blank">Startups Are Hard. So Work More, Cry Less, And Quit All The Whining</a>&#8221; which quotes extensively from my 1994 diary.</em></p>
<p style="padding-left:30px;"><em>He&#8217;s trying to make the point that the only path to success in the software industry is to work insane hours, sleep under your desk, and give up your one and only youth, and if you don&#8217;t do that, you&#8217;re a pussy. He&#8217;s using my words to try and back up that thesis.</em></p>
<p style="padding-left:30px;"><em>I hate this, because it&#8217;s not true, and it&#8217;s disingenuous.</em></p>
<p style="padding-left:30px;"><em>What <strong>is</strong> true is that for a VC&#8217;s business model to work, it&#8217;s necessary for <strong>you</strong> to give up <strong>your</strong> life in order for <strong>him</strong> to become richer.</em></p>
<p style="padding-left:30px;"><em>Follow the fucking money. When a VC tells you what&#8217;s good for you, check your wallet, then count your fingers.</em></p>
<p style="padding-left:30px;"><em>He&#8217;s telling you the story of, &#8220;If you bust your ass and don&#8217;t sleep, you&#8217;ll get rich&#8221; because the only way that people in his line of work get richer is if young, poorly-socialized, naive geniuses believe that story! Without those coat-tails to ride, VCs might have to work for a living. Once that kid burns out, they&#8217;ll just slot a new one in.</em></p>
<p style="padding-left:30px;"><em>I did make a bunch of money by winning the Netscape Startup Lottery, it&#8217;s true. So did most of the early engineers. But the people who made 100x as much as the engineers did? I can tell you for a fact that none of <strong>them</strong> slept under their desk. If you look at a list of financially successful people from the software industry, I&#8217;ll bet you get a very different view of what kind of sleep habits and office hours are successful than the one presented here.</em></p>
<p style="padding-left:30px;"><em>So if your goal is to enrich the Arringtons of the world while maybe, if you win the lottery, scooping some of the groundscore that they overlooked, then by all means, bust your ass while the bankers and speculators cheer you on.</em></p>
<p style="padding-left:30px;"><em>Instead of that, <strong>I</strong> recommend that you do what you love because you love doing it. If that means long hours, fantastic. If that means leaving the office by 6pm every day for your underwater basket-weaving class, also fantastic.</em></p>
<p style="text-align:center;">__________</p>
<p>The words that Zawinski italicized for emphasis I have chosen to present in bold, due to the fact that the whole quoted text is already italicized. Amusingly, Zawinski&#8217;s blog post caused quite a bit of &#8220;fear and (self-) loathing&#8221; at <a href="http://news.ycombinator.com/item?id=3288671" target="_blank">Hacker News</a> ;-)</p>
<p style="text-align:center;">__________</p>
<p>Source:</p>
<p style="padding-left:30px;">Jamie Zawinski, <em><a href="http://www.jwz.org/blog/2011/11/watch-a-vc-use-my-name-to-sell-a-con/" target="_blank">Watch a VC use my name to sell a con</a></em>, November 28, 2011.</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/thoughts/'>Thoughts</a> Tagged: <a href='http://stochastix.wordpress.com/tag/hiwtyl/'>HIWTYL</a>, <a href='http://stochastix.wordpress.com/tag/jamie-zawinski/'>Jamie Zawinski</a>, <a href='http://stochastix.wordpress.com/tag/silicon-valley/'>Silicon Valley</a>, <a href='http://stochastix.wordpress.com/tag/silly-con-valley/'>Silly Con Valley</a>, <a href='http://stochastix.wordpress.com/tag/software-industry/'>Software Industry</a>, <a href='http://stochastix.wordpress.com/tag/useful-idiots/'>Useful Idiots</a>, <a href='http://stochastix.wordpress.com/tag/venture-capitalists/'>Venture Capitalists</a>, <a href='http://stochastix.wordpress.com/tag/vulture-capitalists/'>Vulture Capitalists</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/9058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/9058/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=9058&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2012/11/29/zawinski-on-venture-capitalists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>
	</item>
		<item>
		<title>Generalizing Heron’s method</title>
		<link>http://stochastix.wordpress.com/2012/11/25/generalizing-herons-method/</link>
		<comments>http://stochastix.wordpress.com/2012/11/25/generalizing-herons-method/#comments</comments>
		<pubDate>Sun, 25 Nov 2012 18:53:38 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Numerical Methods]]></category>
		<category><![CDATA[Arbitrary-Precision Arithmetic]]></category>
		<category><![CDATA[Data.Ratio]]></category>
		<category><![CDATA[Golden Ratio]]></category>
		<category><![CDATA[Heron’s Method]]></category>
		<category><![CDATA[Newton’s Method]]></category>
		<category><![CDATA[Rational Approximations]]></category>
		<category><![CDATA[Rational Arithmetic]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=8995</guid>
		<description><![CDATA[Suppose we are given a positive rational number . We would like to compute an approximation of the -th root of , which we denote by . If , we can use Heron&#8217;s method to approximate , as we saw a few days ago. But, what if we have that ? Is it possible to [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=8995&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Suppose we are given a positive rational number <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' />. We would like to compute an approximation of the <img src='http://s0.wp.com/latex.php?latex=n&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n' title='n' class='latex' />-<a href="http://en.wikipedia.org/wiki/Nth_root" target="_blank">th root</a> of <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' />, which we denote by <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%5Bn%5D%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt[n]{y}' title='&#92;sqrt[n]{y}' class='latex' />. If <img src='http://s0.wp.com/latex.php?latex=n+%3D+2&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n = 2' title='n = 2' class='latex' />, we can use <a href="http://en.wikipedia.org/wiki/Heron%27s_method" target="_blank">Heron&#8217;s method</a> to approximate <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{y}' title='&#92;sqrt{y}' class='latex' />, as we <a href="http://stochastix.wordpress.com/2012/11/22/herons-method-using-integer-arithmetic/" target="_blank">saw</a> a few days ago. But, what if we have that <img src='http://s0.wp.com/latex.php?latex=n+%3E+2&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n &gt; 2' title='n &gt; 2' class='latex' />? Is it possible to generalize <a href="http://en.wikipedia.org/wiki/Heron%27s_method" target="_blank">Heron&#8217;s method</a>?</p>
<p>Indeed, it is. Let us introduce a function <img src='http://s0.wp.com/latex.php?latex=f_%7Bn%2Cy%7D+%3A+%5Cmathbb%7BR%7D+%5Cto+%5Cmathbb%7BR%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{n,y} : &#92;mathbb{R} &#92;to &#92;mathbb{R}' title='f_{n,y} : &#92;mathbb{R} &#92;to &#92;mathbb{R}' class='latex' />, defined by <img src='http://s0.wp.com/latex.php?latex=f_%7Bn%2Cy%7D+%28x%29+%3D+x%5En+-+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{n,y} (x) = x^n - y' title='f_{n,y} (x) = x^n - y' class='latex' />, where <img src='http://s0.wp.com/latex.php?latex=n+%5Cgeq+2&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n &#92;geq 2' title='n &#92;geq 2' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y+%3E+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y &gt; 0' title='y &gt; 0' class='latex' />. By construction, the positive zero of function <img src='http://s0.wp.com/latex.php?latex=f_%7Bn%2Cy%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{n,y}' title='f_{n,y}' class='latex' /> is <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%5Bn%5D%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt[n]{y}' title='&#92;sqrt[n]{y}' class='latex' />. Do note that if <img src='http://s0.wp.com/latex.php?latex=n&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n' title='n' class='latex' /> is odd, then <img src='http://s0.wp.com/latex.php?latex=-%5Csqrt%5Bn%5D%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='-&#92;sqrt[n]{y}' title='-&#92;sqrt[n]{y}' class='latex' /> is <em>not</em> a zero of <img src='http://s0.wp.com/latex.php?latex=f_%7Bn%2Cy%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{n,y}' title='f_{n,y}' class='latex' />. Recall that <a href="http://en.wikipedia.org/wiki/Newton%27s_method" target="_blank">Newton’s method</a> uses the recurrence relation <img src='http://s0.wp.com/latex.php?latex=x_%7Bk%2B1%7D+%3D+g_%7Bn%2Cy%7D+%28+x_k+%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_{k+1} = g_{n,y} ( x_k )' title='x_{k+1} = g_{n,y} ( x_k )' class='latex' />, where function <img src='http://s0.wp.com/latex.php?latex=g_%7Bn%2Cy%7D+%3A+%5Cmathbb%7BR%7D+%5Cto+%5Cmathbb%7BR%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='g_{n,y} : &#92;mathbb{R} &#92;to &#92;mathbb{R}' title='g_{n,y} : &#92;mathbb{R} &#92;to &#92;mathbb{R}' class='latex' /> is defined by</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=g_%7Bn%2Cy%7D+%28x%29+%3D+x+-+%5Cdisplaystyle%5Cfrac%7Bf_%7Bn%2Cy%7D+%28x%29%7D%7Bf_%7Bn%2Cy%7D%27+%28x%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='g_{n,y} (x) = x - &#92;displaystyle&#92;frac{f_{n,y} (x)}{f_{n,y}&#039; (x)}' title='g_{n,y} (x) = x - &#92;displaystyle&#92;frac{f_{n,y} (x)}{f_{n,y}&#039; (x)}' class='latex' /></p>
<p>where <img src='http://s0.wp.com/latex.php?latex=f_%7Bn%2Cy%7D%27&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{n,y}&#039;' title='f_{n,y}&#039;' class='latex' /> is the first derivative of <img src='http://s0.wp.com/latex.php?latex=f_%7Bn%2Cy%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{n,y}' title='f_{n,y}' class='latex' />. Hence, we obtain</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=g_%7Bn%2Cy%7D+%28x%29+%3D+x+-+%5Cdisplaystyle%5Cfrac%7Bf_%7Bn%2Cy%7D+%28x%29%7D%7Bf_%7Bn%2Cy%7D%27+%28x%29%7D+%3D+x+-+%5Cdisplaystyle%5Cleft%28%5Cfrac%7Bx%5En+-+y%7D%7Bn+x%5E%7Bn-1%7D%7D%5Cright%29+%3D+%5Cdisplaystyle%5Cfrac%7B1%7D%7Bn%7D+%5Cleft%28+%28n-1%29+x+%2B+%5Cfrac%7By%7D%7Bx%5E%7Bn-1%7D%7D%5Cright%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='g_{n,y} (x) = x - &#92;displaystyle&#92;frac{f_{n,y} (x)}{f_{n,y}&#039; (x)} = x - &#92;displaystyle&#92;left(&#92;frac{x^n - y}{n x^{n-1}}&#92;right) = &#92;displaystyle&#92;frac{1}{n} &#92;left( (n-1) x + &#92;frac{y}{x^{n-1}}&#92;right)' title='g_{n,y} (x) = x - &#92;displaystyle&#92;frac{f_{n,y} (x)}{f_{n,y}&#039; (x)} = x - &#92;displaystyle&#92;left(&#92;frac{x^n - y}{n x^{n-1}}&#92;right) = &#92;displaystyle&#92;frac{1}{n} &#92;left( (n-1) x + &#92;frac{y}{x^{n-1}}&#92;right)' class='latex' /></p>
<p>Thus, we have the generalized <a href="http://en.wikipedia.org/wiki/Heron%27s_method" target="_blank">Heron&#8217;s method</a></p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_%7Bk%2B1%7D+%3D+%5Cdisplaystyle%5Cfrac%7B1%7D%7Bn%7D+%5Cleft%28+%28n-1%29+x_k+%2B+%5Cfrac%7By%7D%7Bx_k%5E%7Bn-1%7D%7D%5Cright%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_{k+1} = &#92;displaystyle&#92;frac{1}{n} &#92;left( (n-1) x_k + &#92;frac{y}{x_k^{n-1}}&#92;right)' title='x_{k+1} = &#92;displaystyle&#92;frac{1}{n} &#92;left( (n-1) x_k + &#92;frac{y}{x_k^{n-1}}&#92;right)' class='latex' /></p>
<p>If we make <img src='http://s0.wp.com/latex.php?latex=n+%3D+2&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n = 2' title='n = 2' class='latex' />, we obtain the standard <a href="http://en.wikipedia.org/wiki/Heron%27s_method" target="_blank">Heron&#8217;s method</a>, as we expected. The following <a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" target="_blank">Haskell</a> script implements this generalized <a href="http://en.wikipedia.org/wiki/Heron%27s_method" target="_blank">Heron&#8217;s method</a> using <a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_blank">arbitrary-precision</a> rational numbers (included in the <a href="http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Ratio.html" target="_blank">Data.Ratio</a> library) to represent <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' /> and the sequence of approximations <img src='http://s0.wp.com/latex.php?latex=%28x_k%29_%7Bk+%5Cin+%5Cmathbb%7BN%7D_0%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='(x_k)_{k &#92;in &#92;mathbb{N}_0}' title='(x_k)_{k &#92;in &#92;mathbb{N}_0}' class='latex' />:</p>
<pre style="padding-left:30px;background:#EEEEEE;">import Data.Ratio

-- define generalized Heron map
g :: Integer -&gt; Rational -&gt; Rational -&gt; Rational
g n y x = (1 % n) * ((fromIntegral (n-1) * x) + (y / (x^(n-1))))

-- initial approximation
x0 :: Rational
x0 = 1 % 1

-- list of approximations of the n-th root of y
roots :: Integer -&gt; Rational -&gt; [Rational]
roots n y | n  &gt; 1 = iterate (g n y) x0
          | n &lt;= 1 = error "Invalid value of n!!"</pre>
<p>We load this script into <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a>. Let us now perform some numerical experiments.</p>
<p style="text-align:center;">__________</p>
<p><strong>Experiment #1</strong></p>
<p>We would like to compute a rational approximation of <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7B2%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{2}' title='&#92;sqrt{2}' class='latex' />. We have <img src='http://s0.wp.com/latex.php?latex=n+%3D+2&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n = 2' title='n = 2' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y+%3D+2&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = 2' title='y = 2' class='latex' />. Here is a very brief <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> session:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; take 6 (roots 2 2)
[1 % 1,3 % 2,17 % 12,577 % 408,665857 % 470832,
 886731088897 % 627013566048]</pre>
<p>We obtain the following rational approximation after five iterations</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_5+%3D+%5Cdisplaystyle%5Cfrac%7B886731088897%7D%7B627013566048%7D+%5Capprox+%5Csqrt%7B2%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5 = &#92;displaystyle&#92;frac{886731088897}{627013566048} &#92;approx &#92;sqrt{2}' title='x_5 = &#92;displaystyle&#92;frac{886731088897}{627013566048} &#92;approx &#92;sqrt{2}' class='latex' /></p>
<p>which is the same approximation I obtained <a href="https://stochastix.wordpress.com/2012/04/02/newtons-method-using-rational-arithmetic/" target="_blank">twice</a> <a href="http://stochastix.wordpress.com/2012/11/22/herons-method-using-integer-arithmetic/" target="_blank">before</a>.</p>
<p style="text-align:center;">__________</p>
<p><strong>Experiment #2</strong></p>
<p>We would like to compute a rational approximation of <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7B5%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{5}' title='&#92;sqrt{5}' class='latex' />. We have <img src='http://s0.wp.com/latex.php?latex=n+%3D+2&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n = 2' title='n = 2' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y+%3D+5&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = 5' title='y = 5' class='latex' />. Here is a very brief <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> session:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; take 7 (roots 2 5)
[1 % 1,3 % 1,7 % 3,47 % 21,2207 % 987,4870847 % 2178309,
 23725150497407 % 10610209857723]</pre>
<p>We obtain the following rational approximation after six iterations</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_6+%3D+%5Cdisplaystyle%5Cfrac%7B23725150497407%7D%7B10610209857723%7D+%5Capprox+%5Csqrt%7B5%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_6 = &#92;displaystyle&#92;frac{23725150497407}{10610209857723} &#92;approx &#92;sqrt{5}' title='x_6 = &#92;displaystyle&#92;frac{23725150497407}{10610209857723} &#92;approx &#92;sqrt{5}' class='latex' /></p>
<p>How good is this approximation? Let us check:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; (23725150497407 % 10610209857723)^2 - 5
4 % 112576553224922323902744729
*Main Data.Ratio&gt; 4 / 112576553224922323902744729
3.5531377408652764e-26</pre>
<p>Not bad! We could now obtain a rational approximation of the famous <a href="http://en.wikipedia.org/wiki/Golden_ratio" target="_blank">golden ratio</a> <img src='http://s0.wp.com/latex.php?latex=%5Cvarphi+%3A%3D+%5Cfrac%7B1+%2B+%5Csqrt%7B5%7D%7D%7B2%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;varphi := &#92;frac{1 + &#92;sqrt{5}}{2}' title='&#92;varphi := &#92;frac{1 + &#92;sqrt{5}}{2}' class='latex' />, as follows:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; let xs = roots 2 5
*Main Data.Ratio&gt; let phis = map (/2) (map (+1) xs)
*Main Data.Ratio&gt; take 7 phis
[1 % 1,2 % 1,5 % 3,34 % 21,1597 % 987,3524578 % 2178309,
 17167680177565 % 10610209857723]</pre>
<p>We obtain the following rational approximation after six iterations</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Ctilde%7B%5Cvarphi%7D_6+%3D+%5Cdisplaystyle%5Cfrac%7B17167680177565%7D%7B10610209857723%7D+%5Capprox+%5Cvarphi&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;tilde{&#92;varphi}_6 = &#92;displaystyle&#92;frac{17167680177565}{10610209857723} &#92;approx &#92;varphi' title='&#92;tilde{&#92;varphi}_6 = &#92;displaystyle&#92;frac{17167680177565}{10610209857723} &#92;approx &#92;varphi' class='latex' /></p>
<p>How good is this approximation? Let us recall that the <a href="http://en.wikipedia.org/wiki/Golden_ratio" target="_blank">golden ratio</a> is one of the solutions of the equation <img src='http://s0.wp.com/latex.php?latex=x%5E2+-+x+-+1+%3D+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x^2 - x - 1 = 0' title='x^2 - x - 1 = 0' class='latex' />. Hence, we can check how close to zero <img src='http://s0.wp.com/latex.php?latex=%5Ctilde%7B%5Cvarphi%7D_6%5E2+-+%5Ctilde%7B%5Cvarphi%7D_6+-+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;tilde{&#92;varphi}_6^2 - &#92;tilde{&#92;varphi}_6 - 1' title='&#92;tilde{&#92;varphi}_6^2 - &#92;tilde{&#92;varphi}_6 - 1' class='latex' /> is:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; let phi6 = 17167680177565 % 10610209857723
*Main Data.Ratio&gt; phi6^2 - phi6 - 1
1 % 112576553224922323902744729
*Main Data.Ratio&gt; 1 / 112576553224922323902744729
8.882844352163191e-27</pre>
<p>I would say that is fairly close.</p>
<p style="text-align:center;">__________</p>
<p><strong>Experiment #3</strong></p>
<p>We now would like to compute a rational approximation of <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%5B3%5D%7B10%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt[3]{10}' title='&#92;sqrt[3]{10}' class='latex' />. We have <img src='http://s0.wp.com/latex.php?latex=n+%3D+3&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n = 3' title='n = 3' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y+%3D+10&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = 10' title='y = 10' class='latex' />. Here is a very brief <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> session:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; take 6 (roots 3 10)
[1 % 1,4 % 1,23 % 8,4909 % 2116,55223315303 % 25495981298,
83759169926117983945469262167029 % 38876457805393768546966848104041]</pre>
<p>We obtain the following rational approximation after five iterations</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_5+%3D+%5Cdisplaystyle%5Cfrac%7B83759169926117983945469262167029%7D%7B38876457805393768546966848104041%7D+%5Capprox+%5Csqrt%5B3%5D%7B10%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5 = &#92;displaystyle&#92;frac{83759169926117983945469262167029}{38876457805393768546966848104041} &#92;approx &#92;sqrt[3]{10}' title='x_5 = &#92;displaystyle&#92;frac{83759169926117983945469262167029}{38876457805393768546966848104041} &#92;approx &#92;sqrt[3]{10}' class='latex' /></p>
<p>Is this approximation any good? Let us check:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; let x5 = (roots 3 10) !! 5 
*Main Data.Ratio&gt; x5^3
5876207108075025254603649658428809744645894398375582704
87986732898174481543266076676033790365389 % 58757060813
2677736272189042625165443146909261971794220978628909441
43919908404893015241356540921
*Main Data.Ratio&gt; 5876207108075025254603649658428809744
6458943983755827048798673289817448154326607667603379036
5389 / 587570608132677736272189042625165443146909261971
79422097862890944143919908404893015241356540921
10.000852709004354</pre>
<p>This is somewhat disappointing. The rational approximation <img src='http://s0.wp.com/latex.php?latex=x_5&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5' title='x_5' class='latex' /> is a ratio of two enormously long integers, but we do not have such a small error. Note that <img src='http://s0.wp.com/latex.php?latex=x_5%5E3+-+10+%5Capprox+10%5E%7B-3%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5^3 - 10 &#92;approx 10^{-3}' title='x_5^3 - 10 &#92;approx 10^{-3}' class='latex' />. We can do some quick error analysis. Let <img src='http://s0.wp.com/latex.php?latex=f_%7B3%2C10%7D+%28x%29+%3D+x%5E3+-+10&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{3,10} (x) = x^3 - 10' title='f_{3,10} (x) = x^3 - 10' class='latex' />. The 1st order Taylor approximation of <img src='http://s0.wp.com/latex.php?latex=f_%7B3%2C10%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{3,10}' title='f_{3,10}' class='latex' /> around <img src='http://s0.wp.com/latex.php?latex=x_5&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5' title='x_5' class='latex' /> evaluated at <img src='http://s0.wp.com/latex.php?latex=x+%3D+%5Csqrt%5B3%5D%7B10%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = &#92;sqrt[3]{10}' title='x = &#92;sqrt[3]{10}' class='latex' /> is</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=f_%7B3%2C10%7D+%28%5Csqrt%5B3%5D%7B10%7D%29+%5Capprox+f_%7B3%2C10%7D+%28x_5%29+%2B+f_%7B3%2C10%7D%27+%28x_5%29+%28%5Csqrt%5B3%5D%7B10%7D+-+x_5%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{3,10} (&#92;sqrt[3]{10}) &#92;approx f_{3,10} (x_5) + f_{3,10}&#039; (x_5) (&#92;sqrt[3]{10} - x_5)' title='f_{3,10} (&#92;sqrt[3]{10}) &#92;approx f_{3,10} (x_5) + f_{3,10}&#039; (x_5) (&#92;sqrt[3]{10} - x_5)' class='latex' /></p>
<p>and, since <img src='http://s0.wp.com/latex.php?latex=f_%7B3%2C10%7D+%28%5Csqrt%5B3%5D%7B10%7D%29+%3D+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{3,10} (&#92;sqrt[3]{10}) = 0' title='f_{3,10} (&#92;sqrt[3]{10}) = 0' class='latex' />, we obtain the estimate of the error</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_5+-+%5Csqrt%5B3%5D%7B10%7D+%5Capprox+%5Cdisplaystyle%5Cfrac%7Bf_%7B3%2C10%7D+%28x_5%29%7D%7Bf_%7B3%2C10%7D%27+%28x_5%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5 - &#92;sqrt[3]{10} &#92;approx &#92;displaystyle&#92;frac{f_{3,10} (x_5)}{f_{3,10}&#039; (x_5)}' title='x_5 - &#92;sqrt[3]{10} &#92;approx &#92;displaystyle&#92;frac{f_{3,10} (x_5)}{f_{3,10}&#039; (x_5)}' class='latex' /></p>
<p>In other words, the output deviation <img src='http://s0.wp.com/latex.php?latex=f_%7B3%2C10%7D+%28x_5%29+-+f_%7B3%2C10%7D+%28%5Csqrt%5B3%5D%7B10%7D%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{3,10} (x_5) - f_{3,10} (&#92;sqrt[3]{10})' title='f_{3,10} (x_5) - f_{3,10} (&#92;sqrt[3]{10})' class='latex' /> should be divided by the slope <img src='http://s0.wp.com/latex.php?latex=f_%7B3%2C10%7D%27+%28x_5%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f_{3,10}&#039; (x_5)' title='f_{3,10}&#039; (x_5)' class='latex' /> to obtain an estimate of the magnitude of the approximation error <img src='http://s0.wp.com/latex.php?latex=x_5+-+%5Csqrt%5B3%5D%7B10%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5 - &#92;sqrt[3]{10}' title='x_5 - &#92;sqrt[3]{10}' class='latex' />. Let us use <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> yet once again:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; let error = (x5^3 - 10) / (3 * x5^2)
*Main Data.Ratio&gt; error
1670089160826306272530773923851043922672595525468316978
5941152245094153072382174540074985393 % 272741620880842
8590518540423731512512814773109630109912907276686930689
12248623218095571481624481
*Main Data.Ratio&gt; 1670089160826306272530773923851043922
6725955254683169785941152245094153072382174540074985393
 / 2727416208808428590518540423731512512814773109630109
91290727668693068912248623218095571481624481
6.123338108179484e-5</pre>
<p>This is still quite a huge error, I would say.</p>
<p style="text-align:center;">__________</p>
<p><strong>Bonus Experiment<br />
</strong></p>
<p>Let us go crazy and attempt to compute a rational approximation of <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%5B100%5D%7B100%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt[100]{100}' title='&#92;sqrt[100]{100}' class='latex' />. We have <img src='http://s0.wp.com/latex.php?latex=n+%3D+100&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='n = 100' title='n = 100' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y+%3D+100&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = 100' title='y = 100' class='latex' />. We expect the rational numbers to quickly become ratios of <em>astronomically long</em> integers. Therefore, we will not be showing any rational approximations on <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a>. Here is something scary:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main Data.Ratio&gt; let x3 = (roots 100 100) !! 3
*Main Data.Ratio&gt; let error = (x3^100 - 100) / (100 * x3^99)
*Main Data.Ratio&gt; let error_float = fromIntegral (numerator error) 
                                  / fromIntegral (denominator error)
*Main Data.Ratio&gt; error_float</pre>
<p>After some 20 minutes without an output, I decided to abort this experiment. If you want to show <code>x3</code>, you can, but you will see thousands of digits. Thousands! You have been warned.</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/programming/haskell/'>Haskell</a>, <a href='http://stochastix.wordpress.com/category/mathematics/numerical-methods/'>Numerical Methods</a> Tagged: <a href='http://stochastix.wordpress.com/tag/arbitrary-precision-arithmetic/'>Arbitrary-Precision Arithmetic</a>, <a href='http://stochastix.wordpress.com/tag/data-ratio/'>Data.Ratio</a>, <a href='http://stochastix.wordpress.com/tag/golden-ratio/'>Golden Ratio</a>, <a href='http://stochastix.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://stochastix.wordpress.com/tag/herons-method/'>Heron’s Method</a>, <a href='http://stochastix.wordpress.com/tag/newtons-method/'>Newton’s Method</a>, <a href='http://stochastix.wordpress.com/tag/numerical-methods/'>Numerical Methods</a>, <a href='http://stochastix.wordpress.com/tag/rational-approximations/'>Rational Approximations</a>, <a href='http://stochastix.wordpress.com/tag/rational-arithmetic/'>Rational Arithmetic</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/8995/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/8995/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=8995&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2012/11/25/generalizing-herons-method/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>
	</item>
		<item>
		<title>Heron’s method using integer arithmetic</title>
		<link>http://stochastix.wordpress.com/2012/11/22/herons-method-using-integer-arithmetic/</link>
		<comments>http://stochastix.wordpress.com/2012/11/22/herons-method-using-integer-arithmetic/#comments</comments>
		<pubDate>Fri, 23 Nov 2012 02:21:34 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Numerical Methods]]></category>
		<category><![CDATA[Arbitrary-Precision Arithmetic]]></category>
		<category><![CDATA[Data.Ratio]]></category>
		<category><![CDATA[Heron’s Method]]></category>
		<category><![CDATA[Integer Arithmetic]]></category>
		<category><![CDATA[Newton’s Method]]></category>
		<category><![CDATA[Rational Approximations]]></category>
		<category><![CDATA[Rational Arithmetic]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=8923</guid>
		<description><![CDATA[Suppose we are given a positive rational number , whose square root we would like to compute. To be more precise, we would like to compute an approximation of . Let be an approximation of . Hence, we have that  is the geometric mean of and . If we replace the geometric mean of these [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=8923&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Suppose we are given a positive rational number <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' />, whose <a href="http://en.wikipedia.org/wiki/Square_root" target="_blank">square root</a> <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{y}' title='&#92;sqrt{y}' class='latex' /> we would like to compute. To be more precise, we would like to compute an <em>approximation</em> of <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{y}' title='&#92;sqrt{y}' class='latex' />.</p>
<p>Let <img src='http://s0.wp.com/latex.php?latex=x_k+%5Cneq+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_k &#92;neq 0' title='x_k &#92;neq 0' class='latex' /> be an approximation of <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{y}' title='&#92;sqrt{y}' class='latex' />. Hence, we have that <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{y}' title='&#92;sqrt{y}' class='latex' /> is the <a href="http://en.wikipedia.org/wiki/Geometric_mean" target="_blank">geometric mean</a> of <img src='http://s0.wp.com/latex.php?latex=x_k&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_k' title='x_k' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y+%2F+x_k&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y / x_k' title='y / x_k' class='latex' />. If we replace the geometric mean of these two numbers by their <a href="http://en.wikipedia.org/wiki/Arithmetic_mean" target="_blank">arithmetic mean</a>, we hopefully obtain a &#8220;better&#8221; approximation <img src='http://s0.wp.com/latex.php?latex=x_%7Bk%2B1%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_{k+1}' title='x_{k+1}' class='latex' />, as follows</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_%7Bk%2B1%7D+%3D+%5Cdisplaystyle%5Cfrac%7B1%7D%7B2%7D+%5Cleft%28+x_k+%2B+%5Cfrac%7By%7D%7Bx_k%7D%5Cright%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_{k+1} = &#92;displaystyle&#92;frac{1}{2} &#92;left( x_k + &#92;frac{y}{x_k}&#92;right)' title='x_{k+1} = &#92;displaystyle&#92;frac{1}{2} &#92;left( x_k + &#92;frac{y}{x_k}&#92;right)' class='latex' /></p>
<p>If all goes well, then <img src='http://s0.wp.com/latex.php?latex=x_N&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_N' title='x_N' class='latex' /> will be &#8220;sufficiently close&#8221; to <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{y}' title='&#92;sqrt{y}' class='latex' /> for a &#8220;sufficiently large&#8221; integer <img src='http://s0.wp.com/latex.php?latex=N&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='N' title='N' class='latex' />. This algorithm is the famous <a href="http://en.wikipedia.org/wiki/Heron's_method" target="_blank">Heron&#8217;s method</a>, devised by <a href="http://en.wikipedia.org/wiki/Hero_of_Alexandria" target="_blank">Heron of Alexandria</a> some 2000 years ago. Some call it the <em>Babylonian method</em>, which suggests that the algorithm may be some 4000 years old. It&#8217;s not merely <em>vintage</em>, it&#8217;s <em>antique</em>.</p>
<p>Nonetheless, this is <em>not</em> a post on archaeology. We don&#8217;t want to sit around and talk about <a href="http://en.wikipedia.org/wiki/Heron's_method" target="_blank">Heron&#8217;s method</a>, we want to actually implement it. What programming language should we use? Let us use <a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" target="_blank">Haskell</a>. How are we going to represent <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' /> and the sequence of approximations <img src='http://s0.wp.com/latex.php?latex=%28x_k%29_%7Bk+%5Cin+%5Cmathbb%7BN%7D_0%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='(x_k)_{k &#92;in &#92;mathbb{N}_0}' title='(x_k)_{k &#92;in &#92;mathbb{N}_0}' class='latex' />?</p>
<p style="text-align:center;">__________</p>
<p><strong>Heron&#8217;s method using floating-point arithmetic<br />
</strong></p>
<p>Though millions of people have already implemented <a href="http://en.wikipedia.org/wiki/Heron's_method" target="_blank">Heron&#8217;s method</a> using <a href="http://en.wikipedia.org/wiki/Floating_point" target="_blank">floating-point</a> arithmetic (I implemented it in <a href="http://en.wikipedia.org/wiki/C_%28programming_language%29" target="_blank">C</a> in late 2000), one more implementation would do no harm:</p>
<pre style="padding-left:30px;background:#EEEEEE;">y :: Floating a =&gt; a
y = 2

-- define Heron map
g :: Floating a =&gt; a -&gt; a
g x = 0.5 * (x + y/x)

-- initial approximation
x0:: Floating a =&gt; a
x0 = 1

-- list of approximations
xs :: Floating a =&gt; [a]
xs = iterate g x0</pre>
<p>Let us load this script into <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a>. Here&#8217;s a <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> session:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main&gt; take 6 xs
[1.0,1.5,1.4166666666666665,1.4142156862745097,
 1.4142135623746899,1.414213562373095]
*Main&gt; let x5 = xs !! 5
*Main&gt; x5**2 - 2
-4.440892098500626e-16</pre>
<p>We thus have the following approximation after five iterations</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_5+%3D+1.414213562373095+%5Capprox+%5Csqrt%7B2%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5 = 1.414213562373095 &#92;approx &#92;sqrt{2}' title='x_5 = 1.414213562373095 &#92;approx &#92;sqrt{2}' class='latex' /></p>
<p style="text-align:center;">__________</p>
<p><strong>Heron&#8217;s method using rational arithmetic</strong></p>
<p>Let us now use rational numbers of <a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_blank">arbitrary precision</a>. The following script uses the <a href="http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Ratio.html" target="_blank">Data.Ratio</a> library:</p>
<pre style="padding-left:30px;background:#EEEEEE;">import Data.Ratio

y :: Rational
y = 2

-- define Heron map
g :: Rational -&gt; Rational
g x = 0.5 * (x + y/x)

-- initial approximation
x0:: Rational
x0 = 1 % 1

-- list of approximations
xs :: [Rational]
xs = iterate g x0</pre>
<p>Let us load this script into <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a>. Here&#8217;s a <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> session:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main&gt; take 6 xs
[1 % 1,3 % 2,17 % 12,577 % 408,665857 % 470832,
 886731088897 % 627013566048]
*Main&gt; let x5 = xs !! 5
*Main&gt; x5*x5 - 2
1 % 393146012008229658338304
*Main&gt; 1 / 393146012008229658338304
2.5435842395854372e-24</pre>
<p>Note that the error is eight orders of magnitude smaller than in the previous case (where we used finite-precision <a href="http://en.wikipedia.org/wiki/Floating_point" target="_blank">floating-point</a> numbers). We pay for more accuracy with more computation. Thus, after five iterations, we have the following rational approximation</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_5+%3D+%5Cdisplaystyle%5Cfrac%7B886731088897%7D%7B627013566048%7D+%5Capprox+%5Csqrt%7B2%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5 = &#92;displaystyle&#92;frac{886731088897}{627013566048} &#92;approx &#92;sqrt{2}' title='x_5 = &#92;displaystyle&#92;frac{886731088897}{627013566048} &#92;approx &#92;sqrt{2}' class='latex' /></p>
<p>This is probably not news to you, my dear reader. Last April, I did, in fact, <a href="https://stochastix.wordpress.com/2012/04/02/newtons-method-using-rational-arithmetic/" target="_blank">implement Heron&#8217;s method under the disguise of Newton&#8217;s method</a> (see the appendix).</p>
<p style="text-align:center;">__________</p>
<p><strong>Heron&#8217;s method using integer arithmetic</strong></p>
<p>A <a href="http://en.wikipedia.org/wiki/Rational_number" target="_blank">rational number</a> <img src='http://s0.wp.com/latex.php?latex=y+%5Cin+%5Cmathbb%7BQ%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y &#92;in &#92;mathbb{Q}' title='y &#92;in &#92;mathbb{Q}' class='latex' /> can be expressed as a fraction <img src='http://s0.wp.com/latex.php?latex=a+%2F+b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a / b' title='a / b' class='latex' />, where <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='b' title='b' class='latex' /> are integers and <img src='http://s0.wp.com/latex.php?latex=b+%5Cneq+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='b &#92;neq 0' title='b &#92;neq 0' class='latex' />. Note that <img src='http://s0.wp.com/latex.php?latex=a+%2F+b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a / b' title='a / b' class='latex' /> can (obviously?) be represented as a pair of integers <img src='http://s0.wp.com/latex.php?latex=%28a%2Cb%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='(a,b)' title='(a,b)' class='latex' />. Since <a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" target="_blank">Haskell</a> has arbitrary-precision integers, we can implement <a href="http://en.wikipedia.org/wiki/Heron's_method" target="_blank">Heron&#8217;s method</a> using pairs of arbitrary-precision integers to represent <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' /> and the sequence of approximations <img src='http://s0.wp.com/latex.php?latex=%28x_k%29_%7Bk+%5Cin+%5Cmathbb%7BN%7D_0%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='(x_k)_{k &#92;in &#92;mathbb{N}_0}' title='(x_k)_{k &#92;in &#92;mathbb{N}_0}' class='latex' />.</p>
<p>Let <img src='http://s0.wp.com/latex.php?latex=y+%3A%3D+a+%2F+b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y := a / b' title='y := a / b' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=x_k+%3A%3D+p_k+%2F+q_k&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_k := p_k / q_k' title='x_k := p_k / q_k' class='latex' />. The recurrence relation</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_%7Bk%2B1%7D+%3D+%5Cdisplaystyle%5Cfrac%7B1%7D%7B2%7D+%5Cleft%28+x_k+%2B+%5Cfrac%7By%7D%7Bx_k%7D%5Cright%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_{k+1} = &#92;displaystyle&#92;frac{1}{2} &#92;left( x_k + &#92;frac{y}{x_k}&#92;right)' title='x_{k+1} = &#92;displaystyle&#92;frac{1}{2} &#92;left( x_k + &#92;frac{y}{x_k}&#92;right)' class='latex' /></p>
<p>can thus be rewritten in the following form</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Cfrac%7Bp_%7Bk%2B1%7D%7D%7Bq_%7Bk%2B1%7D%7D+%3D+%5Cfrac%7B1%7D%7B2%7D+%5Cleft%28+%5Cfrac%7Bp_k%7D%7Bq_k%7D+%2B+%5Cfrac%7Ba%7D%7Bb%7D+%5Cfrac%7Bq_k%7D%7Bp_k%7D+%5Cright%29+%3D+%5Cfrac%7Bb+%5C%2C+p_k%5E2+%2B+a+%5C%2C+q_k%5E2%7D%7B2+b+%5C%2C+p_k+%5C%2C+q_k%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;frac{p_{k+1}}{q_{k+1}} = &#92;frac{1}{2} &#92;left( &#92;frac{p_k}{q_k} + &#92;frac{a}{b} &#92;frac{q_k}{p_k} &#92;right) = &#92;frac{b &#92;, p_k^2 + a &#92;, q_k^2}{2 b &#92;, p_k &#92;, q_k}' title='&#92;displaystyle&#92;frac{p_{k+1}}{q_{k+1}} = &#92;frac{1}{2} &#92;left( &#92;frac{p_k}{q_k} + &#92;frac{a}{b} &#92;frac{q_k}{p_k} &#92;right) = &#92;frac{b &#92;, p_k^2 + a &#92;, q_k^2}{2 b &#92;, p_k &#92;, q_k}' class='latex' /></p>
<p>We then have two coupled recurrence relations</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cleft%5B%5Cbegin%7Barray%7D%7Bc%7D+p_%7Bk%2B1%7D%5C%5C+q_%7Bk%2B1%7D%5Cend%7Barray%7D%5Cright%5D+%3D+%5Cleft%5B%5Cbegin%7Barray%7D%7Bc%7D+b+%5C%2C+p_k%5E2+%2B+a+%5C%2C+q_k%5E2%5C%5C+2+b+%5C%2C+p_k+%5C%2C+q_k%5Cend%7Barray%7D%5Cright%5D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;left[&#92;begin{array}{c} p_{k+1}&#92;&#92; q_{k+1}&#92;end{array}&#92;right] = &#92;left[&#92;begin{array}{c} b &#92;, p_k^2 + a &#92;, q_k^2&#92;&#92; 2 b &#92;, p_k &#92;, q_k&#92;end{array}&#92;right]' title='&#92;left[&#92;begin{array}{c} p_{k+1}&#92;&#92; q_{k+1}&#92;end{array}&#92;right] = &#92;left[&#92;begin{array}{c} b &#92;, p_k^2 + a &#92;, q_k^2&#92;&#92; 2 b &#92;, p_k &#92;, q_k&#92;end{array}&#92;right]' class='latex' /></p>
<p>where <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='b' title='b' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=p_k&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='p_k' title='p_k' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=q_k&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='q_k' title='q_k' class='latex' /> are integers. Here is a <a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" target="_blank">Haskell</a> script that implements this vector recurrence relation:</p>
<pre style="padding-left:30px;background:#EEEEEE;">a, b :: Integer
a = 2
b = 1

-- define Heron map
g :: (Integer,Integer) -&gt; (Integer,Integer)
g (p,q) = (b * p^2 + a * q^2, 2 * b * p * q)

-- initial approximation
p0, q0 :: Integer
p0 = 1
q0 = 1

-- list of approximations
xs :: [(Integer,Integer)]
xs = iterate g (p0,q0)</pre>
<p>Let us load this script into <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a>. Here&#8217;s a <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> session:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main&gt; take 6 xs
[(1,1),(3,2),(17,12),(577,408),(665857,470832),
 (886731088897,627013566048)]
*Main&gt; let x5 = xs !! 5
*Main&gt; x5
(886731088897,627013566048)</pre>
<p>Hence, after five iterations, we obtain the very same rational approximation we obtained in the previous case (where we used rational numbers of arbitrary-precision)</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=x_5+%3D+%5Cdisplaystyle%5Cfrac%7B886731088897%7D%7B627013566048%7D+%5Capprox+%5Csqrt%7B2%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_5 = &#92;displaystyle&#92;frac{886731088897}{627013566048} &#92;approx &#92;sqrt{2}' title='x_5 = &#92;displaystyle&#92;frac{886731088897}{627013566048} &#92;approx &#92;sqrt{2}' class='latex' /></p>
<p>It should be noted, however, that this implementation using arbitrary-precision integers is different in one very important aspect from the one using arbitrary-precision rational numbers. What is the difference? Let <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> answer this question:</p>
<pre style="padding-left:30px;background:#FFFFFF;">*Main&gt; import Data.Ratio
*Main Data.Ratio&gt; 2 % 2
1 % 1
*Main Data.Ratio&gt; 4 % 4
1 % 1
*Main Data.Ratio&gt; 3 % 6
1 % 2</pre>
<p>The main difference between the two implementations is that when we use arbitrary-precision rational numbers, there is automatic reduction of every fraction to its <a href="http://en.wikipedia.org/wiki/Irreducible_fraction" target="_blank">irreducible</a> form, which requires computing the <a href="http://en.wikipedia.org/wiki/Greatest_common_divisor" target="_blank">greatest common divisor</a> (GCD) of the numerator and denominator of each rational number at each iteration. This has a computational cost, of course, but it also has the benefit of avoiding reducible fractions (which are inefficient representations of rational numbers). When we use pairs of arbitrary-precision integers, we do not compute the <a href="http://en.wikipedia.org/wiki/Greatest_common_divisor" target="_blank">GCD </a>(although we could, if we wanted to), but we may have to work with pairs of unnecessarily long integers (that correspond to reducible fractions), which is potentially dangerous.</p>
<p>For example, suppose that we replace the first three lines in the script above with the following three lines:</p>
<pre style="padding-left:30px;background:#EEEEEE;">a, b :: Integer
a = 2000
b = 1000</pre>
<p>We run the script again. Here&#8217;s yet another <a href="http://www.haskell.org/haskellwiki/GHC/GHCi" target="_blank">GHCi</a> session:</p>
<pre style="padding-left:30px;background:#FFFFFF;"> 
*Main&gt; take 6 xs
[(1,1),(3000,2000),(17000000000,12000000000),
(577000000000000000000000,408000000000000000000000),
(665857000000000000000000000000000000000000000000000,
470832000000000000000000000000000000000000000000000),
(8867310888970000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000,
62701356604800000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000)]
*Main&gt; let x5 = xs !! 5
*Main&gt; x5
(8867310888970000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000,
62701356604800000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000)</pre>
<p>Frankly, I am shocked! Multiplying <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=b&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='b' title='b' class='latex' /> by <img src='http://s0.wp.com/latex.php?latex=1000&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='1000' title='1000' class='latex' /> results in <img src='http://s0.wp.com/latex.php?latex=p_5&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='p_5' title='p_5' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=q_5&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='q_5' title='q_5' class='latex' /> being multiplied by <img src='http://s0.wp.com/latex.php?latex=10%5E%7B90%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='10^{90}' title='10^{90}' class='latex' />. I may have made a mistake counting all those zeros, but it&#8217;s a lot more zeros than I expected.</p>
<p style="text-align:center;">__________</p>
<p><strong>Appendix: from Heron to Newton</strong></p>
<p>Interestingly, <a href="http://en.wikipedia.org/wiki/Heron's_method" target="_blank">Heron&#8217;s method</a> can be derived from the no less famous <a href="http://en.wikipedia.org/wiki/Newton%27s_method" target="_blank">Newton&#8217;s method</a>. Let us introduce a function <img src='http://s0.wp.com/latex.php?latex=f+%3A+%5Cmathbb%7BR%7D+%5Cto+%5Cmathbb%7BR%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f : &#92;mathbb{R} &#92;to &#92;mathbb{R}' title='f : &#92;mathbb{R} &#92;to &#92;mathbb{R}' class='latex' />, defined by <img src='http://s0.wp.com/latex.php?latex=f+%28x%29+%3D+x%5E2+-+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f (x) = x^2 - y' title='f (x) = x^2 - y' class='latex' />. By construction, the zeros of function <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f' title='f' class='latex' /> are <img src='http://s0.wp.com/latex.php?latex=%5Csqrt%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;sqrt{y}' title='&#92;sqrt{y}' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=-%5Csqrt%7By%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='-&#92;sqrt{y}' title='-&#92;sqrt{y}' class='latex' />. Recall that <a href="http://en.wikipedia.org/wiki/Newton%27s_method" target="_blank">Newton&#8217;s method</a> uses the recurrence relation <img src='http://s0.wp.com/latex.php?latex=x_%7Bk%2B1%7D+%3D+g+%28+x_k+%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x_{k+1} = g ( x_k )' title='x_{k+1} = g ( x_k )' class='latex' />, where function <img src='http://s0.wp.com/latex.php?latex=g+%3A+%5Cmathbb%7BR%7D+%5Cto+%5Cmathbb%7BR%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='g : &#92;mathbb{R} &#92;to &#92;mathbb{R}' title='g : &#92;mathbb{R} &#92;to &#92;mathbb{R}' class='latex' /> is defined by</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=g+%28x%29+%3D+x+-+%5Cdisplaystyle%5Cfrac%7Bf+%28x%29%7D%7Bf%27+%28x%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='g (x) = x - &#92;displaystyle&#92;frac{f (x)}{f&#039; (x)}' title='g (x) = x - &#92;displaystyle&#92;frac{f (x)}{f&#039; (x)}' class='latex' /></p>
<p>where <img src='http://s0.wp.com/latex.php?latex=f%27&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f&#039;' title='f&#039;' class='latex' /> is the first derivative of <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f' title='f' class='latex' />. Hence, we obtain the following</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=g+%28x%29+%3D+x+-+%5Cdisplaystyle%5Cfrac%7Bf+%28x%29%7D%7Bf%27+%28x%29%7D+%3D+x+-+%5Cdisplaystyle%5Cleft%28%5Cfrac%7Bx%5E2+-+y%7D%7B2+x%7D%5Cright%29+%3D+%5Cdisplaystyle%5Cfrac%7B1%7D%7B2%7D+%5Cleft%28+x+%2B+%5Cfrac%7By%7D%7Bx%7D%5Cright%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='g (x) = x - &#92;displaystyle&#92;frac{f (x)}{f&#039; (x)} = x - &#92;displaystyle&#92;left(&#92;frac{x^2 - y}{2 x}&#92;right) = &#92;displaystyle&#92;frac{1}{2} &#92;left( x + &#92;frac{y}{x}&#92;right)' title='g (x) = x - &#92;displaystyle&#92;frac{f (x)}{f&#039; (x)} = x - &#92;displaystyle&#92;left(&#92;frac{x^2 - y}{2 x}&#92;right) = &#92;displaystyle&#92;frac{1}{2} &#92;left( x + &#92;frac{y}{x}&#92;right)' class='latex' /></p>
<p>which is the recurrence relation used in <a href="http://en.wikipedia.org/wiki/Heron's_method" target="_blank">Heron&#8217;s method</a>.</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/programming/haskell/'>Haskell</a>, <a href='http://stochastix.wordpress.com/category/mathematics/numerical-methods/'>Numerical Methods</a> Tagged: <a href='http://stochastix.wordpress.com/tag/arbitrary-precision-arithmetic/'>Arbitrary-Precision Arithmetic</a>, <a href='http://stochastix.wordpress.com/tag/data-ratio/'>Data.Ratio</a>, <a href='http://stochastix.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://stochastix.wordpress.com/tag/herons-method/'>Heron’s Method</a>, <a href='http://stochastix.wordpress.com/tag/integer-arithmetic/'>Integer Arithmetic</a>, <a href='http://stochastix.wordpress.com/tag/newtons-method/'>Newton’s Method</a>, <a href='http://stochastix.wordpress.com/tag/numerical-methods/'>Numerical Methods</a>, <a href='http://stochastix.wordpress.com/tag/rational-approximations/'>Rational Approximations</a>, <a href='http://stochastix.wordpress.com/tag/rational-arithmetic/'>Rational Arithmetic</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/8923/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/8923/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=8923&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2012/11/22/herons-method-using-integer-arithmetic/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>
	</item>
		<item>
		<title>Conservatives and Progressives</title>
		<link>http://stochastix.wordpress.com/2012/11/05/conservatives-and-progressives/</link>
		<comments>http://stochastix.wordpress.com/2012/11/05/conservatives-and-progressives/#comments</comments>
		<pubDate>Mon, 05 Nov 2012 16:49:30 +0000</pubDate>
		<dc:creator>Rod Carvalho</dc:creator>
				<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[Apoliteia]]></category>
		<category><![CDATA[Conservatism]]></category>
		<category><![CDATA[Conservatives]]></category>
		<category><![CDATA[G. K. Chesterton]]></category>
		<category><![CDATA[Nihil novi sub sole]]></category>
		<category><![CDATA[Political Polarization]]></category>
		<category><![CDATA[Progressives]]></category>
		<category><![CDATA[Progressivism]]></category>
		<category><![CDATA[Zeitgeist]]></category>

		<guid isPermaLink="false">http://stochastix.wordpress.com/?p=8912</guid>
		<description><![CDATA[G. K. Chesterton on conservatives and progressives: The whole modern world has divided itself into Conservatives and Progressives. The business of Progressives is to go on making mistakes. The business of the Conservatives is to prevent the mistakes being corrected. Even when the revolutionist might himself repent of his revolution, the traditionalist is already defending it [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=8912&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/G._K._Chesterton" target="_blank">G. K. Chesterton</a> on conservatives and progressives:</p>
<p style="padding-left:30px;"><em>The whole modern world has divided itself into Conservatives and Progressives. The business of Progressives is to go on making mistakes. The business of the Conservatives is to prevent the mistakes being corrected. Even when the revolutionist might himself repent of his revolution, the traditionalist is already defending it as part of his tradition. Thus we have the two great types&#8212;the advanced person who rushes us into ruin, and the retrospective person who admires the ruins. He admires them especially by moonlight, not to say moonshine. Each new blunder of the progressive or prig becomes instantly a legend of immemorial antiquity for the snob. This is called the balance, or mutual check, in our Constitution.</em></p>
<p>This passage is taken from an article entitled <em>The Blunders of Our Parties</em> that was published on April 19, 1924 in the now-defunct <a href="http://en.wikipedia.org/wiki/The_Illustrated_London_News" target="_blank">The Illustrated London News</a>.</p>
<p style="text-align:center;">__________</p>
<p>Source:</p>
<p style="padding-left:30px;">Gilbert Keith Chesterton, <em><a href="http://books.google.com/books?id=tJhsywPcWJMC" target="_blank">The Collected Works of G. K. Chesterton, Volume XXXIII: The Illustrated London News 1923-1925</a></em>, Ignatius Press, San Francisco, 1990.</p>
<br />Filed under: <a href='http://stochastix.wordpress.com/category/thoughts/'>Thoughts</a> Tagged: <a href='http://stochastix.wordpress.com/tag/apoliteia/'>Apoliteia</a>, <a href='http://stochastix.wordpress.com/tag/conservatism/'>Conservatism</a>, <a href='http://stochastix.wordpress.com/tag/conservatives/'>Conservatives</a>, <a href='http://stochastix.wordpress.com/tag/g-k-chesterton/'>G. K. Chesterton</a>, <a href='http://stochastix.wordpress.com/tag/nihil-novi-sub-sole/'>Nihil novi sub sole</a>, <a href='http://stochastix.wordpress.com/tag/political-polarization/'>Political Polarization</a>, <a href='http://stochastix.wordpress.com/tag/progressives/'>Progressives</a>, <a href='http://stochastix.wordpress.com/tag/progressivism/'>Progressivism</a>, <a href='http://stochastix.wordpress.com/tag/zeitgeist/'>Zeitgeist</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stochastix.wordpress.com/8912/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stochastix.wordpress.com/8912/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stochastix.wordpress.com&#038;blog=300626&#038;post=8912&#038;subd=stochastix&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stochastix.wordpress.com/2012/11/05/conservatives-and-progressives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dad6f9ce00c4485d418494ebf78bf4e8?s=96&#38;d=identicon" medium="image">
			<media:title type="html">stochastix</media:title>
		</media:content>
	</item>
	</channel>
</rss>
