[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.127 and 1.130

version 1.127, 2005/08/03 05:01:01 version 1.130, 2006/05/30 07:35:31
Line 1 
Line 1 
 /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.126 2005/02/09 14:30:47 noro Exp $ */  /* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.129 2006/04/17 04:35:20 noro Exp $ */
   
 #include "nd.h"  #include "nd.h"
   
Line 47  NumberField get_numberfield();
Line 47  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);
   NDV plain_vect_to_ndv_q(Q *mat,int col,UINT *s0vect);
   
 void nd_free_private_storage()  void nd_free_private_storage()
 {  {
Line 1284  int ndv_check_candidate(NODE input,int obpe,int oadv,E
Line 1285  int ndv_check_candidate(NODE input,int obpe,int oadv,E
         NODE t,s;          NODE t,s;
         union oNDC dn;          union oNDC dn;
   
         ndv_setup(0,0,cand);          ndv_setup(0,0,cand,0);
         n = length(cand);          n = length(cand);
   
         /* membercheck : list is a subset of Id(cand) ? */          /* membercheck : list is a subset of Id(cand) ? */
Line 1706  int do_diagonalize_trace(int sugar,int m)
Line 1707  int do_diagonalize_trace(int sugar,int m)
   
 static struct oEGT eg_invdalg;  static struct oEGT eg_invdalg;
 struct oEGT eg_le;  struct oEGT eg_le;
   int diag_period = 6;
   
 NODE nd_gb_trace(int m,int ishomo)  NODE nd_gb_trace(int m,int ishomo)
 {  {
Line 1718  NODE nd_gb_trace(int m,int ishomo)
Line 1720  NODE nd_gb_trace(int m,int ishomo)
         Q q,den,num;          Q q,den,num;
         union oNDC dn;          union oNDC dn;
         struct oEGT eg_monic,egm0,egm1;          struct oEGT eg_monic,egm0,egm1;
           int diag_count = 0;
   
         init_eg(&eg_monic);          init_eg(&eg_monic);
         init_eg(&eg_invdalg);          init_eg(&eg_invdalg);
Line 1732  NODE nd_gb_trace(int m,int ishomo)
Line 1735  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 1
                         if ( ishomo ) {                          if ( ishomo ) {
                                 stat = do_diagonalize_trace(sugar,m);                                  stat = do_diagonalize_trace(sugar,m);
                                   diag_count = 0;
                                 if ( !stat ) {                                  if ( !stat ) {
                                         NEXT(l) = d; d = l;                                          NEXT(l) = d; d = l;
                                         d = nd_reconstruct(1,d);                                          d = nd_reconstruct(1,d);
                                         goto again;                                          goto again;
                                 }                                  }
                         }                          }
   #endif
                         sugar = SG(l);                          sugar = SG(l);
                         if ( DP_Print ) fprintf(asir_out,"%d",sugar);                          if ( DP_Print ) fprintf(asir_out,"%d",sugar);
                 }                  }
Line 1788  again:
Line 1794  again:
                                         nd_removecont(m,nf); nfv = ndtondv(m,nf); nd_free(nf);                                          nd_removecont(m,nf); nfv = ndtondv(m,nf); nd_free(nf);
                                 }                                  }
                                 nh = ndv_newps(0,nfv,nfqv);                                  nh = ndv_newps(0,nfv,nfqv);
                                   if ( ishomo && ++diag_count == diag_period ) {
                                           diag_count = 0;
                                           stat = do_diagonalize_trace(sugar,m);
                                           if ( !stat ) {
                                                   NEXT(l) = d; d = l;
                                                   d = nd_reconstruct(1,d);
                                                   goto again;
                                           }
                                   }
                                 d = update_pairs(d,g,nh);                                  d = update_pairs(d,g,nh);
                                 g = update_base(g,nh);                                  g = update_base(g,nh);
                         } else {                          } else {
Line 1839  NODE ndv_reduceall(int m,NODE f)
Line 1854  NODE ndv_reduceall(int m,NODE f)
                 (int (*)(const void *,const void *))ndv_compare);                  (int (*)(const void *,const void *))ndv_compare);
         for ( t = f, i = 0; t; i++, t = NEXT(t) ) BDY(t) = (pointer)w[i];          for ( t = f, i = 0; t; i++, t = NEXT(t) ) BDY(t) = (pointer)w[i];
 #endif  #endif
         ndv_setup(m,0,f);          ndv_setup(m,0,f,0);
         for ( i = 0; i < n; ) {          for ( i = 0; i < n; ) {
                 g = ndvtond(m,nd_ps[i]);                  g = ndvtond(m,nd_ps[i]);
                 g = nd_separate_head(g,&head);                  g = nd_separate_head(g,&head);
Line 2179  int ndv_newps(int m,NDV a,NDV aq)
Line 2194  int ndv_newps(int m,NDV a,NDV aq)
         return nd_psn++;          return nd_psn++;
 }  }
   
 void ndv_setup(int mod,int trace,NODE f)  void ndv_setup(int mod,int trace,NODE f,int dont_sort)
 {  {
         int i,j,td,len,max;          int i,j,td,len,max;
         NODE s,s0,f0;          NODE s,s0,f0;
Line 2193  void ndv_setup(int mod,int trace,NODE f)
Line 2208  void ndv_setup(int mod,int trace,NODE f)
         for ( nd_psn = 0, s = f; s; s = NEXT(s) ) if ( BDY(s) ) nd_psn++;          for ( nd_psn = 0, s = f; s; s = NEXT(s) ) if ( BDY(s) ) nd_psn++;
         w = (NDV *)ALLOCA(nd_psn*sizeof(NDV));          w = (NDV *)ALLOCA(nd_psn*sizeof(NDV));
         for ( i = 0, s = f; s; s = NEXT(s) ) if ( BDY(s) ) w[i++] = BDY(s);          for ( i = 0, s = f; s; s = NEXT(s) ) if ( BDY(s) ) w[i++] = BDY(s);
         qsort(w,nd_psn,sizeof(NDV),          if ( !dont_sort )
                 (int (*)(const void *,const void *))ndv_compare);                  qsort(w,nd_psn,sizeof(NDV),
                           (int (*)(const void *,const void *))ndv_compare);
         nd_pslen = 2*nd_psn;          nd_pslen = 2*nd_psn;
         nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV));          nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV));
         nd_ps_trace = (NDV *)MALLOC(nd_pslen*sizeof(NDV));          nd_ps_trace = (NDV *)MALLOC(nd_pslen*sizeof(NDV));
Line 2396  void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe
Line 2412  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);          ndv_setup(m,0,fd0,0);
         x = f4?nd_f4(m):nd_gb(m,ishomo,0);          x = f4?nd_f4(m):nd_gb(m,ishomo,0);
         nd_demand = 0;          nd_demand = 0;
         x = ndv_reducebase(x);          x = ndv_reducebase(x);
Line 2469  void nd_gr_postproc(LIST f,LIST v,int m,struct order_s
Line 2485  void nd_gr_postproc(LIST f,LIST v,int m,struct order_s
                 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);          ndv_setup(m,0,fd0,0);
         for ( x = 0, i = 0; i < nd_psn; i++ )          for ( x = 0, i = 0; i < nd_psn; i++ )
                 x = update_base(x,i);                  x = update_base(x,i);
         if ( do_check ) {          if ( do_check ) {
Line 2581  void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru
Line 2597  void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru
         while ( 1 ) {          while ( 1 ) {
                 if ( Demand )                  if ( Demand )
                         nd_demand = 1;                          nd_demand = 1;
                 ndv_setup(m,1,fd0);                  ndv_setup(m,1,fd0,0);
                 cand = nd_gb_trace(m,ishomo || homo);                  cand = nd_gb_trace(m,ishomo || homo);
                 if ( !cand ) {                  if ( !cand ) {
                         /* failure */                          /* failure */
Line 4032  void nd_nf_p(P f,LIST g,LIST v,int m,struct order_spec
Line 4048  void nd_nf_p(P f,LIST g,LIST v,int m,struct order_spec
         if ( m ) ndv_mod(m,(NDV)BDY(in));          if ( m ) ndv_mod(m,(NDV)BDY(in));
         NEXT(in) = 0;          NEXT(in) = 0;
   
         ndv_setup(m,0,in0);          /* dont sort */
           ndv_setup(m,0,in0,1);
         nd_psn--;          nd_psn--;
         nd_scale=2;          nd_scale=2;
         while ( 1 ) {          while ( 1 ) {
Line 4080  int nd_to_vect_q(UINT *s0,int n,ND d,Q *r)
Line 4097  int nd_to_vect_q(UINT *s0,int n,ND d,Q *r)
         return i;          return i;
 }  }
   
   Q *nm_ind_pair_to_vect(int mod,UINT *s0,int n,NM_ind_pair pair)
   {
           NM m;
           NMV mr;
           UINT *d,*t,*s;
           NDV p;
           int i,j,len;
           Q *r;
   
           m = pair->mul;
           d = DL(m);
           p = nd_ps[pair->index];
           len = LEN(p);
           r = (Q *)CALLOC(n,sizeof(Q));
           t = (UINT *)ALLOCA(nd_wpd*sizeof(UINT));
           for ( i = j = 0, s = s0, mr = BDY(p); j < len; j++, NMV_ADV(mr) ) {
                   ndl_add(d,DL(mr),t);
                   for ( ; !ndl_equal(t,s); s += nd_wpd, i++ );
                   r[i] = CQ(mr);
           }
           return r;
   }
   
 IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0,int n,NM_ind_pair pair)  IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0,int n,NM_ind_pair pair)
 {  {
         NM m;          NM m;
Line 4325  NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea
Line 4365  NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea
         }          }
 }  }
   
   /* for preprocessed vector */
   
 NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead,UINT *s0vect)  NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead,UINT *s0vect)
 {  {
         int j,k,len;          int j,k,len;
Line 4355  NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead
Line 4397  NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead
         }          }
 }  }
   
   /* for plain vector */
   
   NDV plain_vect_to_ndv_q(Q *vect,int col,UINT *s0vect)
   {
           int j,k,len;
           UINT *p;
           Q c;
           NDV r;
           NMV mr0,mr;
   
           for ( j = 0, len = 0; j < col; j++ ) if ( vect[j] ) len++;
           if ( !len ) return 0;
           else {
                   mr0 = (NMV)GC_malloc(nmv_adv*len);
   #if 0
                   ndv_alloc += nmv_adv*len;
   #endif
                   mr = mr0;
                   p = s0vect;
                   for ( j = k = 0; j < col; j++, p += nd_wpd, k++ )
                           if ( c = vect[k] ) {
                                   if ( DN(c) )
                                           error("afo");
                                   ndl_copy(p,DL(mr)); CQ(mr) = c; NMV_ADV(mr);
                           }
                   MKNDV(nd_nvar,mr0,len,r);
                   return r;
           }
   }
   
 int nd_sp_f4(int m,ND_pairs l,PGeoBucket bucket)  int nd_sp_f4(int m,ND_pairs l,PGeoBucket bucket)
 {  {
         ND_pairs t;          ND_pairs t;
Line 4474  NODE nd_f4(int m)
Line 4546  NODE nd_f4(int m)
                 for ( r = nflist; r; r = NEXT(r) ) {                  for ( r = nflist; r; r = NEXT(r) ) {
                         nf = (NDV)BDY(r);                          nf = (NDV)BDY(r);
                         ndv_removecont(m,nf);                          ndv_removecont(m,nf);
                           if ( !m && nd_nalg ) {
                                   ND nf1;
   
                                   nf1 = ndvtond(m,nf);
                                   nd_monic(0,&nf1);
                                   nd_removecont(m,nf1);
                                   nf = ndtondv(m,nf1);
                           }
                         nh = ndv_newps(m,nf,0);                          nh = ndv_newps(m,nf,0);
                         d = update_pairs(d,g,nh);                          d = update_pairs(d,g,nh);
                         g = update_base(g,nh);                          g = update_base(g,nh);
Line 4588  NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s
Line 4668  NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s
         return r0;          return r0;
 }  }
   
   #if 0
 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vect,int col,  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vect,int col,
         NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred)          NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred)
 {  {
Line 4655  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
Line 4736  NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec
         }          }
         return r0;          return r0;
 }  }
   #else
   void printm(Q **mat,int row,int col)
   {
           int i,j;
           printf("[");
           for ( i = 0; i < row; i++ ) {
                   for ( j = 0; j < col; j++ ) {
                           printexpr(CO,mat[i][j]); printf(" ");
                   }
                   printf("]\n");
           }
   }
   
   NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vect,int col,
           NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred)
   {
           int row,a;
           int i,j,rank;
           NODE r0,r;
           ND_pairs sp;
           ND spol;
           Q **mat;
           int *colstat;
           int *sugar;
   
           row = nsp+nred;
           /* make the matrix */
           mat = (Q **)ALLOCA(row*sizeof(Q *));
           sugar = (int *)ALLOCA(row*sizeof(int));
           for ( row = a = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) {
                   nd_sp(0,0,sp,&spol);
                   if ( !spol ) continue;
                   mat[row] = (Q *)MALLOC(col*sizeof(Q));
                   nd_to_vect_q(s0vect,col,spol,mat[row]);
                   sugar[row] = SG(spol);
                   row++;
           }
           for ( i = 0; i < nred; i++, row++ ) {
                   mat[row] = nm_ind_pair_to_vect(0,s0vect,col,rvect[i]);
                   sugar[row] = rvect[i]->sugar;
           }
           /* elimination */
           colstat = (int *)ALLOCA(col*sizeof(int));
           rank = nd_gauss_elim_q(mat,sugar,row,col,colstat);
           r0 = 0;
           for ( i = 0; i < rank; i++ ) {
                   for ( j = 0; j < col; j++ ) if ( mat[i][j] ) break;
                   if ( j == col ) error("nd_f4_red_q_main : cannot happen");
                   if ( rhead[j] ) continue;
                   NEXTNODE(r0,r); BDY(r) =
                           (pointer)plain_vect_to_ndv_q(mat[i],col,s0vect);
                   SG((NDV)BDY(r)) = sugar[i];
           }
           if ( r0 ) NEXT(r) = 0;
           printf("\n");
           return r0;
   }
   #endif
   
 FILE *nd_write,*nd_read;  FILE *nd_write,*nd_read;
   

Legend:
Removed from v.1.127  
changed lines
  Added in v.1.130

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