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

Diff for /OpenXM_contrib2/asir2000/engine/nd.c between version 1.176 and 1.186

version 1.176, 2009/09/24 07:13:00 version 1.186, 2010/04/23 07:35:44
Line 1 
Line 1 
 /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.175 2009/09/09 08:13:24 noro Exp $ */  /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.185 2010/04/23 04:44:51 noro Exp $ */
   
 #include "nd.h"  #include "nd.h"
   
Line 49  static int nd_demand;
Line 49  static int nd_demand;
 static int nd_module,nd_ispot,nd_mpos,nd_pot_nelim;  static int nd_module,nd_ispot,nd_mpos,nd_pot_nelim;
 static NODE nd_tracelist;  static NODE nd_tracelist;
 static NODE nd_alltracelist;  static NODE nd_alltracelist;
 static int nd_gentrace,nd_gensyz,nd_nora;  static int nd_gentrace,nd_gensyz,nd_nora,nd_incr;
   
 NumberField get_numberfield();  NumberField get_numberfield();
 UINT *nd_det_compute_bound(NDV **dm,int n,int j);  UINT *nd_det_compute_bound(NDV **dm,int n,int j);
Line 2308  ND_pairs nd_newpairs( NODE g, int t )
Line 2308  ND_pairs nd_newpairs( NODE g, int t )
     for ( r0 = 0, h = g; h; h = NEXT(h) ) {      for ( r0 = 0, h = g; h; h = NEXT(h) ) {
         if ( nd_module && (MPOS(DL(nd_psh[(long)BDY(h)])) != MPOS(dl)) )          if ( nd_module && (MPOS(DL(nd_psh[(long)BDY(h)])) != MPOS(dl)) )
                 continue;                  continue;
                   if ( (long)BDY(h) < nd_incr && t < nd_incr ) continue;
         NEXTND_pairs(r0,r);          NEXTND_pairs(r0,r);
         r->i1 = (long)BDY(h);          r->i1 = (long)BDY(h);
         r->i2 = t;          r->i2 = t;
Line 2594  int ndv_newps(int m,NDV a,NDV aq)
Line 2595  int ndv_newps(int m,NDV a,NDV aq)
 }  }
   
 /* nd_tracelist = [[0,index,div],...,[nd_psn-1,index,div]] */  /* nd_tracelist = [[0,index,div],...,[nd_psn-1,index,div]] */
   /* return 1 if success, 0 if failure (HC(a mod p)) */
   
 void ndv_setup(int mod,int trace,NODE f,int dont_sort,int dont_removecont)  int ndv_setup(int mod,int trace,NODE f,int dont_sort,int dont_removecont)
 {  {
     int i,j,td,len,max;      int i,j,td,len,max;
     NODE s,s0,f0,tn;      NODE s,s0,f0,tn;
Line 2649  void ndv_setup(int mod,int trace,NODE f,int dont_sort,
Line 2651  void ndv_setup(int mod,int trace,NODE f,int dont_sort,
             register_hcf(a);              register_hcf(a);
             am = nd_ps[i] = ndv_dup(mod,a);              am = nd_ps[i] = ndv_dup(mod,a);
             ndv_mod(mod,am);              ndv_mod(mod,am);
               if ( DL_COMPARE(HDL(am),HDL(a)) )
                   return 0;
             ndv_removecont(mod,am);              ndv_removecont(mod,am);
         } else {          } else {
             a = nd_ps[i] = ndv_dup(mod,w[i].p);              a = nd_ps[i] = ndv_dup(mod,w[i].p);
Line 2675  void ndv_setup(int mod,int trace,NODE f,int dont_sort,
Line 2679  void ndv_setup(int mod,int trace,NODE f,int dont_sort,
         }          }
     }      }
     if ( nd_gentrace && nd_tracelist ) NEXT(tn) = 0;      if ( nd_gentrace && nd_tracelist ) NEXT(tn) = 0;
       return 1;
 }  }
   
 struct order_spec *append_block(struct order_spec *spec,  struct order_spec *append_block(struct order_spec *spec,
Line 2782  NODE postprocess_algcoef(VL av,NODE alist,NODE r)
Line 2787  NODE postprocess_algcoef(VL av,NODE alist,NODE r)
     return u0;      return u0;
 }  }
   
 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spec *ord,LIST *rp)  void nd_gr(LIST f,LIST v,int m,int homo,int f4,struct order_spec *ord,LIST *rp)
 {  {
     VL tv,fv,vv,vc,av;      VL tv,fv,vv,vc,av;
     NODE fd,fd0,r,r0,t,x,s,xx,alist;      NODE fd,fd0,r,r0,t,x,s,xx,alist;
     int e,max,nvar,i;      int e,max,nvar,i;
     NDV b;      NDV b;
     int ishomo,nalg,mrank,trank;      int ishomo,nalg,mrank,trank,wmax,len;
           NMV a;
     Alg alpha,dp;      Alg alpha,dp;
     P p,zp;      P p,zp;
     Q dmy;      Q dmy;
Line 2841  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
Line 2847  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
     }      }
     nd_init_ord(ord);      nd_init_ord(ord);
     mrank = 0;      mrank = 0;
     for ( t = BDY(f), max = 0; t; t = NEXT(t) )      for ( t = BDY(f), max = 1; t; t = NEXT(t) )
         for ( tv = vv; tv; tv = NEXT(tv) ) {          for ( tv = vv; tv; tv = NEXT(tv) ) {
             if ( nd_module ) {              if ( nd_module ) {
                 s = BDY((LIST)BDY(t));                  s = BDY((LIST)BDY(t));
Line 2875  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
Line 2881  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
         if ( b ) { NEXTNODE(fd0,fd); BDY(fd) = (pointer)b; }          if ( b ) { NEXTNODE(fd0,fd); BDY(fd) = (pointer)b; }
     }      }
     if ( fd0 ) NEXT(fd) = 0;      if ( fd0 ) NEXT(fd) = 0;
     ndv_setup(m,0,fd0,0,0);  
           if ( !ishomo && homo ) {
           for ( t = fd0, wmax = max; t; t = NEXT(t) ) {
               b = (NDV)BDY(t); len = LEN(b);
               for ( a = BDY(b), i = 0; i < len; i++, NMV_ADV(a) )
                   wmax = MAX(TD(DL(a)),wmax);
           }
           homogenize_order(ord,nvar,&ord1);
           nd_init_ord(ord1);
           nd_setup_parameters(nvar+1,wmax);
           for ( t = fd0; t; t = NEXT(t) )
               ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos,ompos);
       }
   
       ndv_setup(m,0,fd0,nd_incr?1:0,0);
     if ( nd_gentrace ) {      if ( nd_gentrace ) {
         MKLIST(l1,nd_tracelist); MKNODE(nd_alltracelist,l1,0);          MKLIST(l1,nd_tracelist); MKNODE(nd_alltracelist,l1,0);
     }      }
     x = f4?nd_f4(m,&perm):nd_gb(m,ishomo,0,0,&perm);      x = f4?nd_f4(m,&perm):nd_gb(m,ishomo || homo,0,0,&perm);
           if ( !ishomo && homo ) {
                   /* dehomogenization */
                   for ( t = x; t; t = NEXT(t) ) ndv_dehomogenize((NDV)BDY(t),ord);
                   nd_init_ord(ord);
                   nd_setup_parameters(nvar,0);
           }
     nd_demand = 0;      nd_demand = 0;
     x = ndv_reducebase(x,perm);      x = ndv_reducebase(x,perm);
     if ( nd_gentrace ) { tl1 = nd_alltracelist; nd_alltracelist = 0; }      if ( nd_gentrace ) { tl1 = nd_alltracelist; nd_alltracelist = 0; }
Line 2922  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
Line 2948  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
                 }                  }
        MKLIST(l1,tl1); MKLIST(l2,tl2); MKLIST(l3,t); MKLIST(l4,tl3);         MKLIST(l1,tl1); MKLIST(l2,tl2); MKLIST(l3,t); MKLIST(l4,tl3);
        MKLIST(l5,tl4);         MKLIST(l5,tl4);
       tr = mknode(7,*rp,0,l1,l2,l3,l4,l5); MKLIST(*rp,tr);        tr = mknode(7,*rp,(!ishomo&&homo)?ONE:0,l1,l2,l3,l4,l5); MKLIST(*rp,tr);
     }      }
 #if 0  #if 0
     fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc);      fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc);
Line 2971  void nd_gr_postproc(LIST f,LIST v,int m,struct order_s
Line 2997  void nd_gr_postproc(LIST f,LIST v,int m,struct order_s
         nvar += nalg;          nvar += nalg;
     }      }
     nd_init_ord(ord);      nd_init_ord(ord);
     for ( t = BDY(f), max = 0; t; t = NEXT(t) )      for ( t = BDY(f), max = 1; t; t = NEXT(t) )
         for ( tv = vv; tv; tv = NEXT(tv) ) {          for ( tv = vv; tv; tv = NEXT(tv) ) {
             e = getdeg(tv->v,(P)BDY(t));              e = getdeg(tv->v,(P)BDY(t));
             max = MAX(e,max);              max = MAX(e,max);
Line 3083  void nd_gr_trace(LIST f,LIST v,int trace,int homo,int 
Line 3109  void nd_gr_trace(LIST f,LIST v,int trace,int homo,int 
     m = trace > 1 ? trace : get_lprime(mindex);      m = trace > 1 ? trace : get_lprime(mindex);
     nd_init_ord(ord);      nd_init_ord(ord);
     mrank = 0;      mrank = 0;
     for ( t = BDY(f), max = 0; t; t = NEXT(t) )      for ( t = BDY(f), max = 1; t; t = NEXT(t) )
         for ( tv = vv; tv; tv = NEXT(tv) ) {          for ( tv = vv; tv; tv = NEXT(tv) ) {
             if ( nd_module ) {              if ( nd_module ) {
                 s = BDY((LIST)BDY(t));                  s = BDY((LIST)BDY(t));
Line 3133  void nd_gr_trace(LIST f,LIST v,int trace,int homo,int 
Line 3159  void nd_gr_trace(LIST f,LIST v,int trace,int homo,int 
             ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos,ompos);              ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos,ompos);
     }      }
     while ( 1 ) {      while ( 1 ) {
                   tl1 = tl2 = tl3 = tl4 = 0;
         if ( Demand )          if ( Demand )
             nd_demand = 1;              nd_demand = 1;
         ndv_setup(m,1,fd0,0,0);          ret = ndv_setup(m,1,fd0,nd_incr?1:0,0);
         if ( nd_gentrace ) {          if ( nd_gentrace ) {
             MKLIST(l1,nd_tracelist); MKNODE(nd_alltracelist,l1,0);              MKLIST(l1,nd_tracelist); MKNODE(nd_alltracelist,l1,0);
         }          }
         cand = f4?nd_f4_trace(m,&perm):nd_gb_trace(m,ishomo || homo,&perm);          if ( ret )
         if ( !cand ) {              cand = f4?nd_f4_trace(m,&perm):nd_gb_trace(m,ishomo || homo,&perm);
           if ( !ret || !cand ) {
             /* failure */              /* failure */
             if ( trace > 1 ) { *rp = 0; return; }              if ( trace > 1 ) { *rp = 0; return; }
             else m = get_lprime(++mindex);              else m = get_lprime(++mindex);
Line 3443  void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos
Line 3471  void ndv_homogenize(NDV p,int obpe,int oadv,EPOS oepos
     NMV m,mr0,mr,t;      NMV m,mr0,mr,t;
   
     len = p->len;      len = p->len;
     for ( m = BDY(p), i = 0, max = 0; i < len; NMV_OADV(m), i++ )      for ( m = BDY(p), i = 0, max = 1; i < len; NMV_OADV(m), i++ )
         max = MAX(max,TD(DL(m)));          max = MAX(max,TD(DL(m)));
     mr0 = nmv_adv>oadv?(NMV)REALLOC(BDY(p),len*nmv_adv):BDY(p);      mr0 = nmv_adv>oadv?(NMV)REALLOC(BDY(p),len*nmv_adv):BDY(p);
     m = (NMV)((char *)mr0+(len-1)*oadv);      m = (NMV)((char *)mr0+(len-1)*oadv);
Line 4047  void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta
Line 4075  void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta
     NEWNM(m); d = DL(m);      NEWNM(m); d = DL(m);
     if ( mod ) {      if ( mod ) {
         c0 = CM(m0); c1 = CM(m1); DMAR(c0,c1,0,mod,c); CM(m) = c;          c0 = CM(m0); c1 = CM(m1); DMAR(c0,c1,0,mod,c); CM(m) = c;
     } else      } else if ( nd_vc )
           mulp(nd_vc,CP(m0),CP(m1),&CP(m));
           else
         mulq(CQ(m0),CQ(m1),&CQ(m));          mulq(CQ(m0),CQ(m1),&CQ(m));
     for ( i = 0; i < nd_wpd; i++ ) d[i] = 0;      for ( i = 0; i < nd_wpd; i++ ) d[i] = 0;
     homo = n&1 ? 1 : 0;      homo = n&1 ? 1 : 0;
Line 4102  void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta
Line 4132  void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta
                         ndl_addto(DL(tab[u]),d);                          ndl_addto(DL(tab[u]),d);
                         if ( mod ) {                          if ( mod ) {
                             c0 = CM(tab[u]); DMAR(c0,c,0,mod,c1); CM(tab[u]) = c1;                              c0 = CM(tab[u]); DMAR(c0,c,0,mod,c1); CM(tab[u]) = c1;
                         } else {                          } else if ( nd_vc )
                               mulp(nd_vc,CP(tab[u]),(P)q,&CP(tab[u]));
                                                   else {
                             mulq(CQ(tab[u]),q,&q1); CQ(tab[u]) = q1;                              mulq(CQ(tab[u]),q,&q1); CQ(tab[u]) = q1;
                         }                          }
                     }                      }
Line 4114  void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta
Line 4146  void weyl_mul_nm_nmv(int n,int mod,NM m0,NMV m1,NM *ta
                         ndl_add(DL(tab[u]),d,DL(t));                          ndl_add(DL(tab[u]),d,DL(t));
                         if ( mod ) {                          if ( mod ) {
                             c0 = CM(tab[u]); DMAR(c0,c,0,mod,c1); CM(t) = c1;                              c0 = CM(tab[u]); DMAR(c0,c,0,mod,c1); CM(t) = c1;
                         } else                          } else if ( nd_vc )
                               mulp(nd_vc,CP(tab[u]),(P)q,&CP(t));
                                                   else
                             mulq(CQ(tab[u]),q,&CQ(t));                              mulq(CQ(tab[u]),q,&CQ(t));
                         *p = t;                          *p = t;
                     }                      }
Line 4903  void nd_nf_p(P f,LIST g,LIST v,int m,struct order_spec
Line 4937  void nd_nf_p(P f,LIST g,LIST v,int m,struct order_spec
     for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ );      for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ );
   
     /* get the degree bound */      /* get the degree bound */
     for ( t = BDY(g), max = 0; t; t = NEXT(t) )      for ( t = BDY(g), max = 1; t; t = NEXT(t) )
         for ( tv = vv; tv; tv = NEXT(tv) ) {          for ( tv = vv; tv; tv = NEXT(tv) ) {
             e = getdeg(tv->v,(P)BDY(t));              e = getdeg(tv->v,(P)BDY(t));
             max = MAX(e,max);              max = MAX(e,max);
Line 6498  void nd_det(int mod,MAT f,P *rp)
Line 6532  void nd_det(int mod,MAT f,P *rp)
         m = (pointer **)w;          m = (pointer **)w;
     }      }
   
     for ( i = 0, max = 0; i < n; i++ )      for ( i = 0, max = 1; i < n; i++ )
         for ( j = 0; j < n; j++ )          for ( j = 0; j < n; j++ )
             for ( tv = fv; tv; tv = NEXT(tv) ) {              for ( tv = fv; tv; tv = NEXT(tv) ) {
                 e = getdeg(tv->v,(P)m[i][j]);                  e = getdeg(tv->v,(P)m[i][j]);
Line 6506  void nd_det(int mod,MAT f,P *rp)
Line 6540  void nd_det(int mod,MAT f,P *rp)
             }              }
     nd_setup_parameters(nvar,max);      nd_setup_parameters(nvar,max);
     dm = (NDV **)almat_pointer(n,n);      dm = (NDV **)almat_pointer(n,n);
     for ( i = 0, max = 0; i < n; i++ )      for ( i = 0, max = 1; i < n; i++ )
         for ( j = 0; j < n; j++ ) {          for ( j = 0; j < n; j++ ) {
             dm[i][j] = ptondv(CO,fv,m[i][j]);              dm[i][j] = ptondv(CO,fv,m[i][j]);
             if ( mod ) ndv_mod(mod,dm[i][j]);              if ( mod ) ndv_mod(mod,dm[i][j]);
Line 6556  void nd_det(int mod,MAT f,P *rp)
Line 6590  void nd_det(int mod,MAT f,P *rp)
                 bucket = create_pbucket();                  bucket = create_pbucket();
                 if ( mi[k] ) {                  if ( mi[k] ) {
                     nmv = BDY(mjj); len = LEN(mjj);                      nmv = BDY(mjj); len = LEN(mjj);
                                           fprintf(stderr,"len=%d\n",len);
                     for ( a = 0; a < len; a++, NMV_ADV(nmv) ) {                      for ( a = 0; a < len; a++, NMV_ADV(nmv) ) {
                                                   fprintf(stderr,".");
                         u = ndv_mul_nmv_trunc(mod,nmv,mi[k],DL(BDY(d)));                          u = ndv_mul_nmv_trunc(mod,nmv,mi[k],DL(BDY(d)));
                         add_pbucket(mod,bucket,u);                          add_pbucket(mod,bucket,u);
                                                   if ( !(a%1000) )
                                                           fprintf(stderr,"%d\n",a);
                     }                      }
                 }                  }
                 if ( mj[k] && mij ) {                  if ( mj[k] && mij ) {
                     nmv = BDY(mij); len = LEN(mij);                      nmv = BDY(mij); len = LEN(mij);
                                           fprintf(stderr,"len=%d\n",len);
                     for ( a = 0; a < len; a++, NMV_ADV(nmv) ) {                      for ( a = 0; a < len; a++, NMV_ADV(nmv) ) {
                                                   fprintf(stderr,".");
                         u = ndv_mul_nmv_trunc(mod,nmv,mj[k],DL(BDY(d)));                          u = ndv_mul_nmv_trunc(mod,nmv,mj[k],DL(BDY(d)));
                         add_pbucket(mod,bucket,u);                          add_pbucket(mod,bucket,u);
                                                   if ( !(a%1000) )
                                                           fprintf(stderr,"%d\n",a);
                     }                      }
                 }                  }
                 u = nd_quo(mod,bucket,d);                  u = nd_quo(mod,bucket,d);
Line 6899  void parse_nd_option(NODE opt)
Line 6941  void parse_nd_option(NODE opt)
     char *key;      char *key;
     Obj value;      Obj value;
   
     nd_gentrace = 0; nd_gensyz = 0; nd_nora = 0;      nd_gentrace = 0; nd_gensyz = 0; nd_nora = 0; nd_incr = 0;
     for ( t = opt; t; t = NEXT(t) ) {      for ( t = opt; t; t = NEXT(t) ) {
         p = BDY((LIST)BDY(t));          p = BDY((LIST)BDY(t));
         key = BDY((STRING)BDY(p));          key = BDY((STRING)BDY(p));
Line 6910  void parse_nd_option(NODE opt)
Line 6952  void parse_nd_option(NODE opt)
             nd_gensyz = value?1:0;              nd_gensyz = value?1:0;
         else if ( !strcmp(key,"nora") )          else if ( !strcmp(key,"nora") )
             nd_nora = value?1:0;              nd_nora = value?1:0;
           else if ( !strcmp(key,"incr") )
               nd_incr = QTOS((Q)value);
     }      }
 }  }

Legend:
Removed from v.1.176  
changed lines
  Added in v.1.186

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