Karim BELABAS on Mon, 8 Mar 1999 18:34:00 +0100 (MET)


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

Re: pari-2.0.14 bugs


[Igor:]
> 1) quadclassunit(-148-16!)			\\ Infinite loop
You can get a stack overflow also. Too little garbage collecting + unlucky
choice of initial parameters:

(17:41) gp > quadclassunit(-148-16!, , [0.2])
%1 = [540880, [135220, 2, 2], [Qfb(43, 20, 121644127259), Qfb(603166, 603166, 8822861), Qfb(2, 2, 2615348736019)], 1, 1.002722657933447551205884129]

The following patch prevents the overflow and allows extra_relation to
abort if no relations are found (still about 10 times slower than with the
above parameters...). As a side effect, it also corrects:

> 4) bnfclassunit(x^2-x-1)			\\ Error

Karim.

*** src/basemath/buch1.c.orig	Fri Mar  5 08:51:42 1999
--- src/basemath/buch1.c	Mon Mar  8 18:23:15 1999
***************
*** 977,985 ****
  double
  check_bach(double cbach, double B)
  {
-   cbach *= 2;
    if (cbach > B)
     err(talker,"sorry, buchxxx couldn't deal with this field PLEASE REPORT!");
    if (DEBUGLEVEL) fprintferr("\nBach constant: %f\n", cbach);
    return cbach;
  }
--- 977,985 ----
  double
  check_bach(double cbach, double B)
  {
    if (cbach > B)
     err(talker,"sorry, buchxxx couldn't deal with this field PLEASE REPORT!");
+   cbach *= 2; if (cbach > B) cbach = B;
    if (DEBUGLEVEL) fprintferr("\nBach constant: %f\n", cbach);
    return cbach;
  }
***************
*** 1186,1192 ****
  }
  
  static void
! desalloc(long **mat, long KCCO)
  {
    long i,*p,*q;
  
--- 1186,1192 ----
  }
  
  static void
! desalloc(long **mat)
  {
    long i,*p,*q;
  
***************
*** 1195,1201 ****
    {
      free(subbase);
      for (i=1; i<lg(subfactorbase); i++) free(powsubfactorbase[i]);
!     for (i=1; i<=KCCO; i++) free(mat[i]);
      free(mat); free(powsubfactorbase);
      for (i=1; i<HASHT; i++)
        for (p = hashtab[i]; p; p = q) { q=(long*)p[0]; free(p-3); }
--- 1195,1201 ----
    {
      free(subbase);
      for (i=1; i<lg(subfactorbase); i++) free(powsubfactorbase[i]);
!     for (i=1; i<lg(mat); i++) free(mat[i]);
      free(mat); free(powsubfactorbase);
      for (i=1; i<HASHT; i++)
        for (p = hashtab[i]; p; p = q) { q=(long*)p[0]; free(p-3); }
***************
*** 1250,1256 ****
  static GEN
  extra_relations(long LIMC, long *ex, long nlze, GEN extramatc)
  {
!   long fpc,p,ep,i,j,k,nlze2, *col, *colg, s = 0, extrarel = nlze+2;
    GEN p1,form, extramat = cgetg(extrarel+1,t_MAT);
  
    if (DEBUGLEVEL)
--- 1250,1257 ----
  static GEN
  extra_relations(long LIMC, long *ex, long nlze, GEN extramatc)
  {
!   long av,fpc,p,ep,i,j,k,nlze2, *col, *colg, s = 0, extrarel = nlze+2;
!   long MAXRELSUP = min(50,4*KC);
    GEN p1,form, extramat = cgetg(extrarel+1,t_MAT);
  
    if (DEBUGLEVEL)
***************
*** 1261,1266 ****
--- 1262,1268 ----
    for (j=1; j<=extrarel; j++) extramat[j]=lgetg(KC+1,t_COL);
    nlze2 = PRECREG? max(nlze,lgsub): min(nlze+1,KC);
    if (nlze2 < 3 && KC > 2) nlze2 = 3;
+   av = avma;
    while (s<extrarel)
    {
      form = NULL;
***************
*** 1289,1297 ****
        }
        for (i=1; i<=KC; i++)
          if (col[i]) break;
!       if (i>KC) s--;
!       else if (PRECREG) coeff(extramatc,1,s) = form[4];
      }
      if (DEBUGLEVEL)
      {
        if (fpc == 1) fprintferr(" %ld",s);
--- 1291,1304 ----
        }
        for (i=1; i<=KC; i++)
          if (col[i]) break;
!       if (i>KC)
!       {
!         s--; avma = av;
!         if (--MAXRELSUP == 0) return NULL;
!       }
!       else { av = avma; if (PRECREG) coeff(extramatc,1,s) = form[4]; }
      }
+     else avma = av;
      if (DEBUGLEVEL)
      {
        if (fpc == 1) fprintferr(" %ld",s);
***************
*** 1817,1826 ****
    if (!PRECREG) lim /= sqrt(3.);
    cp = (long)exp(sqrt(LOGD*log(LOGD)/8.0));
    if (cp < 13) cp = 13;
!   av = avma;
  
! INCREASE:
!   if (DEBUGLEVEL) { fprintferr("cbach = %f\n",cbach); flusherr(); }
    nreldep = nrelsup = 0;
    LIMC = (long)(cbach*LOGD*LOGD);
    if (LIMC < cp) LIMC=cp;
--- 1824,1832 ----
    if (!PRECREG) lim /= sqrt(3.);
    cp = (long)exp(sqrt(LOGD*log(LOGD)/8.0));
    if (cp < 13) cp = 13;
!   av = avma; cbach /= 2;
  
! INCREASE: avma = av; cbach = check_bach(cbach,6.);
    nreldep = nrelsup = 0;
    LIMC = (long)(cbach*LOGD*LOGD);
    if (LIMC < cp) LIMC=cp;
***************
*** 1834,1853 ****
      isqrtD = gfloor(sqrtD);
    }
    factorbasequad(Disc,LIMC2,LIMC);
!   if (!KC) { avma=av; cbach = check_bach(cbach,6.); goto INCREASE; }
  
    vperm = new_chunk(KC+1); for (i=1; i<=KC; i++) vperm[i]=i;
    nbram = subfactorbasequad(lim,KC);
!   if (nbram == -1)
!   {
!     desalloc(NULL,0); avma=av;
!     cbach = check_bach(cbach,6.); goto INCREASE;
!   }
    KCCO = KC + RELSUP;
    if (DEBUGLEVEL) { fprintferr("KC = %ld, KCCO = %ld\n",KC,KCCO); flusherr(); }
    powsubfact(lgsub,CBUCH+7);
  
    mat = (long**) gpmalloc((KCCO+1)*sizeof(long*));
    for (i=1; i<=KCCO; i++)
    {
      mat[i] = (long*) gpmalloc((KC+1)*sizeof(long));
--- 1840,1856 ----
      isqrtD = gfloor(sqrtD);
    }
    factorbasequad(Disc,LIMC2,LIMC);
!   if (!KC) goto INCREASE;
  
    vperm = new_chunk(KC+1); for (i=1; i<=KC; i++) vperm[i]=i;
    nbram = subfactorbasequad(lim,KC);
!   if (nbram == -1) { desalloc(NULL); goto INCREASE; }
    KCCO = KC + RELSUP;
    if (DEBUGLEVEL) { fprintferr("KC = %ld, KCCO = %ld\n",KC,KCCO); flusherr(); }
    powsubfact(lgsub,CBUCH+7);
  
    mat = (long**) gpmalloc((KCCO+1)*sizeof(long*));
+   setlg(mat, KCCO+1);
    for (i=1; i<=KCCO; i++)
    {
      mat[i] = (long*) gpmalloc((KC+1)*sizeof(long));
***************
*** 1881,1891 ****
        fprintferr("\n");
        msgtimer("be honest");
      }
!     if (!s)
!     {
!       desalloc(mat,KCCO); avma=av;
!       cbach = check_bach(cbach,6.); goto INCREASE;
!     }
    }
    matc=cgetg(KCCO+1,t_MAT);
    if (PRECREG)
--- 1884,1890 ----
        fprintferr("\n");
        msgtimer("be honest");
      }
!     if (!s) { desalloc(mat); goto INCREASE; }
    }
    matc=cgetg(KCCO+1,t_MAT);
    if (PRECREG)
***************
*** 1908,1925 ****
      extramatc=cgetg(extrarel+1,t_MAT);
      for (i=1; i<=extrarel; i++) extramatc[i]=lgetg(s,t_COL);
      extramat = extra_relations(LIMC,ex,nlze,extramatc);
      if (nrelsup) nlze=0;
      mit=hnfadd(mit,&pdep,&matc,vperm,&matalpha,KCCOPRO,KC,col,&nlze,
                 extramat,extramatc);
      KCCOPRO += extrarel; col = KCCOPRO-lg(matalpha)+1;
      if (nlze)
      {
!       nreldep++;
!       if (nreldep>5)
!       {
!         desalloc(mat,KCCO); avma=av;
!         cbach = check_bach(cbach,6.); goto INCREASE;
!       }
        goto EXTRAREL;
      }
    }
--- 1907,1920 ----
      extramatc=cgetg(extrarel+1,t_MAT);
      for (i=1; i<=extrarel; i++) extramatc[i]=lgetg(s,t_COL);
      extramat = extra_relations(LIMC,ex,nlze,extramatc);
+     if (!extramat) { desalloc(mat); goto INCREASE; }
      if (nrelsup) nlze=0;
      mit=hnfadd(mit,&pdep,&matc,vperm,&matalpha,KCCOPRO,KC,col,&nlze,
                 extramat,extramatc);
      KCCOPRO += extrarel; col = KCCOPRO-lg(matalpha)+1;
      if (nlze)
      {
!       if (++nreldep > 5) { desalloc(mat); goto INCREASE; }
        goto EXTRAREL;
      }
    }
***************
*** 1931,1949 ****
      reg = get_reg(matc, col-lg(mit)+1);
      if (!reg)
      {
!       desalloc(mat,KCCO); avma=av;
        prec = (PRECREG<<1)-2; goto INCREASE;
      }
      if (gexpo(reg)<=-3)
      {
!       nrelsup++;
!       if (nrelsup<=7)
        {
          if (DEBUGLEVEL) { fprintferr("regulateur nul\n"); flusherr(); }
          nlze=min(KC,nrelsup); goto EXTRAREL;
        }
!       desalloc(mat,KCCO); avma=av;
!       cbach = check_bach(cbach,6.); goto INCREASE;
      }
      c_1 = divrr(gmul2n(gmul(h,reg),1), cst);
    }
--- 1926,1942 ----
      reg = get_reg(matc, col-lg(mit)+1);
      if (!reg)
      {
!       desalloc(mat);
        prec = (PRECREG<<1)-2; goto INCREASE;
      }
      if (gexpo(reg)<=-3)
      {
!       if (++nrelsup <= 7)
        {
          if (DEBUGLEVEL) { fprintferr("regulateur nul\n"); flusherr(); }
          nlze=min(KC,nrelsup); goto EXTRAREL;
        }
!       desalloc(mat); goto INCREASE;
      }
      c_1 = divrr(gmul2n(gmul(h,reg),1), cst);
    }
***************
*** 1963,1977 ****
          { fprintferr("***** check = %f\n\n",gtodouble(c_1)); flusherr(); }
        nlze=min(KC,nrelsup); goto EXTRAREL;
      }
!     if (cbach < 5.99)
!     {
!       desalloc(mat,KCCO); avma=av;
!       cbach = check_bach(cbach,6.); goto INCREASE;
!     }
      err(warner,"suspicious check. Suggest increasing extra relations.");
    }
    basecl = get_clgp(Disc,mit,&met,PRECREG);
!   s = lg(basecl); desalloc(mat,KCCO); tetpil=avma;
  
    res=cgetg(6,t_VEC);
    res[1]=lcopy(h); p1=cgetg(s,t_VEC);
--- 1956,1966 ----
          { fprintferr("***** check = %f\n\n",gtodouble(c_1)); flusherr(); }
        nlze=min(KC,nrelsup); goto EXTRAREL;
      }
!     if (cbach < 5.99) { desalloc(mat); goto INCREASE; }
      err(warner,"suspicious check. Suggest increasing extra relations.");
    }
    basecl = get_clgp(Disc,mit,&met,PRECREG);
!   s = lg(basecl); desalloc(mat); tetpil=avma;
  
    res=cgetg(6,t_VEC);
    res[1]=lcopy(h); p1=cgetg(s,t_VEC);
--
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/