<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Reliability with Erlang</title>
	<atom:link href="http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/feed/" rel="self" type="application/rss+xml" />
	<link>http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/</link>
	<description>Ask forgiveness, not permission.</description>
	<pubDate>Sun, 07 Sep 2008 17:31:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Mike Giroux</title>
		<link>http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-257</link>
		<dc:creator>Mike Giroux</dc:creator>
		<pubDate>Wed, 07 Nov 2007 18:29:38 +0000</pubDate>
		<guid isPermaLink="false">http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-257</guid>
		<description>PS: Yes, I realize that without the unrolling, Square*Square will be computed once too often by the "generic" geometric_pow/3.  But the slowness happened even with versions of geometric_pow/3 that didn't have that problem.  Very strange...</description>
		<content:encoded><![CDATA[<p>PS: Yes, I realize that without the unrolling, Square*Square will be computed once too often by the &#8220;generic&#8221; geometric_pow/3.  But the slowness happened even with versions of geometric_pow/3 that didn&#8217;t have that problem.  Very strange&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Giroux</title>
		<link>http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-254</link>
		<dc:creator>Mike Giroux</dc:creator>
		<pubDate>Tue, 06 Nov 2007 12:42:03 +0000</pubDate>
		<guid isPermaLink="false">http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-254</guid>
		<description>Steve,

Nice articles, thanks.  I'm trying to learn Erlang, and having fun.

One entertaining exercise was trying to speed up pow.

Obviously, doing pow linearly shouldn't be faster than doing a "binary exponentiation" pow computation.

http://en.wikipedia.org/wiki/Exponentiation_by_squaring

What was driving me crazy is that although this algorithm is O(lg n) and the other pow is O(n), I had a heck of a time getting a powers of 2 implementation that beat the linear one in erlang.

I had to "unroll" the last few levels of my function to explicitly match exponents 1, 2, and 3 before this approach started to win.

This final implementation wins big, though, and also has a big advantage in terms of the largest power that can be computed.  Trying to compute pow(5000,50000) on my mac runs out of memory, but geometric_pow(5000,50000) computes it in 
2.7 seconds.

Here's the implementation:

% Licensed under Artistic License, see 
% http://www.perl.com/pub/a/language/misc/Artistic.html
% Mike Giroux, rmgiroux@gmail.com

-module(geometric_pow).
-export([geometric_pow/2]).

geometric_pow(_, 0, Acc) -&#62; Acc;
% It's interesting that if 1 and 2 aren't "unrolled",
% the linear implementation beats geometric_pow.
geometric_pow(Square, 1, Acc) -&#62; Square*Acc;
geometric_pow(Square, 2, Acc) -&#62; Square*Square*Acc;
geometric_pow(Square, 3, Acc) -&#62; Square*Square*Square*Acc;
geometric_pow(Square, 4, Acc) -&#62; Square*Square*Square*Square*Acc;
geometric_pow(Square, Exp, Acc) -&#62;
        geometric_pow(Square*Square, Exp div 2, ((Exp rem 2)*(Square-1)*Acc + Acc)).

geometric_pow(Base, Exponent) -&#62;
  geometric_pow(Base,Exponent,1).</description>
		<content:encoded><![CDATA[<p>Steve,</p>
<p>Nice articles, thanks.  I&#8217;m trying to learn Erlang, and having fun.</p>
<p>One entertaining exercise was trying to speed up pow.</p>
<p>Obviously, doing pow linearly shouldn&#8217;t be faster than doing a &#8220;binary exponentiation&#8221; pow computation.</p>
<p><a href="http://en.wikipedia.org/wiki/Exponentiation_by_squaring" rel="nofollow">http://en.wikipedia.org/wiki/Exponentiation_by_squaring</a></p>
<p>What was driving me crazy is that although this algorithm is O(lg n) and the other pow is O(n), I had a heck of a time getting a powers of 2 implementation that beat the linear one in erlang.</p>
<p>I had to &#8220;unroll&#8221; the last few levels of my function to explicitly match exponents 1, 2, and 3 before this approach started to win.</p>
<p>This final implementation wins big, though, and also has a big advantage in terms of the largest power that can be computed.  Trying to compute pow(5000,50000) on my mac runs out of memory, but geometric_pow(5000,50000) computes it in<br />
2.7 seconds.</p>
<p>Here&#8217;s the implementation:</p>
<p>% Licensed under Artistic License, see<br />
% <a href="http://www.perl.com/pub/a/language/misc/Artistic.html" rel="nofollow">http://www.perl.com/pub/a/language/misc/Artistic.html</a><br />
% Mike Giroux, <a href="mailto:rmgiroux@gmail.com">rmgiroux@gmail.com</a></p>
<p>-module(geometric_pow).<br />
-export([geometric_pow/2]).</p>
<p>geometric_pow(_, 0, Acc) -&gt; Acc;<br />
% It&#8217;s interesting that if 1 and 2 aren&#8217;t &#8220;unrolled&#8221;,<br />
% the linear implementation beats geometric_pow.<br />
geometric_pow(Square, 1, Acc) -&gt; Square*Acc;<br />
geometric_pow(Square, 2, Acc) -&gt; Square*Square*Acc;<br />
geometric_pow(Square, 3, Acc) -&gt; Square*Square*Square*Acc;<br />
geometric_pow(Square, 4, Acc) -&gt; Square*Square*Square*Square*Acc;<br />
geometric_pow(Square, Exp, Acc) -&gt;<br />
        geometric_pow(Square*Square, Exp div 2, ((Exp rem 2)*(Square-1)*Acc + Acc)).</p>
<p>geometric_pow(Base, Exponent) -&gt;<br />
  geometric_pow(Base,Exponent,1).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darach</title>
		<link>http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-234</link>
		<dc:creator>Darach</dc:creator>
		<pubDate>Fri, 02 Nov 2007 23:12:25 +0000</pubDate>
		<guid isPermaLink="false">http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-234</guid>
		<description>I've built strategized fast-fail into asynchronous FSMs in trading platforms as a default transition. When you have 40+ states and 100s of state-changing transitions in a state machine it gets hard to test every single possible race condition due to the size of the state space involved.

Either way Steve/Lauri you've both convinced me to pick up the book! Also, it seems FSM's are very well supported in erlang:

http://portal.acm.org/ft_gateway.cfm?id=1292529&#38;type=pdf&#38;coll=GUIDE&#38;dl=&#38;CFID=15151515&#38;CFTOKEN=6184618</description>
		<content:encoded><![CDATA[<p>I&#8217;ve built strategized fast-fail into asynchronous FSMs in trading platforms as a default transition. When you have 40+ states and 100s of state-changing transitions in a state machine it gets hard to test every single possible race condition due to the size of the state space involved.</p>
<p>Either way Steve/Lauri you&#8217;ve both convinced me to pick up the book! Also, it seems FSM&#8217;s are very well supported in erlang:</p>
<p><a href="http://portal.acm.org/ft_gateway.cfm?id=1292529&amp;type=pdf&amp;coll=GUIDE&amp;dl=&amp;CFID=15151515&amp;CFTOKEN=6184618" rel="nofollow">http://portal.acm.org/ft_gateway.cfm?id=1292529&amp;type=pdf&amp;coll=GUIDE&amp;dl=&amp;CFID=15151515&amp;CFTOKEN=6184618</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Logan</title>
		<link>http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-230</link>
		<dc:creator>Patrick Logan</dc:creator>
		<pubDate>Fri, 02 Nov 2007 00:11:58 +0000</pubDate>
		<guid isPermaLink="false">http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-230</guid>
		<description>I prefer ErUnit over EUnit. It was simply easier for me to start using.

http://bestfriendchris.com/blog/2007/04/23/erunit-unit-testing-for-erlang/

Not sure about feature comparison. I don't demand much of a unit test framework.</description>
		<content:encoded><![CDATA[<p>I prefer ErUnit over EUnit. It was simply easier for me to start using.</p>
<p><a href="http://bestfriendchris.com/blog/2007/04/23/erunit-unit-testing-for-erlang/" rel="nofollow">http://bestfriendchris.com/blog/2007/04/23/erunit-unit-testing-for-erlang/</a></p>
<p>Not sure about feature comparison. I don&#8217;t demand much of a unit test framework.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Abley</title>
		<link>http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-228</link>
		<dc:creator>James Abley</dc:creator>
		<pubDate>Thu, 01 Nov 2007 21:29:53 +0000</pubDate>
		<guid isPermaLink="false">http://steve.vinoski.net/blog/2007/10/31/reliability-with-erlang/#comment-228</guid>
		<description>Do you have any thoughts on Erlang's test frameworks? Something that put me off learning Lisp for a very long time was the lack of LispUnit, but I eventually persevered with Peter Seibel's &lt;a href="http://www.gigamonkeys.com/book/" rel="nofollow"&gt;excellent book&lt;/a&gt;. I'm going through Joe's book now, and all I've found thus far is "write a makefile that exercises  the code with test code". It feels a bit far off JUnit, ANT and Ivy, and that worries me. Should it?</description>
		<content:encoded><![CDATA[<p>Do you have any thoughts on Erlang&#8217;s test frameworks? Something that put me off learning Lisp for a very long time was the lack of LispUnit, but I eventually persevered with Peter Seibel&#8217;s <a href="http://www.gigamonkeys.com/book/" rel="nofollow">excellent book</a>. I&#8217;m going through Joe&#8217;s book now, and all I&#8217;ve found thus far is &#8220;write a makefile that exercises  the code with test code&#8221;. It feels a bit far off JUnit, ANT and Ivy, and that worries me. Should it?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
