=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/builtin/gr.c,v retrieving revision 1.19 retrieving revision 1.26 diff -u -p -r1.19 -r1.26 --- OpenXM_contrib2/asir2000/builtin/gr.c 2001/06/07 04:54:38 1.19 +++ OpenXM_contrib2/asir2000/builtin/gr.c 2001/09/11 01:30:31 1.26 @@ -45,7 +45,7 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/builtin/gr.c,v 1.18 2001/01/12 09:03:33 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/builtin/gr.c,v 1.25 2001/09/10 05:55:14 noro Exp $ */ #include "ca.h" #include "parse.h" @@ -106,7 +106,7 @@ DP_pairs criterion_B(DP_pairs,int); DP_pairs newpairs(NODE,int); DP_pairs updpairs(DP_pairs,NODE,int); void _dp_nf(NODE,DP,DP *,int,DP *); -void _dp_nf_ptozp(NODE,DP,DP *,int,int,DP *); +void _dp_nf_z(NODE,DP,DP *,int,int,DP *); NODE gb_mod(NODE,int); NODE gbd(NODE,int,NODE,NODE); NODE gb(NODE,int,NODE); @@ -135,7 +135,7 @@ void pltovl(LIST,VL *); void printdl(DL); int DPPlength(DP_pairs); void dp_gr_mod_main(LIST,LIST,Num,int,struct order_spec *,LIST *); -void dp_gr_main(LIST,LIST,Num,int,struct order_spec *,LIST *); +void dp_gr_main(LIST,LIST,Num,int,int,struct order_spec *,LIST *); void dp_f4_main(LIST,LIST,struct order_spec *,LIST *); void dp_f4_mod_main(LIST,LIST,int,struct order_spec *,LIST *); double get_rtime(); @@ -180,6 +180,7 @@ static int PtozpRA = 0; int doing_f4; NODE TraceList; +NODE AllTraceList; int eqdl(nv,dl1,dl2) int nv; @@ -216,6 +217,54 @@ int *b; } } +/* create compressed poly */ + +void _dpmod_to_vect_compress(f,at,b) +DP f; +DL *at; +CDP *b; +{ + int i,j,nv,len; + MP m; + CDP r; + + nv = f->nv; + for ( m = BDY(f), len = 0; m; m = NEXT(m), len++ ); + r = (CDP)MALLOC(sizeof(struct oCDP)); + r->len = len; + r->body = (CM)MALLOC(sizeof(struct oCM)*len); + + for ( m = BDY(f), i = j = 0; m; m = NEXT(m), j++ ) { + for ( ; !eqdl(nv,m->dl,at[i]); i++ ); + r->body[j].index = i; + r->body[j].c = ITOS(m->c); + } + *b = r; +} + +/* dense vector -> CDP */ +void compress_vect(a,n,rp) +int *a; +int n; +CDP *rp; +{ + int i,j,nz; + CDP r; + + for ( i = 0, nz = 0; i < n; i++ ) + if ( a[i] ) nz++; + *rp = r = (CDP)MALLOC(sizeof(struct oCDP)); + r->len = nz; + r->body = (CM)MALLOC(sizeof(struct oCM)*nz); + for ( i = 0, j = 0; i < n; i++ ) { + if ( a[i] ) { + r->body[j].index = i; + r->body[j].c = ITOS(a[i]); + j++; + } + } +} + void dp_to_vect(f,at,b) DP f; DL *at; @@ -257,19 +306,22 @@ NODE f; printf("\n"); } -void dp_gr_main(f,v,homo,modular,ord,rp) +void dp_gr_main(f,v,homo,modular,field,ord,rp) LIST f,v; Num homo; -int modular; +int modular,field; struct order_spec *ord; LIST *rp; { int i,mindex,m,nochk; struct order_spec ord1; + Q q; VL fv,vv,vc; NODE fd,fd0,fi,fi0,r,r0,t,subst,x,s,xx; + NODE ind,ind0; + LIST trace,gbindex; - mindex = 0; nochk = 0; dp_fcoeffs = 0; + mindex = 0; nochk = 0; dp_fcoeffs = field; get_vars((Obj)f,&fv); pltovl(v,&vv); vlminus(fv,vv,&vc); NVars = length((NODE)vv); PCoeffs = vc ? 1 : 0; VC = vc; CNVars = homo ? NVars+1 : NVars; @@ -333,12 +385,27 @@ LIST *rp; pss[i] = 0; psh[i] = 0; psc[i] = 0; ps[i] = 0; } } - for ( r0 = 0; x; x = NEXT(x) ) { + for ( r0 = 0, ind0 = 0; x; x = NEXT(x) ) { NEXTNODE(r0,r); dp_load((int)BDY(x),&ps[(int)BDY(x)]); dtop(CO,vv,ps[(int)BDY(x)],(P *)&BDY(r)); + NEXTNODE(ind0,ind); + STOQ((int)BDY(x),q); BDY(ind) = q; } if ( r0 ) NEXT(r) = 0; + if ( ind0 ) NEXT(ind) = 0; MKLIST(*rp,r0); + MKLIST(gbindex,ind0); + + if ( GenTrace && OXCheck < 0 ) { + + x = AllTraceList; + for ( r = 0; x; x = NEXT(x) ) { + MKNODE(r0,BDY(x),r); r = r0; + } + MKLIST(trace,r); + r0 = mknode(3,*rp,gbindex,trace); + MKLIST(*rp,r0); + } print_stat(); if ( ShowMag ) fprintf(asir_out,"\nMax_mag=%d\n",Max_mag); @@ -617,10 +684,12 @@ int m; MP mp,mp0; NODE blist,bt,nt; DL *ht,*at,*st; - int **spmat,**redmat; - int *colstat,*w; + int **spmat; + CDP *redmat; + int *colstat,*w,*w1; int rank,nred,nsp,nonzero,spcol; - int *indred,*isred,*ri; + int *indred,*isred; + CDP ri; struct oEGT tmp0,tmp1,tmp2,eg_split_symb,eg_split_elim1,eg_split_elim2; extern struct oEGT eg_symb,eg_elim1,eg_elim2; @@ -647,8 +716,28 @@ int m; s0 = symb_merge(s0,dp_dllist(sp),nv); } } - /* s0 : all the terms appeared in symbolic redunction */ + /* s0 : all the terms appeared in symbolic reduction */ +#if 0 for ( s = s0, nred = 0; s; s = NEXT(s) ) { + for ( j = psn-1; j >= 0; j-- ) + if ( _dl_redble(BDY(ps[j])->dl,BDY(s),nv) ) + break; + if ( j >= 0 ) { + dltod(BDY(s),nv,&tdp); + dp_subd(tdp,ps[j],&sd); + for ( k = 0, i = 0; k < nv; k++ ) + if ( BDY(sd)->dl->d[k] ) + i++; + fprintf(stderr,"%c ",i<=1 ? 'o' : 'x'); + _dp_mod(sd,m,0,&sdm); + mulmd_dup(m,sdm,ps[j],&f2); + MKNODE(bt,f2,blist); blist = bt; + s = symb_merge(s,dp_dllist(f2),nv); + nred++; + } + } +#else + for ( s = s0, nred = 0; s; s = NEXT(s) ) { for ( r = gall; r; r = NEXT(r) ) if ( _dl_redble(BDY(ps[(int)BDY(r)])->dl,BDY(s),nv) ) break; @@ -662,6 +751,8 @@ int m; nred++; } } +#endif + fprintf(stderr,"\n"); get_eg(&tmp1); add_eg(&eg_symb,&tmp0,&tmp1); init_eg(&eg_split_symb); add_eg(&eg_split_symb,&tmp0,&tmp1); @@ -687,9 +778,17 @@ int m; nsp = row-nred; /* reducer matrix */ - redmat = (int **)almat(nred,col); + /* indred : register the position of the head term */ +#if 0 + reduce_reducers_mod_compress(blist,nred,at,col,m,&redmat,&indred); + isred = (int *)MALLOC(col*sizeof(int)); + bzero(isred,col*sizeof(int)); + for ( i = 0; i < nred; i++ ) + isred[indred[i]] = 1; +#else + redmat = (CDP *)MALLOC(nred*sizeof(CDP)); for ( i = 0, r = blist; i < nred; r = NEXT(r), i++ ) - _dpmod_to_vect(BDY(r),at,redmat[i]); + _dpmod_to_vect_compress(BDY(r),at,&redmat[i]); /* XXX */ /* reduce_reducers_mod(redmat,nred,col,m); */ /* register the position of the head term */ @@ -699,10 +798,10 @@ int m; bzero(isred,col*sizeof(int)); for ( i = 0; i < nred; i++ ) { ri = redmat[i]; - for ( j = 0; j < col && !ri[j]; j++ ); - indred[i] = j; - isred[j] = 1; + indred[i] = ri->body[0].index; + isred[indred[i]] = 1; } +#endif spcol = col-nred; /* head terms not in ht */ @@ -711,22 +810,37 @@ int m; if ( !isred[j] ) st[k++] = at[j]; + get_eg(&tmp1); /* spoly matrix; stored in reduced form; terms in ht[] are omitted */ - spmat = almat(nsp,spcol); + spmat = (int **)MALLOC(nsp*sizeof(int *)); w = (int *)MALLOC(col*sizeof(int)); - for ( ; i < row; r = NEXT(r), i++ ) { + + /* skip reducers in blist */ + for ( i = 0, r = blist; i < nred; r = NEXT(r), i++ ); + for ( i = 0; r; r = NEXT(r) ) { bzero(w,col*sizeof(int)); _dpmod_to_vect(BDY(r),at,w); - reduce_sp_by_red_mod(w,redmat,indred,nred,col,m); - for ( j = 0, k = 0; j < col; j++ ) - if ( !isred[j] ) - spmat[i-nred][k++] = w[j]; + reduce_sp_by_red_mod_compress(w,redmat,indred,nred,col,m); + for ( j = 0; j < col; j++ ) + if ( w[j] ) + break; + if ( j < col ) { + w1 = (int *)MALLOC_ATOMIC(spcol*sizeof(int)); + for ( j = 0, k = 0; j < col; j++ ) + if ( !isred[j] ) + w1[k++] = w[j]; + spmat[i] = w1; + i++; + } } + /* update nsp */ + nsp = i; get_eg(&tmp0); add_eg(&eg_elim1,&tmp1,&tmp0); init_eg(&eg_split_elim1); add_eg(&eg_split_elim1,&tmp1,&tmp0); colstat = (int *)MALLOC_ATOMIC(spcol*sizeof(int)); + bzero(colstat,spcol*sizeof(int)); for ( i = 0, nonzero=0; i < nsp; i++ ) for ( j = 0; j < spcol; j++ ) if ( spmat[i][j] ) @@ -748,6 +862,10 @@ int m; print_eg("Elim2",&eg_split_elim2); fprintf(asir_out,"\n"); } + + if ( !rank ) + continue; + for ( j = 0, i = 0; j < spcol; j++ ) if ( colstat[j] ) { mp0 = 0; @@ -920,18 +1038,28 @@ int m; pss[i] = ps[i]->sugar; psc[i] = BDY(ps[i])->c; } - if ( GenTrace && (OXCheck >= 0) ) { + if ( GenTrace ) { Q q; STRING fname; LIST input; - NODE arg; + NODE arg,t,t1; Obj dmy; + + t = 0; + for ( i = psn-1; i >= 0; i-- ) { + MKNODE(t1,ps[i],t); + t = t1; + } + MKLIST(input,t); - STOQ(OXCheck,q); - MKSTR(fname,"register_input"); - MKLIST(input,f0); - arg = mknode(3,q,fname,input); - Pox_cmo_rpc(arg,&dmy); + if ( OXCheck >= 0 ) { + STOQ(OXCheck,q); + MKSTR(fname,"register_input"); + arg = mknode(3,q,fname,input); + Pox_cmo_rpc(arg,&dmy); + } else if ( OXCheck < 0 ) { + MKNODE(AllTraceList,input,0); + } } for ( s0 = 0, i = 0; i < psn; i++ ) { NEXTNODE(s0,s); BDY(s) = (pointer)i; @@ -959,6 +1087,8 @@ int m; else dp_ptozp(f,r); if ( GenTrace && TraceList ) { + /* adust the denominator according to the final + content reduction */ divsp(CO,BDY(f)->c,BDY(*r)->c,&d); mulp(CO,(P)ARG3(BDY((LIST)BDY(TraceList))),d,&t); ARG3(BDY((LIST)BDY(TraceList))) = t; @@ -1166,7 +1296,11 @@ NODE subst; _dp_mod(a,m,subst,&psm[psn]); if ( GenTrace ) { NODE tn,tr,tr1; - LIST trace; + LIST trace,trace1; + NODE arg; + Q q1,q2; + STRING fname; + Obj dmy; /* reverse the TraceList */ tn = TraceList; @@ -1175,16 +1309,17 @@ NODE subst; } MKLIST(trace,tr); if ( OXCheck >= 0 ) { - NODE arg; - Q q1,q2; - STRING fname; - Obj dmy; - STOQ(OXCheck,q1); MKSTR(fname,"check_trace"); STOQ(psn,q2); arg = mknode(5,q1,fname,a,q2,trace); Pox_cmo_rpc(arg,&dmy); + } else if ( OXCheck < 0 ) { + STOQ(psn,q1); + tn = mknode(2,q1,trace); + MKLIST(trace1,tn); + MKNODE(tr,trace1,AllTraceList); + AllTraceList = tr; } else dp_save(psn,(Obj)trace,"t"); TraceList = 0; @@ -1419,7 +1554,7 @@ NODE subst; if ( PCoeffs || dp_fcoeffs ) _dp_nf(gall,h,ps,!Top,&nf); else - _dp_nf_ptozp(gall,h,ps,!Top,DP_Multiple,&nf); + _dp_nf_z(gall,h,ps,!Top,DP_Multiple,&nf); if ( DP_Print ) fprintf(asir_out,"(%.3g)",get_rtime()-t_0); get_eg(&tnf1); add_eg(&eg_nf,&tnf0,&tnf1); @@ -1930,6 +2065,7 @@ LIST *list; STOQ(Reverse,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"Reverse"); MKNODE(n1,name,n); n = n1; STOQ(Stat,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"Stat"); MKNODE(n1,name,n); n = n1; STOQ(DP_Print,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"Print"); MKNODE(n1,name,n); n = n1; + STOQ(DP_PrintShort,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"PrintShort"); MKNODE(n1,name,n); n = n1; STOQ(DP_NFStat,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"NFStat"); MKNODE(n1,name,n); n = n1; STOQ(OXCheck,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"OXCheck"); MKNODE(n1,name,n); n = n1; STOQ(GenTrace,v); MKNODE(n1,v,n); n = n1; MKSTR(name,"GenTrace"); MKNODE(n1,name,n); n = n1; @@ -2107,7 +2243,7 @@ DP *rp; *rp = d; } -void _dp_nf_ptozp(b,g,ps,full,multiple,r) +void _dp_nf_z(b,g,ps,full,multiple,r) NODE b; DP g; DP *ps;