0
|
2825 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# Finding the Order of A Number Modulo 17

Posted 9 years ago
 I'm trying to write a code to find a number in the field of integers Mod 17 which has order 16. This is my first time using Mathematica and I feel really lost in the syntax (my file is attached). My approach is to start with the number 2 and just see if 2^2 (mod 17) is equivalent to 1. If not, I increase the power by one and check it again. I keep doing this until 2^p (mod 17) is equivalent to 1, and then I check to see if p == 16. If not, I just start the whole process over again with 3, and I do this until I find a number which is equivalent to 1 for the first time when taken to the power 16. Where am I going wrong with my code? Edit: I've uploaded a more current file but I'm still not sure what is wrong. Attachments:
3 Replies
Sort By:
Posted 9 years ago
 Yes, k needs to be incremented whether we print something or not, also p needs to go back to 2 for each new k. k = 2; While[k < 16, p = 2; While[Mod[k^p, 17] =!= 1, p++]; If[p == 16, Print[k]]; k++] A simpler way might be In:= Select[Range, FreeQ[Mod[#^Range, 17], 1] &] Out= {3, 5, 6, 7, 10, 11, 12, 14} or just use the built-in function In:= PrimitiveRootList Out= {3, 5, 6, 7, 10, 11, 12, 14} 
Posted 9 years ago
 My new file has fixes to a lot of these syntax errors. The new code I have looks like: k = 2; p = 2; While[k < 17, While[(GF[{k}])^p =!= GF[{1}], p ++]; If[p == 16, Print [k], k++]; ] This seems to be stuck in an infinite loop because it started printing out a bunch of 3s (and I do know that 3 is the first number with order 16 mod 17). I figure this is because the (k++) is in the "else" part of the If statement, but I'm not sure where to put this (k++) in the code so that it will end appropriately.
Posted 9 years ago
 Where am I going wrong with my code? You've got lots of basic syntax error. May be you should start with small example first in order to learn the basic syntax., You need ";" to separate statements in M. You can't write k = 2; p = 2 While[k < 17, p = 1 While[GF[{k}]^p =!= 1, p ++ ] If[p == 16, Print [k] Break[] ]; k++ ] notice there is no ";" after the p=1 and no ";" after the ] there., You also need ";" after the Print.It is important to know the difference between "," and ";" in Mathematica. I have not tried to run your code, just an observation. Also the GF[{k}]^p looks strange but I never used this function. Have you tried to test this on its own first to make sure you get the syntax correct?