Karim BELABAS on Mon, 11 Oct 1999 17:10:26 +0200 (MET DST)


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

Re: bug report


[Bill Allombert:]
>  I have trigger the following SIGBUS:
> 
> with version 2.0.15 and current CVS version
> 
> ? charpoly(Mod(Mod(Mod(1, 2)*y^2, Mod(1, 2)*y^3 + Mod(1, 2)*y + Mod(1, 2))*x^4 + Mod(Mod(1, 2)*y^2 + Mod(1, 2)*y, Mod(1, 2)*y^3 + Mod(1, 2)*y + Mod(1, 2))*x^2 + Mod(Mod(1, 2), Mod(1, 2)*y^3 + Mod(1, 2)*y + Mod(1, 2))*x, Mod(Mod(1, 2), Mod(1, 2)*y^3 + Mod(1, 2)*y + Mod(1, 2))*x^7 + Mod(Mod(1, 2)*y, Mod(1, 2)*y^3 + Mod(1, 2)*y + Mod(1, 2))))
> ***   bus error: bug in GP (please report)
> 
> It's really a bug since it works with version 2.0.11, and still works
> with bigger examples
> 
> The bug seem to be in caract2.(I tested it with install)
> With gdb, the SIGBUS occurs in gmodulcp.

A tough one... The bug was in poldivres and was due to an incorrect use of
gmod when gmul( , gmodulcp(gun,mod)) should have been used.

[ gmod(t_POL, t_INT) is defined to be zero since the euclidean division is
done in k[x] for a suitable field k. Due to some delayed simplifications, a
polynomial of degree 0 was produced where an integer was expected and an
ordinary division intended. In the end, degrees didn't match... ]

  Karim.

P.S: The first part of the patch corrects a possible problem in caract2,
when an intermediate result was assumed to be a polynomial, which it needn't
be [as in Bill's example, before the bug was corrected.].

Index: src/basemath/alglin2.c
===================================================================
RCS file: /home/megrez/cvsroot/pari/src/basemath/alglin2.c,v
retrieving revision 1.3
diff -c -r1.3 alglin2.c
*** src/basemath/alglin2.c	1999/09/23 17:50:55	1.3
--- src/basemath/alglin2.c	1999/10/11 14:58:27
***************
*** 36,42 ****
    if (!signe(x)) return gpowgs(polx[v], lgef(p)-3);
    x = gneg_i(x); x[2] = ladd((GEN)x[2], polx[MAXVARN]);
    p1=subres_f(p, x, NULL);
!   if (varn(p1)==MAXVARN) setvarn(p1,v); else p1=gsubst(p1,MAXVARN,polx[v]);
  
    if (!gcmp1(p2) && (d=lgef(x)-3) > 0) p1 = gdiv(p1, gpuigs(p2,d));
    return gerepileupto(av,p1);
--- 36,45 ----
    if (!signe(x)) return gpowgs(polx[v], lgef(p)-3);
    x = gneg_i(x); x[2] = ladd((GEN)x[2], polx[MAXVARN]);
    p1=subres_f(p, x, NULL);
!   if (typ(p1) == t_POL && varn(p1)==MAXVARN)
!     setvarn(p1,v);
!   else
!     p1 = gsubst(p1,MAXVARN,polx[v]);
  
    if (!gcmp1(p2) && (d=lgef(x)-3) > 0) p1 = gdiv(p1, gpuigs(p2,d));
    return gerepileupto(av,p1);
Index: src/basemath/polarit1.c
===================================================================
RCS file: /home/megrez/cvsroot/pari/src/basemath/polarit1.c,v
retrieving revision 1.3
diff -c -r1.3 polarit1.c
*** src/basemath/polarit1.c	1999/10/04 12:14:49	1.3
--- src/basemath/polarit1.c	1999/10/11 14:58:30
***************
*** 269,275 ****
    {
      case t_INTMOD:
      case t_POLMOD: y_lead = ginv(y_lead);
!       f = gmul; mod = (GEN)y_lead[1];
        break;
      default: if (gcmp1(y_lead)) y_lead = NULL;
        mod = NULL;
--- 269,275 ----
    {
      case t_INTMOD:
      case t_POLMOD: y_lead = ginv(y_lead);
!       f = gmul; mod = gmodulcp(gun, (GEN)y_lead[1]);
        break;
      default: if (gcmp1(y_lead)) y_lead = NULL;
        mod = NULL;
***************
*** 298,304 ****
      /* we always enter this loop at least once */
      for (j=0; j<=i && j<=dz; j++)
        if (y[i-j]) p1 = gadd(p1, gmul((GEN)z[j],(GEN)y[i-j]));
!     if (mod && avma==av1) p1 = gmod(p1,mod);
      if (!gcmp0(p1)) { sx = 1; break; } /* remainder is non-zero */
      if (!isinexactreal(p1) && !isexactzero(p1)) break;
      if (!i) break;
--- 298,304 ----
      /* we always enter this loop at least once */
      for (j=0; j<=i && j<=dz; j++)
        if (y[i-j]) p1 = gadd(p1, gmul((GEN)z[j],(GEN)y[i-j]));
!     if (mod && avma==av1) p1 = gmul(p1,mod);
      if (!gcmp0(p1)) { sx = 1; break; } /* remainder is non-zero */
      if (!isinexactreal(p1) && !isexactzero(p1)) break;
      if (!i) break;
***************
*** 322,328 ****
      av1=avma; p1 = (GEN)x[i];
      for (j=0; j<=i && j<=dz; j++)
        if (y[i-j]) p1 = gadd(p1, gmul((GEN)z[j],(GEN)y[i-j]));
!     if (mod && avma==av1) p1 = gmod(p1,mod);
      rem[i]=avma==av1? lcopy(p1):lpileupto(av1,p1);
    }
    rem -= 2;
--- 322,328 ----
      av1=avma; p1 = (GEN)x[i];
      for (j=0; j<=i && j<=dz; j++)
        if (y[i-j]) p1 = gadd(p1, gmul((GEN)z[j],(GEN)y[i-j]));
!     if (mod && avma==av1) p1 = gmul(p1,mod);
      rem[i]=avma==av1? lcopy(p1):lpileupto(av1,p1);
    }
    rem -= 2;
__
Karim Belabas                    email: Karim.Belabas@math.u-psud.fr
Dep. de Mathematiques, Bat. 425
Universite Paris-Sud             Tel: (00 33) 1 69 15 57 48
F-91405 Orsay (France)           Fax: (00 33) 1 69 15 60 19
--
PARI/GP Home Page: http://hasse.mathematik.tu-muenchen.de/ntsw/pari/