Karim Belabas on Sat, 24 Jan 2015 13:50:16 +0100


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

Re: Mixing variables in Mod expressions


* Charles Greathouse [2015-01-21 21:52]:
> > Maybe a warning when 'debug' is non-zero ?
> 
> Yes, please!

Done in master.

(13:48) gp > \g0
(13:48) gp >  Mod(x,x^2-3) + Mod(x,x^2-5)
%1 = Mod(0, 1)
(13:48) gp > \g1
   debug = 1
(13:48) gp >  Mod(x,x^2-3) + Mod(x,x^2-5)
  *** _+_: Warning: coercing quotient rings; moduli x^2 - 3 and x^2 - 5 -> 1.
%2 = Mod(0, 1)

Cheers,

    K.B.

> > * Karim Belabas [2015-01-20 11:51]:
> > > * Pascal Molin [2015-01-20 11:39]:
> > > > What suprises me is that the moduli is removed in the result.
> > [...]
> > > The moduli is not removed, but indeed not printed:
> > [...]
> > > A 0 t_POLMOD is printed as 0 and omitted in polynomial coefficients.
> > > For t_INTMOD, 0 is still explicitly written as Mod(0, N) [ but still
> > omitted
> > > when a polynomial coefficient ]
> > >
> > > I don't see any rationale for this. I can fix the discrepancy, and
> > > explicitly write Mod(0, x) above instead of 0.
> >
> > Done in master. Now we have
> >
> > \\ 0 by itself is printed verbosely
> > (21:26) gp >  Mod(x,x^2-3) + Mod(x,x^2-5)
> > %1 = Mod(0, 1)
> >
> > (21:26) gp > Mod(1,2)+Mod(1,3)
> > %2 = Mod(0, 1)
> >
> > \\ ... but not as polynomial coefficients
> > (21:26) gp > (x^100+1)*Mod(1,2)
> > %3 = Mod(1, 2)*x^100 + Mod(1, 2)
> >
> > (21:26) gp > (x^100+1)*Mod(1,y)
> > %4 = Mod(1, y)*x^100 + Mod(1, y)
> >
> > * Aurel.Page@math.u-bordeaux1.fr [2015-01-20 11:21]:
> > > What about a warning when having to take gcd of moduli ? It would keep
> > the
> > > current behaviour but a student should understand he is doing something
> > > wrong.
> >
> > If we consider an operation as legitimate (and here I do, PARI
> > philosophy...)
> > there should be no warning. OTOH it's *probably* a mistake when the "base
> > ring"
> > suddenly changes in this way.
> >
> > Maybe a warning when 'debug' is non-zero ? As in
> >
> >   (21:32) gp > f(x)=0;
> >   (21:32) gp > \g1
> >      debug = 1
> >   (21:32) gp > f(y)
> >     ***   Warning: compiler generates copy for `y'.
> >   %1 = 0
> > <aside>
> > Here the copy optimizer tells us it had to generate a copy of 'y' when
> > calling user function 'f', although it would probably be alright not to.
> > The user can then rewrite his code as e.g.
> >   my(y=y);f(y)
> > thereby killing the warning and producing faster bytecode:
> >   ? y=vector(10^5);
> >   ? for(i=1,1000,f(y))
> >     ***   Warning: compiler generates copy for `y'.
> >   time = 884 ms.
> >   ? my(y=y);for(i=1,1000,f(y))
> >   time = 12 ms.
> > </aside>
> >
> > Something like
> >
> >   ? Mod(1,2)+Mod(1,3)
> >   %1 = Mod(0, 1)
> >   ? \g1
> >      debug = 1
> >   ? Mod(1,2)+Mod(1,3)
> >     *** _+_: Warning: coercing quotient rings; moduli 2 and 3 -> 1.
> >   %2 = Mod(0, 1)
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`