<?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: Narcissus prime in Python</title>
	<atom:link href="http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/</link>
	<description>John D. Cook</description>
	<lastBuildDate>Mon, 20 May 2013 18:47:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: A suffix prime &#8212; The Endeavour</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-231</link>
		<dc:creator>A suffix prime &#8212; The Endeavour</dc:creator>
		<pubDate>Tue, 12 Mar 2013 22:20:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-231</guid>
		<description><![CDATA[[...] Narcissus prime Sonnet primes Limerick primes  Prime telephone numbers Prime words [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] Narcissus prime Sonnet primes Limerick primes  Prime telephone numbers Prime words [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Waldir</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-230</link>
		<dc:creator>Waldir</dc:creator>
		<pubDate>Thu, 24 Jan 2013 01:24:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-230</guid>
		<description><![CDATA[This is a naive (and probably flawed) version for Julia: 

&lt;pre&gt;
require(&quot;bigint&quot;)
isprime( BigInt( strcat( repeat( &quot;1808010808&quot;, 1560 ), &quot;1&quot; ) ) )
&lt;/pre&gt;

I assume it is flawed because I get a segmentation fault. In fact, even with prime numbers as &quot;small&quot; as 953467954114363 I get segfaults often, though when the it works, it takes over a minute.]]></description>
		<content:encoded><![CDATA[<p>This is a naive (and probably flawed) version for Julia: </p>
<pre>
require("bigint")
isprime( BigInt( strcat( repeat( "1808010808", 1560 ), "1" ) ) )
</pre>
<p>I assume it is flawed because I get a segmentation fault. In fact, even with prime numbers as &#8220;small&#8221; as 953467954114363 I get segfaults often, though when the it works, it takes over a minute.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SymPy &#171; Ok, panico</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-229</link>
		<dc:creator>SymPy &#171; Ok, panico</dc:creator>
		<pubDate>Sat, 19 Jan 2013 08:46:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-229</guid>
		<description><![CDATA[[...] è partito, l&#8217;altro giorno, da un post di John D. Cook, questo: Narcissus prime in Python. Non ho rifatto il calcolo di John, troppo lungo, ma SymPy l&#8217;ho installato subito. Per Ubuntu [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] è partito, l&#8217;altro giorno, da un post di John D. Cook, questo: Narcissus prime in Python. Non ho rifatto il calcolo di John, troppo lungo, ma SymPy l&#8217;ho installato subito. Per Ubuntu [...] </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sol</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-228</link>
		<dc:creator>Sol</dc:creator>
		<pubDate>Sat, 19 Jan 2013 01:12:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-228</guid>
		<description><![CDATA[Perl6 version: &lt;code&gt;say (&quot;1808010808&quot; x 1560 ~ &quot;1&quot;).Int.is-prime;&lt;/code&gt;
On Rakudo Perl 6 it runs in 4 hours.]]></description>
		<content:encoded><![CDATA[<p>Perl6 version: <code>say ("1808010808" x 1560 ~ "1").Int.is-prime;</code><br />
On Rakudo Perl 6 it runs in 4 hours.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glyph</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-227</link>
		<dc:creator>Glyph</dc:creator>
		<pubDate>Fri, 18 Jan 2013 23:09:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-227</guid>
		<description><![CDATA[Arguably, &lt;a href=&quot;https://code.google.com/p/sympy/issues/detail?id=1026&quot; rel=&quot;nofollow&quot;&gt;this is the cause of the problem&lt;/a&gt;. ;-)]]></description>
		<content:encoded><![CDATA[<p>Arguably, <a href="https://code.google.com/p/sympy/issues/detail?id=1026" rel="nofollow">this is the cause of the problem</a>. <img src='http://www.johndcook.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charlie</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-226</link>
		<dc:creator>Charlie</dc:creator>
		<pubDate>Thu, 17 Jan 2013 20:04:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-226</guid>
		<description><![CDATA[This one is deterministic, but when running it under pypy on my rig, it finishes in under 18 minutes. Surely a probabilistic algorithm can finish much faster.
&lt;code&gt;
def modpower(b, e, n):
    &#039;&#039;&#039;Iterative method for Fermat&#039;s Test, O(n^3) instead of exponential.
    From Computations in Number Theory Using Python: A Brief Introduction,
    Jim Carlson, March 2003&#039;&#039;&#039;
    result = 1
    s = b
    q = e
    while q &gt; 0:
        #r = q % 2
        r = q &amp; 1
        if r == 1:
            result = result * s % n
        # print q, r, s, result
        s = s * s % n
        #q = q/2
        q = q &gt;&gt; 1
    return result

def is_prime(n):
    return modpower(2, n-1, n) == 1
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>This one is deterministic, but when running it under pypy on my rig, it finishes in under 18 minutes. Surely a probabilistic algorithm can finish much faster.<br />
<code><br />
def modpower(b, e, n):<br />
    '''Iterative method for Fermat's Test, O(n^3) instead of exponential.<br />
    From Computations in Number Theory Using Python: A Brief Introduction,<br />
    Jim Carlson, March 2003'''<br />
    result = 1<br />
    s = b<br />
    q = e<br />
    while q &gt; 0:<br />
        #r = q % 2<br />
        r = q &amp; 1<br />
        if r == 1:<br />
            result = result * s % n<br />
        # print q, r, s, result<br />
        s = s * s % n<br />
        #q = q/2<br />
        q = q &gt;&gt; 1<br />
    return result</p>
<p>def is_prime(n):<br />
    return modpower(2, n-1, n) == 1<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TheBlackCat</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-225</link>
		<dc:creator>TheBlackCat</dc:creator>
		<pubDate>Thu, 17 Jan 2013 18:25:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-225</guid>
		<description><![CDATA[In addition to the other issues, there are a couple things I notice in the sympy code:

1.  It tests if the target number is a pseudoprime &lt;i&gt;after&lt;/i&gt; running the mathematical test.  I would think this would be a relatively fast operation so maybe it could be done first.  This isn&#039;t related to this issue, though.

2.  It doesn&#039;t use any threading.  Tests for different bases could be run simultaneously.

3. The actual test function does some of the exact same calculations multiple times for each base, even though the calculations in question are independent of the base.  

4. If I am reading it correctly, the test function could skip the tests as long as b**2 is lower than n-1, since that case b**2%n will never equal n-1.]]></description>
		<content:encoded><![CDATA[<p>In addition to the other issues, there are a couple things I notice in the sympy code:</p>
<p>1.  It tests if the target number is a pseudoprime <i>after</i> running the mathematical test.  I would think this would be a relatively fast operation so maybe it could be done first.  This isn&#8217;t related to this issue, though.</p>
<p>2.  It doesn&#8217;t use any threading.  Tests for different bases could be run simultaneously.</p>
<p>3. The actual test function does some of the exact same calculations multiple times for each base, even though the calculations in question are independent of the base.  </p>
<p>4. If I am reading it correctly, the test function could skip the tests as long as b**2 is lower than n-1, since that case b**2%n will never equal n-1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TheBlackCat</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-224</link>
		<dc:creator>TheBlackCat</dc:creator>
		<pubDate>Thu, 17 Jan 2013 18:00:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-224</guid>
		<description><![CDATA[The last paragraph in this article describes the algorithm in Mathematica:

http://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html

It appears they use similar versions of one algorithm (although not identical), while mathematica also uses another algorithm.]]></description>
		<content:encoded><![CDATA[<p>The last paragraph in this article describes the algorithm in Mathematica:</p>
<p><a href="http://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html" rel="nofollow">http://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html</a></p>
<p>It appears they use similar versions of one algorithm (although not identical), while mathematica also uses another algorithm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-223</link>
		<dc:creator>Kyle</dc:creator>
		<pubDate>Thu, 17 Jan 2013 16:36:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-223</guid>
		<description><![CDATA[For reference: https://github.com/sympy/sympy/blob/master/sympy/ntheory/primetest.py]]></description>
		<content:encoded><![CDATA[<p>For reference: <a href="https://github.com/sympy/sympy/blob/master/sympy/ntheory/primetest.py" rel="nofollow">https://github.com/sympy/sympy/blob/master/sympy/ntheory/primetest.py</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-222</link>
		<dc:creator>John</dc:creator>
		<pubDate>Thu, 17 Jan 2013 14:50:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-222</guid>
		<description><![CDATA[Kyle: I don&#039;t know. They&#039;re probably using different algorithms, different big integer implementations, etc. I don&#039;t know whether either algorithm is deterministic: probabilistic algorithms are much faster, but could possibly be wrong.]]></description>
		<content:encoded><![CDATA[<p>Kyle: I don&#8217;t know. They&#8217;re probably using different algorithms, different big integer implementations, etc. I don&#8217;t know whether either algorithm is deterministic: probabilistic algorithms are much faster, but could possibly be wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle</title>
		<link>http://www.johndcook.com/blog/2013/01/17/narcissus-prime-in-python/comment-page-1/#comment-221</link>
		<dc:creator>Kyle</dc:creator>
		<pubDate>Thu, 17 Jan 2013 14:37:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.johndcook.com/blog/?p=12757#comment-221</guid>
		<description><![CDATA[Any reason as to why? Is Python&#039;s isprime more expensive? Can it be improved?]]></description>
		<content:encoded><![CDATA[<p>Any reason as to why? Is Python&#8217;s isprime more expensive? Can it be improved?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
