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

version 1.117, 2004/12/03 08:57:30 version 1.124, 2005/02/09 07:58:43
Line 1 
Line 1 
 /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.116 2004/12/01 12:36:17 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);
 ND nd_pseudo_monic(int m,ND p);  int nd_monic(int m,ND *p);
   
 void nd_free_private_storage()  void nd_free_private_storage()
 {  {
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 1621  again:
Line 1631  again:
                         if ( checkonly ) return 0;                          if ( checkonly ) return 0;
                         if ( DP_Print ) { printf("+"); fflush(stdout); }                          if ( DP_Print ) { printf("+"); fflush(stdout); }
                         nd_removecont(m,nf);                          nd_removecont(m,nf);
                         if ( nd_nalg ) {                          if ( !m && nd_nalg ) {
                                 nf1 = nd_pseudo_monic(m,nf); nd_free(nf);                                  nd_monic(0,&nf);
                                 stat = nd_nf(m,nf1,nd_ps,1,0,&nf);                                  nd_removecont(m,nf);
                                 if ( stat ) {  
                                         NEXT(l) = d; d = l;  
                                         d = nd_reconstruct(0,d);  
                                         goto again;  
                                 }  
                         }                          }
                         nfv = ndtondv(m,nf); nd_free(nf);                          nfv = ndtondv(m,nf); nd_free(nf);
                         nh = ndv_newps(m,nfv,0);                          nh = ndv_newps(m,nfv,0);
Line 1649  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 1662  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 1675  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 1694  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;
   struct oEGT eg_le;
   
 NODE nd_gb_trace(int m,int ishomo)  NODE nd_gb_trace(int m,int ishomo)
 {  {
         int i,nh,sugar,stat;          int i,nh,sugar,stat;
Line 1706  NODE nd_gb_trace(int m,int ishomo)
Line 1717  NODE nd_gb_trace(int m,int ishomo)
         NDV nfv,nfqv;          NDV nfv,nfqv;
         Q q,den,num;          Q q,den,num;
         union oNDC dn;          union oNDC dn;
           struct oEGT eg_monic,egm0,egm1;
   
           init_eg(&eg_monic);
           init_eg(&eg_invdalg);
           init_eg(&eg_le);
         g = 0; d = 0;          g = 0; d = 0;
         for ( i = 0; i < nd_psn; i++ ) {          for ( i = 0; i < nd_psn; i++ ) {
                 d = update_pairs(d,g,i);                  d = update_pairs(d,g,i);
Line 1717  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 1754  again:
Line 1776  again:
                                 if ( !rem(NM(HCQ(nfq)),m) ) return 0;                                  if ( !rem(NM(HCQ(nfq)),m) ) return 0;
   
                                 if ( DP_Print ) { printf("+"); fflush(stdout); }                                  if ( DP_Print ) { printf("+"); fflush(stdout); }
                                 nd_removecont(m,nf); nfv = ndtondv(m,nf); nd_free(nf);                                  if ( nd_nalg ) {
                                 nd_removecont(0,nfq); nfqv = ndtondv(0,nfq); nd_free(nfq);                                          /* m|DN(HC(nf)^(-1)) => failure */
                                           get_eg(&egm0);
                                           if ( !nd_monic(m,&nfq) ) return 0;
                                           get_eg(&egm1); add_eg(&eg_monic,&egm0,&egm1);
                                           nd_removecont(0,nfq); nfqv = ndtondv(0,nfq); nd_free(nfq);
                                           nfv = ndv_dup(0,nfqv); ndv_mod(m,nfv); nd_free(nf);
                                   } else {
                                           nd_removecont(0,nfq); nfqv = ndtondv(0,nfq); nd_free(nfq);
                                           nd_removecont(m,nf); nfv = ndtondv(m,nf); nd_free(nf);
                                   }
                                 nh = ndv_newps(0,nfv,nfqv);                                  nh = ndv_newps(0,nfv,nfqv);
                                 d = update_pairs(d,g,nh);                                  d = update_pairs(d,g,nh);
                                 g = update_base(g,nh);                                  g = update_base(g,nh);
Line 1773  again:
Line 1804  again:
         else          else
                 for ( t = g; t; t = NEXT(t) )                  for ( t = g; t; t = NEXT(t) )
                         BDY(t) = (pointer)nd_ps_trace[(int)BDY(t)];                          BDY(t) = (pointer)nd_ps_trace[(int)BDY(t)];
           if ( nd_nalg ) {
                   print_eg("monic",&eg_monic);
                   print_eg("invdalg",&eg_invdalg);
                   print_eg("le",&eg_le);
           }
         return g;          return g;
 }  }
   
Line 2194  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 2218  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 2244  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 2252  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 2272  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 2305  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 2361  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 3230  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 5110  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;
 }  }
   
 ND nd_pseudo_monic(int mod,ND p)  int nd_monic(int mod,ND *p)
 {  {
         UINT *trans,*t;          UINT *trans,*t;
         DL alg;          DL alg;
         MP mp0,mp;          MP mp0,mp;
         NM m,m0,m1;          NM m,m0,m1,ma0,ma,mb,mr0,mr;
           ND r;
         DL dl;          DL dl;
         DP nm;          DP nm;
         NDV ndv;          NDV ndv;
         DAlg lc,inv;          DAlg inv,cd;
         ND s,c;          ND s,c;
         int n,ntrans,i,e,td;          Q l,mul;
           N ln;
           int n,ntrans,i,e,td,is_lc,len;
           NumberField nf;
           struct oEGT eg0,eg1;
   
         n = nd_nvar; ntrans = n-nd_nalg;          if ( !(nf = get_numberfield()) )
         NEWNM(m0);                  error("nd_monic : current_numberfield is not set");
         NEWNM(m1);  
         alg = nd_separate_d(HDL(p),DL(m0));          /* Q coef -> DAlg coef */
         mp0 = 0; NEXTMP(mp0,mp); mp->c = (P)HCQ(p); mp->dl = alg;          NEWNM(ma0); ma = ma0;
         if ( !mp->dl->td )          m = BDY(*p);
                 return p;          is_lc = 1;
         for ( m = NEXT(BDY(p)); m; m = NEXT(m) ) {          while ( 1 ) {
                 alg = nd_separate_d(DL(m),DL(m1));                  NEWMP(mp0); mp = mp0;
                 if ( !ndl_equal(DL(m0),DL(m1)) )                  mp->c = (P)CQ(m);
                   mp->dl = nd_separate_d(DL(m),DL(ma));
                   NEWNM(mb);
                   for ( m = NEXT(m); m; m = NEXT(m) ) {
                           alg = nd_separate_d(DL(m),DL(mb));
                           if ( !ndl_equal(DL(ma),DL(mb)) )
                                   break;
                           NEXTMP(mp0,mp); mp->c = (P)CQ(m); mp->dl = alg;
                   }
                   NEXT(mp) = 0;
                   MKDP(nd_nalg,mp0,nm);
                   MKDAlg(nm,ONE,cd);
                   if ( is_lc == 1 ) {
                           /* if the lc is a rational number, we have nothing to do */
                           if ( !mp0->dl->td )
                                   return 1;
   
                           get_eg(&eg0);
                           invdalg(cd,&inv);
                           get_eg(&eg1); add_eg(&eg_invdalg,&eg0,&eg1);
                           /* check the validity of inv */
                           if ( mod && !rem(NM(inv->dn),mod) )
                                   return 0;
                           CA(ma) = nf->one;
                           is_lc = 0;
                           ln = ONEN;
                   } else {
                           muldalg(cd,inv,&CA(ma));
                           lcmn(ln,NM(CA(ma)->dn),&ln);
                   }
                   if ( m ) {
                           NEXT(ma) = mb; ma = mb;
                   } else {
                           NEXT(ma) = 0;
                         break;                          break;
                 NEXTMP(mp0,mp); mp->c = (P)CQ(m); mp->dl = alg;                  }
         }          }
         NEXT(mp) = 0;          /* l = lcm(denoms) */
         MKDP(nd_nalg,mp0,nm);          NTOQ(ln,1,l);
         MKDAlg(nm,ONE,lc);          for ( mr0 = 0, m = ma0; m; m = NEXT(m) ) {
         invdalg(lc,&inv);                  divq(l,CA(m)->dn,&mul);
         ndv = ndtondv(0,p);                  for ( mp = BDY(CA(m)->nm); mp; mp = NEXT(mp) ) {
         for ( s = 0, mp = BDY(inv->nm); mp; mp = NEXT(mp) ) {                          NEXTNM(mr0,mr);
                 CQ(m0) = (Q)mp->c;                          mulq((Q)mp->c,mul,&CQ(mr));
                 dl = mp->dl;                          dl = mp->dl;
                 for ( td = 0, i = ntrans; i < n; i++ ) {                          td = TD(DL(m));
                         e = dl->d[i-ntrans];                          ndl_copy(DL(m),DL(mr));
                         ndl_zero(DL(m0));                          for ( i = 0; i < nd_nalg; i++ ) {
                         PUT_EXP(DL(m0),i,e);                                  e = dl->d[i];
                         td += MUL_WEIGHT(e,i);                                  PUT_EXP(DL(mr),i+nd_ntrans,e);
                                   td += MUL_WEIGHT(e,i+nd_ntrans);
                           }
                           TD(DL(mr)) = td;
                           if ( nd_blockmask) ndl_weight_mask(DL(mr));
                 }                  }
                 TD(DL(m0)) = td;  
                 if ( nd_blockmask) ndl_weight_mask(trans);  
                 s = nd_add(0,s,ndv_mul_nm(0,m0,ndv));  
         }          }
         ndv_free(ndv);          NEXT(mr) = 0;
         return s;          for ( len = 0, mr = mr0; mr; mr = NEXT(mr), len++ );
           MKND(NV(*p),mr0,len,r);
           /* XXX */
           SG(r) = SG(*p);
           nd_free(*p);
           *p = r;
           return 1;
 }  }

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

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