[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.118 and 1.124

version 1.118, 2004/12/04 09:39:27 version 1.124, 2005/02/09 07:58:43
Line 1 
Line 1 
 /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.117 2004/12/03 08:57:30 noro Exp $ */  /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.123 2005/01/23 14:03:48 noro Exp $ */
   
 #include "nd.h"  #include "nd.h"
   
Line 8  NM _nm_free_list;
Line 8  NM _nm_free_list;
 ND _nd_free_list;  ND _nd_free_list;
 ND_pairs _ndp_free_list;  ND_pairs _ndp_free_list;
   
   static int nd_ntrans;
 static int nd_nalg;  static int nd_nalg;
 #if 0  #if 0
 static int ndv_alloc;  static int ndv_alloc;
Line 42  static int nd_found,nd_create,nd_notfirst;
Line 43  static int nd_found,nd_create,nd_notfirst;
 static int nmv_adv;  static int nmv_adv;
 static int nd_demand;  static int nd_demand;
   
   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);
 void nd_det_reconstruct(NDV **dm,int n,int j,NDV d);  void nd_det_reconstruct(NDV **dm,int n,int j,NDV d);
 int nd_monic(int m,ND *p);  int nd_monic(int m,ND *p);
Line 1535  ND normalize_pbucket(int mod,PGeoBucket g)
Line 1537  ND normalize_pbucket(int mod,PGeoBucket g)
         return r;          return r;
 }  }
   
 void do_diagonalize(int sugar,int m)  int do_diagonalize(int sugar,int m)
 {  {
         int i,nh,stat;          int i,nh,stat;
         NODE r,g,t;          NODE r,g,t;
Line 1551  void do_diagonalize(int sugar,int m)
Line 1553  void do_diagonalize(int sugar,int m)
                         nfv = nd_ps[i];                          nfv = nd_ps[i];
                 s = ndvtond(m,nfv);                  s = ndvtond(m,nfv);
                 s = nd_separate_head(s,&head);                  s = nd_separate_head(s,&head);
                 nd_nf(m,s,nd_ps,1,&dn,&nf);                  stat = nd_nf(m,s,nd_ps,1,&dn,&nf);
                   if ( !stat ) return 0;
                 if ( !m ) {                  if ( !m ) {
                         NTOQ(NM(dn.z),SGN(dn.z),num);                          NTOQ(NM(dn.z),SGN(dn.z),num);
                         mulq(HCQ(head),num,&q); HCQ(head) = q;                          mulq(HCQ(head),num,&q); HCQ(head) = q;
Line 1572  void do_diagonalize(int sugar,int m)
Line 1575  void do_diagonalize(int sugar,int m)
                 } else                  } else
                         nd_ps[i] = nfv;                          nd_ps[i] = nfv;
         }          }
           return 1;
 }  }
   
 /* return value = 0 => input is not a GB */  /* return value = 0 => input is not a GB */
Line 1597  NODE nd_gb(int m,int ishomo,int checkonly)
Line 1601  NODE nd_gb(int m,int ishomo,int checkonly)
 again:  again:
                 l = nd_minp(d,&d);                  l = nd_minp(d,&d);
                 if ( SG(l) != sugar ) {                  if ( SG(l) != sugar ) {
                         if ( ishomo ) do_diagonalize(sugar,m);                          if ( ishomo ) {
                                   stat = do_diagonalize(sugar,m);
                                   if ( !stat ) {
                                           NEXT(l) = d; d = l;
                                           d = nd_reconstruct(0,d);
                                           goto again;
                                   }
                           }
                         sugar = SG(l);                          sugar = SG(l);
                         if ( DP_Print ) fprintf(asir_out,"%d",sugar);                          if ( DP_Print ) fprintf(asir_out,"%d",sugar);
                 }                  }
Line 1644  again:
Line 1654  again:
         return g;          return g;
 }  }
   
 void do_diagonalize_trace(int sugar,int m)  int do_diagonalize_trace(int sugar,int m)
 {  {
         int i,nh,stat;          int i,nh,stat;
         NODE r,g,t;          NODE r,g,t;
Line 1657  void do_diagonalize_trace(int sugar,int m)
Line 1667  void do_diagonalize_trace(int sugar,int m)
                 /* for nd_ps */                  /* for nd_ps */
                 s = ndvtond(m,nd_ps[i]);                  s = ndvtond(m,nd_ps[i]);
                 s = nd_separate_head(s,&head);                  s = nd_separate_head(s,&head);
                 nd_nf_pbucket(m,s,nd_ps,1,&nf);                  stat = nd_nf_pbucket(m,s,nd_ps,1,&nf);
                   if ( !stat ) return 0;
                 nf = nd_add(m,head,nf);                  nf = nd_add(m,head,nf);
                 ndv_free(nd_ps[i]);                  ndv_free(nd_ps[i]);
                 nd_ps[i] = ndtondv(m,nf);                  nd_ps[i] = ndtondv(m,nf);
Line 1670  void do_diagonalize_trace(int sugar,int m)
Line 1681  void do_diagonalize_trace(int sugar,int m)
                         nfv = nd_ps_trace[i];                          nfv = nd_ps_trace[i];
                 s = ndvtond(0,nfv);                  s = ndvtond(0,nfv);
                 s = nd_separate_head(s,&head);                  s = nd_separate_head(s,&head);
                 nd_nf(0,s,nd_ps_trace,1,&dn,&nf);                  stat = nd_nf(0,s,nd_ps_trace,1,&dn,&nf);
                   if ( !stat ) return 0;
                 NTOQ(NM(dn.z),SGN(dn.z),num);                  NTOQ(NM(dn.z),SGN(dn.z),num);
                 mulq(HCQ(head),num,&q); HCQ(head) = q;                  mulq(HCQ(head),num,&q); HCQ(head) = q;
                 if ( DN(dn.z) ) {                  if ( DN(dn.z) ) {
Line 1689  void do_diagonalize_trace(int sugar,int m)
Line 1701  void do_diagonalize_trace(int sugar,int m)
                 } else                  } else
                         nd_ps_trace[i] = nfv;                          nd_ps_trace[i] = nfv;
         }          }
           return 1;
 }  }
   
 static struct oEGT eg_invdalg;  static struct oEGT eg_invdalg;
Line 1719  NODE nd_gb_trace(int m,int ishomo)
Line 1732  NODE nd_gb_trace(int m,int ishomo)
 again:  again:
                 l = nd_minp(d,&d);                  l = nd_minp(d,&d);
                 if ( SG(l) != sugar ) {                  if ( SG(l) != sugar ) {
                         if ( ishomo ) do_diagonalize_trace(sugar,m);                          if ( ishomo ) {
                                   stat = do_diagonalize_trace(sugar,m);
                                   if ( !stat ) {
                                           NEXT(l) = d; d = l;
                                           d = nd_reconstruct(1,d);
                                           goto again;
                                   }
                           }
                         sugar = SG(l);                          sugar = SG(l);
                         if ( DP_Print ) fprintf(asir_out,"%d",sugar);                          if ( DP_Print ) fprintf(asir_out,"%d",sugar);
                 }                  }
Line 2210  void ndv_setup(int mod,int trace,NODE f)
Line 2230  void ndv_setup(int mod,int trace,NODE f)
         }          }
 }  }
   
   struct order_spec *append_block(struct order_spec *spec,
       int nv,int nalg,int ord);
   
   extern VECT current_dl_weight_vector_obj;
   static VECT prev_weight_vector_obj;
   
   void preprocess_algcoef(VL vv,VL av,struct order_spec *ord,LIST f,
           struct order_spec **ord1p,LIST *f1p,NODE *alistp)
   {
           NODE alist,t,s,r0,r,arg;
           VL tv;
           P poly;
           DP d;
           Alg alpha,dp;
           DAlg inv,da,hc;
           MP m;
           int i,nvar,nalg,n;
           NumberField nf;
           LIST f1,f2;
           struct order_spec *current_spec;
           VECT obj,obj0;
           Obj tmp;
   
           for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++);
           for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++);
   
           for ( alist = 0, tv = av; tv; tv = NEXT(tv) ) {
                   NEXTNODE(alist,t); MKV(tv->v,poly);
                   MKAlg(poly,alpha); BDY(t) = (pointer)alpha;
                   tv->v = tv->v->priv;
           }
           NEXT(t) = 0;
   
           /* simplification, makeing polynomials monic */
           setfield_dalg(alist);
           obj_algtodalg(f,&f1);
           for ( t = BDY(f); t; t = NEXT(t) ) {
                   initd(ord); ptod(vv,vv,(P)BDY(t),&d);
                   hc = (DAlg)BDY(d)->c;
                   if ( NID(hc) == N_DA ) {
                           invdalg(hc,&inv);
                           for ( m = BDY(d); m; m = NEXT(m) ) {
                                   muldalg(inv,(DAlg)m->c,&da); m->c = (P)da;
                           }
                   }
                   initd(ord); dtop(vv,vv,d,&poly); BDY(f) = (pointer)poly;
           }
           obj_dalgtoalg(f1,&f);
   
           /* append alg vars to the var list */
           for ( tv = vv; NEXT(tv); tv = NEXT(tv) );
           NEXT(tv) = av;
   
           /* append a block to ord */
           *ord1p = append_block(ord,nvar,nalg,2);
   
           /* create generator list */
           nf = get_numberfield();
           for ( i = nalg-1, t = BDY(f); i >= 0; i-- ) {
                   MKAlg(nf->defpoly[i],dp);
                   MKNODE(s,dp,t); t = s;
           }
           MKLIST(f1,t);
           *alistp = alist;
           algobjtorat(f1,f1p);
   
           /* creating a new weight vector */
           prev_weight_vector_obj = obj0 = current_dl_weight_vector_obj;
           n = nvar+nalg+1;
           MKVECT(obj,n);
           if ( obj0 && obj0->len == nvar )
                   for ( i = 0; i < nvar; i++ ) BDY(obj)[i] = BDY(obj0)[i];
           else
                   for ( i = 0; i < nvar; i++ ) BDY(obj)[i] = (pointer)ONE;
           for ( i = 0; i < nalg; i++ ) BDY(obj)[i+nvar] = 0;
           BDY(obj)[n-1] = (pointer)ONE;
           arg = mknode(1,obj);
           Pdp_set_weight(arg,&tmp);
   }
   
   NODE postprocess_algcoef(VL av,NODE alist,NODE r)
   {
           NODE s,t,u0,u;
           P p;
           VL tv;
           Obj obj,tmp;
           NODE arg;
   
           u0 = 0;
           for ( t = r; t; t = NEXT(t) ) {
                   p = (P)BDY(t);
                   for ( tv = av, s = alist; tv; tv = NEXT(tv), s = NEXT(s) ) {
                           substr(CO,0,(Obj)p,tv->v,(Obj)BDY(s),&obj); p = (P)obj;
                   }
                   if ( OID(p) == O_P || (OID(p) == O_N && NID((Num)p) != N_A) ) {
                           NEXTNODE(u0,u);
                           BDY(u) = (pointer)p;
                   }
           }
           arg = mknode(1,prev_weight_vector_obj);
           Pdp_set_weight(arg,&tmp);
   
           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 f4,struct order_spec *ord,LIST *rp)
 {  {
         VL tv,fv,vv,vc;          VL tv,fv,vv,vc,av;
         NODE fd,fd0,r,r0,t,x,s,xx;          NODE fd,fd0,r,r0,t,x,s,xx,alist;
         int e,max,nvar;          int e,max,nvar,i;
         NDV b;          NDV b;
         int ishomo;          int ishomo,nalg;
           Alg alpha,dp;
           P p;
           LIST f1,f2;
           Obj obj;
           NumberField nf;
           struct order_spec *ord1;
   
         if ( !m && Demand ) nd_demand = 1;          if ( !m && Demand ) nd_demand = 1;
         else nd_demand = 0;          else nd_demand = 0;
Line 2234  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
Line 2365  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
                 default:                  default:
                         break;                          break;
         }          }
           nd_nalg = 0;
           av = 0;
           if ( !m ) {
                   get_algtree((Obj)f,&av);
                   for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ );
                   nd_ntrans = nvar;
                   nd_nalg = nalg;
                   /* #i -> t#i */
                   if ( nalg ) {
                           preprocess_algcoef(vv,av,ord,f,&ord1,&f1,&alist);
                           ord = ord1;
                           f = f1;
                   }
                   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 = 0; t; t = NEXT(t) )
                 for ( tv = vv; tv; tv = NEXT(tv) ) {                  for ( tv = vv; tv; tv = NEXT(tv) ) {
Line 2260  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
Line 2406  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
                 BDY(r) = ndvtop(m,CO,vv,BDY(t));                  BDY(r) = ndvtop(m,CO,vv,BDY(t));
         }          }
         if ( r0 ) NEXT(r) = 0;          if ( r0 ) NEXT(r) = 0;
           if ( nalg )
                   r0 = postprocess_algcoef(av,alist,r0);
         MKLIST(*rp,r0);          MKLIST(*rp,r0);
 #if 0  #if 0
         fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc);          fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc);
Line 2268  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
Line 2416  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
   
 void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp)  void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp)
 {  {
         struct order_spec *ord1;          VL tv,fv,vv,vc,av;
         VL tv,fv,vv,vc;          NODE fd,fd0,in0,in,r,r0,t,s,cand,alist;
         NODE fd,fd0,in0,in,r,r0,t,s,cand;  
         int m,nocheck,nvar,mindex,e,max;          int m,nocheck,nvar,mindex,e,max;
         NDV c;          NDV c;
         NMV a;          NMV a;
         P p;          P p;
         EPOS oepos;          EPOS oepos;
         int obpe,oadv,wmax,i,len,cbpe,ishomo;          int obpe,oadv,wmax,i,len,cbpe,ishomo,nalg;
           Alg alpha,dp;
           P poly;
           LIST f1,f2;
           Obj obj;
           NumberField nf;
           struct order_spec *ord1;
   
         get_vars((Obj)f,&fv); pltovl(v,&vv);          get_vars((Obj)f,&fv); pltovl(v,&vv);
         for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ );          for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ );
Line 2288  void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru
Line 2441  void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru
                 default:                  default:
                         break;                          break;
         }          }
   
           get_algtree((Obj)f,&av);
           for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ );
           nd_ntrans = nvar;
           nd_nalg = nalg;
           /* #i -> t#i */
           if ( nalg ) {
                   preprocess_algcoef(vv,av,ord,f,&ord1,&f1,&alist);
                   ord = ord1;
                   f = f1;
           }
           nvar += nalg;
   
         nocheck = 0;          nocheck = 0;
         mindex = 0;          mindex = 0;
   
Line 2321  void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru
Line 2487  void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru
         if ( in0 ) NEXT(in) = 0;          if ( in0 ) NEXT(in) = 0;
         if ( fd0 ) NEXT(fd) = 0;          if ( fd0 ) NEXT(fd) = 0;
         if ( !ishomo && homo ) {          if ( !ishomo && homo ) {
                 for ( t = in0, wmax = 0; t; t = NEXT(t) ) {                  for ( t = in0, wmax = max; t; t = NEXT(t) ) {
                         c = (NDV)BDY(t); len = LEN(c);                          c = (NDV)BDY(t); len = LEN(c);
                         for ( a = BDY(c), i = 0; i < len; i++, NMV_ADV(a) )                          for ( a = BDY(c), i = 0; i < len; i++, NMV_ADV(a) )
                                 wmax = MAX(TD(DL(a)),wmax);                                  wmax = MAX(TD(DL(a)),wmax);
Line 2377  void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru
Line 2543  void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru
         /* dp->p */          /* dp->p */
         nd_bpe = cbpe;          nd_bpe = cbpe;
         nd_setup_parameters(nd_nvar,0);          nd_setup_parameters(nd_nvar,0);
         for ( r = cand; r; r = NEXT(r) ) BDY(r) = (pointer)ndvtop(0,CO,vv,BDY(r));          for ( r = cand; r; r = NEXT(r) )
                   BDY(r) = (pointer)ndvtop(0,CO,vv,BDY(r));
           if ( nalg )
                   cand = postprocess_algcoef(av,alist,cand);
         MKLIST(*rp,cand);          MKLIST(*rp,cand);
 }  }
   
Line 3246  ND nd_quo(int mod,PGeoBucket bucket,NDV d)
Line 3415  ND nd_quo(int mod,PGeoBucket bucket,NDV d)
         ND p,t,r;          ND p,t,r;
         N tnm;          N tnm;
   
         if ( !p ) return 0;          if ( bucket->m < 0 ) return 0;
         else {          else {
                 nv = NV(d);                  nv = NV(d);
                 mq0 = 0;                  mq0 = 0;
Line 5126  UINT *nd_det_compute_bound(NDV **dm,int n,int j)
Line 5295  UINT *nd_det_compute_bound(NDV **dm,int n,int j)
   
 DL nd_separate_d(UINT *d,UINT *trans)  DL nd_separate_d(UINT *d,UINT *trans)
 {  {
         int n,ntrans,td,i,e;          int n,td,i,e,j;
         DL a;          DL a;
   
         n = nd_nvar; ntrans = n-nd_nalg;  
         ndl_zero(trans);          ndl_zero(trans);
         td = 0;          td = 0;
         for ( i = 0; i < ntrans; i++ ) {          for ( i = 0; i < nd_ntrans; i++ ) {
                 e = GET_EXP(d,i);                  e = GET_EXP(d,i);
                 PUT_EXP(trans,i,e);                  PUT_EXP(trans,i,e);
                 td += MUL_WEIGHT(e,i);                  td += MUL_WEIGHT(e,i);
         }          }
           if ( nd_ntrans+nd_nalg < nd_nvar ) {
                   /* homogenized */
                   i = nd_nvar-1;
                   e = GET_EXP(d,i);
                   PUT_EXP(trans,i,e);
                   td += MUL_WEIGHT(e,i);
           }
         TD(trans) = td;          TD(trans) = td;
         if ( nd_blockmask) ndl_weight_mask(trans);          if ( nd_blockmask) ndl_weight_mask(trans);
         NEWDL(a,nd_nalg);          NEWDL(a,nd_nalg);
         td = 0;          td = 0;
         for ( ; i < n; i++ ) {          for ( i = 0; i < nd_nalg; i++ ) {
                 e = GET_EXP(d,i);                  j = nd_ntrans+i;
                 a->d[i-ntrans] = e;                  e = GET_EXP(d,j);
                   a->d[i] = e;
                 td += e;                  td += e;
         }          }
         a->td = td;          a->td = td;
         return a;          return a;
 }  }
   
 NumberField get_numberfield();  
   
 int nd_monic(int mod,ND *p)  int nd_monic(int mod,ND *p)
 {  {
         UINT *trans,*t;          UINT *trans,*t;
Line 5173  int nd_monic(int mod,ND *p)
Line 5347  int nd_monic(int mod,ND *p)
         if ( !(nf = get_numberfield()) )          if ( !(nf = get_numberfield()) )
                 error("nd_monic : current_numberfield is not set");                  error("nd_monic : current_numberfield is not set");
   
         n = nd_nvar; ntrans = n-nd_nalg;  
         /* Q coef -> DAlg coef */          /* Q coef -> DAlg coef */
         NEWNM(ma0); ma = ma0;          NEWNM(ma0); ma = ma0;
         m = BDY(*p);          m = BDY(*p);
Line 5227  int nd_monic(int mod,ND *p)
Line 5400  int nd_monic(int mod,ND *p)
                         dl = mp->dl;                          dl = mp->dl;
                         td = TD(DL(m));                          td = TD(DL(m));
                         ndl_copy(DL(m),DL(mr));                          ndl_copy(DL(m),DL(mr));
                         for ( i = ntrans; i < n; i++ ) {                          for ( i = 0; i < nd_nalg; i++ ) {
                                 e = dl->d[i-ntrans];                                  e = dl->d[i];
                                 PUT_EXP(DL(mr),i,e);                                  PUT_EXP(DL(mr),i+nd_ntrans,e);
                                 td += MUL_WEIGHT(e,i);                                  td += MUL_WEIGHT(e,i+nd_ntrans);
                         }                          }
                         TD(DL(mr)) = td;                          TD(DL(mr)) = td;
                         if ( nd_blockmask) ndl_weight_mask(DL(mr));                          if ( nd_blockmask) ndl_weight_mask(DL(mr));
Line 5244  int nd_monic(int mod,ND *p)
Line 5417  int nd_monic(int mod,ND *p)
         nd_free(*p);          nd_free(*p);
         *p = r;          *p = r;
         return 1;          return 1;
 }  
   
 void nd_set_nalg(int nalg)  
 {  
         nd_nalg = nalg;  
 }  }

Legend:
Removed from v.1.118  
changed lines
  Added in v.1.124

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