0

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?

markalex
  • 8,623
  • 2
  • 7
  • 32
Future
  • 101

1 Answers1

0

I don't know gp, but can you verify that your list of cubics is correct? I get the following.

((0x + 0)^3) mod (x^2 - 1x - 1) = 0x + 0 = {0,0}
((0x + 1)^3) mod (x^2 - 1x - 1) = 0x + 1 = {0,1}
((0x + 2)^3) mod (x^2 - 1x - 1) = 0x + 2 = {0,2}
((1x + 0)^3) mod (x^2 - 1x - 1) = 2x + 1 = {2,1}
((1x + 1)^3) mod (x^2 - 1x - 1) = 2x + 2 = {2,2}
((1x + 2)^3) mod (x^2 - 1x - 1) = 2x + 0 = {2,0}
((2x + 0)^3) mod (x^2 - 1x - 1) = 1x + 2 = {1,2}
((2x + 1)^3) mod (x^2 - 1x - 1) = 1x + 0 = {1,0}
((2x + 2)^3) mod (x^2 - 1x - 1) = 1x + 1 = {1,1}

All 8 non-zero elements can be considered to be powers of 1x + 0:

((1x + 0)^0) mod (x^2 - 1x - 1) = 0x + 1 = {0,1}
((1x + 0)^1) mod (x^2 - 1x - 1) = 1x + 0 = {1,0}
((1x + 0)^2) mod (x^2 - 1x - 1) = 1x + 1 = {1,1}
((1x + 0)^3) mod (x^2 - 1x - 1) = 2x + 1 = {2,1}
((1x + 0)^4) mod (x^2 - 1x - 1) = 0x + 2 = {0,2}
((1x + 0)^5) mod (x^2 - 1x - 1) = 2x + 0 = {2,0}
((1x + 0)^6) mod (x^2 - 1x - 1) = 2x + 2 = {2,2}
((1x + 0)^7) mod (x^2 - 1x - 1) = 1x + 2 = {1,2}
((1x + 0)^8) mod (x^2 - 1x - 1) = 0x + 1 = {0,1} (sequence repeats)

So multiply or exponentiation could be implemented using the equivalent of log and antilog:

((2x + 2)^3) => ((1x + 0)^6)^3 => ((1x + 0)^(18 mod 8)) => (1x + 0)^2 => 1x + 1
rcgldr
  • 27,407
  • 3
  • 36
  • 61