<?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/"
	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>Comments for Numerical Recipes</title>
	<atom:link href="http://numericalrecipes.wordpress.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://numericalrecipes.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 24 Nov 2011 20:16:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>Comment on Naive Integer Factorization by Reilithion</title>
		<link>http://numericalrecipes.wordpress.com/2009/04/09/naive-integer-factorization/#comment-263</link>
		<dc:creator><![CDATA[Reilithion]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 20:16:51 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/2009/04/09/naive-integer-factorization/#comment-263</guid>
		<description><![CDATA[Wordpress seems to have rendered my code&#039;s formatting ugly and deleted some important lines. I&#039;ll see if there&#039;s a place I can host it or something.]]></description>
		<content:encoded><![CDATA[<p>WordPress seems to have rendered my code&#8217;s formatting ugly and deleted some important lines. I&#8217;ll see if there&#8217;s a place I can host it or something.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Naive Integer Factorization by Reilithion</title>
		<link>http://numericalrecipes.wordpress.com/2009/04/09/naive-integer-factorization/#comment-262</link>
		<dc:creator><![CDATA[Reilithion]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 20:14:15 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/2009/04/09/naive-integer-factorization/#comment-262</guid>
		<description><![CDATA[Actually, my implementation factors 10^15+37 in 1.69 seconds. It can do so because it stops at the square root of the number -- a much easier target to hit. And the target can be lowered every time we find a factor.

Here is the code, if you&#039;re interested:


def factor(n, verbose = False):
	&quot;&quot;&quot;
	Returns all prime factors of n, using simple trial division.
	Returns a list of (possibly repeating) prime factors
	&quot;&quot;&quot;
	t = clock()
	ret =[]
	nn = n
	# Remove 2&#039;s and 3&#039;s first
	while nn % 2 == 0:
		nn //= 2
		ret += [2]
	while nn % 3 == 0:
		nn //= 3
		ret += [3]
	maxFactor = int(nn**0.5)
	
	# Prime factors after 2 and 3 will be of the form 6x+-1
	# This is equivalent to alternately adding 2 and 4 to each
	# successive factor-candidate.
	oldnn = nn
	i = 5
	while i &gt;&gt; from factorAndSieve import *
&gt;&gt;&gt; factor(10**15+37,True)
Calculated factors of 1000000000000037 in 1.69 sec.
[1000000000000037]
&gt;&gt;&gt; factorAndSieve(10**15+37,True)
Calculated factors of 1000000000000037 in 5.61 sec.
Stopped trial division at 31622775 instead of 31622776
[1000000000000037]
&gt;&gt;&gt;

Perhaps a number that has a few large prime factors would produce different results?

But to me it appears that bailing out at the square root of the current number is at least as efficient as sieving as you go. Here&#039;s why I think that is: The sieve-as-you-go strategy is to reduce the number of trial-divisions you must make. But finding primes for this purpose is every bit as expensive (perhaps more so) as those same trial-divisions you hoped to avoid. You must still iterate over your sieve looking for true values that indicate the presence of a prime, and every time you find a prime, you must go through the remainder of the sieve marking multiples false. This is a lot of work. The only thing that would really make your approach perform better would be if a trial-division was a much more expensive operation than the combination of several comparison branches, reads, and writes. The mod operation /is/ pretty expensive on most modern processors, but my guess is it&#039;s not expensive enough to give your approach a serious competitive advantage.]]></description>
		<content:encoded><![CDATA[<p>Actually, my implementation factors 10^15+37 in 1.69 seconds. It can do so because it stops at the square root of the number &#8212; a much easier target to hit. And the target can be lowered every time we find a factor.</p>
<p>Here is the code, if you&#8217;re interested:</p>
<p>def factor(n, verbose = False):<br />
	&#8220;&#8221;"<br />
	Returns all prime factors of n, using simple trial division.<br />
	Returns a list of (possibly repeating) prime factors<br />
	&#8220;&#8221;"<br />
	t = clock()<br />
	ret =[]<br />
	nn = n<br />
	# Remove 2&#8242;s and 3&#8242;s first<br />
	while nn % 2 == 0:<br />
		nn //= 2<br />
		ret += [2]<br />
	while nn % 3 == 0:<br />
		nn //= 3<br />
		ret += [3]<br />
	maxFactor = int(nn**0.5)</p>
<p>	# Prime factors after 2 and 3 will be of the form 6x+-1<br />
	# This is equivalent to alternately adding 2 and 4 to each<br />
	# successive factor-candidate.<br />
	oldnn = nn<br />
	i = 5<br />
	while i &gt;&gt; from factorAndSieve import *<br />
&gt;&gt;&gt; factor(10**15+37,True)<br />
Calculated factors of 1000000000000037 in 1.69 sec.<br />
[1000000000000037]<br />
&gt;&gt;&gt; factorAndSieve(10**15+37,True)<br />
Calculated factors of 1000000000000037 in 5.61 sec.<br />
Stopped trial division at 31622775 instead of 31622776<br />
[1000000000000037]<br />
&gt;&gt;&gt;</p>
<p>Perhaps a number that has a few large prime factors would produce different results?</p>
<p>But to me it appears that bailing out at the square root of the current number is at least as efficient as sieving as you go. Here&#8217;s why I think that is: The sieve-as-you-go strategy is to reduce the number of trial-divisions you must make. But finding primes for this purpose is every bit as expensive (perhaps more so) as those same trial-divisions you hoped to avoid. You must still iterate over your sieve looking for true values that indicate the presence of a prime, and every time you find a prime, you must go through the remainder of the sieve marking multiples false. This is a lot of work. The only thing that would really make your approach perform better would be if a trial-division was a much more expensive operation than the combination of several comparison branches, reads, and writes. The mod operation /is/ pretty expensive on most modern processors, but my guess is it&#8217;s not expensive enough to give your approach a serious competitive advantage.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Naive Integer Factorization by Jaime</title>
		<link>http://numericalrecipes.wordpress.com/2009/04/09/naive-integer-factorization/#comment-261</link>
		<dc:creator><![CDATA[Jaime]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 09:46:04 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/2009/04/09/naive-integer-factorization/#comment-261</guid>
		<description><![CDATA[The number you propose, though very large, has no large divisor, hence there is little benefit in doing anything other than trial division. Actually, most numbers have lots of small divisors: 50% of all numbers are divisible by 2, 33.3% are divisible by 3, 20% are divisible by 5, 14.3% are divisible by 7... So most of the time trial division is a good choice to get the job done.

But sometimes it is not: try any number with a large prime factor and you are in for miserably slow code. With my first example, 10^15+37, which is a prime, I seriously doubt you will get an answer within your lifetime! And Sundar&#039;s tricks (which are great optimizations for everyday numbers, don&#039;t get me wrong) are useless: there isn&#039;t much practical use in dividing a billion years of computing time by 4...

It is true, though, that what I propose is very inefficient in memory use, and it will not work with very large easy numbers that are a piece of cake for trial division. Even if it meant sacrificing some efficiency, it could be a good idea to compute primes as fast as when sieving, but allocating memory on the go. This is a somewhat contradictory statement, but there apparently are ways of doing it. Or at least so says this paper sitting in my &quot;to read in detail&quot; folder:

http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf

Now that you&#039;ve asked, I may even try to figure out the details, turn that Haskell code into python and revive this blog...]]></description>
		<content:encoded><![CDATA[<p>The number you propose, though very large, has no large divisor, hence there is little benefit in doing anything other than trial division. Actually, most numbers have lots of small divisors: 50% of all numbers are divisible by 2, 33.3% are divisible by 3, 20% are divisible by 5, 14.3% are divisible by 7&#8230; So most of the time trial division is a good choice to get the job done.</p>
<p>But sometimes it is not: try any number with a large prime factor and you are in for miserably slow code. With my first example, 10^15+37, which is a prime, I seriously doubt you will get an answer within your lifetime! And Sundar&#8217;s tricks (which are great optimizations for everyday numbers, don&#8217;t get me wrong) are useless: there isn&#8217;t much practical use in dividing a billion years of computing time by 4&#8230;</p>
<p>It is true, though, that what I propose is very inefficient in memory use, and it will not work with very large easy numbers that are a piece of cake for trial division. Even if it meant sacrificing some efficiency, it could be a good idea to compute primes as fast as when sieving, but allocating memory on the go. This is a somewhat contradictory statement, but there apparently are ways of doing it. Or at least so says this paper sitting in my &#8220;to read in detail&#8221; folder:</p>
<p><a href="http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf" rel="nofollow">http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf</a></p>
<p>Now that you&#8217;ve asked, I may even try to figure out the details, turn that Haskell code into python and revive this blog&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Naive Integer Factorization by Reilithion</title>
		<link>http://numericalrecipes.wordpress.com/2009/04/09/naive-integer-factorization/#comment-260</link>
		<dc:creator><![CDATA[Reilithion]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 05:59:37 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/2009/04/09/naive-integer-factorization/#comment-260</guid>
		<description><![CDATA[Your factorAndSieve solution does not appear to be any better than a properly implemented trial-division approach, such as Sundar&#039;s (as detailed on http://thetaoishere.blogspot.com/2009/04/finding-largest-prime-factor.html ). Indeed, your solution fails for very large numbers because it attempts to allocate memory for its sieve, and either runs out of memory or runs into a type conversion problem (I tested it with python 2.6 and a composite number equal to the product of all primes less than or equal to 659). A simpler +2+4 implementation similar to Sundar&#039;s I wrote on the spot had no trouble with this number, and factored it in &quot;0.0 sec&quot; even though it was 276 digits long.

The trivial example of how much faster your factorAndSieve implementation is than an extremely naive trial-division implementation in the case of a large power of 2 is irrelevant because the speed advantage in this case comes not from the sieving but from dividing out the discovered factor and recalculating the upper bound to which trial-divisions must be made. A non-sieving algorithm can do this just as well as yours, and mine does a pretty good job.

I&#039;d be delighted if you could produce an example of a number this factor-and-sieve algorithm could actually outperform a more ordinary trial-division algorithm on.]]></description>
		<content:encoded><![CDATA[<p>Your factorAndSieve solution does not appear to be any better than a properly implemented trial-division approach, such as Sundar&#8217;s (as detailed on <a href="http://thetaoishere.blogspot.com/2009/04/finding-largest-prime-factor.html" rel="nofollow">http://thetaoishere.blogspot.com/2009/04/finding-largest-prime-factor.html</a> ). Indeed, your solution fails for very large numbers because it attempts to allocate memory for its sieve, and either runs out of memory or runs into a type conversion problem (I tested it with python 2.6 and a composite number equal to the product of all primes less than or equal to 659). A simpler +2+4 implementation similar to Sundar&#8217;s I wrote on the spot had no trouble with this number, and factored it in &#8220;0.0 sec&#8221; even though it was 276 digits long.</p>
<p>The trivial example of how much faster your factorAndSieve implementation is than an extremely naive trial-division implementation in the case of a large power of 2 is irrelevant because the speed advantage in this case comes not from the sieving but from dividing out the discovered factor and recalculating the upper bound to which trial-divisions must be made. A non-sieving algorithm can do this just as well as yours, and mine does a pretty good job.</p>
<p>I&#8217;d be delighted if you could produce an example of a number this factor-and-sieve algorithm could actually outperform a more ordinary trial-division algorithm on.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on The radix-2 Cooley-Tukey FFT Algorithm with Decimation in Time by Paul</title>
		<link>http://numericalrecipes.wordpress.com/2009/04/30/the-radix-2-cooley-tukey-fft-algorithm-with-decimation-in-time/#comment-234</link>
		<dc:creator><![CDATA[Paul]]></dc:creator>
		<pubDate>Sun, 15 May 2011 20:11:31 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/?p=170#comment-234</guid>
		<description><![CDATA[Excuse me, why does this line 

X += [X_e[k-M] - X_o[k-M] * twiddles[(k - M) * twiddles[-1] // N]]

(present also in the correct code) do multiply by N and then divide by N?]]></description>
		<content:encoded><![CDATA[<p>Excuse me, why does this line </p>
<p>X += [X_e[k-M] &#8211; X_o[k-M] * twiddles[(k - M) * twiddles[-1] // N]]</p>
<p>(present also in the correct code) do multiply by N and then divide by N?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Divisors by wjjw</title>
		<link>http://numericalrecipes.wordpress.com/2009/05/13/divisors/#comment-209</link>
		<dc:creator><![CDATA[wjjw]]></dc:creator>
		<pubDate>Tue, 14 Dec 2010 01:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/?p=222#comment-209</guid>
		<description><![CDATA[Hello again.

I rewritten (unsorted version) it into C (and added few other optimalisation). I needed divisors for determining an order of element a in finite field Z/pZ. (order of element a is smallest positive number k, such that a^k mod p == 1, and I know it is true for k==p-1, via Fermat&#039;s theorem, but it is not nacassarly smallest k. so need to check also divisors of p-1, because if a^k == a^(k1*k2) == (a^k1)^k2 == 1^k2 , then we see k1 (a divisor of k), or its divisor, can be an order of a )

You can find it at http://pastebin.com/tMBTYSx7
It is small, fast and interesting code I think.

I will also implement ordered heap to check if it faster, but for my purpose it can be beneficial to also use identity a^(x*y) = (a^x)^y first, as it will be faster to perform powpod probably incrementally, than checking from smallest ones (but early termination in ordered heap will be really nice for me also).]]></description>
		<content:encoded><![CDATA[<p>Hello again.</p>
<p>I rewritten (unsorted version) it into C (and added few other optimalisation). I needed divisors for determining an order of element a in finite field Z/pZ. (order of element a is smallest positive number k, such that a^k mod p == 1, and I know it is true for k==p-1, via Fermat&#8217;s theorem, but it is not nacassarly smallest k. so need to check also divisors of p-1, because if a^k == a^(k1*k2) == (a^k1)^k2 == 1^k2 , then we see k1 (a divisor of k), or its divisor, can be an order of a )</p>
<p>You can find it at <a href="http://pastebin.com/tMBTYSx7" rel="nofollow">http://pastebin.com/tMBTYSx7</a><br />
It is small, fast and interesting code I think.</p>
<p>I will also implement ordered heap to check if it faster, but for my purpose it can be beneficial to also use identity a^(x*y) = (a^x)^y first, as it will be faster to perform powpod probably incrementally, than checking from smallest ones (but early termination in ordered heap will be really nice for me also).</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Prime Numbers 2. The Sieve of Erathostenes by Finding prime numbers: The Sieve of Erathostenes</title>
		<link>http://numericalrecipes.wordpress.com/2009/03/16/prime-numbers-2-the-sieve-of-erathostenes/#comment-208</link>
		<dc:creator><![CDATA[Finding prime numbers: The Sieve of Erathostenes]]></dc:creator>
		<pubDate>Fri, 10 Dec 2010 23:13:35 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/2009/03/16/prime-numbers-2-the-sieve-of-erathostenes/#comment-208</guid>
		<description><![CDATA[[...] As a few Project Euler problems require a list of primes, and I&#8217;ve been using a horrible inefficient way to generate that list (brute force), I found a good resource that explains the Sieve of Erathostenes as a way to generate the list of primes. If you&#8217;re interested, check out the blog Numerical Recipes. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] As a few Project Euler problems require a list of primes, and I&#8217;ve been using a horrible inefficient way to generate that list (brute force), I found a good resource that explains the Sieve of Erathostenes as a way to generate the list of primes. If you&#8217;re interested, check out the blog Numerical Recipes. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Divisors by wjjw</title>
		<link>http://numericalrecipes.wordpress.com/2009/05/13/divisors/#comment-206</link>
		<dc:creator><![CDATA[wjjw]]></dc:creator>
		<pubDate>Wed, 08 Dec 2010 21:52:31 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/?p=222#comment-206</guid>
		<description><![CDATA[Nice and interesting post! Both recursive and priority queue based version are beutifull. Will definietly use it from time to time :)]]></description>
		<content:encoded><![CDATA[<p>Nice and interesting post! Both recursive and priority queue based version are beutifull. Will definietly use it from time to time <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on The Discrete Fourier Transform by Alessio Treglia</title>
		<link>http://numericalrecipes.wordpress.com/2009/04/30/the-discrete-fourier-transform/#comment-201</link>
		<dc:creator><![CDATA[Alessio Treglia]]></dc:creator>
		<pubDate>Wed, 01 Dec 2010 09:56:32 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/?p=111#comment-201</guid>
		<description><![CDATA[Hi,

thanks for the great tutorial!

I&#039;d like to use and adapt this code in my thesis project so it would be good to know under which license it is released.

Thanks in advance.]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>thanks for the great tutorial!</p>
<p>I&#8217;d like to use and adapt this code in my thesis project so it would be good to know under which license it is released.</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on The Discrete Fourier Transform by Jaime</title>
		<link>http://numericalrecipes.wordpress.com/2009/04/30/the-discrete-fourier-transform/#comment-199</link>
		<dc:creator><![CDATA[Jaime]]></dc:creator>
		<pubDate>Tue, 23 Nov 2010 15:00:43 +0000</pubDate>
		<guid isPermaLink="false">http://numericalrecipes.wordpress.com/?p=111#comment-199</guid>
		<description><![CDATA[With zero based arrays, if k &gt; N, then X(k) = X(k % N).

You may want to read this, as it elaborates on the effects of windowing and sampling of a real world signal:

http://en.wikipedia.org/wiki/A_derivation_of_the_discrete_Fourier_transform]]></description>
		<content:encoded><![CDATA[<p>With zero based arrays, if k &gt; N, then X(k) = X(k % N).</p>
<p>You may want to read this, as it elaborates on the effects of windowing and sampling of a real world signal:</p>
<p><a href="http://en.wikipedia.org/wiki/A_derivation_of_the_discrete_Fourier_transform" rel="nofollow">http://en.wikipedia.org/wiki/A_derivation_of_the_discrete_Fourier_transform</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

