Jump to content

Lucas-Lehmer test: Difference between revisions

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

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.