poly* wt_collect(void) { if (pos_acc->nrows>0) sorted=Add_pol_pol(sorted,pos_acc,false); else freemem(pos_acc); if (neg_acc->nrows>0) sorted=Add_pol_pol(sorted,neg_acc,true); else freemem(neg_acc); { poly* result=sorted; sorted=NULL; return result; } }
poly* SAtensor(boolean alt,_index m,poly* p) { _index n,r=Lierank(grp); poly** adams,** q,* result; if (m==0) return poly_one(r); else if (m==1) return p; adams=alloc_array(poly*,m+1); for (n=1; n<=m; ++n) adams[n]=Adams(n,p); q=alloc_array(poly*,m+1); q[0]=poly_one(r); for (n=1; n<=m; ++n) { { _index i; q[n]=Tensor(p,q[n-1]); /* the initial term of the summation */ for (i=2; i<=n; ++i) q[n] = Add_pol_pol(q[n],Tensor(adams[i],q[n-i]),alt&&i%2==0); } { _index i; bigint* big_n=entry2bigint(n); setshared(big_n); for (i=0; i<q[n]->nrows; ++i) { bigint** cc= &q[n]->coef[i] ,* c= (clrshared(*cc),isshared(*cc)) ? copybigint(*cc,NULL) : *cc; *cc=divq(c,big_n); setshared(*cc); { if (c->size != 0) error("Internal error (SAtensor): remainder from %ld.\n" ,(long)n); freemem(c); } } clrshared(big_n); freemem(big_n); } } result=q[m]; { for (n=1; n<=m; ++n) freepol(adams[n]); } freearr(adams); { for (n=0; n<m; ++n) freepol(q[n]); } freearr(q); return result; }
void wt_ins(entry* wt, bigint* c, boolean neg) { if (c->size==0) { freemem(c); return; } { lie_Index i=searchterm(sorted,wt); if (i>=0) { clrshared(sorted->coef[i]); sorted->coef[i]= (neg ? sub : add)(sorted->coef[i],c); setshared(sorted->coef[i]); } else { poly** acc= neg ? &neg_acc : &pos_acc; lie_Index i=(*acc)->nrows; if (i==(*acc)->rowsize) { sorted=Add_pol_pol(sorted,*acc,neg); *acc=mkpoly(Max(sorted->nrows,ACCMIN),sorted->ncols); i=0; } copyrow(wt,(*acc)->elm[i],sorted->ncols); (*acc)->coef[i++]=c; setshared(c); (*acc)->nrows=i; } } }