Lucas-Lehmer test: Difference between revisions

m
→‎{{header|REXX}}: corrected verb conjugation, added comments, changed (title) header, added whitespace, enforced correct numeric form (scientific), added DO-END comment labels. -- ~~~~
(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:
conducive to find large primes.
<lang rexx>/*REXX program to use Lucas-Lehmer primality test for prime powers of 2.*/
 
parse arg limit . /*get the argument (if any). */
if limit=='' then limit=1000 /*if no argument, assume 1000. */
Line 1,118 ⟶ 1,119:
 
do j=1 by 2 to limit /*only process so much... */
/*there'sre only so many hours in a day...*/
power=j
if j==1 then power=2 /*special case for the even prime*/
if \isprime(power) then iterate /*if not prime, then ignore it. */
 
list=list Lucas_Lehmer2(power) /*add to list (or maybe not). */
end /*j*/
 
list=space(list) /*remove extraneous blanks. */
say; say center('list',60-3,"═") /*show a fancy-dancy header/title*/
say
say center do k=1 for words('list',60-3,"-") /*show aentries fancy-dancyin headerlist, 1/titleline. */
say right(word(list,jk),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
exit
/*──────────────────────────────────LUCAS_LEHMER2 subroutine────────────*/
/*-------------------------------------LUCAS_LEHMER2 subroutine---------*/
Lucas_Lehmer2: procedure; parse arg ? /*Lucas-Lehmer test on 2**? - 1 */
numeric form /*ensure correct scientific form.*/
 
if ?==2 then s=0
else s=4
 
/* DIGITs of 1 million could be used, but that really */
/* slows up the whole works. So, we start with the */
Line 1,159 ⟶ 1,156:
 
q=2**?-1 /*now, compute the real McCoy. */
s=(s*s do ?-2)//q /*modulusapply, inrinse, REXXrepeat is:... // */
 
do ?-2 s=(s*s-2)//q /*modulus in REXX is: /*apply, rinse, repeat ... // */
end
s=(s*s-2)//q /*modulus in REXX is: // */
end
 
if s\==0 then return '' /*return nuttin' if not prime. */
return 'M'? /*return modified (prime) number.*/
/*──────────────────────────────────ISPRIME subroutine──────────────────*/
/*-------------------------------------ISPRIME subroutine---------------*/
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 x//3==0 then return 0 /*divisible by three? Not prime.*/
Line 1,177 ⟶ 1,173:
end /*j*/</lang>
'''output''' when the following is used: <tt> 10000 </tt>
<pre style="height:30ex;overflow:scroll">
══════════════════════════list═══════════════════════════
 
--------------------------list---------------------------
 
M2