version 1.16, 2001/05/02 09:03:53 |
version 1.27, 2004/02/03 23:31:57 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/engine/dist.c,v 1.15 2001/03/29 09:49:57 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/dist.c,v 1.26 2003/08/22 08:14:45 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
|
|
|
|
#define ORD_ELIM 9 |
#define ORD_ELIM 9 |
#define ORD_WEYL_ELIM 10 |
#define ORD_WEYL_ELIM 10 |
#define ORD_HOMO_WW_DRL 11 |
#define ORD_HOMO_WW_DRL 11 |
|
#define ORD_DRL_ZIGZAG 12 |
|
#define ORD_HOMO_WW_DRL_ZIGZAG 13 |
|
|
|
int cmpdl_drl_zigzag(), cmpdl_homo_ww_drl_zigzag(); |
|
|
int (*cmpdl)()=cmpdl_revgradlex; |
int (*cmpdl)()=cmpdl_revgradlex; |
int (*primitive_cmpdl[3])() = {cmpdl_revgradlex,cmpdl_gradlex,cmpdl_lex}; |
int (*primitive_cmpdl[3])() = {cmpdl_revgradlex,cmpdl_gradlex,cmpdl_lex}; |
|
|
void comm_muld(VL,DP,DP,DP *); |
|
void weyl_muld(VL,DP,DP,DP *); |
|
void weyl_muldm(VL,MP,DP,DP *); |
|
void weyl_mulmm(VL,MP,MP,int,struct cdl *,int); |
|
void comm_muld_tab(VL,int,struct cdl *,int,struct cdl *,int,struct cdl *); |
|
|
|
void mkwc(int,int,Q *); |
|
|
|
int cmpdl_weyl_elim(); |
|
int cmpdl_homo_ww_drl(); |
|
|
|
int do_weyl; |
int do_weyl; |
|
|
int dp_nelim,dp_fcoeffs; |
int dp_nelim,dp_fcoeffs; |
struct order_spec dp_current_spec; |
struct order_spec *dp_current_spec; |
int *dp_dl_work; |
int *dp_dl_work; |
|
|
int has_fcoef(DP); |
void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr); |
int has_fcoef_p(P); |
void comm_quod(VL vl,DP p1,DP p2,DP *pr); |
|
void muldm_trunc(VL vl,DP p,MP m0,DL dl,DP *pr); |
|
void muldc_trunc(VL vl,DP p,P c,DL dl,DP *pr); |
|
|
int has_fcoef(f) |
int has_sfcoef(DP f) |
DP f; |
|
{ |
{ |
MP t; |
MP t; |
|
|
if ( !f ) |
if ( !f ) |
return 0; |
return 0; |
for ( t = BDY(f); t; t = NEXT(t) ) |
for ( t = BDY(f); t; t = NEXT(t) ) |
if ( has_fcoef_p(t->c) ) |
if ( has_sfcoef_p(t->c) ) |
break; |
break; |
return t ? 1 : 0; |
return t ? 1 : 0; |
} |
} |
|
|
int has_fcoef_p(f) |
int has_sfcoef_p(P f) |
P f; |
|
{ |
{ |
DCP dc; |
DCP dc; |
|
|
if ( !f ) |
if ( !f ) |
return 0; |
return 0; |
else if ( NUM(f) ) |
else if ( NUM(f) ) |
return (NID((Num)f) == N_LM |
return (NID((Num)f) == N_GFS) ? 1 : 0; |
|| NID((Num)f) == N_GF2N |
|
|| NID((Num)f) == N_GFPN |
|
|| NID((Num)f) == N_GFS) ? 1 : 0; |
|
else { |
else { |
for ( dc = DC(f); dc; dc = NEXT(dc) ) |
for ( dc = DC(f); dc; dc = NEXT(dc) ) |
if ( has_fcoef_p(COEF(dc)) ) |
if ( has_sfcoef_p(COEF(dc)) ) |
return 1; |
return 1; |
return 0; |
return 0; |
} |
} |
} |
} |
|
|
void initd(spec) |
void initd(struct order_spec *spec) |
struct order_spec *spec; |
|
{ |
{ |
switch ( spec->id ) { |
switch ( spec->id ) { |
case 2: |
case 2: |
Line 153 struct order_spec *spec; |
|
Line 142 struct order_spec *spec; |
|
cmpdl = cmpdl_weyl_elim; break; |
cmpdl = cmpdl_weyl_elim; break; |
case ORD_HOMO_WW_DRL: |
case ORD_HOMO_WW_DRL: |
cmpdl = cmpdl_homo_ww_drl; break; |
cmpdl = cmpdl_homo_ww_drl; break; |
|
case ORD_DRL_ZIGZAG: |
|
cmpdl = cmpdl_drl_zigzag; break; |
|
case ORD_HOMO_WW_DRL_ZIGZAG: |
|
cmpdl = cmpdl_homo_ww_drl_zigzag; break; |
case ORD_LEX: default: |
case ORD_LEX: default: |
cmpdl = cmpdl_lex; break; |
cmpdl = cmpdl_lex; break; |
} |
} |
break; |
break; |
} |
} |
dp_current_spec = *spec; |
dp_current_spec = spec; |
} |
} |
|
|
void ptod(vl,dvl,p,pr) |
void ptod(VL vl,VL dvl,P p,DP *pr) |
VL vl,dvl; |
|
P p; |
|
DP *pr; |
|
{ |
{ |
int isconst = 0; |
int isconst = 0; |
int n,i,j,k; |
int n,i,j,k; |
|
|
|
|
for ( j = k-1, s = 0; j >= 0; j-- ) { |
for ( j = k-1, s = 0; j >= 0; j-- ) { |
ptod(vl,dvl,COEF(w[j]),&t); |
ptod(vl,dvl,COEF(w[j]),&t); |
NEWDL(d,n); d->td = QTOS(DEG(w[j])); d->d[i] = d->td; |
NEWDL(d,n); d->d[i] = QTOS(DEG(w[j])); |
|
d->td = MUL_WEIGHT(d->d[i],i); |
NEWMP(m); m->dl = d; C(m) = (P)ONE; NEXT(m) = 0; MKDP(n,m,u); u->sugar = d->td; |
NEWMP(m); m->dl = d; C(m) = (P)ONE; NEXT(m) = 0; MKDP(n,m,u); u->sugar = d->td; |
comm_muld(vl,t,u,&r); addd(vl,r,s,&t); s = t; |
comm_muld(vl,t,u,&r); addd(vl,r,s,&t); s = t; |
} |
} |
|
|
} |
} |
} |
} |
} |
} |
if ( !dp_fcoeffs && has_fcoef(*pr) ) |
#if 0 |
dp_fcoeffs = 1; |
if ( !dp_fcoeffs && has_sfcoef(*pr) ) |
|
dp_fcoeffs = N_GFS; |
|
#endif |
} |
} |
|
|
void dtop(vl,dvl,p,pr) |
void dtop(VL vl,VL dvl,DP p,P *pr) |
VL vl,dvl; |
|
DP p; |
|
P *pr; |
|
{ |
{ |
int n,i,j,k; |
int n,i,j,k; |
DL d; |
DL d; |
|
|
} |
} |
} |
} |
|
|
void nodetod(node,dp) |
void nodetod(NODE node,DP *dp) |
NODE node; |
|
DP *dp; |
|
{ |
{ |
NODE t; |
NODE t; |
int len,i,td; |
int len,i,td; |
|
|
else if ( !NUM(e) || !RATN(e) || !INT(e) ) |
else if ( !NUM(e) || !RATN(e) || !INT(e) ) |
error("nodetod : invalid input"); |
error("nodetod : invalid input"); |
else { |
else { |
d->d[i] = QTOS((Q)e); td += d->d[i]; |
d->d[i] = QTOS((Q)e); td += MUL_WEIGHT(d->d[i],i); |
} |
} |
} |
} |
d->td = td; |
d->td = td; |
|
|
MKDP(len,m,u); u->sugar = td; *dp = u; |
MKDP(len,m,u); u->sugar = td; *dp = u; |
} |
} |
|
|
int sugard(m) |
int sugard(MP m) |
MP m; |
|
{ |
{ |
int s; |
int s; |
|
|
|
|
return s; |
return s; |
} |
} |
|
|
void addd(vl,p1,p2,pr) |
void addd(VL vl,DP p1,DP p2,DP *pr) |
VL vl; |
|
DP p1,p2,*pr; |
|
{ |
{ |
int n; |
int n; |
MP m1,m2,mr,mr0; |
MP m1,m2,mr,mr0; |
|
|
|
|
/* for F4 symbolic reduction */ |
/* for F4 symbolic reduction */ |
|
|
void symb_addd(p1,p2,pr) |
void symb_addd(DP p1,DP p2,DP *pr) |
DP p1,p2,*pr; |
|
{ |
{ |
int n; |
int n; |
MP m1,m2,mr,mr0; |
MP m1,m2,mr,mr0; |
P t; |
|
|
|
if ( !p1 ) |
if ( !p1 ) |
*pr = p2; |
*pr = p2; |
|
|
* return : a merged list |
* return : a merged list |
*/ |
*/ |
|
|
NODE symb_merge(m1,m2,n) |
NODE symb_merge(NODE m1,NODE m2,int n) |
NODE m1,m2; |
|
int n; |
|
{ |
{ |
NODE top,prev,cur,m,t; |
NODE top,prev,cur,m,t; |
|
int c,i; |
|
DL d1,d2; |
|
|
if ( !m1 ) |
if ( !m1 ) |
return m2; |
return m2; |
|
|
prev = top; cur = NEXT(top); |
prev = top; cur = NEXT(top); |
/* BDY(prev) > BDY(m) always holds */ |
/* BDY(prev) > BDY(m) always holds */ |
while ( cur && m ) { |
while ( cur && m ) { |
|
d1 = (DL)BDY(cur); |
|
d2 = (DL)BDY(m); |
|
#if 1 |
switch ( (*cmpdl)(n,(DL)BDY(cur),(DL)BDY(m)) ) { |
switch ( (*cmpdl)(n,(DL)BDY(cur),(DL)BDY(m)) ) { |
|
#else |
|
/* XXX only valid for DRL */ |
|
if ( d1->td > d2->td ) |
|
c = 1; |
|
else if ( d1->td < d2->td ) |
|
c = -1; |
|
else { |
|
for ( i = n-1; i >= 0 && d1->d[i] == d2->d[i]; i-- ); |
|
if ( i < 0 ) |
|
c = 0; |
|
else if ( d1->d[i] < d2->d[i] ) |
|
c = 1; |
|
else |
|
c = -1; |
|
} |
|
switch ( c ) { |
|
#endif |
case 0: |
case 0: |
m = NEXT(m); |
m = NEXT(m); |
prev = cur; cur = NEXT(cur); |
prev = cur; cur = NEXT(cur); |
|
|
} |
} |
} |
} |
|
|
void subd(vl,p1,p2,pr) |
void _adddl(int n,DL d1,DL d2,DL d3) |
VL vl; |
|
DP p1,p2,*pr; |
|
{ |
{ |
|
int i; |
|
|
|
d3->td = d1->td+d2->td; |
|
for ( i = 0; i < n; i++ ) |
|
d3->d[i] = d1->d[i]+d2->d[i]; |
|
} |
|
|
|
/* m1 <- m1 U dl*f, destructive */ |
|
|
|
NODE mul_dllist(DL dl,DP f); |
|
|
|
NODE symb_mul_merge(NODE m1,DL dl,DP f,int n) |
|
{ |
|
NODE top,prev,cur,n1; |
|
DP g; |
|
DL t,s; |
|
MP m; |
|
|
|
if ( !m1 ) |
|
return mul_dllist(dl,f); |
|
else if ( !f ) |
|
return m1; |
|
else { |
|
m = BDY(f); |
|
NEWDL_NOINIT(t,n); |
|
_adddl(n,m->dl,dl,t); |
|
top = m1; prev = 0; cur = m1; |
|
while ( m ) { |
|
switch ( (*cmpdl)(n,(DL)BDY(cur),t) ) { |
|
case 0: |
|
prev = cur; cur = NEXT(cur); |
|
if ( !cur ) { |
|
MKDP(n,m,g); |
|
NEXT(prev) = mul_dllist(dl,g); |
|
return; |
|
} |
|
m = NEXT(m); |
|
if ( m ) _adddl(n,m->dl,dl,t); |
|
break; |
|
case 1: |
|
prev = cur; cur = NEXT(cur); |
|
if ( !cur ) { |
|
MKDP(n,m,g); |
|
NEXT(prev) = mul_dllist(dl,g); |
|
return; |
|
} |
|
break; |
|
case -1: |
|
NEWDL_NOINIT(s,n); |
|
s->td = t->td; |
|
bcopy(t->d,s->d,n*sizeof(int)); |
|
NEWNODE(n1); |
|
n1->body = (pointer)s; |
|
NEXT(n1) = cur; |
|
if ( !prev ) { |
|
top = n1; cur = n1; |
|
} else { |
|
NEXT(prev) = n1; prev = n1; |
|
} |
|
m = NEXT(m); |
|
if ( m ) _adddl(n,m->dl,dl,t); |
|
break; |
|
} |
|
} |
|
return top; |
|
} |
|
} |
|
|
|
DLBUCKET symb_merge_bucket(DLBUCKET m1,DLBUCKET m2,int n) |
|
{ |
|
DLBUCKET top,prev,cur,m,t; |
|
|
|
if ( !m1 ) |
|
return m2; |
|
else if ( !m2 ) |
|
return m1; |
|
else { |
|
if ( m1->td == m2->td ) { |
|
top = m1; |
|
BDY(top) = symb_merge(BDY(top),BDY(m2),n); |
|
m = NEXT(m2); |
|
} else if ( m1->td > m2->td ) { |
|
top = m1; m = m2; |
|
} else { |
|
top = m2; m = m1; |
|
} |
|
prev = top; cur = NEXT(top); |
|
/* prev->td > m->td always holds */ |
|
while ( cur && m ) { |
|
if ( cur->td == m->td ) { |
|
BDY(cur) = symb_merge(BDY(cur),BDY(m),n); |
|
m = NEXT(m); |
|
prev = cur; cur = NEXT(cur); |
|
} else if ( cur->td > m->td ) { |
|
t = NEXT(cur); NEXT(cur) = m; m = t; |
|
prev = cur; cur = NEXT(cur); |
|
} else { |
|
NEXT(prev) = m; m = cur; |
|
prev = NEXT(prev); cur = NEXT(prev); |
|
} |
|
} |
|
if ( !cur ) |
|
NEXT(prev) = m; |
|
return top; |
|
} |
|
} |
|
|
|
void subd(VL vl,DP p1,DP p2,DP *pr) |
|
{ |
DP t; |
DP t; |
|
|
if ( !p2 ) |
if ( !p2 ) |
|
|
} |
} |
} |
} |
|
|
void chsgnd(p,pr) |
void chsgnd(DP p,DP *pr) |
DP p,*pr; |
|
{ |
{ |
MP m,mr,mr0; |
MP m,mr,mr0; |
|
|
|
|
} |
} |
} |
} |
|
|
void muld(vl,p1,p2,pr) |
void muld(VL vl,DP p1,DP p2,DP *pr) |
VL vl; |
|
DP p1,p2,*pr; |
|
{ |
{ |
if ( ! do_weyl ) |
if ( ! do_weyl ) |
comm_muld(vl,p1,p2,pr); |
comm_muld(vl,p1,p2,pr); |
|
|
weyl_muld(vl,p1,p2,pr); |
weyl_muld(vl,p1,p2,pr); |
} |
} |
|
|
void comm_muld(vl,p1,p2,pr) |
void comm_muld(VL vl,DP p1,DP p2,DP *pr) |
VL vl; |
|
DP p1,p2,*pr; |
|
{ |
{ |
MP m; |
MP m; |
DP s,t,u; |
DP s,t,u; |
|
|
} |
} |
} |
} |
|
|
void muldm(vl,p,m0,pr) |
/* discard terms which is not a multiple of dl */ |
VL vl; |
|
DP p; |
void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr) |
MP m0; |
|
DP *pr; |
|
{ |
{ |
|
MP m; |
|
DP s,t,u; |
|
int i,l,l1; |
|
static MP *w; |
|
static int wlen; |
|
|
|
if ( !p1 || !p2 ) |
|
*pr = 0; |
|
else if ( OID(p1) <= O_P ) |
|
muldc_trunc(vl,p2,(P)p1,dl,pr); |
|
else if ( OID(p2) <= O_P ) |
|
muldc_trunc(vl,p1,(P)p2,dl,pr); |
|
else { |
|
for ( m = BDY(p1), l1 = 0; m; m = NEXT(m), l1++ ); |
|
for ( m = BDY(p2), l = 0; m; m = NEXT(m), l++ ); |
|
if ( l1 < l ) { |
|
t = p1; p1 = p2; p2 = t; |
|
l = l1; |
|
} |
|
if ( l > wlen ) { |
|
if ( w ) GC_free(w); |
|
w = (MP *)MALLOC(l*sizeof(MP)); |
|
wlen = l; |
|
} |
|
for ( m = BDY(p2), i = 0; i < l; m = NEXT(m), i++ ) |
|
w[i] = m; |
|
for ( s = 0, i = l-1; i >= 0; i-- ) { |
|
muldm_trunc(vl,p1,w[i],dl,&t); addd(vl,s,t,&u); s = u; |
|
} |
|
bzero(w,l*sizeof(MP)); |
|
*pr = s; |
|
} |
|
} |
|
|
|
void comm_quod(VL vl,DP p1,DP p2,DP *pr) |
|
{ |
|
MP m,m0; |
|
DP s,t; |
|
int i,n,sugar; |
|
DL d1,d2,d; |
|
Q a,b; |
|
|
|
if ( !p2 ) |
|
error("comm_quod : invalid input"); |
|
if ( !p1 ) |
|
*pr = 0; |
|
else { |
|
n = NV(p1); |
|
d2 = BDY(p2)->dl; |
|
m0 = 0; |
|
sugar = p1->sugar; |
|
while ( p1 ) { |
|
d1 = BDY(p1)->dl; |
|
NEWDL(d,n); |
|
d->td = d1->td - d2->td; |
|
for ( i = 0; i < n; i++ ) |
|
d->d[i] = d1->d[i]-d2->d[i]; |
|
NEXTMP(m0,m); |
|
m->dl = d; |
|
divq((Q)BDY(p1)->c,(Q)BDY(p2)->c,&a); chsgnq(a,&b); |
|
C(m) = (P)b; |
|
muldm_trunc(vl,p2,m,d2,&t); |
|
addd(vl,p1,t,&s); p1 = s; |
|
C(m) = (P)a; |
|
} |
|
if ( m0 ) { |
|
NEXT(m) = 0; MKDP(n,m0,*pr); |
|
} else |
|
*pr = 0; |
|
/* XXX */ |
|
if ( *pr ) |
|
(*pr)->sugar = sugar - d2->td; |
|
} |
|
} |
|
|
|
void muldm(VL vl,DP p,MP m0,DP *pr) |
|
{ |
MP m,mr,mr0; |
MP m,mr,mr0; |
P c; |
P c; |
DL d; |
DL d; |
|
|
} |
} |
} |
} |
|
|
void weyl_muld(vl,p1,p2,pr) |
void muldm_trunc(VL vl,DP p,MP m0,DL dl,DP *pr) |
VL vl; |
|
DP p1,p2,*pr; |
|
{ |
{ |
|
MP m,mr,mr0; |
|
P c; |
|
DL d,tdl; |
|
int n,i; |
|
|
|
if ( !p ) |
|
*pr = 0; |
|
else { |
|
n = NV(p); |
|
NEWDL(tdl,n); |
|
for ( mr0 = 0, m = BDY(p), c = C(m0), d = m0->dl; |
|
m; m = NEXT(m) ) { |
|
_adddl(n,m->dl,d,tdl); |
|
for ( i = 0; i < n; i++ ) |
|
if ( tdl->d[i] < dl->d[i] ) |
|
break; |
|
if ( i < n ) |
|
continue; |
|
NEXTMP(mr0,mr); |
|
mr->dl = tdl; |
|
NEWDL(tdl,n); |
|
if ( NUM(C(m)) && RATN(C(m)) && NUM(c) && RATN(c) ) |
|
mulq((Q)C(m),(Q)c,(Q *)&C(mr)); |
|
else |
|
mulp(vl,C(m),c,&C(mr)); |
|
} |
|
if ( mr0 ) { |
|
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
|
} else |
|
*pr = 0; |
|
if ( *pr ) |
|
(*pr)->sugar = p->sugar + m0->dl->td; |
|
} |
|
} |
|
|
|
void weyl_muld(VL vl,DP p1,DP p2,DP *pr) |
|
{ |
MP m; |
MP m; |
DP s,t,u; |
DP s,t,u; |
int i,l; |
int i,l; |
|
|
|
|
/* monomial * polynomial */ |
/* monomial * polynomial */ |
|
|
void weyl_muldm(vl,m0,p,pr) |
void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
VL vl; |
|
MP m0; |
|
DP p; |
|
DP *pr; |
|
{ |
{ |
DP r,t,t1; |
DP r,t,t1; |
MP m; |
MP m; |
|
|
/* m0 = x0^d0*x1^d1*... * dx0^e0*dx1^e1*... */ |
/* m0 = x0^d0*x1^d1*... * dx0^e0*dx1^e1*... */ |
/* rtab : array of length (e0+1)*(e1+1)*... */ |
/* rtab : array of length (e0+1)*(e1+1)*... */ |
|
|
void weyl_mulmm(vl,m0,m1,n,rtab,rtablen) |
void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rtab,int rtablen) |
VL vl; |
|
MP m0,m1; |
|
int n; |
|
struct cdl *rtab; |
|
int rtablen; |
|
{ |
{ |
MP m,mr,mr0; |
P c,c0,c1; |
DP r,t,t1; |
|
P c,c0,c1,cc; |
|
DL d,d0,d1,dt; |
DL d,d0,d1,dt; |
int i,j,a,b,k,l,n2,s,min,curlen; |
int i,j,a,b,k,l,n2,s,min,curlen; |
struct cdl *p; |
struct cdl *p; |
|
|
for ( i = 0; i < n2; i++ ) { |
for ( i = 0; i < n2; i++ ) { |
a = d0->d[i]; b = d1->d[n2+i]; |
a = d0->d[i]; b = d1->d[n2+i]; |
k = d0->d[n2+i]; l = d1->d[i]; |
k = d0->d[n2+i]; l = d1->d[i]; |
|
|
|
/* degree of xi^a*(Di^k*xi^l)*Di^b */ |
|
a += l; |
|
b += k; |
|
s = MUL_WEIGHT(a,i)+MUL_WEIGHT(b,n2+i); |
|
|
if ( !k || !l ) { |
if ( !k || !l ) { |
a += l; |
|
b += k; |
|
s = a+b; |
|
for ( j = 0, p = rtab; j < curlen; j++, p++ ) { |
for ( j = 0, p = rtab; j < curlen; j++, p++ ) { |
if ( p->c ) { |
if ( p->c ) { |
dt = p->d; |
dt = p->d; |
|
|
tab = (struct cdl *)MALLOC(tablen*sizeof(struct cdl)); |
tab = (struct cdl *)MALLOC(tablen*sizeof(struct cdl)); |
ctab = (Q *)MALLOC(tablen*sizeof(Q)); |
ctab = (Q *)MALLOC(tablen*sizeof(Q)); |
} |
} |
/* degree of xi^a*(Di^k*xi^l)*Di^b */ |
|
s = a+k+l+b; |
|
/* compute xi^a*(Di^k*xi^l)*Di^b */ |
/* compute xi^a*(Di^k*xi^l)*Di^b */ |
min = MIN(k,l); |
min = MIN(k,l); |
mkwc(k,l,ctab); |
mkwc(k,l,ctab); |
|
|
if ( n & 1 ) |
if ( n & 1 ) |
for ( j = 0; j <= min; j++ ) { |
for ( j = 0; j <= min; j++ ) { |
NEWDL(d,n); |
NEWDL(d,n); |
d->d[i] = l-j+a; d->d[n2+i] = k-j+b; |
d->d[i] = a-j; d->d[n2+i] = b-j; |
d->td = s; |
d->td = s; |
d->d[n-1] = s-(d->d[i]+d->d[n2+i]); |
d->d[n-1] = s-(MUL_WEIGHT(a-j,i)+MUL_WEIGHT(b-j,n2+i)); |
tab[j].d = d; |
tab[j].d = d; |
tab[j].c = (P)ctab[j]; |
tab[j].c = (P)ctab[j]; |
} |
} |
else |
else |
for ( j = 0; j <= min; j++ ) { |
for ( j = 0; j <= min; j++ ) { |
NEWDL(d,n); |
NEWDL(d,n); |
d->d[i] = l-j+a; d->d[n2+i] = k-j+b; |
d->d[i] = a-j; d->d[n2+i] = b-j; |
d->td = d->d[i]+d->d[n2+i]; /* XXX */ |
d->td = MUL_WEIGHT(a-j,i)+MUL_WEIGHT(b-j,n2+i); /* XXX */ |
tab[j].d = d; |
tab[j].d = d; |
tab[j].c = (P)ctab[j]; |
tab[j].c = (P)ctab[j]; |
} |
} |
|
|
] |
] |
*/ |
*/ |
|
|
void comm_muld_tab(vl,nv,t,n,t1,n1,rt) |
void comm_muld_tab(VL vl,int nv,struct cdl *t,int n,struct cdl *t1,int n1,struct cdl *rt) |
VL vl; |
|
int nv; |
|
struct cdl *t; |
|
int n; |
|
struct cdl *t1; |
|
int n1; |
|
struct cdl *rt; |
|
{ |
{ |
int i,j; |
int i,j; |
struct cdl *p; |
struct cdl *p; |
|
|
} |
} |
} |
} |
|
|
void muldc(vl,p,c,pr) |
void muldc(VL vl,DP p,P c,DP *pr) |
VL vl; |
|
DP p; |
|
P c; |
|
DP *pr; |
|
{ |
{ |
MP m,mr,mr0; |
MP m,mr,mr0; |
|
|
|
|
} |
} |
} |
} |
|
|
void divsdc(vl,p,c,pr) |
void muldc_trunc(VL vl,DP p,P c,DL dl,DP *pr) |
VL vl; |
|
DP p; |
|
P c; |
|
DP *pr; |
|
{ |
{ |
MP m,mr,mr0; |
MP m,mr,mr0; |
|
DL mdl; |
|
int i,n; |
|
|
|
if ( !p || !c ) { |
|
*pr = 0; return; |
|
} |
|
n = NV(p); |
|
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
|
mdl = m->dl; |
|
for ( i = 0; i < n; i++ ) |
|
if ( mdl->d[i] < dl->d[i] ) |
|
break; |
|
if ( i < n ) |
|
break; |
|
NEXTMP(mr0,mr); |
|
if ( NUM(C(m)) && RATN(C(m)) && NUM(c) && RATN(c) ) |
|
mulq((Q)C(m),(Q)c,(Q *)&C(mr)); |
|
else |
|
mulp(vl,C(m),c,&C(mr)); |
|
mr->dl = m->dl; |
|
} |
|
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
|
if ( *pr ) |
|
(*pr)->sugar = p->sugar; |
|
} |
|
|
|
void divsdc(VL vl,DP p,P c,DP *pr) |
|
{ |
|
MP m,mr,mr0; |
|
|
if ( !c ) |
if ( !c ) |
error("disvsdc : division by 0"); |
error("disvsdc : division by 0"); |
else if ( !p ) |
else if ( !p ) |
|
|
} |
} |
} |
} |
|
|
void adddl(n,d1,d2,dr) |
void adddl(int n,DL d1,DL d2,DL *dr) |
int n; |
|
DL d1,d2; |
|
DL *dr; |
|
{ |
{ |
DL dt; |
DL dt; |
int i; |
int i; |
|
|
|
|
/* d1 += d2 */ |
/* d1 += d2 */ |
|
|
void adddl_destructive(n,d1,d2) |
void adddl_destructive(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
DL dt; |
|
int i; |
int i; |
|
|
d1->td += d2->td; |
d1->td += d2->td; |
|
|
d1->d[i] += d2->d[i]; |
d1->d[i] += d2->d[i]; |
} |
} |
|
|
int compd(vl,p1,p2) |
int compd(VL vl,DP p1,DP p2) |
VL vl; |
|
DP p1,p2; |
|
{ |
{ |
int n,t; |
int n,t; |
MP m1,m2; |
MP m1,m2; |
|
|
} |
} |
} |
} |
|
|
int cmpdl_lex(n,d1,d2) |
int cmpdl_lex(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int i; |
int i; |
|
|
|
|
return i == n ? 0 : (d1->d[i] > d2->d[i] ? 1 : -1); |
return i == n ? 0 : (d1->d[i] > d2->d[i] ? 1 : -1); |
} |
} |
|
|
int cmpdl_revlex(n,d1,d2) |
int cmpdl_revlex(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int i; |
int i; |
|
|
|
|
return i < 0 ? 0 : (d1->d[i] < d2->d[i] ? 1 : -1); |
return i < 0 ? 0 : (d1->d[i] < d2->d[i] ? 1 : -1); |
} |
} |
|
|
int cmpdl_gradlex(n,d1,d2) |
int cmpdl_gradlex(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
if ( d1->td > d2->td ) |
if ( d1->td > d2->td ) |
return 1; |
return 1; |
|
|
return cmpdl_lex(n,d1,d2); |
return cmpdl_lex(n,d1,d2); |
} |
} |
|
|
int cmpdl_revgradlex(n,d1,d2) |
int cmpdl_revgradlex(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
register int i; |
register int i,c; |
register int *p1,*p2; |
register int *p1,*p2; |
|
|
if ( d1->td > d2->td ) |
if ( d1->td > d2->td ) |
|
|
else if ( d1->td < d2->td ) |
else if ( d1->td < d2->td ) |
return -1; |
return -1; |
else { |
else { |
for ( i= n - 1, p1 = d1->d+n-1, p2 = d2->d+n-1; |
i = n-1; |
i >= 0 && *p1 == *p2; i--, p1--, p2-- ); |
p1 = d1->d+n-1; |
return i < 0 ? 0 : (*p1 < *p2 ? 1 : -1); |
p2 = d2->d+n-1; |
|
while ( i >= 7 ) { |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
i -= 8; |
|
} |
|
switch ( i ) { |
|
case 6: |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
return 0; |
|
case 5: |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
return 0; |
|
case 4: |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
return 0; |
|
case 3: |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
return 0; |
|
case 2: |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
return 0; |
|
case 1: |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
return 0; |
|
case 0: |
|
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
|
return 0; |
|
default: |
|
return 0; |
|
} |
|
LAST: |
|
if ( c > 0 ) return -1; |
|
else return 1; |
} |
} |
} |
} |
|
|
int cmpdl_blex(n,d1,d2) |
int cmpdl_blex(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int c; |
int c; |
|
|
|
|
} |
} |
} |
} |
|
|
int cmpdl_bgradlex(n,d1,d2) |
int cmpdl_bgradlex(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int e1,e2,c; |
int e1,e2,c; |
|
|
|
|
} |
} |
} |
} |
|
|
int cmpdl_brevgradlex(n,d1,d2) |
int cmpdl_brevgradlex(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int e1,e2,c; |
int e1,e2,c; |
|
|
|
|
} |
} |
} |
} |
|
|
int cmpdl_brevrev(n,d1,d2) |
int cmpdl_brevrev(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int e1,e2,f1,f2,c,i; |
int e1,e2,f1,f2,c,i; |
|
|
|
|
} |
} |
} |
} |
|
|
int cmpdl_bgradrev(n,d1,d2) |
int cmpdl_bgradrev(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int e1,e2,f1,f2,c,i; |
int e1,e2,f1,f2,c,i; |
|
|
|
|
} |
} |
} |
} |
|
|
int cmpdl_blexrev(n,d1,d2) |
int cmpdl_blexrev(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int e1,e2,f1,f2,c,i; |
int e1,e2,f1,f2,c,i; |
|
|
|
|
} |
} |
} |
} |
|
|
int cmpdl_elim(n,d1,d2) |
int cmpdl_elim(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int e1,e2,i; |
int e1,e2,i; |
|
|
|
|
return cmpdl_revgradlex(n,d1,d2); |
return cmpdl_revgradlex(n,d1,d2); |
} |
} |
|
|
int cmpdl_weyl_elim(n,d1,d2) |
int cmpdl_weyl_elim(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int e1,e2,i; |
int e1,e2,i; |
|
|
|
|
3. DRL for the first 2*m variables |
3. DRL for the first 2*m variables |
*/ |
*/ |
|
|
extern int *current_weight_vector; |
extern int *current_weyl_weight_vector; |
|
|
int cmpdl_homo_ww_drl(n,d1,d2) |
int cmpdl_homo_ww_drl(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int e1,e2,m,i; |
int e1,e2,m,i; |
int *p1,*p2; |
int *p1,*p2; |
|
|
return -1; |
return -1; |
|
|
m = n>>1; |
m = n>>1; |
for ( i = 0, e1 = e2 = 0; i < m; i++ ) { |
for ( i = 0, e1 = e2 = 0, p1 = d1->d, p2 = d2->d; i < m; i++ ) { |
e1 += current_weight_vector[i]*(d1->d[m+i] - d1->d[i]); |
e1 += current_weyl_weight_vector[i]*(p1[m+i] - p1[i]); |
e2 += current_weight_vector[i]*(d2->d[m+i] - d2->d[i]); |
e2 += current_weyl_weight_vector[i]*(p2[m+i] - p2[i]); |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
|
|
return i < 0 ? 0 : (*p1 < *p2 ? 1 : -1); |
return i < 0 ? 0 : (*p1 < *p2 ? 1 : -1); |
} |
} |
|
|
int cmpdl_order_pair(n,d1,d2) |
int cmpdl_drl_zigzag(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
|
int i,t,m; |
|
int *p1,*p2; |
|
|
|
if ( d1->td > d2->td ) |
|
return 1; |
|
else if ( d1->td < d2->td ) |
|
return -1; |
|
else { |
|
m = n>>1; |
|
for ( i= m - 1, p1 = d1->d, p2 = d2->d; i >= 0; i-- ) { |
|
if ( t = p1[m+i] - p2[m+i] ) return t > 0 ? -1 : 1; |
|
if ( t = p1[i] - p2[i] ) return t > 0 ? -1 : 1; |
|
} |
|
return 0; |
|
} |
|
} |
|
|
|
int cmpdl_homo_ww_drl_zigzag(int n,DL d1,DL d2) |
|
{ |
|
int e1,e2,m,i,t; |
|
int *p1,*p2; |
|
|
|
if ( d1->td > d2->td ) |
|
return 1; |
|
else if ( d1->td < d2->td ) |
|
return -1; |
|
|
|
m = n>>1; |
|
for ( i = 0, e1 = e2 = 0, p1 = d1->d, p2 = d2->d; i < m; i++ ) { |
|
e1 += current_weyl_weight_vector[i]*(p1[m+i] - p1[i]); |
|
e2 += current_weyl_weight_vector[i]*(p2[m+i] - p2[i]); |
|
} |
|
if ( e1 > e2 ) |
|
return 1; |
|
else if ( e1 < e2 ) |
|
return -1; |
|
|
|
e1 = d1->td - d1->d[n-1]; |
|
e2 = d2->td - d2->d[n-1]; |
|
if ( e1 > e2 ) |
|
return 1; |
|
else if ( e1 < e2 ) |
|
return -1; |
|
|
|
for ( i= m - 1, p1 = d1->d, p2 = d2->d; i >= 0; i-- ) { |
|
if ( t = p1[m+i] - p2[m+i] ) return t > 0 ? -1 : 1; |
|
if ( t = p1[i] - p2[i] ) return t > 0 ? -1 : 1; |
|
} |
|
return 0; |
|
} |
|
|
|
int cmpdl_order_pair(int n,DL d1,DL d2) |
|
{ |
int e1,e2,i,j,l; |
int e1,e2,i,j,l; |
int *t1,*t2; |
int *t1,*t2; |
int len; |
int len,head; |
struct order_pair *pair; |
struct order_pair *pair; |
|
|
len = dp_current_spec.ord.block.length; |
len = dp_current_spec->ord.block.length; |
pair = dp_current_spec.ord.block.order_pair; |
pair = dp_current_spec->ord.block.order_pair; |
|
|
|
head = 0; |
for ( i = 0, t1 = d1->d, t2 = d2->d; i < len; i++ ) { |
for ( i = 0, t1 = d1->d, t2 = d2->d; i < len; i++ ) { |
l = pair[i].length; |
l = pair[i].length; |
switch ( pair[i].order ) { |
switch ( pair[i].order ) { |
case 0: |
case 0: |
for ( j = 0, e1 = e2 = 0; j < l; j++ ) { |
for ( j = 0, e1 = e2 = 0; j < l; j++ ) { |
e1 += t1[j]; e2 += t2[j]; |
e1 += MUL_WEIGHT(t1[j],head+j); |
|
e2 += MUL_WEIGHT(t2[j],head+j); |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
|
|
break; |
break; |
case 1: |
case 1: |
for ( j = 0, e1 = e2 = 0; j < l; j++ ) { |
for ( j = 0, e1 = e2 = 0; j < l; j++ ) { |
e1 += t1[j]; e2 += t2[j]; |
e1 += MUL_WEIGHT(t1[j],head+j); |
|
e2 += MUL_WEIGHT(t2[j],head+j); |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
|
|
default: |
default: |
error("cmpdl_order_pair : invalid order"); break; |
error("cmpdl_order_pair : invalid order"); break; |
} |
} |
t1 += l; t2 += l; |
t1 += l; t2 += l; head += l; |
} |
} |
return 0; |
return 0; |
} |
} |
|
|
int cmpdl_matrix(n,d1,d2) |
int cmpdl_matrix(int n,DL d1,DL d2) |
int n; |
|
DL d1,d2; |
|
{ |
{ |
int *v,*w,*t1,*t2; |
int *v,*w,*t1,*t2; |
int s,i,j,len; |
int s,i,j,len; |
|
|
|
|
for ( i = 0, t1 = d1->d, t2 = d2->d, w = dp_dl_work; i < n; i++ ) |
for ( i = 0, t1 = d1->d, t2 = d2->d, w = dp_dl_work; i < n; i++ ) |
w[i] = t1[i]-t2[i]; |
w[i] = t1[i]-t2[i]; |
len = dp_current_spec.ord.matrix.row; |
len = dp_current_spec->ord.matrix.row; |
matrix = dp_current_spec.ord.matrix.matrix; |
matrix = dp_current_spec->ord.matrix.matrix; |
for ( j = 0; j < len; j++ ) { |
for ( j = 0; j < len; j++ ) { |
v = matrix[j]; |
v = matrix[j]; |
for ( i = 0, s = 0; i < n; i++ ) |
for ( i = 0, s = 0; i < n; i++ ) |
|
|
return -1; |
return -1; |
} |
} |
return 0; |
return 0; |
|
} |
|
|
|
GeoBucket create_bucket() |
|
{ |
|
GeoBucket g; |
|
|
|
g = CALLOC(1,sizeof(struct oGeoBucket)); |
|
g->m = 32; |
|
return g; |
|
} |
|
|
|
void add_bucket(GeoBucket g,NODE d,int nv) |
|
{ |
|
int l,k,m; |
|
|
|
l = length(d); |
|
for ( k = 0, m = 1; l > m; k++, m <<= 1 ); |
|
/* 2^(k-1) < l <= 2^k */ |
|
d = symb_merge(g->body[k],d,nv); |
|
for ( ; length(d) > (1<<(k)); k++ ) { |
|
g->body[k] = 0; |
|
d = symb_merge(g->body[k+1],d,nv); |
|
} |
|
g->body[k] = d; |
|
g->m = MAX(g->m,k); |
|
} |
|
|
|
DL remove_head_bucket(GeoBucket g,int nv) |
|
{ |
|
int j,i,c,m; |
|
DL d; |
|
|
|
j = -1; |
|
m = g->m; |
|
for ( i = 0; i <= m; i++ ) { |
|
if ( !g->body[i] ) |
|
continue; |
|
if ( j < 0 ) j = i; |
|
else { |
|
c = (*cmpdl)(nv,g->body[i]->body,g->body[j]->body); |
|
if ( c > 0 ) |
|
j = i; |
|
else if ( c == 0 ) |
|
g->body[i] = NEXT(g->body[i]); |
|
} |
|
} |
|
if ( j < 0 ) |
|
return 0; |
|
else { |
|
d = g->body[j]->body; |
|
g->body[j] = NEXT(g->body[j]); |
|
return d; |
|
} |
} |
} |