<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Java Haskell on Chase the Devil</title>
		<link>https://31416.org/tags/java-haskell/</link>
		<description>Recent content in Java Haskell on Chase the Devil</description>
		<generator>Hugo</generator>
		<language>en-us</language>
		
		
		
		
			<lastBuildDate>Fri, 22 Mar 2013 12:20:00 +0000</lastBuildDate>
		
			<atom:link href="https://31416.org/tags/java-haskell/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Cracking the Double Precision Gaussian Puzzle</title>
				<link>https://31416.org/post/cracking-the-double-precision-gaussian-puzzle/</link>
				<pubDate>Fri, 22 Mar 2013 12:20:00 +0000</pubDate>
				<guid>https://31416.org/post/cracking-the-double-precision-gaussian-puzzle/</guid>
				<description>&lt;p&gt;In my &lt;a href=&#34;https://31416.org/post/a-double-precision-puzzle-with-the-gaussian/&#34;&gt;previous post&lt;/a&gt;, I stated that some library (SPECFUN by W.D. Cody) computes \(e^{-\frac{x^2}{2}}\) the following way:&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-C&#34; data-lang=&#34;C&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;xsq &lt;span style=&#34;color:#666&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#06287e&#34;&gt;fint&lt;/span&gt;(x &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#40a070&#34;&gt;1.6&lt;/span&gt;) &lt;span style=&#34;color:#666&#34;&gt;/&lt;/span&gt; &lt;span style=&#34;color:#40a070&#34;&gt;1.6&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;del &lt;span style=&#34;color:#666&#34;&gt;=&lt;/span&gt; (x &lt;span style=&#34;color:#666&#34;&gt;-&lt;/span&gt; xsq) &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; (x &lt;span style=&#34;color:#666&#34;&gt;+&lt;/span&gt; xsq);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;result &lt;span style=&#34;color:#666&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#06287e&#34;&gt;exp&lt;/span&gt;(&lt;span style=&#34;color:#666&#34;&gt;-&lt;/span&gt;xsq &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; xsq &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#40a070&#34;&gt;0.5&lt;/span&gt;) &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#06287e&#34;&gt;exp&lt;/span&gt;(&lt;span style=&#34;color:#666&#34;&gt;-&lt;/span&gt;del &lt;span style=&#34;color:#666&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#40a070&#34;&gt;0.5&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;code class=&#34;code-inline language-C&#34;&gt;&lt;span style=&#34;color:#06287e&#34;&gt;fint&lt;/span&gt;(z)&lt;/code&gt; computes the floor of z.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Why 1.6?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;An integer divided by 1.6 will be an exact representation of the corresponding number in double: 1.6 because of 16 (dividing by 1.6 is equivalent to multiplying by 10 and dividing by 16 which is an exact operation). It also allows to have something very close to a rounding function: x=2.6 will make xsq=2.5, x=2.4 will make xsq=1.875, x=2.5 will make xsq=2.5. The maximum difference between x and xsq will be 0.625.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Haskell Fibonacci Revisited</title>
				<link>https://31416.org/post/haskell-fibonacci-revisited/</link>
				<pubDate>Wed, 12 Dec 2007 17:08:00 +0000</pubDate>
				<guid>https://31416.org/post/haskell-fibonacci-revisited/</guid>
				<description>Recently, there was an &lt;a href=&#34;http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core&#34;&gt;interesting post&lt;/a&gt; about Haskell performance and Haskell parallelization showing Haskell could outperform C on a simple Fibonacci example.&lt;br /&gt;&lt;br /&gt;A friend of mine, Peter (that I seem to manage to constantly piss off) thought about it on another level, saying you could achieve a _MILLION_ times better using a direct formula in C or Java, &lt;a href=&#34;http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibFormula.html#formula&#34;&gt;the Binet formula&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I decided to try as the improvement scale seemed a bit surprising. I first compared a Java recursive fibonacci with a Haskell one. Here are the results for Haskell GHC 6.6.1 vs Java 1.6.0 on Linux for fib(44):&lt;br /&gt;&lt;a onblur=&#34;try {parent.deselectBloggerImageGracefully();} catch(e) {}&#34; href=&#34;http://4.bp.blogspot.com/_9RyqGT46Fbk/R2AevOMNqtI/AAAAAAAABI4/Ju0-GjX6W14/s1600-h/simple_haskell.png&#34;&gt;&lt;img style=&#34;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&#34; src=&#34;http://4.bp.blogspot.com/_9RyqGT46Fbk/R2AevOMNqtI/AAAAAAAABI4/Ju0-GjX6W14/s320/simple_haskell.png&#34; border=&#34;0&#34; alt=&#34;&#34;id=&#34;BLOGGER_PHOTO_ID_5143144571069115090&#34; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur=&#34;try {parent.deselectBloggerImageGracefully();} catch(e) {}&#34; href=&#34;http://1.bp.blogspot.com/_9RyqGT46Fbk/R2AeveMNquI/AAAAAAAABJA/DJDx3Vw0LyU/s1600-h/simple_java.png&#34;&gt;&lt;img style=&#34;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&#34; src=&#34;http://1.bp.blogspot.com/_9RyqGT46Fbk/R2AeveMNquI/AAAAAAAABJA/DJDx3Vw0LyU/s320/simple_java.png&#34; border=&#34;0&#34; alt=&#34;&#34;id=&#34;BLOGGER_PHOTO_ID_5143144575364082402&#34; /&gt;&lt;/a&gt;&lt;br /&gt;Then I decided to check out the time for fib(44) or any fib at all, I was unable to measure precisely enough since it always came out as 0ms, in Haskell, or in Java. Looping out 10 million times, Java gave out 7.3s and Haskell something similar (but my method to loop 10 million times in Haskell is probably very bad).&lt;br /&gt;&lt;a onblur=&#34;try {parent.deselectBloggerImageGracefully();} catch(e) {}&#34; href=&#34;http://4.bp.blogspot.com/_9RyqGT46Fbk/R2AnZOMNqvI/AAAAAAAABJI/DHpUw2wMiTc/s1600-h/binet_haskell.png&#34;&gt;&lt;img style=&#34;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&#34; src=&#34;http://4.bp.blogspot.com/_9RyqGT46Fbk/R2AnZOMNqvI/AAAAAAAABJI/DHpUw2wMiTc/s320/binet_haskell.png&#34; border=&#34;0&#34; alt=&#34;&#34;id=&#34;BLOGGER_PHOTO_ID_5143154088716643058&#34; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur=&#34;try {parent.deselectBloggerImageGracefully();} catch(e) {}&#34; href=&#34;http://4.bp.blogspot.com/_9RyqGT46Fbk/R2AnZOMNqwI/AAAAAAAABJQ/dkgIlZuXSPE/s1600-h/binet_java.png&#34;&gt;&lt;img style=&#34;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&#34; src=&#34;http://4.bp.blogspot.com/_9RyqGT46Fbk/R2AnZOMNqwI/AAAAAAAABJQ/dkgIlZuXSPE/s320/binet_java.png&#34; border=&#34;0&#34; alt=&#34;&#34;id=&#34;BLOGGER_PHOTO_ID_5143154088716643074&#34; /&gt;&lt;/a&gt;&lt;br /&gt;The original post actually points to a link that describes various algorithms for Fibonacci. They basically say that for large n, the rounding is not precise enough, they also propose algorithms in log(n). I tried and was really impressed by the performance of those algorithms. Again I could not measure the difference for a single calculation between it and the binet formula as elapsed time is always 0. The binet formula becomes inexact already at n=71 in Java with doubles.&lt;br /&gt;&lt;a onblur=&#34;try {parent.deselectBloggerImageGracefully();} catch(e) {}&#34; href=&#34;http://2.bp.blogspot.com/_9RyqGT46Fbk/R2AoLuMNqxI/AAAAAAAABJY/o0Z4pI0ELPY/s1600-h/fancy_haskell.png&#34;&gt;&lt;img style=&#34;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&#34; src=&#34;http://2.bp.blogspot.com/_9RyqGT46Fbk/R2AoLuMNqxI/AAAAAAAABJY/o0Z4pI0ELPY/s320/fancy_haskell.png&#34; border=&#34;0&#34; alt=&#34;&#34;id=&#34;BLOGGER_PHOTO_ID_5143154956300036882&#34; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Of course the original post is still quite interesting, it shows how easy it can be to parallelize calculations in Haskell. But the example is silly as another algorithm can lead to 10 millions times the performance. Still Haskell performs well with the shit or good algorithm when compared to Java.</description>
			</item>
	</channel>
</rss>
