Question: Testing primes

Question:Testing primes

CKOne 40 Maple

Could someone please help me with this procedure please. Testing weather numberss are prime of not.

restart:
Miller_Rabin:=proc(a,n)
local minus1, d, test,r,p,q,i,w:
minus1:=n-1:
d:=minus1:

while ((d mod 2) = 0) do
d:=d/2:
end do;

test:=Power(a,d) mod n:
r:=minus1/d:
p:=ifactor(r):
q:=op(2,p):
for i from 0 to q do
w:=a^(2^(i)*d) mod n:
od:

if (test = 1) and ( w = minus1 or w = 1) then

printf(" Therefore %a is either a Prime or %a is a Miller Rabin Liar",n,a):
return():
else
printf(" %a cannot be a Prime ",n)
end if:

end proc:
 

Miller_Rabin(3,39);
Error, (in Miller_Rabin) improper op or subscript selector

I don't really understand why this is happening. it works for some numbers but not for all.

Cheers

Please Wait...