Karim BELABAS on Mon, 1 Jul 2002 19:49:27 +0200 (MEST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: polcoeff() mystery


On Mon, 1 Jul 2002, Ilya Zakharevich wrote:
> How polcoeff() is supposed to work?  I try to understand why the
> coeff() example of the manual works, and fail...  I try this:
>
>    coeffs(P, nbvar) =
>    {
>      local(v);
>
>      if (type(P) != "t_POL",
>        for (i=0, nbvar-1, P = [P]);
>        return (P)
>      );
>      v = vector(poldegree(P)+1, i, polcoeff(P,i-1));
>      vector(length(v), i, coeffs(v[i], nbvar-1))
>    }
>
>    c(P) = coeffs(P,2)
>
>    PP = x^2 + x*y + z;
>    temp  = polcoeff(PP,0);
>    temp1 = polcoeff(PP,1);
>    print("z     -> "z", c(z)        -> "c(z));
>    print("temp  -> "z", c(temp)     -> "c(temp));
>    print("y     -> "y", c(y)        -> "c(y));
>    print("temp1 -> "temp1", c(temp)     -> "c(temp1));
>
> This gives
>
>   z     -> z, c(z)        -> [[0], [1]]
>   temp  -> z, c(temp)     -> [[0, 1]]
>   y     -> y, c(y)        -> [[0], [1]]
>   temp1 -> y, c(temp)     -> [[0], [1]]
>
> As one can see, z and temp have the same value,

No. They evaluate to the same printed output.

> but the results of c() are different!  Moreover, x and temp give the same \x

They don't. The history objects obtained from x and temp give the same \x.

But, assuming factory settings, the history result is obtained after
simplify() has been applied to the result of the command evaluation. So
  ? temp  = polcoeff(PP,0) \\ in R[z][y]  (degree 0 in y)
  %1 = z \\ in R[z] after simplification

  ? \x
[&=00a5d93c] POL(lg=4,CLONE):15000004  (+,varn=10,lgef=4):400a0004  00a5d958 00a5d94c
  coef of degree 0 = [&=00a5d958] INT(lg=2):02000002  (0,lgef=2):00000002
  coef of degree 1 = [&=00a5d94c] INT(lg=3):02000003  (+,lgef=3):40000003 00000001

  ? install(voir, "vGD,-1,L,")  \\ library routine underlying \x
  ? voir(temp)
[&=00a5d58c] POL(lg=3,CLONE):15000003  (+,varn=9,lgef=3):40090003  00a5d5ac
  coef of degree 0 = [&=00a5d5ac] POL(lg=4):14000004 (+,varn=10,lgef=4):400a0004  00a5d5a4  00a5d598
    coef of degree 0 = [&=00a5d5a4] INT(lg=2):02000002  (0,lgef=2):00000002
    coef of degree 1 = [&=00a5d598] INT(lg=3):02000003  (+,lgef=3):40000003 00000001

You have the same kind of weird problems with

  ? x = 2 + 0*I;
  ? factor(%)
%2 =
[2 1]
  ? factor(x)
  ***   can't factor 2.  \\ huh ?

Type coercion is nearly inexistent in PARI, you have to force it with
simplify().

Cheers,

    Karim.
-- 
Karim Belabas                    Tel: (+33) (0)1 69 15 57 48
Dép. de Mathematiques, Bat. 425  Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud             Email: Karim.Belabas@math.u-psud.fr
F-91405 Orsay (France)           http://www.math.u-psud.fr/~belabas/
--
PARI/GP Home Page: http://www.parigp-home.de/