Karim BELABAS on Tue, 2 Jul 2002 13:30:38 +0200 (MEST)


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

Re: polcoeff() mystery


On Tue, 2 Jul 2002, Ilya Zakharevich wrote:
> On Mon, Jul 01, 2002 at 07:49:27PM +0200, Karim BELABAS wrote:
>> > 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.
>
>>   ? 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
>
>> Type coercion is nearly inexistent in PARI, you have to force it with
>> simplify().
>
> What the time coercion has to do with simplify()???  Why is not it
> documented that polcoeff() uses a very pessimized algorithm and *does
> not* return what I asked it to do?

I think it does, assuming we do not have automatic type coercion from

   { polynomials of degree 0 in R[X] } --> R

What polcoeff returns is the polynomial of degree 0 which is the actual
(unsimplified) coefficient.

> ? x^2+y*x+z
> %1 = x^2 + y*x + z
> ? \x
> [&=00485374] POL(lg=5,CLONE):15000005  (+,varn=0,lgef=5):40000005  00485388  004853ac  004853d0
>   coef of degree 0 = [&=00485388] POL(lg=4):14000004  (+,varn=2,lgef=4):40020004  00485398  004853a0
>     coef of degree 0 = [&=00485398] INT(lg=2):02000002  (0,lgef=2):00000002
>     coef of degree 1 = [&=004853a0] INT(lg=3):02000003  (+,lgef=3):40000003  00000001
>   coef of degree 1 = [&=004853ac] POL(lg=4):14000004  (+,varn=1,lgef=4):40010004  004853bc  004853c4
>     coef of degree 0 = [&=004853bc] INT(lg=2):02000002  (0,lgef=2):00000002
>     coef of degree 1 = [&=004853c4] INT(lg=3):02000003  (+,lgef=3):40000003  00000001
>   coef of degree 2 = [&=004853d0] INT(lg=3):02000003  (+,lgef=3):40000003  00000001
>
> So when I ask for coef of degree 0, I would expect to get
>
>   coef of degree 0 = [&=00485388] POL(lg=4):14000004  (+,varn=2,lgef=4):40020004  00485398  004853a0
>     coef of degree 0 = [&=00485398] INT(lg=2):02000002  (0,lgef=2):00000002
>     coef of degree 1 = [&=004853a0] INT(lg=3):02000003  (+,lgef=3):40000003  00000001

And you do, when you start from %1 (which is shown by \x).

Let's try again.

? install(voir,"vGD-1,L,")
? T = x^2+y*x+z;
? voir(T) \\ _not_ the same as voir(%), i.e \x

[&=00a5d26c] POL(lg=5,CLONE):15000005  (+,varn=0,lgef=5):40000005  00a5d2d4
00a5d2a0  00a5d280
  coef of degree 0 = [&=00a5d2d4] POL(lg=3):14000003 (+,varn=7,lgef=3):40070003  00a5d2c4
    coef of degree 0 = [&=00a5d2c4] POL(lg=4):14000004 (+,varn=8,lgef=4):40080004  00a5d2bc  00a5d2b0
      coef of degree 0 = [&=00a5d2bc]
      coef of degree 1 = [&=00a5d2b0]
  coef of degree 1 = [&=00a5d2a0] POL(lg=4):14000004 (+,varn=7,lgef=4):40070004  00a5d298  00a5d28c
    coef of degree 0 = [&=00a5d298]
    coef of degree 1 = [&=00a5d28c] [...]

See the extra layer ? What you get is

  coef of degree 0 = [&=00a5d2d4] POL(lg=3):14000003 (+,varn=7,lgef=3):40070003  00a5d2c4
    coef of degree 0 = [&=00a5d2c4] POL(lg=4):14000004 (+,varn=8,lgef=4):40080004  00a5d2bc  00a5d2b0
      coef of degree 0 = [&=00a5d2bc]
      coef of degree 1 = [&=00a5d2b0]

> What other PARI functions return "unsimplified" results?

Very few PARI functions return "simplified" results. For instance a few very
high-level number field routines [like rnfkummer] return rational numbers
(viewed as elements in the base field, which is in general not Q) as
t_FRAC/t_INT, not as t_POLMOD.

By default, gp applies simplify() before putting results in history.

Hope this is clearer,

    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/