Gerhard Niklasch on Thu, 21 Dec 2000 00:20:14 +0100 (MET)

 Re: finite field

```Prompted by writing my response to
> Message-ID: <005901c06a0d\$b15487c0\$87faf9c1@default>
> To: <pari-users@list.cr.yp.to>
> Subject: finite field
> Date: Tue, 19 Dec 2000 01:55:22 +0100
>
> I am new on Pari. I would like to consider the 2^n elements fiite field, for
> a given n, with the 2^n-1 roots of unity as representatives, and I would
> like to make some computing on these elements (for instance, compute xi +
> xi' + 1 for given xi and xi') or solve an equation (for instance xi + xi' +
> 1 = 0 for a given xi). Can I do this with Pari?

What I really typed into gp whilst writing what I wrote

.... f=polcyclo(7);factormod(f,2);
g=%[1,1];xi0=Mod(x,g)*Mod(1,2);
(23:25) gp > xi_pwr=vector(7,j,xi0^j);
(23:27) gp > xi_dlg=vector(7,j,0);
(23:27) gp > xi_idx(y)=subst(lift(lift(y)),x,2);
(23:30) gp > xi_idx(xi0)
%14 = 2
...
(23:35) gp > xi_idx(xi0^4)
%25 = 6
...
(23:35) gp > xi_pwr[2]
%27 = Mod(Mod(1, 2)*x^2, Mod(1, 2)*x^3 + Mod(1, 2)*x + Mod(1, 2))
(23:35) gp > for(j=1,7,xi_dlg[xi_idx(xi_pwr[j])=j);
***   expected character: ']' instead of: ...i_dlg[xi_idx(xi_pwr[j])=j);
^--

(rats, too late in the night to get my brackets right... %^)

(23:37) gp > for(j=1,7,xi_dlg[xi_idx(xi_pwr[j])]=j);
***   expected character: ',' instead of: xi_dlg[xi_idx(xi_pwr[j])]=j);
^---------

(me waking up a bit here.)  Errm.  What?

(23:38) gp > xi_idx(xi_pwr[2])
***   expected character: ',' instead of: xi_idx(xi_pwr[2])
^----

Huh?

(23:39) gp > xi_idx(%27)
***   unknown function or error in formal parameters: xi_idx(%27)
^-----------

Oh.

It seems that gp, whilst the parser was bailing out from my syntax
error in the input line following %25, had alzheimered away the
definition of my function xi_idx.  After repeating the definition:

(23:40) gp > xi_idx(y)=subst(lift(lift(y)),x,2);
(23:40) gp > xi_idx(%27)
%28 = 4
(23:40) gp > xi_idx(xi_pwr[2])
%29 = 4

things once again were working as expected.  So what had happened?

My erroneous input line
...i_dlg[xi_idx(xi_pwr[j])=j
had been parsed as far as the j, and the parser, looking at the closing
`)' which followed it, complained.  At this point it had looked at the
subsequence
xi_idx(xi_pwr[j])=j
which *looked* like a redefinition of the function xi_idx with
another syntax error in it  (the thing between the (...) would
not qualify as a formal parameter list).  After this input line
had been processed, the function was in fact still around --
recreating the problem once more as I'm typing this:

(23:52) gp > for(j=1,7,xi_dlg[xi_idx(xi_pwr[j])=j);
***   expected character: ']' instead of: ...i_dlg[xi_idx(xi_pwr[j])=j);
^--

(00:00) gp > ?xi_idx
xi_idx(y) = subst(lift(lift(y)),x,2);
(00:00) gp > xi_idx(%27)
%35 = 4

But:

(00:00) gp > for(j=1,7,xi_dlg[xi_idx(xi_pwr[j])]=j);
***   expected character: ',' instead of: xi_dlg[xi_idx(xi_pwr[j])]=j);
^---------

(00:01) gp > ?xi_idx
***   xi_idx: unknown identifier.
(00:02) gp >

So, to my surprise, the input line after the %35 is what destroys the
function definition.  But if the function definition was still valid
when I entered the line, then IMHO this input line should have worked:

(00:02) gp > xi_idx(y)=subst(lift(lift(y)),x,2); // again
(00:03) gp > for(j=1,7,xi_dlg[xi_idx(xi_pwr[j])]=j);
(00:03) gp >

What is going on here?

On a hunch, the first syntax error may be setting some flag in gp's
symbol table marking xi_idx as about-to-be-redefined, without yet
removing the existing definition.  Somehow it still survives a simple
invocation, like the one giving rise to output %35.  But in the line
after that, the parser somehow seems to pick up the flag, erase the
definition, and then trip over the syntax error indirectly caused
by this -- because now the input line seems to be taken as
"define xi_idx as a function with formal parameter `xi_pwr[j]'
and body `j'"
somehow without letting itself be distracted by the fact that there's
an extra `]' in there between the `)' and the `='.  Or something
along these lines...?

All this with the 2.1.0 release version.