[BACK]Return to Hgfs.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Diff for /OpenXM_contrib2/asir2000/engine/Hgfs.c between version 1.18 and 1.22

version 1.18, 2001/10/09 01:36:10 version 1.22, 2002/09/27 04:24:04
Line 1 
Line 1 
 /* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.17 2001/09/03 07:01:06 noro Exp $ */  /* $OpenXM: OpenXM_contrib2/asir2000/engine/Hgfs.c,v 1.21 2001/11/19 00:57:11 noro Exp $ */
   
 #include "ca.h"  #include "ca.h"
   #include "inline.h"
   
 void lnfsf(int n,UM p0,UM p1,struct p_pair *list,UM np0,UM np1);  void lnfsf(int n,UM p0,UM p1,struct p_pair *list,UM np0,UM np1);
   void extractcoefbm(BM f,int dx,UM r);
   
 int comp_dum(DUM a,DUM b)  int comp_dum(DUM a,DUM b)
 {  {
Line 26  void fctrsf(P p,DCP *dcp)
Line 28  void fctrsf(P p,DCP *dcp)
   
         simp_ff((Obj)p,&obj); p = (P)obj;          simp_ff((Obj)p,&obj); p = (P)obj;
         if ( !p ) {          if ( !p ) {
                 *dcp = 0; return;                  NEWDC(dc); COEF(dc) = 0; DEG(dc) = ONE;
                   NEXT(dc) = 0; *dcp = dc;
                   return;
         }          }
         mp = W_UMALLOC(UDEG(p));          mp = W_UMALLOC(UDEG(p));
         ptosfum(p,mp);          ptosfum(p,mp);
Line 509  void ptosfbm(int,P,BM);
Line 513  void ptosfbm(int,P,BM);
   
 /* f = f(x,y) */  /* f = f(x,y) */
   
 void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *listp)  void sfhensel(int count,P f,V x,int degbound,GFS *evp,P *sfp,ML *listp)
 {  {
         int i;          int i;
         int fn;          int fn;
Line 517  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
Line 521  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
         BM fl;          BM fl;
         VL vl,nvl;          VL vl,nvl;
         V y;          V y;
         int dx,dy;          int dx,dy,bound;
         GFS ev;          GFS ev;
         P f1,t,c,sf;          P f1,t,c,sf;
         DCP dc;          DCP dc,dct,dc0;
         UM q,fm,hm;          UM q,fm,hm;
         UM *gm;          UM *gm;
         struct oEGT tmp0,tmp1,eg_hensel,eg_hensel_t;          struct oEGT tmp0,tmp1,eg_hensel,eg_hensel_t;
Line 543  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
Line 547  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
                 *listp = rlist = MLALLOC(1); rlist->n = fn; rlist->c[0] = 0;                  *listp = rlist = MLALLOC(1); rlist->n = fn; rlist->c[0] = 0;
                 return;                  return;
         }          }
         /* pass the the leading coeff. to the first element */          if ( degbound >= 0 ) {
         c = dc->c; dc = NEXT(dc);                  /*
         mulp(vl,dc->c,c,&t); dc->c = t;                   * reconstruct dc so that
                    * dc[1],... : factors satisfy degree bound
                    * dc[0]     : product of others
                    */
                   c = dc->c; dc = NEXT(dc);
                   dc0 = 0;
                   fn = 0;
                   while ( dc ) {
                           if ( getdeg(x,COEF(dc)) <= degbound ) {
                                   dct = NEXT(dc); NEXT(dc) = dc0; dc0 = dc; dc = dct;
                                   fn++;
                           } else {
                                   mulp(vl,COEF(dc),c,&t); c = t;
                                   dc = NEXT(dc);
                           }
                   }
                   if ( OID(c) == O_P ) {
                           NEWDC(dc); COEF(dc) = c; DEG(dc) = ONE; NEXT(dc) = dc0;
                           fn++;
                   } else {
                           mulp(vl,dc0->c,c,&t); dc0->c = t; dc = dc0;
                   }
           } else {
                   /* pass the the leading coeff. to the first element */
                   c = dc->c; dc = NEXT(dc);
                   mulp(vl,dc->c,c,&t); dc->c = t;
           }
   
         /* convert mod y-a factors into UM */          /* convert mod y-a factors into UM */
         gm = (UM *)ALLOCA(fn*sizeof(UM));          gm = (UM *)ALLOCA(fn*sizeof(UM));
Line 554  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
Line 584  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
                 ptosfum(dc->c,gm[i]);                  ptosfum(dc->c,gm[i]);
         }          }
   
           /* set bound */
           /* g | f, lc_y(g) = lc_y(f) => deg_y(g) <= deg_y(f) */
           /* so, bound = dy is sufficient, but we use slightly large value */
           bound = dy+2;
   
         /* f(x,y) -> f(x,y+ev) */          /* f(x,y) -> f(x,y+ev) */
         fl = BMALLOC(dx,dy);          fl = BMALLOC(dx,bound);
         ptosfbm(dy,f,fl);          ptosfbm(bound,f,fl);
         if ( ev ) shiftsfbm(fl,FTOIF(CONT(ev)));          if ( ev ) shiftsfbm(fl,FTOIF(CONT(ev)));
   
         /* sf = f(x+ev) */          /* sf = f(x+ev) */
Line 568  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
Line 603  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
         hm = W_UMALLOC(dx);          hm = W_UMALLOC(dx);
   
         q = W_UMALLOC(dx);          q = W_UMALLOC(dx);
         rlist = MLALLOC(fn); rlist->n = fn; rlist->bound = dy;          rlist = MLALLOC(fn); rlist->n = fn; rlist->bound = bound;
         fprintf(asir_out,"%d candidates\n",fn);          fprintf(asir_out,"%d candidates\n",fn);
         init_eg(&eg_hensel);          init_eg(&eg_hensel);
         for ( i = 0; i < fn-1; i++ ) {          for ( i = 0; i < fn-1; i++ ) {
Line 578  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
Line 613  void sfhensel(int count,P f,V x,GFS *evp,P *sfp,ML *li
                 get_eg(&tmp0);                  get_eg(&tmp0);
                 /* fl = gm[i]*hm mod y */                  /* fl = gm[i]*hm mod y */
                 divsfum(fm,gm[i],hm);                  divsfum(fm,gm[i],hm);
                 /* fl is replaced by the cofactor of gk mod y^dy */                  /* fl is replaced by the cofactor of gk mod y^bound */
                 /* rlist->c[i] = gk */                  /* rlist->c[i] = gk */
                 sfhenmain2(fl,gm[i],hm,dy,(BM *)&rlist->c[i]);                  sfhenmain2(fl,gm[i],hm,bound,(BM *)&rlist->c[i]);
                 cpyum(hm,fm);                  cpyum(hm,fm);
                 get_eg(&tmp1); add_eg(&eg_hensel_t,&tmp0,&tmp1);                  get_eg(&tmp1); add_eg(&eg_hensel_t,&tmp0,&tmp1);
                 add_eg(&eg_hensel,&tmp0,&tmp1);                  add_eg(&eg_hensel,&tmp0,&tmp1);
Line 863  void sfsqfr(P f,DCP *dcp)
Line 898  void sfsqfr(P f,DCP *dcp)
                 NEWDC(dc); DEG(dc) = ONE; COEF(dc) = f; NEXT(dc) = 0; *dcp = dc;                  NEWDC(dc); DEG(dc) = ONE; COEF(dc) = f; NEXT(dc) = 0; *dcp = dc;
         } else if ( !NEXT(vl) )          } else if ( !NEXT(vl) )
                 sfusqfr(f,dcp);                  sfusqfr(f,dcp);
   #if 0
         else if ( !NEXT(NEXT(vl)) )          else if ( !NEXT(NEXT(vl)) )
                 sfbsqfr(f,vl->v,NEXT(vl)->v,dcp);                  sfbsqfr(f,vl->v,NEXT(vl)->v,dcp);
   #endif
         else          else
                 error("sfsqfr : not implemented yet");                  error("sfsqfr : not implemented yet");
 }  }
Line 897  void sfusqfr(P f,DCP *dcp)
Line 934  void sfusqfr(P f,DCP *dcp)
         *dcp = dct;          *dcp = dct;
 }  }
   
   void sfbsqfrmain(P f,V x,V y,DCP *dcp)
   {
           /* XXX*/
   }
   
   /* f is bivariate */
   
 void sfbsqfr(P f,V x,V y,DCP *dcp)  void sfbsqfr(P f,V x,V y,DCP *dcp)
 {  {
         P t,rf,cx,cy;          P t,rf,cx,cy;
         VL vl,rvl;          VL vl,rvl;
         DCP dcx,dcy;          DCP dcx,dcy,dct,dc;
         struct oVL vl0,vl1;          struct oVL vl0,vl1;
   
         /* vl = [x,y] */          /* cy(y) = cont(f,x), f /= cy */
         vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0;  
         /* cy(y) = cont(f,x), f /= cx */  
         cont_pp_sfp(vl,f,&cy,&t); f = t;          cont_pp_sfp(vl,f,&cy,&t); f = t;
         /* rvl = [y,x] */          /* rvl = [y,x] */
         reordvar(vl,y,&rvl); reorderp(rvl,vl,f,&rf);          reordvar(vl,y,&rvl); reorderp(rvl,vl,f,&rf);
Line 915  void sfbsqfr(P f,V x,V y,DCP *dcp)
Line 957  void sfbsqfr(P f,V x,V y,DCP *dcp)
         reorderp(vl,rvl,rf,&f);          reorderp(vl,rvl,rf,&f);
   
         /* f -> cx*cy*f */          /* f -> cx*cy*f */
         sfusqfr(cx,&dcx);          sfsqfr(cx,&dcx); dcx = NEXT(dcx);
         sfusqfr(cy,&dcy);          sfsqfr(cy,&dcy); dcy = NEXT(dcy);
           if ( dcx ) {
                   for ( dct = dcx; NEXT(dct); dct = NEXT(dct) );
                   NEXT(dct) = dcy;
           } else
                   dcx = dcy;
           if ( OID(f) == O_N )
                   *dcp = dcx;
           else {
                   /* f must be bivariate */
                   sfbsqfrmain(f,x,y,&dc);
                   if ( dcx ) {
                           for ( dct = dcx; NEXT(dct); dct = NEXT(dct) );
                           NEXT(dct) = dc;
                   } else
                           dcx = dc;
                   *dcp = dcx;
           }
 }  }
   
 void sfdtest(P,ML,V,V,DCP *);  void sfdtest(P,ML,V,V,DCP *);
   
 void sfbfctr(P f,V x,V y,DCP *dcp)  /* if degbound >= 0 find factor s.t. deg_x(factor) <= degbound */
   
   void sfbfctr(P f,V x,V y,int degbound,DCP *dcp)
 {  {
         ML list;          ML list;
         P sf;          P sf;
Line 931  void sfbfctr(P f,V x,V y,DCP *dcp)
Line 992  void sfbfctr(P f,V x,V y,DCP *dcp)
         int dx,dy;          int dx,dy;
   
         /* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */          /* sf(x) = f(x+ev) = list->c[0]*list->c[1]*... */
         sfhensel(5,f,x,&ev,&sf,&list);          sfhensel(5,f,x,degbound,&ev,&sf,&list);
         if ( list->n == 0 )          if ( list->n == 0 )
                 error("sfbfctr : short of evaluation points");                  error("sfbfctr : short of evaluation points");
         else if ( list->n == 1 ) {          else if ( list->n == 1 ) {
Line 959  void sfbfctr(P f,V x,V y,DCP *dcp)
Line 1020  void sfbfctr(P f,V x,V y,DCP *dcp)
 void sfdtest(P f,ML list,V x,V y,DCP *dcp)  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
 {  {
         int np,dx,dy;          int np,dx,dy;
         int i,j,k;          int i,j,k,bound;
         int *win;          int *win;
         P g,lcg,factor,cofactor,lcyx;          P g,lcg,factor,cofactor,lcyx;
         P csum;          P csum;
         DCP dcf,dcf0,dc;          DCP dcf,dcf0,dc;
         BM *c;          BM *c;
         BM lcy;          BM lcy;
         UM lcg0;          UM lcg0,lcy0,w;
           UM *d1c;
         ML wlist;          ML wlist;
         struct oVL vl1,vl0;          struct oVL vl1,vl0;
         VL vl;          VL vl;
         int z;          int z,dt,dtok;
   
         /* vl = [x,y] */          /* vl = [x,y] */
         vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0;          vl0.v = x; vl0.next = &vl1; vl1.v = y; vl1.next = 0; vl = &vl0;
Line 982  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
Line 1044  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
         win = W_ALLOC(np+1);          win = W_ALLOC(np+1);
         wlist = W_MLALLOC(np);          wlist = W_MLALLOC(np);
         wlist->n = list->n;          wlist->n = list->n;
         wlist->bound = dy;          bound = wlist->bound = list->bound;
         c = (BM *)COEF(wlist);          c = (BM *)COEF(wlist);
         bcopy((char *)COEF(list),(char *)c,(int)(sizeof(BM)*np));          bcopy((char *)COEF(list),(char *)c,(int)(sizeof(BM)*np));
   
Line 1006  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
Line 1068  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
         NEWP(lcyx); VR(lcyx) = x; DC(lcyx) = dc;          NEWP(lcyx); VR(lcyx) = x; DC(lcyx) = dc;
         ptosfbm(dy,lcyx,lcy);          ptosfbm(dy,lcyx,lcy);
   
           /* initialize lcy0 by LC(f) */
           lcy0 = W_UMALLOC(bound);
           ptosfum(COEF(DC(g)),lcy0);
   
           /* ((d-1 coefs)*lcy0 */
           d1c = (UM *)W_ALLOC(np*sizeof(UM));
           w = W_UMALLOC(2*bound);
           for ( i = 1; i < np; i++ ) {
                   extractcoefbm(c[i],degbm(c[i])-1,w);
                   d1c[i] = W_UMALLOC(2*bound);
                   mulsfum(w,lcy0,d1c[i]);
                   /* d1c[i] = d1c[i] mod y^(bound+1) */
                   if ( DEG(d1c[i]) > bound ) {
                           for ( j = DEG(d1c[i]); j > bound; j-- )
                                   COEF(d1c[i])[j] = 0;
                           degum(d1c[i],bound);
                   }
           }
   
         fprintf(stderr,"np = %d\n",np);          fprintf(stderr,"np = %d\n",np);
           dtok = 0;
         for ( g = f, k = 1, dcf = dcf0 = 0, win[0] = 1, --np, z = 0; ; z++ ) {          for ( g = f, k = 1, dcf = dcf0 = 0, win[0] = 1, --np, z = 0; ; z++ ) {
                 if ( !(z % 1000) ) fprintf(stderr,".");                  if ( !(z % 1000) ) fprintf(stderr,".");
                 if ( sfdtestmain(vl,lcg,lcg0,lcy,csum,wlist,k,win,&factor,&cofactor) ) {                  dt = sfdegtest(dy,bound,d1c,k,win);
                   if ( dt )
                           dtok++;
                   if ( dt && sfdtestmain(vl,lcg,lcg0,lcy,csum,wlist,
                                   k,win,&factor,&cofactor) ) {
                         NEXTDC(dcf0,dcf); DEG(dcf) = ONE; COEF(dcf) = factor;                          NEXTDC(dcf0,dcf); DEG(dcf) = ONE; COEF(dcf) = factor;
                         g = cofactor;                          g = cofactor;
   
Line 1022  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
Line 1108  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
                         /* update csum */                          /* update csum */
                         sfcsump(vl,lcg,&csum);                          sfcsump(vl,lcg,&csum);
   
                           /* update dy */
                           dy = getdeg(y,g);
   
                         /* update lcy */                          /* update lcy */
                         clearbm(0,lcy);                          clearbm(0,lcy);
                         COEF(dc) = COEF(DC(g));                          COEF(dc) = COEF(DC(g));
Line 1043  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
Line 1132  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
                         else                          else
                                 for ( i = 1; i < k; i++ )                                  for ( i = 1; i < k; i++ )
                                         win[i] = win[0] + i;                                          win[i] = win[0] + i;
   
   
                           /* update lcy0  */
                           ptosfum(COEF(DC(g)),lcy0);
   
                           /* update d-1 coeffs */
                           for ( i = 1; i <= np; i++ ) {
                                   extractcoefbm(c[i],degbm(c[i])-1,w);
                                   mulsfum(w,lcy0,d1c[i]);
                                   /* d1c[i] = d1c[1] mod y^(bound+1) */
                                   if ( DEG(d1c[i]) > bound ) {
                                           for ( j = DEG(d1c[i]); j > bound; j-- )
                                                   COEF(d1c[i])[j] = 0;
                                           degum(d1c[i],bound);
                                   }
                           }
                 } else if ( !ncombi(1,np,k,win) )                  } else if ( !ncombi(1,np,k,win) )
                         if ( k == np )                          if ( k == np )
                                 break;                                  break;
Line 1050  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
Line 1155  void sfdtest(P f,ML list,V x,V y,DCP *dcp)
                                 for ( i = 0, ++k; i < k; i++ )                                  for ( i = 0, ++k; i < k; i++ )
                                         win[i] = i + 1;                                          win[i] = i + 1;
         }          }
         fprintf(stderr,"\n");          fprintf(stderr,"total %d, omitted by degtest %d\n",z,z-dtok);
         NEXTDC(dcf0,dcf); COEF(dcf) = g;          NEXTDC(dcf0,dcf); COEF(dcf) = g;
         DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0;          DEG(dcf) = ONE; NEXT(dcf) = 0; *dcp = dcf0;
 }  }
   
   void extractcoefbm(BM f,int dx,UM r)
   {
           int j;
           UM fj;
   
           for ( j = DEG(f); j >= 0; j-- ) {
                   fj = COEF(f)[j];
                   if ( fj && DEG(fj) >= dx ) {
                           COEF(r)[j] = COEF(fj)[dx];
                   } else
                           COEF(r)[j] = 0;
           }
           degum(r,DEG(f));
   }
   
   /* deg_y(prod mod y^(bound+1)) <= dy ? */
   
   int sfdegtest(int dy,int bound,UM *d1c,int k,int *in)
   {
           int i,j;
           UM w,w1,wt;
           BM t;
   
           w = W_UMALLOC(bound);
           w1 = W_UMALLOC(bound);
           clearum(w,bound);
           for ( i = 0; i < k; i++ ) {
                   addsfum(w,d1c[in[i]],w1); wt = w; w = w1; w1 = wt;
           }
           return DEG(w) <= dy ? 1 : 0;
   }
   
 /* lcy = LC(g), lcg = lcy*g, lcg0 = const part of lcg */  /* lcy = LC(g), lcg = lcy*g, lcg0 = const part of lcg */
   
 int sfdtestmain(VL vl,P lcg,UM lcg0,BM lcy,P csum,ML list,  int sfdtestmain(VL vl,P lcg,UM lcg0,BM lcy,P csum,ML list,
         int k,int *in,P *fp,P *cofp)          int k,int *in,P *fp,P *cofp)
 {  {
Line 1250  int divtp_by_sfbm(VL vl,P f,P g,P *qp)
Line 1388  int divtp_by_sfbm(VL vl,P f,P g,P *qp)
 /* XXX generate an irreducible poly of degree n */  /* XXX generate an irreducible poly of degree n */
   
 extern int current_gfs_q1;  extern int current_gfs_q1;
   extern int *current_gfs_ntoi;
   
 void generate_defpoly_sfum(int n,UM *dp)  void generate_defpoly_sfum(int n,UM *dp)
 {  {
Line 1277  void generate_defpoly_sfum(int n,UM *dp)
Line 1416  void generate_defpoly_sfum(int n,UM *dp)
                 for ( j = 0; j < i; j++ )                  for ( j = 0; j < i; j++ )
                         w[j] = 0;                          w[j] = 0;
                 w[i]++;                  w[i]++;
                 for ( i = 0; i < n; i++ )                  if ( !current_gfs_ntoi )
                         c[i] = w[i]?FTOIF(w[i]-1):0;                          for ( i = 0; i < n; i++ )
                                   c[i] = w[i]?FTOIF(w[i]):0;
                   else
                           for ( i = 0; i < n; i++ )
                                   c[i] = w[i]?FTOIF(w[i]-1):0;
                 if ( !c[0] )                  if ( !c[0] )
                         continue;                          continue;
                 diffsfum(r,dr); cpyum(r,t); gcdsfum(t,dr,g);                  diffsfum(r,dr); cpyum(r,t); gcdsfum(t,dr,g);

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.22

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>