Jabz

433 Reputation

5 Badges

12 years, 222 days

MaplePrimes Activity


These are replies submitted by Jabz

Thnx 4 taking a look at my program. I am still trying to gt it 2 wrk wen it works i will put the code up here if u wnt to use it or update it to mke it better.

Thnx 4 taking a look at my program. I am still trying to gt it 2 wrk wen it works i will put the code up here if u wnt to use it or update it to mke it better.

I can't seem to gt this program to work. Can sm1 plz give me sme advice so i cud gt it to work.

 

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

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

test:=Power(a,k) mod n:#
r:=minus1/k:
p:=ifactor(r):
t:=nops(p):
if t = 1 and (test <> 1) then

printf("%a Is not a Prime",n):
return():
else
if t > 1 then
q:=op(2,p):
for i from 0 to q do
w:=a^(2^(i)*k) mod n:

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

printf(" Therefore %a is a Prime ",n):
return():
else
printf("%a is not a Prime",n):
return():
fi:
od:
else
printf("%a is probably a prime",n):
end if:
fi:
end proc:
Miller_Rabin(2,11);
 

 

11 Is not a Prime????????

I can't seem to gt this program to work. Can sm1 plz give me sme advice so i cud gt it to work.

 

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

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

test:=Power(a,k) mod n:#
r:=minus1/k:
p:=ifactor(r):
t:=nops(p):
if t = 1 and (test <> 1) then

printf("%a Is not a Prime",n):
return():
else
if t > 1 then
q:=op(2,p):
for i from 0 to q do
w:=a^(2^(i)*k) mod n:

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

printf(" Therefore %a is a Prime ",n):
return():
else
printf("%a is not a Prime",n):
return():
fi:
od:
else
printf("%a is probably a prime",n):
end if:
fi:
end proc:
Miller_Rabin(2,11);
 

 

11 Is not a Prime????????

Shouldn't  ' ifactor ( 2 ) ' give 2 to power of 1 as its second operand why is it invalid???

y:=ifactor(2);
e:=op(2,(y));
 

Error, improper op or subscript selector

Shouldn't  ' ifactor ( 2 ) ' give 2 to power of 1 as its second operand why is it invalid???

y:=ifactor(2);
e:=op(2,(y));
 

Error, improper op or subscript selector

What do u mean? How do i check the size, wot maple command do i use, there quite a few commands.?

What do u mean? How do i check the size, wot maple command do i use, there quite a few commands.?

How about this. It seems to work.


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:
 

How about this. It seems to work.


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:
 

I have been trying to code Miller_Rabin test in  maple and this is what i have. Is this correct??
 

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:
 

 

Thanks.

I have been trying to code Miller_Rabin test in  maple and this is what i have. Is this correct??
 

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:
 

 

Thanks.

So basically my code isn't correct? But if u enter different values for 'a' unless it's a liar you don't get +/- 1. So is that not a very simple code of the Miller rabin test??

So basically my code isn't correct? But if u enter different values for 'a' unless it's a liar you don't get +/- 1. So is that not a very simple code of the Miller rabin test??

I used k:=k/2: to work out the largest odd factor (or  d:= n-1 / 2^s). I can't seem to work out wot might go wrong??

1 2 3 4 5 6 7 Page 3 of 9