Lucas-Lehmer test: Difference between revisions

Content added Content deleted
(added Bracmat)
m (→‎{{header|REXX}}: corrected verb conjugation, added comments, changed (title) header, added whitespace, enforced correct numeric form (scientific), added DO-END comment labels. -- ~~~~)
Line 1,113: Line 1,113:
conducive to find large primes.
conducive to find large primes.
<lang rexx>/*REXX program to use Lucas-Lehmer primality test for prime powers of 2.*/
<lang rexx>/*REXX program to use Lucas-Lehmer primality test for prime powers of 2.*/

parse arg limit . /*get the argument (if any). */
parse arg limit . /*get the argument (if any). */
if limit=='' then limit=1000 /*if no argument, assume 1000. */
if limit=='' then limit=1000 /*if no argument, assume 1000. */
Line 1,118: Line 1,119:


do j=1 by 2 to limit /*only process so much... */
do j=1 by 2 to limit /*only process so much... */
/*there's only so many hours in a day...*/
/*there're only so many hours in a day...*/
power=j
power=j
if j==1 then power=2 /*special case for the even prime*/
if j==1 then power=2 /*special case for the even prime*/
if \isprime(power) then iterate /*if not prime, then ignore it. */
if \isprime(power) then iterate /*if not prime, then ignore it. */

list=list Lucas_Lehmer2(power) /*add to list (or maybe not). */
list=list Lucas_Lehmer2(power) /*add to list (or maybe not). */
end /*j*/
end /*j*/


list=space(list) /*remove extraneous blanks. */
list=space(list) /*remove extraneous blanks. */
say; say center('list',60-3,"═") /*show a fancy-dancy header/title*/
say
say
say center('list',60-3,"-") /*show a fancy-dancy header/title*/
do k=1 for words(list) /*show entries in list, 1/line. */
say right(word(list,k),30) /*and right-justify 'em. */
say
end /*k*/

do j=1 for words(list) /*show entries in list, 1/line. */
say right(word(list,j),30) /*and right-justify 'em. */
end

say
say
exit
exit
/*──────────────────────────────────LUCAS_LEHMER2 subroutine────────────*/
/*-------------------------------------LUCAS_LEHMER2 subroutine---------*/
Lucas_Lehmer2: procedure; parse arg ? /*Lucas-Lehmer test on 2**? - 1 */
Lucas_Lehmer2: procedure; parse arg ? /*Lucas-Lehmer test on 2**? - 1 */
numeric form /*ensure correct scientific form.*/


if ?==2 then s=0
if ?==2 then s=0
else s=4
else s=4

/* DIGITs of 1 million could be used, but that really */
/* DIGITs of 1 million could be used, but that really */
/* slows up the whole works. So, we start with the */
/* slows up the whole works. So, we start with the */
Line 1,159: Line 1,156:


q=2**?-1 /*now, compute the real McCoy. */
q=2**?-1 /*now, compute the real McCoy. */
do ?-2 /*apply, rinse, repeat ... */

do ?-2 /*apply, rinse, repeat ... */
s=(s*s-2)//q /*modulus in REXX is: // */
end
s=(s*s-2)//q /*modulus in REXX is: // */
end


if s\==0 then return '' /*return nuttin' if not prime. */
if s\==0 then return '' /*return nuttin' if not prime. */
return 'M'? /*return modified (prime) number.*/
return 'M'? /*return modified (prime) number.*/
/*──────────────────────────────────ISPRIME subroutine──────────────────*/
/*-------------------------------------ISPRIME subroutine---------------*/
isprime: procedure; parse arg x; if x<2 then return 0 /*idiot test.*/
isprime: procedure; parse arg x; if x<2 then return 0 /*idiot test.*/
if wordpos(x,'2 3 5 7')\==0 then return 1 /*test for special cases.*/
if wordpos(x,'2 3 5 7')\==0 then return 1 /*test for special cases.*/
if x//3==0 then return 0 /*divisible by three? Not prime.*/
if x//3==0 then return 0 /*divisible by three? Not prime.*/
Line 1,177: Line 1,173:
end /*j*/</lang>
end /*j*/</lang>
'''output''' when the following is used: <tt> 10000 </tt>
'''output''' when the following is used: <tt> 10000 </tt>
<pre style="height:30ex;overflow:scroll">
<pre style="overflow:scroll">
══════════════════════════list═══════════════════════════

--------------------------list---------------------------


M2
M2