I am trying to write a program in GP/PARI which given a finite field (in this example, I will use the degree 2 field of 9 elements over p=3), computes the cube of all elements and stores it in a list (I understand this is very inefficient). Then, I want to evaluate some functions at points in the same field and test whether it is in this list (whether it is a cubic residue). I am attempting to accomplish this with lists in GP/PARI and then using setsearch on it.
I begin by first defining my irreducible polynomial mod 3. I then run through all the elements in my 9 element field cubing them and storing it in a list, which is realized as a quotient of this polynomial ring (double mods). Once I have this list, I am now running into trouble with setsearch. First of all, it seems the list is storing it in terms of double mods. Visually very ugly, but I don't mind as long as it can do the computations. However, it seems that it cannot. For example, 0 should be in the list, but testing it with setsearch returns false. I guess the reason is that in the list, 0 is stored as Mod(Mod(0,3),rpoly)
and indeed, (see below), that does seem to be the case. However, something even worse is happening. >
(15:45) gp > rpoly=Mod(1,3)*(x^2-x-1);
(15:45) gp > polisirreducible(rpoly)
%2 = 1
(15:45) gp > cubic=listcreate(9);
(15:45) gp > for(a=0,2,for(b=0,2,listput(cubic,Mod(Mod(1,3)*(a*x+b)^3,rpoly))))
(15:46) gp > cubic
%5 = List([Mod(Mod(0, 3), Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3)), Mod(Mod(1, 3), Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3)), Mod(Mod(2, 3), Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3)), Mod(Mod(2, 3)*x + Mod(1, 3), Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3)), Mod(Mod(2, 3)*x + Mod(2, 3), Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3)), Mod(Mod(2, 3)*x, Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3)), Mod(Mod(1, 3)*x + Mod(2, 3), Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3)), Mod(Mod(1, 3)*x, Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3)), Mod(Mod(1, 3)*x + Mod(1, 3), Mod(1, 3)*x^2 + Mod(2, 3)*x + Mod(2, 3))])
(15:46) gp > setsearch(cubic,Mod(Mod(0,3),rpoly))
%6 = 0
(15:47) gp > setsearch(cubic,Mod(Mod(0,3)*x+Mod(0,3),rpoly))
%7 = 1
So it seems that not only is it refusing to acknowledge that 0 is in the list, but even other forms of 0 that one would naturally encounter when running through the field isn't working: it specifically wants %7
Why is this happening? More importantly, is there any way to fix this to accomplish my aims here?