<?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: Finding Primes</title>
	<atom:link href="http://cow.neondragon.net/index.php/1765-Finding-Primes/feed" rel="self" type="application/rss+xml" />
	<link>http://cow.neondragon.net/index.php/1765-Finding-Primes</link>
	<description>Helping you to get the most out of modern technology and communications since 2004.</description>
	<lastBuildDate>Tue, 07 Feb 2012 14:38:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Lewis</title>
		<link>http://cow.neondragon.net/index.php/1765-Finding-Primes/comment-page-1#comment-1165</link>
		<dc:creator>Lewis</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1165</guid>
		<description>&lt;p&gt;Couldn&#039;t you just find it for 1001 and times it by 10? &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&#160;&lt;/p&gt;&lt;p&gt;hahaha I crack myself up! &lt;img src=&quot;/ui/emoticons/pinch.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Couldn&#8217;t you just find it for 1001 and times it by 10? </p>
<p>&nbsp;</p>
<p>hahaha I crack myself up! <img src="/ui/emoticons/pinch.png" alt="" /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://cow.neondragon.net/index.php/1765-Finding-Primes/comment-page-1#comment-1166</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1166</guid>
		<description>If you want to be a bit smarter, only use primes-up-to-sqrt(M) as denominators, too. 

Note that this leads to two mutually recursive functions, but runs hellish fast because of the way primes thin-out over increasing N. 

http://pig.sty.nu/temp/isprime-q.txt

(Oh yeah. I&#039;m using a hash in there of previously-computed primes; and I print out true or false for 10 numbers either side of N. Benchmark it! Let there be gnuplot graphs!)</description>
		<content:encoded><![CDATA[<p>If you want to be a bit smarter, only use primes-up-to-sqrt(M) as denominators, too. </p>
<p>Note that this leads to two mutually recursive functions, but runs hellish fast because of the way primes thin-out over increasing N. </p>
<p><a href="http://pig.sty.nu/temp/isprime-q.txt" rel="nofollow">http://pig.sty.nu/temp/isprime-q.txt</a></p>
<p>(Oh yeah. I&#8217;m using a hash in there of previously-computed primes; and I print out true or false for 10 numbers either side of N. Benchmark it! Let there be gnuplot graphs!)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Khlo</title>
		<link>http://cow.neondragon.net/index.php/1765-Finding-Primes/comment-page-1#comment-1167</link>
		<dc:creator>Khlo</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1167</guid>
		<description>Interesting Tim :) Only checking existing primes sounds good; I&#039;m gonna try implementing that. I also got told in IRC that all primes above 2 and 3 are either 1 greater or smaller than a multiple of 6.&lt;br /&gt;</description>
		<content:encoded><![CDATA[<p>Interesting Tim <img src='http://cow.neondragon.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Only checking existing primes sounds good; I&#8217;m gonna try implementing that. I also got told in IRC that all primes above 2 and 3 are either 1 greater or smaller than a multiple of 6.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://cow.neondragon.net/index.php/1765-Finding-Primes/comment-page-1#comment-1168</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1168</guid>
		<description>&lt;p&gt;You can floor the square root, rather than ceil it, which will save (a very tiny amount of) time.&lt;/p&gt;&lt;p&gt;You can see the 6n&#177;1 by doing a Sieve of Erastothenes six wide.&#160; So that would winnow the search pretty well.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The other speedup is that, as Tim said, every natural number greater than one has a unique prime factorisation, so you can do the modulus of the primes you&#039;ve already found, 2, 3, 5, ... up to &#8730;n. You don&#039;t actually have to divide by either 2 or three if you&#039;ve already selected only numbers matching 6n&#177;1. This is part of the fundamental theorem of arithmetic.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>You can floor the square root, rather than ceil it, which will save (a very tiny amount of) time.</p>
<p>You can see the 6n&#177;1 by doing a Sieve of Erastothenes six wide.&nbsp; So that would winnow the search pretty well.</p>
<p>The other speedup is that, as Tim said, every natural number greater than one has a unique prime factorisation, so you can do the modulus of the primes you&#8217;ve already found, 2, 3, 5, &#8230; up to &#8730;n. You don&#8217;t actually have to divide by either 2 or three if you&#8217;ve already selected only numbers matching 6n&#177;1. This is part of the fundamental theorem of arithmetic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xeen</title>
		<link>http://cow.neondragon.net/index.php/1765-Finding-Primes/comment-page-1#comment-1169</link>
		<dc:creator>Xeen</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1169</guid>
		<description>&lt;p&gt;I&#039;m not sure if already mentioned but wouldn&#039;t save it quite some time only checking every 2nd number (by changing n = n + 1 to n = n + 2)? Except of 2, every single prime is odd - of course, otherwise it&#039;s dividable by 2 hence it can&#039;t be a prime.&lt;/p&gt;&lt;p&gt;I don&#039;t have phyton installed, would be nice to know if it really saves that much time since it fails anyway after dividing by 2. Might only make a difference if you go for really big numbers...&lt;/p&gt;&lt;p&gt;Greetings&lt;br /&gt;xeen &lt;br /&gt;&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure if already mentioned but wouldn&#8217;t save it quite some time only checking every 2nd number (by changing n = n + 1 to n = n + 2)? Except of 2, every single prime is odd &#8211; of course, otherwise it&#8217;s dividable by 2 hence it can&#8217;t be a prime.</p>
<p>I don&#8217;t have phyton installed, would be nice to know if it really saves that much time since it fails anyway after dividing by 2. Might only make a difference if you go for really big numbers&#8230;</p>
<p>Greetings<br />xeen </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://cow.neondragon.net/index.php/1765-Finding-Primes/comment-page-1#comment-1170</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1170</guid>
		<description>&lt;p&gt;Well, yes they are: in order for a number not to be divisible by either 2 or 3, it must not be divisible by 2*3; if you consider n%6, then the n for which n%6 ==2 or ==4 are obviously divisible by 2, and n%6 ==3 =&gt; it&#039;s divisible by 3, so you&#039;re left with the n for which n%6 is 1 or 5.&lt;/p&gt;&lt;p&gt;This is tantamount to saying that 2 &amp; 3 are the two most-frequent denominators that can &quot;catch out&quot; a composite the quickest when you start counting from 2. Not exactly surprising and so I don&#039;t expect that peeling-off the &quot;is n%6 == 1 or 5?&quot; test is going to save you anything over and above simply starting from 2 and 3 and 5... :)&#160;&lt;/p&gt;&lt;p&gt;However,&#160; you can scale this further. By the time you&#039;ve examined the number 2, you know every second number is out of the running (duh). By the time you&#039;ve examined the number 3, you know every 3rd number is out of the running. By the time you&#039;ve examined the number 5, .... You&#039;re now looking at http://en.wikipedia.org/wiki/Sieve_of_eratosthenes .&#160;&lt;/p&gt;&lt;p&gt;Now, if you were to implement the Sieve inefficiently, you&#039;d set aside a huge array to store [1..N] in, and mark boxes prime, composite, or unknown as you count up from 2. This is where the hash (dict) in my script comes in: as it goes along computing isprime 4, isprime 5, isprime 6, ... etc, it memoizes the results for later. So you can loop your n from 2..N happily knowing that, while each primality test will involve a whole bunch more tests-for-primes-in-the-range-2..sqrt(n), as time goes on those will become simple instantaneous lookups rather than calculations.&#160; &lt;/p&gt;&lt;p&gt;If you want it to look pretty, plot http://en.wikipedia.org/wiki/Ulam&#039;s_spiral as you go along :)&#160;&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Well, yes they are: in order for a number not to be divisible by either 2 or 3, it must not be divisible by 2*3; if you consider n%6, then the n for which n%6 ==2 or ==4 are obviously divisible by 2, and n%6 ==3 =&gt; it&#8217;s divisible by 3, so you&#8217;re left with the n for which n%6 is 1 or 5.</p>
<p>This is tantamount to saying that 2 &amp; 3 are the two most-frequent denominators that can &quot;catch out&quot; a composite the quickest when you start counting from 2. Not exactly surprising and so I don&#8217;t expect that peeling-off the &quot;is n%6 == 1 or 5?&quot; test is going to save you anything over and above simply starting from 2 and 3 and 5&#8230; <img src='http://cow.neondragon.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &nbsp;</p>
<p>However,&nbsp; you can scale this further. By the time you&#8217;ve examined the number 2, you know every second number is out of the running (duh). By the time you&#8217;ve examined the number 3, you know every 3rd number is out of the running. By the time you&#8217;ve examined the number 5, &#8230;. You&#8217;re now looking at <a href="http://en.wikipedia.org/wiki/Sieve_of_eratosthenes" rel="nofollow">http://en.wikipedia.org/wiki/Sieve_of_eratosthenes</a> .&nbsp;</p>
<p>Now, if you were to implement the Sieve inefficiently, you&#8217;d set aside a huge array to store [1..N] in, and mark boxes prime, composite, or unknown as you count up from 2. This is where the hash (dict) in my script comes in: as it goes along computing isprime 4, isprime 5, isprime 6, &#8230; etc, it memoizes the results for later. So you can loop your n from 2..N happily knowing that, while each primality test will involve a whole bunch more tests-for-primes-in-the-range-2..sqrt(n), as time goes on those will become simple instantaneous lookups rather than calculations.&nbsp; </p>
<p>If you want it to look pretty, plot <a href="http://en.wikipedia.org/wiki/Ulam&#039;s_spiral" rel="nofollow">http://en.wikipedia.org/wiki/Ulam&#039;s_spiral</a> as you go along <img src='http://cow.neondragon.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &nbsp;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc</title>
		<link>http://cow.neondragon.net/index.php/1765-Finding-Primes/comment-page-1#comment-1870</link>
		<dc:creator>Marc</dc:creator>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">#comment-1870</guid>
		<description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;The following statement caught my attention: &quot;To my knowledge, there isn&#039;t anyway of telling if a number is prime except from dividing it by all the numbers between 1 and the number and seeing if they are factors.&quot;&lt;/p&gt;&lt;p&gt;There is actually a way, described at site &lt;a href=&quot;http://www.primestructure.com/&quot;&gt;www.primestructure.com&lt;/a&gt;. This does not work for all integers, but it does work for infinitely many ranges of integers.&lt;/p&gt;&lt;p&gt;Marc&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>The following statement caught my attention: &quot;To my knowledge, there isn&#8217;t anyway of telling if a number is prime except from dividing it by all the numbers between 1 and the number and seeing if they are factors.&quot;</p>
<p>There is actually a way, described at site <a href="http://www.primestructure.com/">http://www.primestructure.com</a>. This does not work for all integers, but it does work for infinitely many ranges of integers.</p>
<p>Marc</p>
]]></content:encoded>
	</item>
</channel>
</rss>

