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.
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[17][{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[17][{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?
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[17][{k}])^p =!= GF[17][{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.