<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Efficient integer exponentiation algorithms</title>
	<atom:link href="http://eli.thegreenplace.net/2009/03/21/efficient-integer-exponentiation-algorithms/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net/2009/03/21/efficient-integer-exponentiation-algorithms/</link>
	<description>Eli Bendersky's personal website</description>
	<lastBuildDate>Wed, 10 Mar 2010 17:32:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2009/03/21/efficient-integer-exponentiation-algorithms/comment-page-1/#comment-188024</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Thu, 30 Jul 2009 03:41:52 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=1581#comment-188024</guid>
		<description>@Greg, thanks for sharing!</description>
		<content:encoded><![CDATA[<p>@Greg, thanks for sharing!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Johnston</title>
		<link>http://eli.thegreenplace.net/2009/03/21/efficient-integer-exponentiation-algorithms/comment-page-1/#comment-187987</link>
		<dc:creator>Greg Johnston</dc:creator>
		<pubDate>Thu, 30 Jul 2009 01:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=1581#comment-187987</guid>
		<description>Just thought it would be cool to share: here&#039;s the recursive algorithm, translated into Haskell. Works really nicely with pattern-matching.

`&lt;code&gt;power :: Integer -__abENT__gt; Integer -__abENT__gt; Integer
power 0 _ = 0
power _ 0 = 1
power a b
 &#124; odd b = a * (power a (b-1))
 &#124; even b = (power a (floor $ (fromIntegral b)__abENT__#8260;2))^2&lt;/code&gt;`

The type declaration (first line) is actually unnecessary, but it helps for clarity. In fact, if you leave it out, GHC deduces the type as `&lt;code&gt;power :: (Num t, Integral b) =__abENT__gt; t -__abENT__gt; b -__abENT__gt; t&lt;/code&gt;`, which actually lets you do something like `&lt;code&gt;power 1__abENT__#46;5 10&lt;/code&gt;` as well.

Just for a silly little comparison*, I ran this Haskell and your Python implementation on 40^1000000, timed using `&lt;code&gt;time __abENT__lt;run whichever version__abENT__gt;&lt;/code&gt;`.

Haskell, a typical time (ran it four or five times, similar results each time):
`&lt;code&gt;real	0m1__abENT__#46;248s
user	0m1__abENT__#46;124s
sys	0m0__abENT__#46;041s&lt;/code&gt;`

Python, the one time I dared:
`&lt;code&gt;real	10m57__abENT__#46;630s
user	10m40__abENT__#46;980s
sys	0m1__abENT__#46;328s&lt;/code&gt;`

* Obviously this is silly for several reasons. One is that Haskell is ridiculously fast. Python is not necessarily designed for speeds, and it excels in a variety of other things. It is my main language. Additionally, the Haskell was compiled using `&lt;code&gt;ghc&lt;/code&gt;`. When I ran it using `&lt;code&gt;ghci&lt;/code&gt;`, an interactive interpreter, it took roughly one or two seconds to compute and much longer to print, oddly enough.</description>
		<content:encoded><![CDATA[<p>Just thought it would be cool to share: here&#8217;s the recursive algorithm, translated into Haskell. Works really nicely with pattern-matching.</p>
<div class="backtick"><pre><code>power :: Integer -&gt; Integer -&gt; Integer
power 0 _ = 0
power _ 0 = 1
power a b
 | odd b = a * (power a (b-1))
 | even b = (power a (floor $ (fromIntegral b)/2))^2</code></pre></div>
<p>The type declaration (first line) is actually unnecessary, but it helps for clarity. In fact, if you leave it out, GHC deduces the type as <code class="backtick">power :: (Num t, Integral b) =&gt; t -&gt; b -&gt; t</code>, which actually lets you do something like <code class="backtick">power 1&#46;5 10</code> as well.</p>
<p>Just for a silly little comparison*, I ran this Haskell and your Python implementation on 40^1000000, timed using <code class="backtick">time &lt;run whichever version&gt;</code>.</p>
<p>Haskell, a typical time (ran it four or five times, similar results each time):<br />
<code class="backtick">real	0m1&#46;248s<br />
user	0m1&#46;124s<br />
sys	0m0&#46;041s</code></p>
<p>Python, the one time I dared:<br />
<code class="backtick">real	10m57&#46;630s<br />
user	10m40&#46;980s<br />
sys	0m1&#46;328s</code></p>
<p>* Obviously this is silly for several reasons. One is that Haskell is ridiculously fast. Python is not necessarily designed for speeds, and it excels in a variety of other things. It is my main language. Additionally, the Haskell was compiled using <code class="backtick">ghc</code>. When I ran it using <code class="backtick">ghci</code>, an interactive interpreter, it took roughly one or two seconds to compute and much longer to print, oddly enough.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anna</title>
		<link>http://eli.thegreenplace.net/2009/03/21/efficient-integer-exponentiation-algorithms/comment-page-1/#comment-162944</link>
		<dc:creator>Anna</dc:creator>
		<pubDate>Tue, 24 Mar 2009 11:50:51 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=1581#comment-162944</guid>
		<description>You&#039;re having trouble with the math formulas again (??!!).</description>
		<content:encoded><![CDATA[<p>You&#8217;re having trouble with the math formulas again (??!!).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: buge</title>
		<link>http://eli.thegreenplace.net/2009/03/21/efficient-integer-exponentiation-algorithms/comment-page-1/#comment-162601</link>
		<dc:creator>buge</dc:creator>
		<pubDate>Sun, 22 Mar 2009 11:52:54 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/?p=1581#comment-162601</guid>
		<description>Ah, this is very cool. Thank you!

Of course, you can also use `&lt;code&gt;(x __abENT__amp; 1) == 1&lt;/code&gt;` to test for odd and `&lt;code&gt;x __abENT__gt;__abENT__gt; 1&lt;/code&gt;` for the integer division by two, but that will only have a minor speed improvement, if at all.</description>
		<content:encoded><![CDATA[<p>Ah, this is very cool. Thank you!</p>
<p>Of course, you can also use <code class="backtick">(x &amp; 1) == 1</code> to test for odd and <code class="backtick">x &gt;&gt; 1</code> for the integer division by two, but that will only have a minor speed improvement, if at all.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
