How i can solve the problem of primitive root?
1 view (last 30 days)
Show older comments
Radhwan Jawad
on 26 Nov 2022
Edited: Walter Roberson
on 27 Nov 2022
Hello matalb community.
Why not all the values of p shows?, where there are (NaN) values in the array of y
p = 54497; % p is a prime number
a=3; % a is a primitive root to p
for i = 1:p-1
y(i) = mod(power(a,i),p);
end
0 Comments
Accepted Answer
John D'Errico
on 26 Nov 2022
Edited: John D'Errico
on 26 Nov 2022
What you mistake is that a and p are represented as DOUBLES. Can you compute a number as you want to do? What happens?
a = 3;
p = 54497;
x = 21666;
power(a,x)
Do you see there are precision problems? Double precision arithmetic overflows when you try to compute those large powers. And then mod must fail.
Instead, while you CAN use syms to compute the moduli, it is far better to learn about the powermod function.
powermod(3,x,p)
Powermod EFFICIENTLY compute the modulus here, without ever computing the number a^x, and so we won't see an overflow, at least not until the modulus gets too large.
y = zeros(100,1);
for i = 1:100
y(i) = powermod(a,i,p);
end
table((1:100)',y)
However, it sounds as if you want to know how to solve for the primitive roots modulo some prime.
In there, you would read:
"In particular, for a to be a primitive root modulo n, φ(n) has to be the smallest power of a that is congruent to 1 modulo n."
We would also learn that
If a is a primitive root modulo a prime p, then mod(a.^(p-1)/2,p) == p-1.
Remember, for n prime, the Euler Totient function has the property that phi(n)==n-1.
What, for example, are the primitive roots of 11? This will be the set of integers r in the interval [2,n-2], such that
powermod(r,(n-1)/2,n) == -1 == n-1 (mod n)
n = 11;
rtest = 2:n-2;
primitiveroots = rtest(powermod(rtest,(n-1)/2,n) == n-1)
And on that wiki page, we would see the primitive roots of 11 are [2,6,7,8].
Finally, we would see this comment:
No simple general formula to compute primitive roots modulo n is known.
So, at best, for a large prime modulus, the above computation seems about the best you can do.
More Answers (0)
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!