<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Seemingly impossible functional programs</title>
	<link>http://math.andrej.com/2007/09/28/seemingly-impossible-functional-programs/</link>
	<description>Mathematics for computers</description>
	<pubDate>Fri, 04 Jul 2008 17:29:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Martin Escardó</title>
		<link>http://math.andrej.com/2007/09/28/seemingly-impossible-functional-programs/#comment-5868</link>
		<dc:creator>Martin Escardó</dc:creator>
		<pubDate>Mon, 01 Oct 2007 14:28:45 +0000</pubDate>
		<guid>http://math.andrej.com/2007/09/28/seemingly-impossible-functional-programs/#comment-5868</guid>
		<description>I've found a way of making the fastest algorithm about 40 faster by avoiding the trees and instead treating functions as trees:
&lt;pre&gt;
&#62; find = find_viii
&#62; findBit :: (Bit -&#62; Bool) -&#62; Bit
&#62; findBit p = if p Zero then Zero else One
&#62; branch :: Bit -&#62; Cantor -&#62; Cantor -&#62; Cantor
&#62; branch x l r n &#124;  n == 0    = x
&#62;                    &#124;  odd n     = l ((n-1) `div` 2)
&#62;                    &#124;  otherwise = r ((n-2) `div` 2)
&#62; find_viii :: (Cantor -&#62; Bool) -&#62; Cantor
&#62; find_viii p = branch x l r
&#62;  where x = findBit(x -&#62; forsome(l -&#62; forsome(r -&#62; p(branch x l r))))
&#62;          l = find_viii(l -&#62; forsome(r -&#62; p(branch x l r)))
&#62;          r = find_viii(r -&#62; p(branch x l r))
&lt;/pre&gt;
This doesn't need the memoization, because the things one needs to remember are bound to variables in the where-clause. Using this algorithm, comparing f' and g', and f' and h' for equality moves from 6.75 and 3.20 seconds to respectively 0.14 and 0.09 seconds (using the Glasgow interpreter in all cases).
</description>
		<content:encoded><![CDATA[<p>I&#8217;ve found a way of making the fastest algorithm about 40 faster by avoiding the trees and instead treating functions as trees:</p>
<pre>
&gt; find = find_viii
&gt; findBit :: (Bit -&gt; Bool) -&gt; Bit
&gt; findBit p = if p Zero then Zero else One
&gt; branch :: Bit -&gt; Cantor -&gt; Cantor -&gt; Cantor
&gt; branch x l r n |  n == 0    = x
&gt;                    |  odd n     = l ((n-1) `div` 2)
&gt;                    |  otherwise = r ((n-2) `div` 2)
&gt; find_viii :: (Cantor -&gt; Bool) -&gt; Cantor
&gt; find_viii p = branch x l r
&gt;  where x = findBit(x -&gt; forsome(l -&gt; forsome(r -&gt; p(branch x l r))))
&gt;          l = find_viii(l -&gt; forsome(r -&gt; p(branch x l r)))
&gt;          r = find_viii(r -&gt; p(branch x l r))
</pre>
<p>This doesn&#8217;t need the memoization, because the things one needs to remember are bound to variables in the where-clause. Using this algorithm, comparing f&#8217; and g&#8217;, and f&#8217; and h&#8217; for equality moves from 6.75 and 3.20 seconds to respectively 0.14 and 0.09 seconds (using the Glasgow interpreter in all cases).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
