Gerhard Niklasch on Tue, 1 Sep 1998 12:45:22 +0200 (MET DST)


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

Re: bug of t_POLMOD ?


In response to:
> Message-Id: <19980901175620F.ohgisi@payila.dj.kit.ac.jp>
> Date: Tue, 01 Sep 1998 17:56:20 +0900 (JST)
> From: Kiyoshi Ohgishi <ohgisi@payila.dj.kit.ac.jp>
> 
> Don't work as I expected.
> 
> Example)
> 
> ? A=Mod(Mod(1, 2)*X, Mod(1, 2)*X^3 + Mod(1, 2)*X + Mod(1, 2))
> %1 = Mod(Mod(1, 2)*X, Mod(1, 2)*X^3 + Mod(1, 2)*X + Mod(1, 2))
> ? A^0
> %2 = Mod(1, Mod(1, 2)*X^3 + Mod(1, 2)*X + Mod(1, 2))
> ? A^0+A^0
> %3 = Mod(2, Mod(1, 2)*X^3 + Mod(1, 2)*X + Mod(1, 2))

You were expecting %2 to read
    Mod(Mod(1, 2), ...)
and %3 to read
    Mod(Mod(0, 2), ...),
right?

The short answer is:  Multiply things by Mod(1,2) to force the
results you want  (and to make equality tests meaningful).

A longer answer is that polynomials in PARI can have coefficients
of mixed type, some integers, some integermods  (there are some
restrictions, and indeed I find these don't seem to work the way
they should -- will investigate later),  and thus it would be
quite impossible to formulate a general rule what sort of unit
element should be the result of (some polynomial)^0 -- should
we let ourselves be guided by the type of the constant coefficient?
or of the leading coefficient?  or choose a type to which each
coefficient can be projected  (integer if all coefficients are
integers, integermod the gcd of all moduli otherwise)?  or a type
which can be projected to each coefficient type?  PARI takes the
latter approach.  The element 1 of the ring of integers is the
only answer which is `safe' in the sense that it can be mapped
canonically into whatever ring you need.

(It can get even worse.  Try 1.2*X^2+3*X+Mod(1,2) ... It behaves
reasonably so long as you don't do anything which causes a real
by integermod multiplication.)

For working in algebras over finite fields, constructions like
    `Mod(representative,
          (ideal in Z[X] generated by a prime and by
           one or more polynomials)
        )'
(as pioneered by Kronecker more than a century ago)  would perhaps
be useful, but PARI's internal representation of an object like A
is not symmetrical in the prime and the modulus polynomial, but
hierarchical -- a polmod of two polynomial components, whose coef-
ficients happen to be integermods to modulus 2  (and could equally
well be of other types).

Gerhard