Lucas-Lehmer test: Difference between revisions

Content added Content deleted
Line 3,430: Line 3,430:
</pre>
</pre>
===RPL HP-28 series===
===RPL HP-28 series===
Unlike RPL implemented on HP-50 series, RPL of HP-28s has neither big integers, nor modular arithmetic operators, nor prime number test functions, nor even modulo operator for unsigned integers.
Unlike RPL implemented on HP-50 series, the first version of the language does not feature big integers, modular arithmetic operators, prime number test functions, nor even modulo operator for unsigned integers.
Let's build them all...
Let's build them all...
{{works with|Halcyon Calc|4.2.7}}
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
{| class="wikitable"
! RPL code
! RPL code
! Comment
! Comment
|-
|-
|
|
Line 3,450: Line 3,450:
DROP2 1 FS?
DROP2 1 FS?
≫ '''END END'''
≫ '''END END'''
‘'''bPRIM?'''’ STO
≫ '<span style="color:blue">bPRIM?</span>' STO
≪ → m
≪ → m
Line 3,461: Line 3,461:
'''END'''
'''END'''
ROT ROT DROP2
ROT ROT DROP2
≫ ≫ ‘'''MODXP'''’ STO
≫ ≫ '<span style="color:blue">MODXP</span>' STO
≪ 2 OVER ^ R→B 1 - → mp
≪ 2 OVER ^ R→B 1 - → mp
≪ #4
≪ #4
3 ROT '''FOR''' n
3 ROT '''FOR''' n
#2 mp '''MODXP'''
#2 mp <span style="color:blue">MODXP</span>
'''IF''' DUP #2 < '''THEN''' mp + '''END''' #2 -
'''IF''' DUP #2 < '''THEN''' mp + '''END''' #2 -
'''NEXT'''
'''NEXT'''
#0 ==
#0 ==
≫ ≫ ‘'''MSNP?'''’ STO
≫ ≫ '<span style="color:blue">MSNP?</span>' STO
≪ { 2 } 3 32 '''FOR''' j
≪ { 2 } 3 32 '''FOR''' j
IF j R→B '''bPRIM?'''
'''IF''' j R→B <span style="color:blue">bPRIM?</span>
'''THEN IF''' j '''MSNP? THEN''' j + '''END END'''
'''THEN IF''' j <span style="color:blue">MNSP?</span> '''THEN''' j + '''END END'''
'''NEXT'''
'''NEXT'''
‘'''TASK'''’ STO
≫ '<span style="color:blue">TASK</span>' STO
|
|
'''bPRIM?''' ''( #a -- boolean )''
<span style="color:blue">bPRIM?</span> ''( #a boolean )''
return 1 if a is 2, 3 or 5 and 0 if a is 1
return 1 if a is 2, 3 or 5 and 0 if a is 1
if 2 or 3 divides a
if 2 or 3 divides a
Line 3,492: Line 3,492:
'''MODXP''' ''( #base #exp #m -- #mod(base^exp,m) )''
<span style="color:blue">MODXP</span> ''( #base #exp #m #mod(base^exp,m) )''
result = 1;
result = 1;
while (exp > 0) {
while (exp > 0) {
Line 3,503: Line 3,503:
'''MSNP?''' ''( p -- boolean )''
<span style="color:blue">MNSP?</span> ''( p boolean )''
s0 = 4
s0 = 4
loop p-2 times
loop p-2 times