version 1.45, 2012/12/17 07:20:44 |
version 1.53, 2018/03/29 01:32:51 |
|
|
* 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.44 2011/03/30 02:43:18 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/dist.c,v 1.52 2017/08/31 02:36:21 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
|
|
Line 71 int (*cmpdl)()=cmpdl_revgradlex; |
|
Line 71 int (*cmpdl)()=cmpdl_revgradlex; |
|
int (*cmpdl_tie_breaker)(); |
int (*cmpdl_tie_breaker)(); |
int (*primitive_cmpdl[3])() = {cmpdl_revgradlex,cmpdl_gradlex,cmpdl_lex}; |
int (*primitive_cmpdl[3])() = {cmpdl_revgradlex,cmpdl_gradlex,cmpdl_lex}; |
|
|
|
Obj current_top_weight; |
|
int current_top_weight_len; |
|
|
int do_weyl; |
int do_weyl; |
|
|
int dp_nelim,dp_fcoeffs; |
int dp_nelim,dp_fcoeffs; |
|
|
void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr); |
void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr); |
void comm_quod(VL vl,DP p1,DP p2,DP *pr); |
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 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); |
void muldc_trunc(VL vl,DP p,Obj c,DL dl,DP *pr); |
|
int create_order_spec(VL vl,Obj obj,struct order_spec **specp); |
|
void create_modorder_spec(int id,LIST shift,struct modorder_spec **s); |
|
|
void order_init() |
void order_init() |
{ |
{ |
struct order_spec *spec; |
struct order_spec *spec; |
|
|
create_order_spec(0,0,&spec); |
create_order_spec(0,0,&spec); |
initd(spec); |
initd(spec); |
create_modorder_spec(0,0,&dp_current_modspec); |
create_modorder_spec(0,0,&dp_current_modspec); |
} |
} |
|
|
|
int has_sfcoef_p(Obj f); |
|
|
int has_sfcoef(DP f) |
int has_sfcoef(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_sfcoef_p(t->c) ) |
if ( has_sfcoef_p(t->c) ) |
break; |
break; |
return t ? 1 : 0; |
return t ? 1 : 0; |
} |
} |
|
|
int has_sfcoef_p(P f) |
int has_sfcoef_p(Obj 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_GFS) ? 1 : 0; |
return (NID((Num)f) == N_GFS) ? 1 : 0; |
else { |
else if ( POLY(f) ) { |
for ( dc = DC(f); dc; dc = NEXT(dc) ) |
for ( dc = DC((P)f); dc; dc = NEXT(dc) ) |
if ( has_sfcoef_p(COEF(dc)) ) |
if ( has_sfcoef_p((Obj)COEF(dc)) ) |
return 1; |
return 1; |
return 0; |
return 0; |
} |
} else |
|
return 0; |
} |
} |
|
|
extern N *current_top_weight_vector; |
extern Obj nd_top_weight; |
static int current_top_weight_len; |
|
|
|
|
void reset_top_weight() |
|
{ |
|
cmpdl = cmpdl_tie_breaker; |
|
cmpdl_tie_breaker = 0; |
|
nd_top_weight = 0; |
|
current_top_weight = 0; |
|
current_top_weight_len = 0; |
|
} |
|
|
void initd(struct order_spec *spec) |
void initd(struct order_spec *spec) |
{ |
{ |
int len,i; |
int len,i,k,row; |
|
Q **mat; |
|
|
switch ( spec->id ) { |
switch ( spec->id ) { |
case 3: |
case 3: |
cmpdl = cmpdl_composite; |
cmpdl = cmpdl_composite; |
dp_dl_work = (int *)MALLOC_ATOMIC(spec->nv*sizeof(int)); |
dp_dl_work = (int *)MALLOC_ATOMIC(spec->nv*sizeof(int)); |
break; |
break; |
case 2: |
case 2: |
cmpdl = cmpdl_matrix; |
cmpdl = cmpdl_matrix; |
dp_dl_work = (int *)MALLOC_ATOMIC(spec->nv*sizeof(int)); |
dp_dl_work = (int *)MALLOC_ATOMIC(spec->nv*sizeof(int)); |
break; |
break; |
case 1: |
case 1: |
cmpdl = cmpdl_order_pair; |
cmpdl = cmpdl_order_pair; |
break; |
break; |
default: |
default: |
switch ( spec->ord.simple ) { |
switch ( spec->ord.simple ) { |
case ORD_REVGRADLEX: |
case ORD_REVGRADLEX: |
cmpdl = cmpdl_revgradlex; break; |
cmpdl = cmpdl_revgradlex; break; |
case ORD_GRADLEX: |
case ORD_GRADLEX: |
cmpdl = cmpdl_gradlex; break; |
cmpdl = cmpdl_gradlex; break; |
case ORD_BREVGRADLEX: |
case ORD_BREVGRADLEX: |
cmpdl = cmpdl_brevgradlex; break; |
cmpdl = cmpdl_brevgradlex; break; |
case ORD_BGRADLEX: |
case ORD_BGRADLEX: |
cmpdl = cmpdl_bgradlex; break; |
cmpdl = cmpdl_bgradlex; break; |
case ORD_BLEX: |
case ORD_BLEX: |
cmpdl = cmpdl_blex; break; |
cmpdl = cmpdl_blex; break; |
case ORD_BREVREV: |
case ORD_BREVREV: |
cmpdl = cmpdl_brevrev; break; |
cmpdl = cmpdl_brevrev; break; |
case ORD_BGRADREV: |
case ORD_BGRADREV: |
cmpdl = cmpdl_bgradrev; break; |
cmpdl = cmpdl_bgradrev; break; |
case ORD_BLEXREV: |
case ORD_BLEXREV: |
cmpdl = cmpdl_blexrev; break; |
cmpdl = cmpdl_blexrev; break; |
case ORD_ELIM: |
case ORD_ELIM: |
cmpdl = cmpdl_elim; break; |
cmpdl = cmpdl_elim; break; |
case ORD_WEYL_ELIM: |
case ORD_WEYL_ELIM: |
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: |
case ORD_DRL_ZIGZAG: |
cmpdl = cmpdl_drl_zigzag; break; |
cmpdl = cmpdl_drl_zigzag; break; |
case ORD_HOMO_WW_DRL_ZIGZAG: |
case ORD_HOMO_WW_DRL_ZIGZAG: |
cmpdl = cmpdl_homo_ww_drl_zigzag; break; |
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; |
} |
} |
if ( current_top_weight_vector ) { |
if ( current_top_weight ) { |
cmpdl_tie_breaker = cmpdl; |
cmpdl_tie_breaker = cmpdl; |
cmpdl = cmpdl_top_weight; |
cmpdl = cmpdl_top_weight; |
for ( len = 0, i = 0; i < spec->nv; i++ ) |
if ( OID(current_top_weight) == O_VECT ) { |
if ( current_top_weight_vector[i] ) |
mat = (Q **)&BDY((VECT)current_top_weight); |
len = MAX(PL(current_top_weight_vector[i]),len); |
row = 1; |
current_top_weight_len = len; |
} else { |
} |
mat = (Q **)BDY((MAT)current_top_weight); |
dp_current_spec = spec; |
row = ((MAT)current_top_weight)->row; |
|
} |
|
for ( k = 0, len = 0; k < row; k++ ) |
|
for ( i = 0; i < spec->nv; i++ ) |
|
if ( mat[k][i] ) |
|
len = MAX(PL(NM(mat[k][i])),len); |
|
current_top_weight_len = len; |
|
} |
|
dp_current_spec = spec; |
} |
} |
|
|
|
int dpm_ispot; |
|
|
|
/* type=0 => TOP, type=1 => POT */ |
|
void initdpm(struct order_spec *spec,int type) |
|
{ |
|
int len,i,k,row; |
|
Q **mat; |
|
|
|
initd(spec); |
|
dpm_ispot = type; |
|
} |
|
|
void ptod(VL vl,VL dvl,P p,DP *pr) |
void ptod(VL vl,VL dvl,P p,DP *pr) |
{ |
{ |
int isconst = 0; |
int n,i,j,k; |
int n,i,j,k; |
VL tvl; |
VL tvl; |
V v; |
V v; |
DL d; |
DL d; |
MP m; |
MP m; |
DCP dc; |
DCP dc; |
DCP *w; |
DCP *w; |
DP r,s,t,u; |
DP r,s,t,u; |
P x,c; |
P x,c; |
|
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
else { |
else if ( OID(p) > O_P ) |
for ( n = 0, tvl = dvl; tvl; tvl = NEXT(tvl), n++ ); |
error("ptod : only polynomials can be converted."); |
if ( NUM(p) ) { |
else { |
NEWDL(d,n); |
for ( n = 0, tvl = dvl; tvl; tvl = NEXT(tvl), n++ ); |
NEWMP(m); m->dl = d; C(m) = p; NEXT(m) = 0; MKDP(n,m,*pr); (*pr)->sugar = 0; |
if ( NUM(p) ) { |
} else { |
NEWDL(d,n); |
for ( i = 0, tvl = dvl, v = VR(p); |
NEWMP(m); m->dl = d; C(m) = (Obj)p; NEXT(m) = 0; MKDP(n,m,*pr); (*pr)->sugar = 0; |
tvl && tvl->v != v; tvl = NEXT(tvl), i++ ); |
} else { |
if ( !tvl ) { |
for ( i = 0, tvl = dvl, v = VR(p); |
for ( dc = DC(p), k = 0; dc; dc = NEXT(dc), k++ ); |
tvl && tvl->v != v; tvl = NEXT(tvl), i++ ); |
w = (DCP *)ALLOCA(k*sizeof(DCP)); |
if ( !tvl ) { |
for ( dc = DC(p), j = 0; j < k; dc = NEXT(dc), j++ ) |
for ( dc = DC(p), k = 0; dc; dc = NEXT(dc), k++ ); |
w[j] = dc; |
w = (DCP *)ALLOCA(k*sizeof(DCP)); |
|
for ( dc = DC(p), j = 0; j < k; dc = NEXT(dc), j++ ) |
|
w[j] = dc; |
|
|
for ( j = k-1, s = 0, MKV(v,x); j >= 0; j-- ) { |
for ( j = k-1, s = 0, MKV(v,x); j >= 0; j-- ) { |
ptod(vl,dvl,COEF(w[j]),&t); pwrp(vl,x,DEG(w[j]),&c); |
ptod(vl,dvl,COEF(w[j]),&t); pwrp(vl,x,DEG(w[j]),&c); |
muldc(vl,t,c,&r); addd(vl,r,s,&t); s = t; |
muldc(vl,t,(Obj)c,&r); addd(vl,r,s,&t); s = t; |
} |
} |
*pr = s; |
*pr = s; |
} else { |
} else { |
for ( dc = DC(p), k = 0; dc; dc = NEXT(dc), k++ ); |
for ( dc = DC(p), k = 0; dc; dc = NEXT(dc), k++ ); |
w = (DCP *)ALLOCA(k*sizeof(DCP)); |
w = (DCP *)ALLOCA(k*sizeof(DCP)); |
for ( dc = DC(p), j = 0; j < k; dc = NEXT(dc), j++ ) |
for ( dc = DC(p), j = 0; j < k; dc = NEXT(dc), j++ ) |
w[j] = dc; |
w[j] = dc; |
|
|
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->d[i] = QTOS(DEG(w[j])); |
NEWDL(d,n); d->d[i] = QTOS(DEG(w[j])); |
d->td = MUL_WEIGHT(d->d[i],i); |
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) = (Obj)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; |
} |
} |
*pr = s; |
*pr = s; |
} |
} |
} |
} |
} |
} |
#if 0 |
#if 0 |
if ( !dp_fcoeffs && has_sfcoef(*pr) ) |
if ( !dp_fcoeffs && has_sfcoef(*pr) ) |
dp_fcoeffs = N_GFS; |
dp_fcoeffs = N_GFS; |
#endif |
#endif |
} |
} |
|
|
void dtop(VL vl,VL dvl,DP p,P *pr) |
void dtop(VL vl,VL dvl,DP p,Obj *pr) |
{ |
{ |
int n,i,j,k; |
int n,i,j,k; |
DL d; |
DL d; |
MP m; |
MP m; |
MP *a; |
MP *a; |
P r,s,t,u,w; |
P r; |
Q q; |
Obj t,w,s,u; |
VL tvl; |
Q q; |
|
VL tvl; |
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
else { |
else { |
for ( k = 0, m = BDY(p); m; m = NEXT(m), k++ ); |
for ( k = 0, m = BDY(p); m; m = NEXT(m), k++ ); |
a = (MP *)ALLOCA(k*sizeof(MP)); |
a = (MP *)ALLOCA(k*sizeof(MP)); |
for ( j = 0, m = BDY(p); j < k; m = NEXT(m), j++ ) |
for ( j = 0, m = BDY(p); j < k; m = NEXT(m), j++ ) |
a[j] = m; |
a[j] = m; |
|
|
for ( n = p->nv, j = k-1, s = 0; j >= 0; j-- ) { |
for ( n = p->nv, j = k-1, s = 0; j >= 0; j-- ) { |
m = a[j]; |
m = a[j]; |
t = C(m); |
t = C(m); |
if ( NUM(t) && NID((Num)t) == N_M ) { |
if ( NUM(t) && NID((Num)t) == N_M ) { |
mptop(t,&u); t = u; |
mptop((P)t,(P *)&u); t = u; |
} |
} |
for ( i = 0, d = m->dl, tvl = dvl; |
for ( i = 0, d = m->dl, tvl = dvl; |
i < n; tvl = NEXT(tvl), i++ ) { |
i < n; tvl = NEXT(tvl), i++ ) { |
MKV(tvl->v,r); STOQ(d->d[i],q); pwrp(vl,r,q,&u); |
MKV(tvl->v,r); STOQ(d->d[i],q); pwrp(vl,r,q,(P *)&u); |
mulp(vl,t,u,&w); t = w; |
arf_mul(vl,t,(Obj)u,&w); t = w; |
} |
} |
addp(vl,s,t,&u); s = u; |
arf_add(vl,s,t,&u); s = u; |
} |
} |
*pr = s; |
*pr = s; |
} |
} |
} |
} |
|
|
void nodetod(NODE node,DP *dp) |
void nodetod(NODE node,DP *dp) |
{ |
{ |
NODE t; |
NODE t; |
int len,i,td; |
int len,i,td; |
Q e; |
Q e; |
DL d; |
DL d; |
MP m; |
MP m; |
DP u; |
DP u; |
|
|
for ( t = node, len = 0; t; t = NEXT(t), len++ ); |
for ( t = node, len = 0; t; t = NEXT(t), len++ ); |
NEWDL(d,len); |
NEWDL(d,len); |
for ( t = node, i = 0, td = 0; i < len; t = NEXT(t), i++ ) { |
for ( t = node, i = 0, td = 0; i < len; t = NEXT(t), i++ ) { |
e = (Q)BDY(t); |
e = (Q)BDY(t); |
if ( !e ) |
if ( !e ) |
d->d[i] = 0; |
d->d[i] = 0; |
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 += MUL_WEIGHT(d->d[i],i); |
d->d[i] = QTOS((Q)e); td += MUL_WEIGHT(d->d[i],i); |
} |
} |
} |
} |
d->td = td; |
d->td = td; |
NEWMP(m); m->dl = d; C(m) = (P)ONE; NEXT(m) = 0; |
NEWMP(m); m->dl = d; C(m) = (Obj)ONE; NEXT(m) = 0; |
MKDP(len,m,u); u->sugar = td; *dp = u; |
MKDP(len,m,u); u->sugar = td; *dp = u; |
} |
} |
|
|
|
void nodetodpm(NODE node,Obj pos,DPM *dp) |
|
{ |
|
NODE t; |
|
int len,i,td; |
|
Q e; |
|
DL d; |
|
DMM m; |
|
DPM u; |
|
|
|
for ( t = node, len = 0; t; t = NEXT(t), len++ ); |
|
NEWDL(d,len); |
|
for ( t = node, i = 0, td = 0; i < len; t = NEXT(t), i++ ) { |
|
e = (Q)BDY(t); |
|
if ( !e ) |
|
d->d[i] = 0; |
|
else if ( !NUM(e) || !RATN(e) || !INT(e) ) |
|
error("nodetodpm : invalid input"); |
|
else { |
|
d->d[i] = QTOS((Q)e); td += MUL_WEIGHT(d->d[i],i); |
|
} |
|
} |
|
d->td = td; |
|
NEWDMM(m); m->dl = d; m->pos = QTOS((Q)pos); C(m) = (Obj)ONE; NEXT(m) = 0; |
|
MKDPM(len,m,u); u->sugar = td; *dp = u; |
|
} |
|
|
|
void dtodpm(DP d,int pos,DPM *dp) |
|
{ |
|
DMM mr0,mr; |
|
MP m; |
|
|
|
if ( !d ) *dp = 0; |
|
else { |
|
for ( m = BDY(d), mr0 = 0; m; m = NEXT(m) ) { |
|
NEXTDMM(mr0,mr); |
|
mr->dl = m->dl; |
|
mr->pos = pos; |
|
C(mr) = C(m); |
|
} |
|
MKDPM(d->nv,mr0,*dp); (*dp)->sugar = d->sugar; |
|
} |
|
} |
|
|
int sugard(MP m) |
int sugard(MP m) |
{ |
{ |
int s; |
int s; |
|
|
for ( s = 0; m; m = NEXT(m) ) |
for ( s = 0; m; m = NEXT(m) ) |
s = MAX(s,m->dl->td); |
s = MAX(s,m->dl->td); |
return s; |
return s; |
} |
} |
|
|
void addd(VL vl,DP p1,DP p2,DP *pr) |
void addd(VL vl,DP p1,DP p2,DP *pr) |
{ |
{ |
int n; |
int n; |
MP m1,m2,mr,mr0; |
MP m1,m2,mr=0,mr0; |
P t; |
Obj t; |
DL d; |
DL d; |
|
|
if ( !p1 ) |
if ( !p1 ) |
*pr = p2; |
*pr = p2; |
else if ( !p2 ) |
else if ( !p2 ) |
*pr = p1; |
*pr = p1; |
else { |
else { |
if ( OID(p1) <= O_R ) { |
if ( OID(p1) <= O_R ) { |
n = NV(p2); NEWDL(d,n); |
n = NV(p2); NEWDL(d,n); |
NEWMP(m1); m1->dl = d; C(m1) = (P)p1; NEXT(m1) = 0; |
NEWMP(m1); m1->dl = d; C(m1) = (Obj)p1; NEXT(m1) = 0; |
MKDP(n,m1,p1); (p1)->sugar = 0; |
MKDP(n,m1,p1); (p1)->sugar = 0; |
} |
} |
if ( OID(p2) <= O_R ) { |
if ( OID(p2) <= O_R ) { |
n = NV(p1); NEWDL(d,n); |
n = NV(p1); NEWDL(d,n); |
NEWMP(m2); m2->dl = d; C(m2) = (P)p2; NEXT(m2) = 0; |
NEWMP(m2); m2->dl = d; C(m2) = (Obj)p2; NEXT(m2) = 0; |
MKDP(n,m2,p2); (p2)->sugar = 0; |
MKDP(n,m2,p2); (p2)->sugar = 0; |
} |
} |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) |
switch ( (*cmpdl)(n,m1->dl,m2->dl) ) { |
switch ( (*cmpdl)(n,m1->dl,m2->dl) ) { |
case 0: |
case 0: |
addp(vl,C(m1),C(m2),&t); |
arf_add(vl,C(m1),C(m2),&t); |
if ( t ) { |
if ( t ) { |
NEXTMP(mr0,mr); mr->dl = m1->dl; C(mr) = t; |
NEXTMP(mr0,mr); mr->dl = m1->dl; C(mr) = t; |
} |
} |
m1 = NEXT(m1); m2 = NEXT(m2); break; |
m1 = NEXT(m1); m2 = NEXT(m2); break; |
case 1: |
case 1: |
NEXTMP(mr0,mr); mr->dl = m1->dl; C(mr) = C(m1); |
NEXTMP(mr0,mr); mr->dl = m1->dl; C(mr) = C(m1); |
m1 = NEXT(m1); break; |
m1 = NEXT(m1); break; |
case -1: |
case -1: |
NEXTMP(mr0,mr); mr->dl = m2->dl; C(mr) = C(m2); |
NEXTMP(mr0,mr); mr->dl = m2->dl; C(mr) = C(m2); |
m2 = NEXT(m2); break; |
m2 = NEXT(m2); break; |
} |
} |
if ( !mr0 ) |
if ( !mr0 ) |
if ( m1 ) |
if ( m1 ) |
mr0 = m1; |
mr0 = m1; |
else if ( m2 ) |
else if ( m2 ) |
mr0 = m2; |
mr0 = m2; |
else { |
else { |
*pr = 0; |
*pr = 0; |
return; |
return; |
} |
} |
else if ( m1 ) |
else if ( m1 ) |
NEXT(mr) = m1; |
NEXT(mr) = m1; |
else if ( m2 ) |
else if ( m2 ) |
NEXT(mr) = m2; |
NEXT(mr) = m2; |
else |
else |
NEXT(mr) = 0; |
NEXT(mr) = 0; |
MKDP(NV(p1),mr0,*pr); |
MKDP(NV(p1),mr0,*pr); |
if ( *pr ) |
if ( *pr ) |
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
} |
} |
} |
} |
|
|
/* for F4 symbolic reduction */ |
/* for F4 symbolic reduction */ |
|
|
void symb_addd(DP p1,DP p2,DP *pr) |
void symb_addd(DP p1,DP p2,DP *pr) |
{ |
{ |
int n; |
int n; |
MP m1,m2,mr,mr0; |
MP m1,m2,mr=0,mr0; |
|
|
if ( !p1 ) |
if ( !p1 ) |
*pr = p2; |
*pr = p2; |
else if ( !p2 ) |
else if ( !p2 ) |
*pr = p1; |
*pr = p1; |
else { |
else { |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) { |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) { |
NEXTMP(mr0,mr); C(mr) = (P)ONE; |
NEXTMP(mr0,mr); C(mr) = (Obj)ONE; |
switch ( (*cmpdl)(n,m1->dl,m2->dl) ) { |
switch ( (*cmpdl)(n,m1->dl,m2->dl) ) { |
case 0: |
case 0: |
mr->dl = m1->dl; |
mr->dl = m1->dl; |
m1 = NEXT(m1); m2 = NEXT(m2); break; |
m1 = NEXT(m1); m2 = NEXT(m2); break; |
case 1: |
case 1: |
mr->dl = m1->dl; |
mr->dl = m1->dl; |
m1 = NEXT(m1); break; |
m1 = NEXT(m1); break; |
case -1: |
case -1: |
mr->dl = m2->dl; |
mr->dl = m2->dl; |
m2 = NEXT(m2); break; |
m2 = NEXT(m2); break; |
} |
} |
} |
} |
if ( !mr0 ) |
if ( !mr0 ) |
if ( m1 ) |
if ( m1 ) |
mr0 = m1; |
mr0 = m1; |
else if ( m2 ) |
else if ( m2 ) |
mr0 = m2; |
mr0 = m2; |
else { |
else { |
*pr = 0; |
*pr = 0; |
return; |
return; |
} |
} |
else if ( m1 ) |
else if ( m1 ) |
NEXT(mr) = m1; |
NEXT(mr) = m1; |
else if ( m2 ) |
else if ( m2 ) |
NEXT(mr) = m2; |
NEXT(mr) = m2; |
else |
else |
NEXT(mr) = 0; |
NEXT(mr) = 0; |
MKDP(NV(p1),mr0,*pr); |
MKDP(NV(p1),mr0,*pr); |
if ( *pr ) |
if ( *pr ) |
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
} |
} |
} |
} |
|
|
/* |
/* |
Line 424 void symb_addd(DP p1,DP p2,DP *pr) |
|
Line 506 void symb_addd(DP p1,DP p2,DP *pr) |
|
|
|
NODE symb_merge(NODE m1,NODE m2,int n) |
NODE symb_merge(NODE m1,NODE m2,int n) |
{ |
{ |
NODE top,prev,cur,m,t; |
NODE top=0,prev,cur,m=0,t; |
int c,i; |
DL d1,d2; |
DL d1,d2; |
|
|
|
if ( !m1 ) |
if ( !m1 ) |
return m2; |
return m2; |
else if ( !m2 ) |
else if ( !m2 ) |
return m1; |
return m1; |
else { |
else { |
switch ( (*cmpdl)(n,(DL)BDY(m1),(DL)BDY(m2)) ) { |
switch ( (*cmpdl)(n,(DL)BDY(m1),(DL)BDY(m2)) ) { |
case 0: |
case 0: |
top = m1; m = NEXT(m2); |
top = m1; m = NEXT(m2); |
break; |
break; |
case 1: |
case 1: |
top = m1; m = m2; |
top = m1; m = m2; |
break; |
break; |
case -1: |
case -1: |
top = m2; m = m1; |
top = m2; m = m1; |
break; |
break; |
} |
} |
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); |
d1 = (DL)BDY(cur); |
d2 = (DL)BDY(m); |
d2 = (DL)BDY(m); |
#if 1 |
#if 1 |
switch ( (*cmpdl)(n,(DL)BDY(cur),(DL)BDY(m)) ) { |
switch ( (*cmpdl)(n,(DL)BDY(cur),(DL)BDY(m)) ) { |
#else |
#else |
/* XXX only valid for DRL */ |
/* XXX only valid for DRL */ |
if ( d1->td > d2->td ) |
if ( d1->td > d2->td ) |
c = 1; |
c = 1; |
else if ( d1->td < d2->td ) |
else if ( d1->td < d2->td ) |
c = -1; |
c = -1; |
else { |
else { |
for ( i = n-1; i >= 0 && d1->d[i] == d2->d[i]; i-- ); |
for ( i = n-1; i >= 0 && d1->d[i] == d2->d[i]; i-- ); |
if ( i < 0 ) |
if ( i < 0 ) |
c = 0; |
c = 0; |
else if ( d1->d[i] < d2->d[i] ) |
else if ( d1->d[i] < d2->d[i] ) |
c = 1; |
c = 1; |
else |
else |
c = -1; |
c = -1; |
} |
} |
switch ( c ) { |
switch ( c ) { |
#endif |
#endif |
case 0: |
case 0: |
m = NEXT(m); |
m = NEXT(m); |
prev = cur; cur = NEXT(cur); |
prev = cur; cur = NEXT(cur); |
break; |
break; |
case 1: |
case 1: |
t = NEXT(cur); NEXT(cur) = m; m = t; |
t = NEXT(cur); NEXT(cur) = m; m = t; |
prev = cur; cur = NEXT(cur); |
prev = cur; cur = NEXT(cur); |
break; |
break; |
case -1: |
case -1: |
NEXT(prev) = m; m = cur; |
NEXT(prev) = m; m = cur; |
prev = NEXT(prev); cur = NEXT(prev); |
prev = NEXT(prev); cur = NEXT(prev); |
break; |
break; |
} |
} |
} |
} |
if ( !cur ) |
if ( !cur ) |
NEXT(prev) = m; |
NEXT(prev) = m; |
return top; |
return top; |
} |
} |
} |
} |
|
|
void _adddl(int n,DL d1,DL d2,DL d3) |
void _adddl(int n,DL d1,DL d2,DL d3) |
{ |
{ |
int i; |
int i; |
|
|
d3->td = d1->td+d2->td; |
d3->td = d1->td+d2->td; |
for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
d3->d[i] = d1->d[i]+d2->d[i]; |
d3->d[i] = d1->d[i]+d2->d[i]; |
} |
} |
|
|
/* m1 <- m1 U dl*f, destructive */ |
/* m1 <- m1 U dl*f, destructive */ |
Line 503 NODE mul_dllist(DL dl,DP f); |
|
Line 584 NODE mul_dllist(DL dl,DP f); |
|
|
|
NODE symb_mul_merge(NODE m1,DL dl,DP f,int n) |
NODE symb_mul_merge(NODE m1,DL dl,DP f,int n) |
{ |
{ |
NODE top,prev,cur,n1; |
NODE top,prev,cur,n1; |
DP g; |
DP g; |
DL t,s; |
DL t,s; |
MP m; |
MP m; |
|
|
if ( !m1 ) |
if ( !m1 ) |
return mul_dllist(dl,f); |
return mul_dllist(dl,f); |
else if ( !f ) |
else if ( !f ) |
return m1; |
return m1; |
else { |
else { |
m = BDY(f); |
m = BDY(f); |
NEWDL_NOINIT(t,n); |
NEWDL_NOINIT(t,n); |
_adddl(n,m->dl,dl,t); |
_adddl(n,m->dl,dl,t); |
top = m1; prev = 0; cur = m1; |
top = m1; prev = 0; cur = m1; |
while ( m ) { |
while ( m ) { |
switch ( (*cmpdl)(n,(DL)BDY(cur),t) ) { |
switch ( (*cmpdl)(n,(DL)BDY(cur),t) ) { |
case 0: |
case 0: |
prev = cur; cur = NEXT(cur); |
prev = cur; cur = NEXT(cur); |
if ( !cur ) { |
if ( !cur ) { |
MKDP(n,m,g); |
MKDP(n,m,g); |
NEXT(prev) = mul_dllist(dl,g); |
NEXT(prev) = mul_dllist(dl,g); |
return; |
return top; |
} |
} |
m = NEXT(m); |
m = NEXT(m); |
if ( m ) _adddl(n,m->dl,dl,t); |
if ( m ) _adddl(n,m->dl,dl,t); |
break; |
break; |
case 1: |
case 1: |
prev = cur; cur = NEXT(cur); |
prev = cur; cur = NEXT(cur); |
if ( !cur ) { |
if ( !cur ) { |
MKDP(n,m,g); |
MKDP(n,m,g); |
NEXT(prev) = mul_dllist(dl,g); |
NEXT(prev) = mul_dllist(dl,g); |
return; |
return top; |
} |
} |
break; |
break; |
case -1: |
case -1: |
NEWDL_NOINIT(s,n); |
NEWDL_NOINIT(s,n); |
s->td = t->td; |
s->td = t->td; |
bcopy(t->d,s->d,n*sizeof(int)); |
bcopy(t->d,s->d,n*sizeof(int)); |
NEWNODE(n1); |
NEWNODE(n1); |
n1->body = (pointer)s; |
n1->body = (pointer)s; |
NEXT(n1) = cur; |
NEXT(n1) = cur; |
if ( !prev ) { |
if ( !prev ) { |
top = n1; cur = n1; |
top = n1; cur = n1; |
} else { |
} else { |
NEXT(prev) = n1; prev = n1; |
NEXT(prev) = n1; prev = n1; |
} |
} |
m = NEXT(m); |
m = NEXT(m); |
if ( m ) _adddl(n,m->dl,dl,t); |
if ( m ) _adddl(n,m->dl,dl,t); |
break; |
break; |
} |
} |
} |
} |
return top; |
return top; |
} |
} |
} |
} |
|
|
DLBUCKET symb_merge_bucket(DLBUCKET m1,DLBUCKET m2,int n) |
DLBUCKET symb_merge_bucket(DLBUCKET m1,DLBUCKET m2,int n) |
{ |
{ |
DLBUCKET top,prev,cur,m,t; |
DLBUCKET top,prev,cur,m,t; |
|
|
if ( !m1 ) |
if ( !m1 ) |
return m2; |
return m2; |
else if ( !m2 ) |
else if ( !m2 ) |
return m1; |
return m1; |
else { |
else { |
if ( m1->td == m2->td ) { |
if ( m1->td == m2->td ) { |
top = m1; |
top = m1; |
BDY(top) = symb_merge(BDY(top),BDY(m2),n); |
BDY(top) = symb_merge(BDY(top),BDY(m2),n); |
m = NEXT(m2); |
m = NEXT(m2); |
} else if ( m1->td > m2->td ) { |
} else if ( m1->td > m2->td ) { |
top = m1; m = m2; |
top = m1; m = m2; |
} else { |
} else { |
top = m2; m = m1; |
top = m2; m = m1; |
} |
} |
prev = top; cur = NEXT(top); |
prev = top; cur = NEXT(top); |
/* prev->td > m->td always holds */ |
/* prev->td > m->td always holds */ |
while ( cur && m ) { |
while ( cur && m ) { |
if ( cur->td == m->td ) { |
if ( cur->td == m->td ) { |
BDY(cur) = symb_merge(BDY(cur),BDY(m),n); |
BDY(cur) = symb_merge(BDY(cur),BDY(m),n); |
m = NEXT(m); |
m = NEXT(m); |
prev = cur; cur = NEXT(cur); |
prev = cur; cur = NEXT(cur); |
} else if ( cur->td > m->td ) { |
} else if ( cur->td > m->td ) { |
t = NEXT(cur); NEXT(cur) = m; m = t; |
t = NEXT(cur); NEXT(cur) = m; m = t; |
prev = cur; cur = NEXT(cur); |
prev = cur; cur = NEXT(cur); |
} else { |
} else { |
NEXT(prev) = m; m = cur; |
NEXT(prev) = m; m = cur; |
prev = NEXT(prev); cur = NEXT(prev); |
prev = NEXT(prev); cur = NEXT(prev); |
} |
} |
} |
} |
if ( !cur ) |
if ( !cur ) |
NEXT(prev) = m; |
NEXT(prev) = m; |
return top; |
return top; |
} |
} |
} |
} |
|
|
void subd(VL vl,DP p1,DP p2,DP *pr) |
void subd(VL vl,DP p1,DP p2,DP *pr) |
{ |
{ |
DP t; |
DP t; |
|
|
if ( !p2 ) |
if ( !p2 ) |
*pr = p1; |
*pr = p1; |
else { |
else { |
chsgnd(p2,&t); addd(vl,p1,t,pr); |
chsgnd(p2,&t); addd(vl,p1,t,pr); |
} |
} |
} |
} |
|
|
void chsgnd(DP p,DP *pr) |
void chsgnd(DP p,DP *pr) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr=0,mr0; |
Obj r; |
Obj r; |
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
else if ( OID(p) <= O_R ) { |
else if ( OID(p) <= O_R ) { |
chsgnr((Obj)p,&r); *pr = (DP)r; |
arf_chsgn((Obj)p,&r); *pr = (DP)r; |
} else { |
} else { |
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
NEXTMP(mr0,mr); chsgnp(C(m),&C(mr)); mr->dl = m->dl; |
NEXTMP(mr0,mr); arf_chsgn(C(m),&C(mr)); mr->dl = m->dl; |
} |
} |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
if ( *pr ) |
if ( *pr ) |
(*pr)->sugar = p->sugar; |
(*pr)->sugar = p->sugar; |
} |
} |
} |
} |
|
|
void muld(VL vl,DP p1,DP p2,DP *pr) |
void muld(VL vl,DP p1,DP p2,DP *pr) |
{ |
{ |
if ( ! do_weyl ) |
if ( ! do_weyl ) |
comm_muld(vl,p1,p2,pr); |
comm_muld(vl,p1,p2,pr); |
else |
else |
weyl_muld(vl,p1,p2,pr); |
weyl_muld(vl,p1,p2,pr); |
} |
} |
|
|
void comm_muld(VL vl,DP p1,DP p2,DP *pr) |
void comm_muld(VL vl,DP p1,DP p2,DP *pr) |
{ |
{ |
MP m; |
MP m; |
DP s,t,u; |
DP s,t,u; |
int i,l,l1; |
int i,l,l1; |
static MP *w; |
static MP *w; |
static int wlen; |
static int wlen; |
|
|
if ( !p1 || !p2 ) |
if ( !p1 || !p2 ) |
*pr = 0; |
*pr = 0; |
else if ( OID(p1) <= O_P ) |
else if ( OID(p1) != O_DP ) |
muldc(vl,p2,(P)p1,pr); |
muldc(vl,p2,(Obj)p1,pr); |
else if ( OID(p2) <= O_P ) |
else if ( OID(p2) != O_DP ) |
muldc(vl,p1,(P)p2,pr); |
muldc(vl,p1,(Obj)p2,pr); |
else { |
else { |
for ( m = BDY(p1), l1 = 0; m; m = NEXT(m), l1++ ); |
for ( m = BDY(p1), l1 = 0; m; m = NEXT(m), l1++ ); |
for ( m = BDY(p2), l = 0; m; m = NEXT(m), l++ ); |
for ( m = BDY(p2), l = 0; m; m = NEXT(m), l++ ); |
if ( l1 < l ) { |
if ( l1 < l ) { |
t = p1; p1 = p2; p2 = t; |
t = p1; p1 = p2; p2 = t; |
l = l1; |
l = l1; |
} |
} |
if ( l > wlen ) { |
if ( l > wlen ) { |
if ( w ) GCFREE(w); |
if ( w ) GCFREE(w); |
w = (MP *)MALLOC(l*sizeof(MP)); |
w = (MP *)MALLOC(l*sizeof(MP)); |
wlen = l; |
wlen = l; |
} |
} |
for ( m = BDY(p2), i = 0; i < l; m = NEXT(m), i++ ) |
for ( m = BDY(p2), i = 0; i < l; m = NEXT(m), i++ ) |
w[i] = m; |
w[i] = m; |
for ( s = 0, i = l-1; i >= 0; i-- ) { |
for ( s = 0, i = l-1; i >= 0; i-- ) { |
muldm(vl,p1,w[i],&t); addd(vl,s,t,&u); s = u; |
muldm(vl,p1,w[i],&t); addd(vl,s,t,&u); s = u; |
} |
} |
bzero(w,l*sizeof(MP)); |
bzero(w,l*sizeof(MP)); |
*pr = s; |
*pr = s; |
} |
} |
} |
} |
|
|
/* discard terms which is not a multiple of dl */ |
/* discard terms which is not a multiple of dl */ |
|
|
void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr) |
void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr) |
{ |
{ |
MP m; |
MP m; |
DP s,t,u; |
DP s,t,u; |
int i,l,l1; |
int i,l,l1; |
static MP *w; |
static MP *w; |
static int wlen; |
static int wlen; |
|
|
if ( !p1 || !p2 ) |
if ( !p1 || !p2 ) |
*pr = 0; |
*pr = 0; |
else if ( OID(p1) <= O_P ) |
else if ( OID(p1) != O_DP ) |
muldc_trunc(vl,p2,(P)p1,dl,pr); |
muldc_trunc(vl,p2,(Obj)p1,dl,pr); |
else if ( OID(p2) <= O_P ) |
else if ( OID(p2) != O_DP ) |
muldc_trunc(vl,p1,(P)p2,dl,pr); |
muldc_trunc(vl,p1,(Obj)p2,dl,pr); |
else { |
else { |
for ( m = BDY(p1), l1 = 0; m; m = NEXT(m), l1++ ); |
for ( m = BDY(p1), l1 = 0; m; m = NEXT(m), l1++ ); |
for ( m = BDY(p2), l = 0; m; m = NEXT(m), l++ ); |
for ( m = BDY(p2), l = 0; m; m = NEXT(m), l++ ); |
if ( l1 < l ) { |
if ( l1 < l ) { |
t = p1; p1 = p2; p2 = t; |
t = p1; p1 = p2; p2 = t; |
l = l1; |
l = l1; |
} |
} |
if ( l > wlen ) { |
if ( l > wlen ) { |
if ( w ) GCFREE(w); |
if ( w ) GCFREE(w); |
w = (MP *)MALLOC(l*sizeof(MP)); |
w = (MP *)MALLOC(l*sizeof(MP)); |
wlen = l; |
wlen = l; |
} |
} |
for ( m = BDY(p2), i = 0; i < l; m = NEXT(m), i++ ) |
for ( m = BDY(p2), i = 0; i < l; m = NEXT(m), i++ ) |
w[i] = m; |
w[i] = m; |
for ( s = 0, i = l-1; i >= 0; i-- ) { |
for ( s = 0, i = l-1; i >= 0; i-- ) { |
muldm_trunc(vl,p1,w[i],dl,&t); addd(vl,s,t,&u); s = u; |
muldm_trunc(vl,p1,w[i],dl,&t); addd(vl,s,t,&u); s = u; |
} |
} |
bzero(w,l*sizeof(MP)); |
bzero(w,l*sizeof(MP)); |
*pr = s; |
*pr = s; |
} |
} |
} |
} |
|
|
void comm_quod(VL vl,DP p1,DP p2,DP *pr) |
void comm_quod(VL vl,DP p1,DP p2,DP *pr) |
{ |
{ |
MP m,m0; |
MP m=0,m0; |
DP s,t; |
DP s,t; |
int i,n,sugar; |
int i,n,sugar; |
DL d1,d2,d; |
DL d1,d2,d; |
Q a,b; |
Q a,b; |
|
|
if ( !p2 ) |
if ( !p2 ) |
error("comm_quod : invalid input"); |
error("comm_quod : invalid input"); |
if ( !p1 ) |
if ( !p1 ) |
*pr = 0; |
*pr = 0; |
else { |
else { |
n = NV(p1); |
n = NV(p1); |
d2 = BDY(p2)->dl; |
d2 = BDY(p2)->dl; |
m0 = 0; |
m0 = 0; |
sugar = p1->sugar; |
sugar = p1->sugar; |
while ( p1 ) { |
while ( p1 ) { |
d1 = BDY(p1)->dl; |
d1 = BDY(p1)->dl; |
NEWDL(d,n); |
NEWDL(d,n); |
d->td = d1->td - d2->td; |
d->td = d1->td - d2->td; |
for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
d->d[i] = d1->d[i]-d2->d[i]; |
d->d[i] = d1->d[i]-d2->d[i]; |
NEXTMP(m0,m); |
NEXTMP(m0,m); |
m->dl = d; |
m->dl = d; |
divq((Q)BDY(p1)->c,(Q)BDY(p2)->c,&a); chsgnq(a,&b); |
divq((Q)BDY(p1)->c,(Q)BDY(p2)->c,&a); chsgnq(a,&b); |
C(m) = (P)b; |
C(m) = (Obj)b; |
muldm_trunc(vl,p2,m,d2,&t); |
muldm_trunc(vl,p2,m,d2,&t); |
addd(vl,p1,t,&s); p1 = s; |
addd(vl,p1,t,&s); p1 = s; |
C(m) = (P)a; |
C(m) = (Obj)a; |
} |
} |
if ( m0 ) { |
if ( m0 ) { |
NEXT(m) = 0; MKDP(n,m0,*pr); |
NEXT(m) = 0; MKDP(n,m0,*pr); |
} else |
} else |
*pr = 0; |
*pr = 0; |
/* XXX */ |
/* XXX */ |
if ( *pr ) |
if ( *pr ) |
(*pr)->sugar = sugar - d2->td; |
(*pr)->sugar = sugar - d2->td; |
} |
} |
} |
} |
|
|
void muldm(VL vl,DP p,MP m0,DP *pr) |
void muldm(VL vl,DP p,MP m0,DP *pr) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr=0,mr0; |
P c; |
Obj c; |
DL d; |
DL d; |
int n; |
int n; |
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
else { |
else { |
for ( mr0 = 0, m = BDY(p), c = C(m0), d = m0->dl, n = NV(p); |
for ( mr0 = 0, m = BDY(p), c = C(m0), d = m0->dl, n = NV(p); |
m; m = NEXT(m) ) { |
m; m = NEXT(m) ) { |
NEXTMP(mr0,mr); |
NEXTMP(mr0,mr); |
if ( NUM(C(m)) && RATN(C(m)) && NUM(c) && RATN(c) ) |
if ( NUM(C(m)) && RATN(C(m)) && NUM(c) && RATN(c) ) |
mulq((Q)C(m),(Q)c,(Q *)&C(mr)); |
mulq((Q)C(m),(Q)c,(Q *)&C(mr)); |
else |
else |
mulp(vl,C(m),c,&C(mr)); |
arf_mul(vl,C(m),c,&C(mr)); |
adddl(n,m->dl,d,&mr->dl); |
adddl(n,m->dl,d,&mr->dl); |
} |
} |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
if ( *pr ) |
if ( *pr ) |
(*pr)->sugar = p->sugar + m0->dl->td; |
(*pr)->sugar = p->sugar + m0->dl->td; |
} |
} |
} |
} |
|
|
void muldm_trunc(VL vl,DP p,MP m0,DL dl,DP *pr) |
void muldm_trunc(VL vl,DP p,MP m0,DL dl,DP *pr) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr=0,mr0; |
P c; |
Obj c; |
DL d,tdl; |
DL d,tdl; |
int n,i; |
int n,i; |
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
else { |
else { |
n = NV(p); |
n = NV(p); |
NEWDL(tdl,n); |
NEWDL(tdl,n); |
for ( mr0 = 0, m = BDY(p), c = C(m0), d = m0->dl; |
for ( mr0 = 0, m = BDY(p), c = C(m0), d = m0->dl; |
m; m = NEXT(m) ) { |
m; m = NEXT(m) ) { |
_adddl(n,m->dl,d,tdl); |
_adddl(n,m->dl,d,tdl); |
for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
if ( tdl->d[i] < dl->d[i] ) |
if ( tdl->d[i] < dl->d[i] ) |
break; |
break; |
if ( i < n ) |
if ( i < n ) |
continue; |
continue; |
NEXTMP(mr0,mr); |
NEXTMP(mr0,mr); |
mr->dl = tdl; |
mr->dl = tdl; |
NEWDL(tdl,n); |
NEWDL(tdl,n); |
if ( NUM(C(m)) && RATN(C(m)) && NUM(c) && RATN(c) ) |
if ( NUM(C(m)) && RATN(C(m)) && NUM(c) && RATN(c) ) |
mulq((Q)C(m),(Q)c,(Q *)&C(mr)); |
mulq((Q)C(m),(Q)c,(Q *)&C(mr)); |
else |
else |
mulp(vl,C(m),c,&C(mr)); |
arf_mul(vl,C(m),(Obj)c,&C(mr)); |
} |
} |
if ( mr0 ) { |
if ( mr0 ) { |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
} else |
} else |
*pr = 0; |
*pr = 0; |
if ( *pr ) |
if ( *pr ) |
(*pr)->sugar = p->sugar + m0->dl->td; |
(*pr)->sugar = p->sugar + m0->dl->td; |
} |
} |
} |
} |
|
|
void weyl_muld(VL vl,DP p1,DP p2,DP *pr) |
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; |
static MP *w; |
static MP *w; |
static int wlen; |
static int wlen; |
|
|
if ( !p1 || !p2 ) |
if ( !p1 || !p2 ) |
*pr = 0; |
*pr = 0; |
else if ( OID(p1) <= O_P ) |
else if ( OID(p1) != O_DP ) |
muldc(vl,p2,(P)p1,pr); |
muldc(vl,p2,(Obj)p1,pr); |
else if ( OID(p2) <= O_P ) |
else if ( OID(p2) != O_DP ) |
muldc(vl,p1,(P)p2,pr); |
muldc(vl,p1,(Obj)p2,pr); |
else { |
else { |
for ( m = BDY(p1), l = 0; m; m = NEXT(m), l++ ); |
for ( m = BDY(p1), l = 0; m; m = NEXT(m), l++ ); |
if ( l > wlen ) { |
if ( l > wlen ) { |
if ( w ) GCFREE(w); |
if ( w ) GCFREE(w); |
w = (MP *)MALLOC(l*sizeof(MP)); |
w = (MP *)MALLOC(l*sizeof(MP)); |
wlen = l; |
wlen = l; |
} |
} |
for ( m = BDY(p1), i = 0; i < l; m = NEXT(m), i++ ) |
for ( m = BDY(p1), i = 0; i < l; m = NEXT(m), i++ ) |
w[i] = m; |
w[i] = m; |
for ( s = 0, i = l-1; i >= 0; i-- ) { |
for ( s = 0, i = l-1; i >= 0; i-- ) { |
weyl_muldm(vl,w[i],p2,&t); addd(vl,s,t,&u); s = u; |
weyl_muldm(vl,w[i],p2,&t); addd(vl,s,t,&u); s = u; |
} |
} |
bzero(w,l*sizeof(MP)); |
bzero(w,l*sizeof(MP)); |
*pr = s; |
*pr = s; |
} |
} |
} |
} |
|
|
|
void actm(VL vl,int nv,MP m1,MP m2,DP *pr) |
|
{ |
|
DL d1,d2,d; |
|
int n2,i,j,k; |
|
Q jq,c,c1; |
|
MP m; |
|
Obj t; |
|
|
|
d1 = m1->dl; |
|
d2 = m2->dl; |
|
for ( i = 0; i < nv; i++ ) |
|
if ( d1->d[i] > d2->d[i] ) { |
|
*pr = 0; return; |
|
} |
|
NEWDL(d,nv); |
|
c = ONE; |
|
for ( i = 0; i < nv; i++ ) { |
|
for ( j = d2->d[i], k = d1->d[i]; k > 0; k--, j-- ) { |
|
STOQ(j,jq); mulq(c,jq,&c1); c = c1; |
|
} |
|
d->d[i] = d2->d[i]-d1->d[i]; |
|
} |
|
arf_mul(vl,C(m1),C(m2),&t); |
|
NEWMP(m); |
|
arf_mul(vl,(Obj)c,t,&C(m)); |
|
m->dl = d; |
|
MKDP(nv,m,*pr); |
|
} |
|
|
|
void weyl_actd(VL vl,DP p1,DP p2,DP *pr) |
|
{ |
|
int n; |
|
MP m1,m2; |
|
DP d,r,s; |
|
|
|
if ( !p1 || !p2 ) *pr = 0; |
|
else { |
|
n = NV(p1); |
|
r = 0; |
|
for ( m1 = BDY(p1); m1; m1 = NEXT(m1) ) |
|
for ( m2 = BDY(p2); m2; m2 = NEXT(m2) ) { |
|
actm(vl,n,m1,m2,&d); |
|
addd(vl,r,d,&s); r = s; |
|
} |
|
*pr = r; |
|
} |
|
} |
|
|
/* monomial * polynomial */ |
/* monomial * polynomial */ |
|
|
void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
{ |
{ |
DP r,t,t1; |
DP r,t,t1; |
MP m; |
MP m; |
DL d0; |
DL d0; |
int n,n2,l,i,j,tlen; |
int n,n2,l,i,j,tlen; |
static MP *w,*psum; |
static MP *w,*psum; |
static struct cdl *tab; |
static struct cdl *tab; |
static int wlen; |
static int wlen; |
static int rtlen; |
static int rtlen; |
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
else { |
else { |
for ( m = BDY(p), l = 0; m; m = NEXT(m), l++ ); |
for ( m = BDY(p), l = 0; m; m = NEXT(m), l++ ); |
if ( l > wlen ) { |
if ( l > wlen ) { |
if ( w ) GCFREE(w); |
if ( w ) GCFREE(w); |
w = (MP *)MALLOC(l*sizeof(MP)); |
w = (MP *)MALLOC(l*sizeof(MP)); |
wlen = l; |
wlen = l; |
} |
} |
for ( m = BDY(p), i = 0; i < l; m = NEXT(m), i++ ) |
for ( m = BDY(p), i = 0; i < l; m = NEXT(m), i++ ) |
w[i] = m; |
w[i] = m; |
|
|
n = NV(p); n2 = n>>1; |
n = NV(p); n2 = n>>1; |
d0 = m0->dl; |
d0 = m0->dl; |
for ( i = 0, tlen = 1; i < n2; i++ ) |
for ( i = 0, tlen = 1; i < n2; i++ ) |
tlen *= d0->d[n2+i]+1; |
tlen *= d0->d[n2+i]+1; |
if ( tlen > rtlen ) { |
if ( tlen > rtlen ) { |
if ( tab ) GCFREE(tab); |
if ( tab ) GCFREE(tab); |
if ( psum ) GCFREE(psum); |
if ( psum ) GCFREE(psum); |
rtlen = tlen; |
rtlen = tlen; |
tab = (struct cdl *)MALLOC(rtlen*sizeof(struct cdl)); |
tab = (struct cdl *)MALLOC(rtlen*sizeof(struct cdl)); |
psum = (MP *)MALLOC(rtlen*sizeof(MP)); |
psum = (MP *)MALLOC(rtlen*sizeof(MP)); |
} |
} |
bzero(psum,tlen*sizeof(MP)); |
bzero(psum,tlen*sizeof(MP)); |
for ( i = l-1; i >= 0; i-- ) { |
for ( i = l-1; i >= 0; i-- ) { |
bzero(tab,tlen*sizeof(struct cdl)); |
bzero(tab,tlen*sizeof(struct cdl)); |
weyl_mulmm(vl,m0,w[i],n,tab,tlen); |
weyl_mulmm(vl,m0,w[i],n,tab,tlen); |
for ( j = 0; j < tlen; j++ ) { |
for ( j = 0; j < tlen; j++ ) { |
if ( tab[j].c ) { |
if ( tab[j].c ) { |
NEWMP(m); m->dl = tab[j].d; C(m) = tab[j].c; NEXT(m) = psum[j]; |
NEWMP(m); m->dl = tab[j].d; C(m) = (Obj)tab[j].c; NEXT(m) = psum[j]; |
psum[j] = m; |
psum[j] = m; |
} |
} |
} |
} |
} |
} |
for ( j = tlen-1, r = 0; j >= 0; j-- ) |
for ( j = tlen-1, r = 0; j >= 0; j-- ) |
if ( psum[j] ) { |
if ( psum[j] ) { |
MKDP(n,psum[j],t); addd(vl,r,t,&t1); r = t1; |
MKDP(n,psum[j],t); addd(vl,r,t,&t1); r = t1; |
} |
} |
if ( r ) |
if ( r ) |
r->sugar = p->sugar + m0->dl->td; |
r->sugar = p->sugar + m0->dl->td; |
*pr = r; |
*pr = r; |
} |
} |
} |
} |
|
|
/* m0 = x0^d0*x1^d1*... * dx0^e0*dx1^e1*... */ |
/* m0 = x0^d0*x1^d1*... * dx0^e0*dx1^e1*... */ |
Line 905 void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
|
Line 1034 void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
|
|
|
void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rtab,int rtablen) |
void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rtab,int rtablen) |
{ |
{ |
P c,c0,c1; |
Obj c,c0,c1; |
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; |
static Q *ctab; |
static Q *ctab; |
static struct cdl *tab; |
static struct cdl *tab; |
static int tablen; |
static int tablen; |
static struct cdl *tmptab; |
static struct cdl *tmptab; |
static int tmptablen; |
static int tmptablen; |
|
|
|
|
if ( !m0 || !m1 ) { |
if ( !m0 || !m1 ) { |
rtab[0].c = 0; |
rtab[0].c = 0; |
rtab[0].d = 0; |
rtab[0].d = 0; |
return; |
return; |
} |
} |
c0 = C(m0); c1 = C(m1); |
c0 = C(m0); c1 = C(m1); |
mulp(vl,c0,c1,&c); |
arf_mul(vl,c0,c1,&c); |
d0 = m0->dl; d1 = m1->dl; |
d0 = m0->dl; d1 = m1->dl; |
n2 = n>>1; |
n2 = n>>1; |
curlen = 1; |
curlen = 1; |
NEWDL(d,n); |
NEWDL(d,n); |
if ( n & 1 ) |
if ( n & 1 ) |
/* offset of h-degree */ |
/* offset of h-degree */ |
d->td = d->d[n-1] = d0->d[n-1]+d1->d[n-1]; |
d->td = d->d[n-1] = d0->d[n-1]+d1->d[n-1]; |
else |
else |
d->td = 0; |
d->td = 0; |
rtab[0].c = c; |
rtab[0].c = c; |
rtab[0].d = d; |
rtab[0].d = d; |
|
|
if ( rtablen > tmptablen ) { |
if ( rtablen > tmptablen ) { |
if ( tmptab ) GCFREE(tmptab); |
if ( tmptab ) GCFREE(tmptab); |
tmptab = (struct cdl *)MALLOC(rtablen*sizeof(struct cdl)); |
tmptab = (struct cdl *)MALLOC(rtablen*sizeof(struct cdl)); |
tmptablen = rtablen; |
tmptablen = rtablen; |
} |
} |
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 */ |
/* degree of xi^a*(Di^k*xi^l)*Di^b */ |
a += l; |
a += l; |
b += k; |
b += k; |
s = MUL_WEIGHT(a,i)+MUL_WEIGHT(b,n2+i); |
s = MUL_WEIGHT(a,i)+MUL_WEIGHT(b,n2+i); |
|
|
if ( !k || !l ) { |
if ( !k || !l ) { |
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; |
dt->d[i] = a; |
dt->d[i] = a; |
dt->d[n2+i] = b; |
dt->d[n2+i] = b; |
dt->td += s; |
dt->td += s; |
} |
} |
} |
} |
curlen *= k+1; |
curlen *= k+1; |
continue; |
continue; |
} |
} |
if ( k+1 > tablen ) { |
if ( k+1 > tablen ) { |
if ( tab ) GCFREE(tab); |
if ( tab ) GCFREE(tab); |
if ( ctab ) GCFREE(ctab); |
if ( ctab ) GCFREE(ctab); |
tablen = k+1; |
tablen = k+1; |
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)); |
} |
} |
/* 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); |
bzero(tab,(k+1)*sizeof(struct cdl)); |
bzero(tab,(k+1)*sizeof(struct cdl)); |
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] = a-j; d->d[n2+i] = b-j; |
d->d[i] = a-j; d->d[n2+i] = b-j; |
d->td = s; |
d->td = s; |
d->d[n-1] = s-(MUL_WEIGHT(a-j,i)+MUL_WEIGHT(b-j,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 = (Obj)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] = a-j; d->d[n2+i] = b-j; |
d->d[i] = a-j; d->d[n2+i] = b-j; |
d->td = MUL_WEIGHT(a-j,i)+MUL_WEIGHT(b-j,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 = (Obj)ctab[j]; |
} |
} |
bzero(ctab,(min+1)*sizeof(Q)); |
bzero(ctab,(min+1)*sizeof(Q)); |
comm_muld_tab(vl,n,rtab,curlen,tab,k+1,tmptab); |
comm_muld_tab(vl,n,rtab,curlen,tab,k+1,tmptab); |
curlen *= k+1; |
curlen *= k+1; |
bcopy(tmptab,rtab,curlen*sizeof(struct cdl)); |
bcopy(tmptab,rtab,curlen*sizeof(struct cdl)); |
} |
} |
} |
} |
|
|
/* direct product of two cdl tables |
/* direct product of two cdl tables |
Line 1007 void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rt |
|
Line 1136 void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rt |
|
|
|
void comm_muld_tab(VL vl,int nv,struct cdl *t,int n,struct cdl *t1,int n1,struct cdl *rt) |
void comm_muld_tab(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; |
P c; |
Obj c; |
DL d; |
DL d; |
|
|
bzero(rt,n*n1*sizeof(struct cdl)); |
bzero(rt,n*n1*sizeof(struct cdl)); |
for ( j = 0, p = rt; j < n1; j++ ) { |
for ( j = 0, p = rt; j < n1; j++ ) { |
c = t1[j].c; |
c = (Obj)t1[j].c; |
d = t1[j].d; |
d = t1[j].d; |
if ( !c ) |
if ( !c ) |
break; |
break; |
for ( i = 0; i < n; i++, p++ ) { |
for ( i = 0; i < n; i++, p++ ) { |
if ( t[i].c ) { |
if ( t[i].c ) { |
mulp(vl,t[i].c,c,&p->c); |
arf_mul(vl,(Obj)t[i].c,c,(Obj *)&p->c); |
adddl(nv,t[i].d,d,&p->d); |
adddl(nv,t[i].d,d,&p->d); |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
void muldc(VL vl,DP p,P c,DP *pr) |
void muldc(VL vl,DP p,Obj c,DP *pr) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr=0,mr0; |
|
|
if ( !p || !c ) |
if ( !p || !c ) |
*pr = 0; |
*pr = 0; |
else if ( NUM(c) && UNIQ((Q)c) ) |
else if ( NUM(c) && UNIQ((Q)c) ) |
*pr = p; |
*pr = p; |
else if ( NUM(c) && MUNIQ((Q)c) ) |
else if ( NUM(c) && MUNIQ((Q)c) ) |
chsgnd(p,pr); |
chsgnd(p,pr); |
else { |
else { |
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
NEXTMP(mr0,mr); |
NEXTMP(mr0,mr); |
if ( NUM(C(m)) && RATN(C(m)) && NUM(c) && RATN(c) ) |
if ( NUM(C(m)) && RATN(C(m)) && NUM(c) && RATN(c) ) |
mulq((Q)C(m),(Q)c,(Q *)&C(mr)); |
mulq((Q)C(m),(Q)c,(Q *)&C(mr)); |
else |
else |
mulp(vl,C(m),c,&C(mr)); |
arf_mul(vl,C(m),c,&C(mr)); |
mr->dl = m->dl; |
mr->dl = m->dl; |
} |
} |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
if ( *pr ) |
if ( *pr ) |
(*pr)->sugar = p->sugar; |
(*pr)->sugar = p->sugar; |
} |
} |
} |
} |
|
|
void muldc_trunc(VL vl,DP p,P c,DL dl,DP *pr) |
void divdc(VL vl,DP p,Obj c,DP *pr) |
{ |
{ |
MP m,mr,mr0; |
Obj inv; |
DL mdl; |
|
int i,n; |
|
|
|
if ( !p || !c ) { |
arf_div(vl,(Obj)ONE,c,&inv); |
*pr = 0; return; |
muld(vl,p,(DP)inv,pr); |
} |
|
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 muldc_trunc(VL vl,DP p,Obj c,DL dl,DP *pr) |
|
{ |
|
MP m,mr=0,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 |
|
arf_mul(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) |
void divsdc(VL vl,DP p,P c,DP *pr) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr=0,mr0; |
|
|
if ( !c ) |
if ( !c ) |
error("disvsdc : division by 0"); |
error("disvsdc : division by 0"); |
else if ( !p ) |
else if ( !p ) |
*pr = 0; |
*pr = 0; |
else { |
else if ( OID(p) > O_P ) |
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
error("divsdc : invalid argument"); |
NEXTMP(mr0,mr); divsp(vl,C(m),c,&C(mr)); mr->dl = m->dl; |
else { |
} |
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
NEXTMP(mr0,mr); divsp(vl,(P)C(m),c,(P *)&C(mr)); mr->dl = m->dl; |
if ( *pr ) |
} |
(*pr)->sugar = p->sugar; |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
} |
if ( *pr ) |
|
(*pr)->sugar = p->sugar; |
|
} |
} |
} |
|
|
void adddl(int n,DL d1,DL d2,DL *dr) |
void adddl(int n,DL d1,DL d2,DL *dr) |
{ |
{ |
DL dt; |
DL dt; |
int i; |
int i; |
|
|
*dr = dt = (DL)MALLOC_ATOMIC((n+1)*sizeof(int)); |
*dr = dt = (DL)MALLOC_ATOMIC((n+1)*sizeof(int)); |
dt->td = d1->td + d2->td; |
dt->td = d1->td + d2->td; |
for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
dt->d[i] = d1->d[i]+d2->d[i]; |
dt->d[i] = d1->d[i]+d2->d[i]; |
} |
} |
|
|
/* d1 += d2 */ |
/* d1 += d2 */ |
|
|
void adddl_destructive(int n,DL d1,DL d2) |
void adddl_destructive(int n,DL d1,DL d2) |
{ |
{ |
int i; |
int i; |
|
|
d1->td += d2->td; |
d1->td += d2->td; |
for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
d1->d[i] += d2->d[i]; |
d1->d[i] += d2->d[i]; |
} |
} |
|
|
int compd(VL vl,DP p1,DP p2) |
int compd(VL vl,DP p1,DP p2) |
{ |
{ |
int n,t; |
int n,t; |
MP m1,m2; |
MP m1,m2; |
|
|
if ( !p1 ) |
if ( !p1 ) |
return p2 ? -1 : 0; |
return p2 ? -1 : 0; |
else if ( !p2 ) |
else if ( !p2 ) |
return 1; |
return 1; |
else if ( NV(p1) != NV(p2) ) |
else if ( NV(p1) != NV(p2) ) { |
error("compd : size mismatch"); |
error("compd : size mismatch"); |
else { |
return 0; /* XXX */ |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2); |
} else { |
m1 && m2; m1 = NEXT(m1), m2 = NEXT(m2) ) |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2); |
if ( (t = (*cmpdl)(n,m1->dl,m2->dl)) || |
m1 && m2; m1 = NEXT(m1), m2 = NEXT(m2) ) |
(t = compp(vl,C(m1),C(m2)) ) ) |
if ( (t = (*cmpdl)(n,m1->dl,m2->dl)) || |
return t; |
(t = arf_comp(vl,C(m1),C(m2)) ) ) |
if ( m1 ) |
return t; |
return 1; |
if ( m1 ) |
else if ( m2 ) |
return 1; |
return -1; |
else if ( m2 ) |
else |
return -1; |
return 0; |
else |
} |
return 0; |
|
} |
} |
} |
|
|
int cmpdl_lex(int n,DL d1,DL d2) |
int cmpdl_lex(int n,DL d1,DL d2) |
{ |
{ |
int i; |
int i; |
|
|
for ( i = 0; i < n && d1->d[i] == d2->d[i]; i++ ); |
for ( i = 0; i < n && d1->d[i] == d2->d[i]; 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(int n,DL d1,DL d2) |
int cmpdl_revlex(int n,DL d1,DL d2) |
{ |
{ |
int i; |
int i; |
|
|
for ( i = n - 1; i >= 0 && d1->d[i] == d2->d[i]; i-- ); |
for ( i = n - 1; i >= 0 && d1->d[i] == d2->d[i]; 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(int n,DL d1,DL d2) |
int cmpdl_gradlex(int n,DL d1,DL d2) |
{ |
{ |
if ( d1->td > d2->td ) |
if ( d1->td > d2->td ) |
return 1; |
return 1; |
else if ( d1->td < d2->td ) |
else if ( d1->td < d2->td ) |
return -1; |
return -1; |
else |
else |
return cmpdl_lex(n,d1,d2); |
return cmpdl_lex(n,d1,d2); |
} |
} |
|
|
int cmpdl_revgradlex(int n,DL d1,DL d2) |
int cmpdl_revgradlex(int n,DL d1,DL d2) |
{ |
{ |
register int i,c; |
register int i,c; |
register int *p1,*p2; |
register int *p1,*p2; |
|
|
if ( d1->td > d2->td ) |
if ( d1->td > d2->td ) |
return 1; |
return 1; |
else if ( d1->td < d2->td ) |
else if ( d1->td < d2->td ) |
return -1; |
return -1; |
else { |
else { |
i = n-1; |
i = n-1; |
p1 = d1->d+n-1; |
p1 = d1->d+n-1; |
p2 = d2->d+n-1; |
p2 = d2->d+n-1; |
while ( i >= 7 ) { |
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; |
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; |
i -= 8; |
} |
} |
switch ( i ) { |
switch ( i ) { |
case 6: |
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; |
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; |
return 0; |
case 5: |
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; |
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; |
return 0; |
case 4: |
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; |
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; |
return 0; |
case 3: |
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; |
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; |
return 0; |
case 2: |
case 2: |
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; |
return 0; |
case 1: |
case 1: |
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; |
return 0; |
case 0: |
case 0: |
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
c = (*p1--) - (*p2--); if ( c ) goto LAST; |
return 0; |
return 0; |
default: |
default: |
return 0; |
return 0; |
} |
} |
LAST: |
LAST: |
if ( c > 0 ) return -1; |
if ( c > 0 ) return -1; |
else return 1; |
else return 1; |
} |
} |
} |
} |
|
|
int cmpdl_blex(int n,DL d1,DL d2) |
int cmpdl_blex(int n,DL d1,DL d2) |
{ |
{ |
int c; |
int c; |
|
|
if ( c = cmpdl_lex(n-1,d1,d2) ) |
if ( (c = cmpdl_lex(n-1,d1,d2)) ) |
return c; |
return c; |
else { |
else { |
c = d1->d[n-1] - d2->d[n-1]; |
c = d1->d[n-1] - d2->d[n-1]; |
return c > 0 ? 1 : c < 0 ? -1 : 0; |
return c > 0 ? 1 : c < 0 ? -1 : 0; |
} |
} |
} |
} |
|
|
int cmpdl_bgradlex(int n,DL d1,DL d2) |
int cmpdl_bgradlex(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,c; |
int e1,e2,c; |
|
|
e1 = d1->td - d1->d[n-1]; e2 = d2->td - d2->d[n-1]; |
e1 = d1->td - d1->d[n-1]; e2 = d2->td - d2->d[n-1]; |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
else { |
else { |
c = cmpdl_lex(n-1,d1,d2); |
c = cmpdl_lex(n-1,d1,d2); |
if ( c ) |
if ( c ) |
return c; |
return c; |
else |
else |
return d1->td > d2->td ? 1 : d1->td < d2->td ? -1 : 0; |
return d1->td > d2->td ? 1 : d1->td < d2->td ? -1 : 0; |
} |
} |
} |
} |
|
|
int cmpdl_brevgradlex(int n,DL d1,DL d2) |
int cmpdl_brevgradlex(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,c; |
int e1,e2,c; |
|
|
e1 = d1->td - d1->d[n-1]; e2 = d2->td - d2->d[n-1]; |
e1 = d1->td - d1->d[n-1]; e2 = d2->td - d2->d[n-1]; |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
else { |
else { |
c = cmpdl_revlex(n-1,d1,d2); |
c = cmpdl_revlex(n-1,d1,d2); |
if ( c ) |
if ( c ) |
return c; |
return c; |
else |
else |
return d1->td > d2->td ? 1 : d1->td < d2->td ? -1 : 0; |
return d1->td > d2->td ? 1 : d1->td < d2->td ? -1 : 0; |
} |
} |
} |
} |
|
|
int cmpdl_brevrev(int n,DL d1,DL d2) |
int cmpdl_brevrev(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,f1,f2,c,i; |
int e1,e2,f1,f2,c,i; |
|
|
for ( i = 0, e1 = 0, e2 = 0; i < dp_nelim; i++ ) { |
for ( i = 0, e1 = 0, e2 = 0; i < dp_nelim; i++ ) { |
e1 += d1->d[i]; e2 += d2->d[i]; |
e1 += d1->d[i]; e2 += d2->d[i]; |
} |
} |
f1 = d1->td - e1; f2 = d2->td - e2; |
f1 = d1->td - e1; f2 = d2->td - e2; |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
else { |
else { |
c = cmpdl_revlex(dp_nelim,d1,d2); |
c = cmpdl_revlex(dp_nelim,d1,d2); |
if ( c ) |
if ( c ) |
return c; |
return c; |
else if ( f1 > f2 ) |
else if ( f1 > f2 ) |
return 1; |
return 1; |
else if ( f1 < f2 ) |
else if ( f1 < f2 ) |
return -1; |
return -1; |
else { |
else { |
for ( i = n - 1; i >= dp_nelim && d1->d[i] == d2->d[i]; i-- ); |
for ( i = n - 1; i >= dp_nelim && d1->d[i] == d2->d[i]; i-- ); |
return i < dp_nelim ? 0 : (d1->d[i] < d2->d[i] ? 1 : -1); |
return i < dp_nelim ? 0 : (d1->d[i] < d2->d[i] ? 1 : -1); |
} |
} |
} |
} |
} |
} |
|
|
int cmpdl_bgradrev(int n,DL d1,DL d2) |
int cmpdl_bgradrev(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,f1,f2,c,i; |
int e1,e2,f1,f2,c,i; |
|
|
for ( i = 0, e1 = 0, e2 = 0; i < dp_nelim; i++ ) { |
for ( i = 0, e1 = 0, e2 = 0; i < dp_nelim; i++ ) { |
e1 += d1->d[i]; e2 += d2->d[i]; |
e1 += d1->d[i]; e2 += d2->d[i]; |
} |
} |
f1 = d1->td - e1; f2 = d2->td - e2; |
f1 = d1->td - e1; f2 = d2->td - e2; |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
else { |
else { |
c = cmpdl_lex(dp_nelim,d1,d2); |
c = cmpdl_lex(dp_nelim,d1,d2); |
if ( c ) |
if ( c ) |
return c; |
return c; |
else if ( f1 > f2 ) |
else if ( f1 > f2 ) |
return 1; |
return 1; |
else if ( f1 < f2 ) |
else if ( f1 < f2 ) |
return -1; |
return -1; |
else { |
else { |
for ( i = n - 1; i >= dp_nelim && d1->d[i] == d2->d[i]; i-- ); |
for ( i = n - 1; i >= dp_nelim && d1->d[i] == d2->d[i]; i-- ); |
return i < dp_nelim ? 0 : (d1->d[i] < d2->d[i] ? 1 : -1); |
return i < dp_nelim ? 0 : (d1->d[i] < d2->d[i] ? 1 : -1); |
} |
} |
} |
} |
} |
} |
|
|
int cmpdl_blexrev(int n,DL d1,DL d2) |
int cmpdl_blexrev(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,f1,f2,c,i; |
int e1,e2,f1,f2,c,i; |
|
|
for ( i = 0, e1 = 0, e2 = 0; i < dp_nelim; i++ ) { |
for ( i = 0, e1 = 0, e2 = 0; i < dp_nelim; i++ ) { |
e1 += d1->d[i]; e2 += d2->d[i]; |
e1 += d1->d[i]; e2 += d2->d[i]; |
} |
} |
f1 = d1->td - e1; f2 = d2->td - e2; |
f1 = d1->td - e1; f2 = d2->td - e2; |
c = cmpdl_lex(dp_nelim,d1,d2); |
c = cmpdl_lex(dp_nelim,d1,d2); |
if ( c ) |
if ( c ) |
return c; |
return c; |
else if ( f1 > f2 ) |
else if ( f1 > f2 ) |
return 1; |
return 1; |
else if ( f1 < f2 ) |
else if ( f1 < f2 ) |
return -1; |
return -1; |
else { |
else { |
for ( i = n - 1; i >= dp_nelim && d1->d[i] == d2->d[i]; i-- ); |
for ( i = n - 1; i >= dp_nelim && d1->d[i] == d2->d[i]; i-- ); |
return i < dp_nelim ? 0 : (d1->d[i] < d2->d[i] ? 1 : -1); |
return i < dp_nelim ? 0 : (d1->d[i] < d2->d[i] ? 1 : -1); |
} |
} |
} |
} |
|
|
int cmpdl_elim(int n,DL d1,DL d2) |
int cmpdl_elim(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,i; |
int e1,e2,i; |
|
|
for ( i = 0, e1 = 0, e2 = 0; i < dp_nelim; i++ ) { |
for ( i = 0, e1 = 0, e2 = 0; i < dp_nelim; i++ ) { |
e1 += d1->d[i]; e2 += d2->d[i]; |
e1 += d1->d[i]; e2 += d2->d[i]; |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
else |
else |
return cmpdl_revgradlex(n,d1,d2); |
return cmpdl_revgradlex(n,d1,d2); |
} |
} |
|
|
int cmpdl_weyl_elim(int n,DL d1,DL d2) |
int cmpdl_weyl_elim(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,i; |
int e1,e2,i; |
|
|
for ( i = 1, e1 = 0, e2 = 0; i <= dp_nelim; i++ ) { |
for ( i = 1, e1 = 0, e2 = 0; i <= dp_nelim; i++ ) { |
e1 += d1->d[n-i]; e2 += d2->d[n-i]; |
e1 += d1->d[n-i]; e2 += d2->d[n-i]; |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
else if ( d1->td > d2->td ) |
else if ( d1->td > d2->td ) |
return 1; |
return 1; |
else if ( d1->td < d2->td ) |
else if ( d1->td < d2->td ) |
return -1; |
return -1; |
else return -cmpdl_revlex(n,d1,d2); |
else return -cmpdl_revlex(n,d1,d2); |
} |
} |
|
|
/* |
/* |
a special ordering |
a special ordering |
1. total order |
1. total order |
2. (-w,w) for the first 2*m variables |
2. (-w,w) for the first 2*m variables |
3. DRL for the first 2*m variables |
3. DRL for the first 2*m variables |
*/ |
*/ |
|
|
extern int *current_weyl_weight_vector; |
extern int *current_weyl_weight_vector; |
|
|
int cmpdl_homo_ww_drl(int n,DL d1,DL d2) |
int cmpdl_homo_ww_drl(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,m,i; |
int e1,e2,m,i; |
int *p1,*p2; |
int *p1,*p2; |
|
|
if ( d1->td > d2->td ) |
if ( d1->td > d2->td ) |
return 1; |
return 1; |
else if ( d1->td < d2->td ) |
else if ( d1->td < d2->td ) |
return -1; |
return -1; |
|
|
m = n>>1; |
m = n>>1; |
for ( i = 0, e1 = e2 = 0, p1 = d1->d, p2 = d2->d; i < m; i++ ) { |
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]); |
e1 += current_weyl_weight_vector[i]*(p1[m+i] - p1[i]); |
e2 += current_weyl_weight_vector[i]*(p2[m+i] - p2[i]); |
e2 += current_weyl_weight_vector[i]*(p2[m+i] - p2[i]); |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
|
|
e1 = d1->td - d1->d[n-1]; |
e1 = d1->td - d1->d[n-1]; |
e2 = d2->td - d2->d[n-1]; |
e2 = d2->td - d2->d[n-1]; |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
|
|
for ( i= n - 1, p1 = d1->d+n-1, p2 = d2->d+n-1; |
for ( i= n - 1, p1 = d1->d+n-1, p2 = d2->d+n-1; |
i >= 0 && *p1 == *p2; i--, p1--, p2-- ); |
i >= 0 && *p1 == *p2; i--, p1--, p2-- ); |
return i < 0 ? 0 : (*p1 < *p2 ? 1 : -1); |
return i < 0 ? 0 : (*p1 < *p2 ? 1 : -1); |
} |
} |
|
|
int cmpdl_drl_zigzag(int n,DL d1,DL d2) |
int cmpdl_drl_zigzag(int n,DL d1,DL d2) |
{ |
{ |
int i,t,m; |
int i,t,m; |
int *p1,*p2; |
int *p1,*p2; |
|
|
if ( d1->td > d2->td ) |
if ( d1->td > d2->td ) |
return 1; |
return 1; |
else if ( d1->td < d2->td ) |
else if ( d1->td < d2->td ) |
return -1; |
return -1; |
else { |
else { |
m = n>>1; |
m = n>>1; |
for ( i= m - 1, p1 = d1->d, p2 = d2->d; i >= 0; i-- ) { |
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[m+i] - p2[m+i]) ) return t > 0 ? -1 : 1; |
if ( t = p1[i] - p2[i] ) return t > 0 ? -1 : 1; |
if ( (t = p1[i] - p2[i]) ) return t > 0 ? -1 : 1; |
} |
} |
return 0; |
return 0; |
} |
} |
} |
} |
|
|
int cmpdl_homo_ww_drl_zigzag(int n,DL d1,DL d2) |
int cmpdl_homo_ww_drl_zigzag(int n,DL d1,DL d2) |
{ |
{ |
int e1,e2,m,i,t; |
int e1,e2,m,i,t; |
int *p1,*p2; |
int *p1,*p2; |
|
|
if ( d1->td > d2->td ) |
if ( d1->td > d2->td ) |
return 1; |
return 1; |
else if ( d1->td < d2->td ) |
else if ( d1->td < d2->td ) |
return -1; |
return -1; |
|
|
m = n>>1; |
m = n>>1; |
for ( i = 0, e1 = e2 = 0, p1 = d1->d, p2 = d2->d; i < m; i++ ) { |
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]); |
e1 += current_weyl_weight_vector[i]*(p1[m+i] - p1[i]); |
e2 += current_weyl_weight_vector[i]*(p2[m+i] - p2[i]); |
e2 += current_weyl_weight_vector[i]*(p2[m+i] - p2[i]); |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
|
|
e1 = d1->td - d1->d[n-1]; |
e1 = d1->td - d1->d[n-1]; |
e2 = d2->td - d2->d[n-1]; |
e2 = d2->td - d2->d[n-1]; |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
|
|
for ( i= m - 1, p1 = d1->d, p2 = d2->d; i >= 0; i-- ) { |
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[m+i] - p2[m+i]) ) return t > 0 ? -1 : 1; |
if ( t = p1[i] - p2[i] ) return t > 0 ? -1 : 1; |
if ( (t = p1[i] - p2[i]) ) return t > 0 ? -1 : 1; |
} |
} |
return 0; |
return 0; |
} |
} |
|
|
int cmpdl_order_pair(int n,DL d1,DL d2) |
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,head; |
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; |
if ( n != dp_current_spec->nv ) |
if ( n != dp_current_spec->nv ) |
error("cmpdl_order_pair : incompatible order specification"); |
error("cmpdl_order_pair : incompatible order specification"); |
pair = dp_current_spec->ord.block.order_pair; |
pair = dp_current_spec->ord.block.order_pair; |
|
|
head = 0; |
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 += MUL_WEIGHT(t1[j],head+j); |
e1 += MUL_WEIGHT(t1[j],head+j); |
e2 += MUL_WEIGHT(t2[j],head+j); |
e2 += MUL_WEIGHT(t2[j],head+j); |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
else { |
else { |
for ( j = l - 1; j >= 0 && t1[j] == t2[j]; j-- ); |
for ( j = l - 1; j >= 0 && t1[j] == t2[j]; j-- ); |
if ( j >= 0 ) |
if ( j >= 0 ) |
return t1[j] < t2[j] ? 1 : -1; |
return t1[j] < t2[j] ? 1 : -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 += MUL_WEIGHT(t1[j],head+j); |
e1 += MUL_WEIGHT(t1[j],head+j); |
e2 += MUL_WEIGHT(t2[j],head+j); |
e2 += MUL_WEIGHT(t2[j],head+j); |
} |
} |
if ( e1 > e2 ) |
if ( e1 > e2 ) |
return 1; |
return 1; |
else if ( e1 < e2 ) |
else if ( e1 < e2 ) |
return -1; |
return -1; |
else { |
else { |
for ( j = 0; j < l && t1[j] == t2[j]; j++ ); |
for ( j = 0; j < l && t1[j] == t2[j]; j++ ); |
if ( j < l ) |
if ( j < l ) |
return t1[j] > t2[j] ? 1 : -1; |
return t1[j] > t2[j] ? 1 : -1; |
} |
} |
break; |
break; |
case 2: |
case 2: |
for ( j = 0; j < l && t1[j] == t2[j]; j++ ); |
for ( j = 0; j < l && t1[j] == t2[j]; j++ ); |
if ( j < l ) |
if ( j < l ) |
return t1[j] > t2[j] ? 1 : -1; |
return t1[j] > t2[j] ? 1 : -1; |
break; |
break; |
default: |
default: |
error("cmpdl_order_pair : invalid order"); break; |
error("cmpdl_order_pair : invalid order"); break; |
} |
} |
t1 += l; t2 += l; head += l; |
t1 += l; t2 += l; head += l; |
} |
} |
return 0; |
return 0; |
} |
} |
|
|
int cmpdl_composite(int nv,DL d1,DL d2) |
int cmpdl_composite(int nv,DL d1,DL d2) |
{ |
{ |
int n,i,j,k,start,s,len; |
int n,i,j,k,start,s,len; |
int *dw; |
int *dw; |
struct sparse_weight *sw; |
struct sparse_weight *sw; |
struct weight_or_block *worb; |
struct weight_or_block *worb; |
int *w,*t1,*t2; |
int *w,*t1,*t2; |
|
|
n = dp_current_spec->ord.composite.length; |
n = dp_current_spec->ord.composite.length; |
worb = dp_current_spec->ord.composite.w_or_b; |
worb = dp_current_spec->ord.composite.w_or_b; |
w = dp_dl_work; |
w = dp_dl_work; |
for ( i = 0, t1 = d1->d, t2 = d2->d; i < nv; i++ ) |
for ( i = 0, t1 = d1->d, t2 = d2->d; i < nv; i++ ) |
w[i] = t1[i]-t2[i]; |
w[i] = t1[i]-t2[i]; |
for ( i = 0; i < n; i++, worb++ ) { |
for ( i = 0; i < n; i++, worb++ ) { |
len = worb->length; |
len = worb->length; |
switch ( worb->type ) { |
switch ( worb->type ) { |
case IS_DENSE_WEIGHT: |
case IS_DENSE_WEIGHT: |
dw = worb->body.dense_weight; |
dw = worb->body.dense_weight; |
for ( j = 0, s = 0; j < len; j++ ) |
for ( j = 0, s = 0; j < len; j++ ) |
s += dw[j]*w[j]; |
s += dw[j]*w[j]; |
if ( s > 0 ) return 1; |
if ( s > 0 ) return 1; |
else if ( s < 0 ) return -1; |
else if ( s < 0 ) return -1; |
break; |
break; |
case IS_SPARSE_WEIGHT: |
case IS_SPARSE_WEIGHT: |
sw = worb->body.sparse_weight; |
sw = worb->body.sparse_weight; |
for ( j = 0, s = 0; j < len; j++ ) |
for ( j = 0, s = 0; j < len; j++ ) |
s += sw[j].value*w[sw[j].pos]; |
s += sw[j].value*w[sw[j].pos]; |
if ( s > 0 ) return 1; |
if ( s > 0 ) return 1; |
else if ( s < 0 ) return -1; |
else if ( s < 0 ) return -1; |
break; |
break; |
case IS_BLOCK: |
case IS_BLOCK: |
start = worb->body.block.start; |
start = worb->body.block.start; |
switch ( worb->body.block.order ) { |
switch ( worb->body.block.order ) { |
case 0: |
case 0: |
for ( j = 0, k = start, s = 0; j < len; j++, k++ ) { |
for ( j = 0, k = start, s = 0; j < len; j++, k++ ) { |
s += MUL_WEIGHT(w[k],k); |
s += MUL_WEIGHT(w[k],k); |
} |
} |
if ( s > 0 ) return 1; |
if ( s > 0 ) return 1; |
else if ( s < 0 ) return -1; |
else if ( s < 0 ) return -1; |
else { |
else { |
for ( j = k-1; j >= start && w[j] == 0; j-- ); |
for ( j = k-1; j >= start && w[j] == 0; j-- ); |
if ( j >= start ) |
if ( j >= start ) |
return w[j] < 0 ? 1 : -1; |
return w[j] < 0 ? 1 : -1; |
} |
} |
break; |
break; |
case 1: |
case 1: |
for ( j = 0, k = start, s = 0; j < len; j++, k++ ) { |
for ( j = 0, k = start, s = 0; j < len; j++, k++ ) { |
s += MUL_WEIGHT(w[k],k); |
s += MUL_WEIGHT(w[k],k); |
} |
} |
if ( s > 0 ) return 1; |
if ( s > 0 ) return 1; |
else if ( s < 0 ) return -1; |
else if ( s < 0 ) return -1; |
else { |
else { |
for ( j = 0, k = start; j < len && w[j] == 0; j++, k++ ); |
for ( j = 0, k = start; j < len && w[j] == 0; j++, k++ ); |
if ( j < len ) |
if ( j < len ) |
return w[j] > 0 ? 1 : -1; |
return w[j] > 0 ? 1 : -1; |
} |
} |
break; |
break; |
case 2: |
case 2: |
for ( j = 0, k = start; j < len && w[j] == 0; j++, k++ ); |
for ( j = 0, k = start; j < len && w[j] == 0; j++, k++ ); |
if ( j < len ) |
if ( j < len ) |
return w[j] > 0 ? 1 : -1; |
return w[j] > 0 ? 1 : -1; |
break; |
break; |
} |
} |
break; |
break; |
} |
} |
} |
} |
return 0; |
return 0; |
} |
} |
|
|
int cmpdl_matrix(int n,DL d1,DL d2) |
int cmpdl_matrix(int n,DL d1,DL d2) |
{ |
{ |
int *v,*w,*t1,*t2; |
int *v,*w,*t1,*t2; |
int s,i,j,len; |
int s,i,j,len; |
int **matrix; |
int **matrix; |
|
|
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++ ) |
s += v[i]*w[i]; |
s += v[i]*w[i]; |
if ( s > 0 ) |
if ( s > 0 ) |
return 1; |
return 1; |
else if ( s < 0 ) |
else if ( s < 0 ) |
return -1; |
return -1; |
} |
} |
return 0; |
return 0; |
} |
} |
|
|
int cmpdl_top_weight(int n,DL d1,DL d2) |
int cmpdl_top_weight(int n,DL d1,DL d2) |
{ |
{ |
int *w; |
int *w; |
N sum,wm,wma,t; |
N sum,wm,wma,t; |
N *a; |
Q **mat; |
struct oN tn; |
Q *a; |
int len,i,sgn,tsgn; |
struct oN tn; |
int *t1,*t2; |
int len,i,sgn,tsgn,row,k; |
|
int *t1,*t2; |
|
|
w = (int *)ALLOCA(n*sizeof(int)); |
w = (int *)ALLOCA(n*sizeof(int)); |
len = current_top_weight_len+3; |
len = current_top_weight_len+3; |
t1 = d1->d; t2 = d2->d; |
t1 = d1->d; t2 = d2->d; |
for ( i = 0; i < n; i++ ) w[i] = t1[i]-t2[i]; |
for ( i = 0; i < n; i++ ) w[i] = t1[i]-t2[i]; |
sum = (N)W_ALLOC(len); sgn = 0; |
sum = (N)W_ALLOC(len); sgn = 0; |
wm = (N)W_ALLOC(len); |
wm = (N)W_ALLOC(len); |
wma = (N)W_ALLOC(len); |
wma = (N)W_ALLOC(len); |
a = current_top_weight_vector; |
if ( OID(current_top_weight) == O_VECT ) { |
for ( i = 0; i < n; i++ ) { |
mat = (Q **)&BDY((VECT)current_top_weight); |
if ( !a[i] || !w[i] ) continue; |
row = 1; |
tn.p = 1; |
} else { |
if ( w[i] > 0 ) { |
mat = (Q **)BDY((MAT)current_top_weight); |
tn.b[0] = w[i]; tsgn = 1; |
row = ((MAT)current_top_weight)->row; |
} else { |
} |
tn.b[0] = -w[i]; tsgn = -1; |
for ( k = 0; k < row; k++ ) { |
} |
a = mat[k]; |
_muln(a[i],&tn,wm); |
for ( i = 0; i < n; i++ ) { |
if ( !sgn ) { |
if ( !a[i] || !w[i] ) continue; |
sgn = tsgn; |
tn.p = 1; |
t = wm; wm = sum; sum = t; |
if ( w[i] > 0 ) { |
} else if ( sgn == tsgn ) { |
tn.b[0] = w[i]; tsgn = 1; |
_addn(sum,wm,wma); |
} else { |
if ( !PL(wma) ) |
tn.b[0] = -w[i]; tsgn = -1; |
sgn = 0; |
} |
t = wma; wma = sum; sum = t; |
_muln(NM(a[i]),&tn,wm); |
} else { |
if ( !sgn ) { |
sgn *= _subn(sum,wm,wma); |
sgn = tsgn; |
t = wma; wma = sum; sum = t; |
t = wm; wm = sum; sum = t; |
} |
} else if ( sgn == tsgn ) { |
} |
_addn(sum,wm,wma); |
if ( sgn > 0 ) return 1; |
if ( !PL(wma) ) |
else if ( sgn < 0 ) return -1; |
sgn = 0; |
else return (*cmpdl_tie_breaker)(n,d1,d2); |
t = wma; wma = sum; sum = t; |
|
} else { |
|
sgn *= _subn(sum,wm,wma); |
|
t = wma; wma = sum; sum = t; |
|
} |
|
} |
|
if ( sgn > 0 ) return 1; |
|
else if ( sgn < 0 ) return -1; |
|
} |
|
return (*cmpdl_tie_breaker)(n,d1,d2); |
} |
} |
|
|
GeoBucket create_bucket() |
GeoBucket create_bucket() |
{ |
{ |
GeoBucket g; |
GeoBucket g; |
|
|
g = CALLOC(1,sizeof(struct oGeoBucket)); |
g = CALLOC(1,sizeof(struct oGeoBucket)); |
g->m = 32; |
g->m = 32; |
return g; |
return g; |
} |
} |
|
|
|
int length(NODE d); |
|
|
void add_bucket(GeoBucket g,NODE d,int nv) |
void add_bucket(GeoBucket g,NODE d,int nv) |
{ |
{ |
int l,k,m; |
int l,k,m; |
|
|
l = length(d); |
l = length(d); |
for ( k = 0, m = 1; l > m; k++, m <<= 1 ); |
for ( k = 0, m = 1; l > m; k++, m <<= 1 ); |
/* 2^(k-1) < l <= 2^k */ |
/* 2^(k-1) < l <= 2^k */ |
d = symb_merge(g->body[k],d,nv); |
d = symb_merge(g->body[k],d,nv); |
for ( ; length(d) > (1<<(k)); k++ ) { |
for ( ; length(d) > (1<<(k)); k++ ) { |
g->body[k] = 0; |
g->body[k] = 0; |
d = symb_merge(g->body[k+1],d,nv); |
d = symb_merge(g->body[k+1],d,nv); |
} |
} |
g->body[k] = d; |
g->body[k] = d; |
g->m = MAX(g->m,k); |
g->m = MAX(g->m,k); |
} |
} |
|
|
DL remove_head_bucket(GeoBucket g,int nv) |
DL remove_head_bucket(GeoBucket g,int nv) |
{ |
{ |
int j,i,c,m; |
int j,i,c,m; |
DL d; |
DL d; |
|
|
j = -1; |
j = -1; |
m = g->m; |
m = g->m; |
for ( i = 0; i <= m; i++ ) { |
for ( i = 0; i <= m; i++ ) { |
if ( !g->body[i] ) |
if ( !g->body[i] ) |
continue; |
continue; |
if ( j < 0 ) j = i; |
if ( j < 0 ) j = i; |
else { |
else { |
c = (*cmpdl)(nv,g->body[i]->body,g->body[j]->body); |
c = (*cmpdl)(nv,g->body[i]->body,g->body[j]->body); |
if ( c > 0 ) |
if ( c > 0 ) |
j = i; |
j = i; |
else if ( c == 0 ) |
else if ( c == 0 ) |
g->body[i] = NEXT(g->body[i]); |
g->body[i] = NEXT(g->body[i]); |
} |
} |
} |
} |
if ( j < 0 ) |
if ( j < 0 ) |
return 0; |
return 0; |
else { |
else { |
d = g->body[j]->body; |
d = g->body[j]->body; |
g->body[j] = NEXT(g->body[j]); |
g->body[j] = NEXT(g->body[j]); |
return d; |
return d; |
} |
} |
} |
} |
|
|
/* DPV functions */ |
/* DPV functions */ |
|
|
void adddv(VL vl,DPV p1,DPV p2,DPV *pr) |
void adddv(VL vl,DPV p1,DPV p2,DPV *pr) |
{ |
{ |
int i,len; |
int i,len; |
DP *e; |
DP *e; |
|
|
if ( !p1 || !p2 ) |
if ( !p1 || !p2 ) |
error("adddv : invalid argument"); |
error("adddv : invalid argument"); |
else if ( p1->len != p2->len ) |
else if ( p1->len != p2->len ) |
error("adddv : size mismatch"); |
error("adddv : size mismatch"); |
else { |
else { |
len = p1->len; |
len = p1->len; |
e = (DP *)MALLOC(p1->len*sizeof(DP)); |
e = (DP *)MALLOC(p1->len*sizeof(DP)); |
for ( i = 0; i < len; i++ ) |
for ( i = 0; i < len; i++ ) |
addd(vl,p1->body[i],p2->body[i],&e[i]); |
addd(vl,p1->body[i],p2->body[i],&e[i]); |
MKDPV(len,e,*pr); |
MKDPV(len,e,*pr); |
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
} |
} |
} |
} |
|
|
void subdv(VL vl,DPV p1,DPV p2,DPV *pr) |
void subdv(VL vl,DPV p1,DPV p2,DPV *pr) |
{ |
{ |
int i,len; |
int i,len; |
DP *e; |
DP *e; |
|
|
if ( !p1 || !p2 ) |
if ( !p1 || !p2 ) |
error("subdv : invalid argument"); |
error("subdv : invalid argument"); |
else if ( p1->len != p2->len ) |
else if ( p1->len != p2->len ) |
error("subdv : size mismatch"); |
error("subdv : size mismatch"); |
else { |
else { |
len = p1->len; |
len = p1->len; |
e = (DP *)MALLOC(p1->len*sizeof(DP)); |
e = (DP *)MALLOC(p1->len*sizeof(DP)); |
for ( i = 0; i < len; i++ ) |
for ( i = 0; i < len; i++ ) |
subd(vl,p1->body[i],p2->body[i],&e[i]); |
subd(vl,p1->body[i],p2->body[i],&e[i]); |
MKDPV(len,e,*pr); |
MKDPV(len,e,*pr); |
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
} |
} |
} |
} |
|
|
void chsgndv(DPV p1,DPV *pr) |
void chsgndv(DPV p1,DPV *pr) |
{ |
{ |
int i,len; |
int i,len; |
DP *e; |
DP *e; |
|
|
if ( !p1 ) |
if ( !p1 ) |
error("subdv : invalid argument"); |
error("subdv : invalid argument"); |
else { |
else { |
len = p1->len; |
len = p1->len; |
e = (DP *)MALLOC(p1->len*sizeof(DP)); |
e = (DP *)MALLOC(p1->len*sizeof(DP)); |
for ( i = 0; i < len; i++ ) |
for ( i = 0; i < len; i++ ) |
chsgnd(p1->body[i],&e[i]); |
chsgnd(p1->body[i],&e[i]); |
MKDPV(len,e,*pr); |
MKDPV(len,e,*pr); |
(*pr)->sugar = p1->sugar; |
(*pr)->sugar = p1->sugar; |
} |
} |
} |
} |
|
|
void muldv(VL vl,DP p1,DPV p2,DPV *pr) |
void muldv(VL vl,DP p1,DPV p2,DPV *pr) |
{ |
{ |
int i,len; |
int i,len; |
DP *e; |
DP *e; |
|
|
len = p2->len; |
len = p2->len; |
e = (DP *)MALLOC(p2->len*sizeof(DP)); |
e = (DP *)MALLOC(p2->len*sizeof(DP)); |
if ( !p1 ) { |
if ( !p1 ) { |
MKDPV(len,e,*pr); |
MKDPV(len,e,*pr); |
(*pr)->sugar = 0; |
(*pr)->sugar = 0; |
} else { |
} else { |
for ( i = 0; i < len; i++ ) |
for ( i = 0; i < len; i++ ) |
muld(vl,p1,p2->body[i],&e[i]); |
muld(vl,p1,p2->body[i],&e[i]); |
MKDPV(len,e,*pr); |
MKDPV(len,e,*pr); |
(*pr)->sugar = p1->sugar + p2->sugar; |
(*pr)->sugar = p1->sugar + p2->sugar; |
} |
} |
} |
} |
|
|
int compdv(VL vl,DPV p1,DPV p2) |
int compdv(VL vl,DPV p1,DPV p2) |
{ |
{ |
int i,t,len; |
int i,t,len; |
|
|
if ( p1->len != p2->len ) |
if ( p1->len != p2->len ) { |
error("compdv : size mismatch"); |
error("compdv : size mismatch"); |
else { |
return 0; /* XXX */ |
len = p1->len; |
} else { |
for ( i = 0; i < len; i++ ) |
len = p1->len; |
if ( t = compd(vl,p1->body[i],p2->body[i]) ) |
for ( i = 0; i < len; i++ ) |
return t; |
if ( (t = compd(vl,p1->body[i],p2->body[i])) ) |
return 0; |
return t; |
} |
return 0; |
|
} |
} |
} |
|
|
int ni_next(int *a,int n) |
int ni_next(int *a,int n) |
{ |
{ |
int i,j,k,kj; |
int i,j,k,kj; |
|
|
/* find the first nonzero a[j] */ |
/* find the first nonzero a[j] */ |
for ( j = 0; j < n && a[j] == 0; j++ ); |
for ( j = 0; j < n && a[j] == 0; j++ ); |
/* find the first zero a[k] after a[j] */ |
/* find the first zero a[k] after a[j] */ |
for ( k = j; k < n && a[k] == 1; k++ ); |
for ( k = j; k < n && a[k] == 1; k++ ); |
if ( k == n ) return 0; |
if ( k == n ) return 0; |
/* a[0] = 0, ... , a[j-1] = 0, a[j] = 1, ..., a[k-1] = 1, a[k] = 0 */ |
/* a[0] = 0, ... , a[j-1] = 0, a[j] = 1, ..., a[k-1] = 1, a[k] = 0 */ |
/* a[0] = 1,..., a[k-j-2] = 1, a[k-j-1] = 0, ..., a[k-1] = 0, a[k] = 1 */ |
/* a[0] = 1,..., a[k-j-2] = 1, a[k-j-1] = 0, ..., a[k-1] = 0, a[k] = 1 */ |
kj = k-j-1; |
kj = k-j-1; |
for ( i = 0; i < kj; i++ ) a[i] = 1; |
for ( i = 0; i < kj; i++ ) a[i] = 1; |
for ( ; i < k; i++ ) a[i] = 0; |
for ( ; i < k; i++ ) a[i] = 0; |
a[k] = 1; |
a[k] = 1; |
return 1; |
return 1; |
} |
} |
|
|
int comp_nbm(NBM a,NBM b) |
int comp_nbm(NBM a,NBM b) |
{ |
{ |
int d,i,w,ai,bi; |
int d,i,ai,bi; |
int *ab,*bb; |
int *ab,*bb; |
|
|
if ( a->d > b->d ) return 1; |
if ( a->d > b->d ) return 1; |
else if ( a->d < b->d ) return -1; |
else if ( a->d < b->d ) return -1; |
else { |
else { |
d = a->d; ab = a->b; bb = b->b; |
d = a->d; ab = a->b; bb = b->b; |
#if 0 |
#if 0 |
w = (d+31)/32; |
w = (d+31)/32; |
for ( i = 0; i < w; i++ ) |
for ( i = 0; i < w; i++ ) |
if ( ab[i] > bb[i] ) return 1; |
if ( ab[i] > bb[i] ) return 1; |
else if ( ab[i] < bb[i] ) return -1; |
else if ( ab[i] < bb[i] ) return -1; |
#else |
#else |
for ( i = 0; i < d; i++ ) { |
for ( i = 0; i < d; i++ ) { |
ai = NBM_GET(ab,i); |
ai = NBM_GET(ab,i); |
bi = NBM_GET(bb,i); |
bi = NBM_GET(bb,i); |
if ( ai > bi ) return 1; |
if ( ai > bi ) return 1; |
else if ( ai < bi ) return -1; |
else if ( ai < bi ) return -1; |
} |
} |
#endif |
#endif |
return 0; |
return 0; |
} |
} |
} |
} |
|
|
NBM mul_nbm(NBM a,NBM b) |
NBM mul_nbm(NBM a,NBM b) |
{ |
{ |
int ad,bd,d,i,j; |
int ad,bd,d,i,j; |
int *ab,*bb,*mb; |
int *ab,*bb,*mb; |
NBM m; |
NBM m; |
NODE r; |
|
NBP u; |
|
|
|
ad = a->d; bd = b->d; ab = a->b; bb = b->b; |
ad = a->d; bd = b->d; ab = a->b; bb = b->b; |
d = ad + bd; |
d = ad + bd; |
NEWNBM(m); NEWNBMBDY(m,d); |
NEWNBM(m); NEWNBMBDY(m,d); |
m->d = d; mulp(CO,a->c,b->c,&m->c); mb = m->b; |
m->d = d; mulp(CO,a->c,b->c,&m->c); mb = m->b; |
j = 0; |
j = 0; |
for ( i = 0; i < ad; i++, j++ ) |
for ( i = 0; i < ad; i++, j++ ) |
if ( NBM_GET(ab,i) ) NBM_SET(mb,j); |
if ( NBM_GET(ab,i) ) NBM_SET(mb,j); |
else NBM_CLR(mb,j); |
else NBM_CLR(mb,j); |
for ( i = 0; i < bd; i++, j++ ) |
for ( i = 0; i < bd; i++, j++ ) |
if ( NBM_GET(bb,i) ) NBM_SET(mb,j); |
if ( NBM_GET(bb,i) ) NBM_SET(mb,j); |
else NBM_CLR(mb,j); |
else NBM_CLR(mb,j); |
return m; |
return m; |
} |
} |
|
|
NBP nbmtonbp(NBM m) |
NBP nbmtonbp(NBM m) |
{ |
{ |
NODE n; |
NODE n; |
NBP u; |
NBP u; |
|
|
MKNODE(n,m,0); |
MKNODE(n,m,0); |
MKNBP(u,n); |
MKNBP(u,n); |
return u; |
return u; |
} |
} |
|
|
/* a=c*x*rest -> a0= x*rest, ah=x, ar=rest */ |
/* a=c*x*rest -> a0= x*rest, ah=x, ar=rest */ |
|
|
P separate_nbm(NBM a,NBP *a0,NBP *ah,NBP *ar) |
P separate_nbm(NBM a,NBP *a0,NBP *ah,NBP *ar) |
{ |
{ |
int i,d1; |
int i,d1; |
NBM t; |
NBM t; |
|
|
if ( !a->d ) error("separate_nbm : invalid argument"); |
if ( !a->d ) error("separate_nbm : invalid argument"); |
|
|
if ( a0 ) { |
if ( a0 ) { |
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
*a0 = nbmtonbp(t); |
*a0 = nbmtonbp(t); |
} |
} |
|
|
if ( ah ) { |
if ( ah ) { |
NEWNBM(t); NEWNBMBDY(t,1); t->d = 1; t->c = (P)ONE; |
NEWNBM(t); NEWNBMBDY(t,1); t->d = 1; t->c = (P)ONE; |
if ( NBM_GET(a->b,0) ) NBM_SET(t->b,0); |
if ( NBM_GET(a->b,0) ) NBM_SET(t->b,0); |
else NBM_CLR(t->b,0); |
else NBM_CLR(t->b,0); |
*ah = nbmtonbp(t); |
*ah = nbmtonbp(t); |
} |
} |
|
|
if ( ar ) { |
if ( ar ) { |
d1 = a->d-1; |
d1 = a->d-1; |
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
for ( i = 0; i < d1; i++ ) { |
for ( i = 0; i < d1; i++ ) { |
if ( NBM_GET(a->b,i+1) ) NBM_SET(t->b,i); |
if ( NBM_GET(a->b,i+1) ) NBM_SET(t->b,i); |
else NBM_CLR(t->b,i); |
else NBM_CLR(t->b,i); |
} |
} |
*ar = nbmtonbp(t); |
*ar = nbmtonbp(t); |
} |
} |
|
|
return a->c; |
return a->c; |
} |
} |
|
|
/* a=c*rest*x -> a0= rest*x, ar=rest, at=x */ |
/* a=c*rest*x -> a0= rest*x, ar=rest, at=x */ |
|
|
P separate_tail_nbm(NBM a,NBP *a0,NBP *ar,NBP *at) |
P separate_tail_nbm(NBM a,NBP *a0,NBP *ar,NBP *at) |
{ |
{ |
int i,d,d1; |
int i,d,d1; |
NBM t; |
NBM t; |
|
|
if ( !(d=a->d) ) error("separate_tail_nbm : invalid argument"); |
if ( !(d=a->d) ) error("separate_tail_nbm : invalid argument"); |
|
|
if ( a0 ) { |
if ( a0 ) { |
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
*a0 = nbmtonbp(t); |
*a0 = nbmtonbp(t); |
} |
} |
|
|
d1 = a->d-1; |
d1 = a->d-1; |
if ( at ) { |
if ( at ) { |
NEWNBM(t); NEWNBMBDY(t,1); t->d = 1; t->c = (P)ONE; |
NEWNBM(t); NEWNBMBDY(t,1); t->d = 1; t->c = (P)ONE; |
if ( NBM_GET(a->b,d1) ) NBM_SET(t->b,0); |
if ( NBM_GET(a->b,d1) ) NBM_SET(t->b,0); |
else NBM_CLR(t->b,0); |
else NBM_CLR(t->b,0); |
*at = nbmtonbp(t); |
*at = nbmtonbp(t); |
} |
} |
|
|
if ( ar ) { |
if ( ar ) { |
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
for ( i = 0; i < d1; i++ ) { |
for ( i = 0; i < d1; i++ ) { |
if ( NBM_GET(a->b,i) ) NBM_SET(t->b,i); |
if ( NBM_GET(a->b,i) ) NBM_SET(t->b,i); |
else NBM_CLR(t->b,i); |
else NBM_CLR(t->b,i); |
} |
} |
*ar = nbmtonbp(t); |
*ar = nbmtonbp(t); |
} |
} |
|
|
return a->c; |
return a->c; |
} |
} |
|
|
NBP make_xky(int k) |
NBP make_xky(int k) |
{ |
{ |
int k1,i; |
int k1,i; |
NBM t; |
NBM t; |
|
|
NEWNBM(t); NEWNBMBDY(t,k); t->d = k; t->c = (P)ONE; |
NEWNBM(t); NEWNBMBDY(t,k); t->d = k; t->c = (P)ONE; |
k1 = k-1; |
k1 = k-1; |
for ( i = 0; i < k1; i++ ) NBM_SET(t->b,i); |
for ( i = 0; i < k1; i++ ) NBM_SET(t->b,i); |
NBM_CLR(t->b,i); |
NBM_CLR(t->b,i); |
return nbmtonbp(t); |
return nbmtonbp(t); |
} |
} |
|
|
/* a=c*x^(k-1)*y*rest -> a0= x^(k-1)*y*rest, ah=x^(k-1)*y, ar=rest */ |
/* a=c*x^(k-1)*y*rest -> a0= x^(k-1)*y*rest, ah=x^(k-1)*y, ar=rest */ |
|
|
P separate_xky_nbm(NBM a,NBP *a0,NBP *ah,NBP *ar) |
P separate_xky_nbm(NBM a,NBP *a0,NBP *ah,NBP *ar) |
{ |
{ |
int i,d1,k,k1; |
int i,d1,k,k1; |
NBM t; |
NBM t; |
|
|
if ( !a->d ) |
if ( !a->d ) |
error("separate_nbm : invalid argument"); |
error("separate_nbm : invalid argument"); |
for ( i = 0; i < a->d && NBM_GET(a->b,i); i++ ); |
for ( i = 0; i < a->d && NBM_GET(a->b,i); i++ ); |
if ( i == a->d ) |
if ( i == a->d ) |
error("separate_nbm : invalid argument"); |
error("separate_nbm : invalid argument"); |
k1 = i; |
k1 = i; |
k = i+1; |
k = i+1; |
|
|
if ( a0 ) { |
if ( a0 ) { |
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
*a0 = nbmtonbp(t); |
*a0 = nbmtonbp(t); |
} |
} |
|
|
if ( ah ) { |
if ( ah ) { |
NEWNBM(t); NEWNBMBDY(t,k); t->d = k; t->c = (P)ONE; |
NEWNBM(t); NEWNBMBDY(t,k); t->d = k; t->c = (P)ONE; |
for ( i = 0; i < k1; i++ ) NBM_SET(t->b,i); |
for ( i = 0; i < k1; i++ ) NBM_SET(t->b,i); |
NBM_CLR(t->b,i); |
NBM_CLR(t->b,i); |
*ah = nbmtonbp(t); |
*ah = nbmtonbp(t); |
} |
} |
|
|
if ( ar ) { |
if ( ar ) { |
d1 = a->d-k; |
d1 = a->d-k; |
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
for ( i = 0; i < d1; i++ ) { |
for ( i = 0; i < d1; i++ ) { |
if ( NBM_GET(a->b,i+k) ) NBM_SET(t->b,i); |
if ( NBM_GET(a->b,i+k) ) NBM_SET(t->b,i); |
else NBM_CLR(t->b,i); |
else NBM_CLR(t->b,i); |
} |
} |
*ar = nbmtonbp(t); |
*ar = nbmtonbp(t); |
} |
} |
|
|
return a->c; |
return a->c; |
} |
} |
|
|
void shuffle_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp); |
void shuffle_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp); |
Line 2039 void mulnbpnbm(VL vl,NBP p,NBM m, NBP *rp); |
|
Line 2190 void mulnbpnbm(VL vl,NBP p,NBM m, NBP *rp); |
|
|
|
NBP shuffle_mul_nbm(NBM a,NBM b) |
NBP shuffle_mul_nbm(NBM a,NBM b) |
{ |
{ |
NBP u,a0,ah,ar,b0,bh,br,a1,b1,t; |
NBP u,a0,ah,ar,b0,bh,br,a1,b1,t; |
P ac,bc,c; |
P ac,bc,c; |
|
|
if ( !a->d || !b->d ) |
if ( !a->d || !b->d ) |
u = nbmtonbp(mul_nbm(a,b)); |
u = nbmtonbp(mul_nbm(a,b)); |
else { |
else { |
ac = separate_nbm(a,&a0,&ah,&ar); |
ac = separate_nbm(a,&a0,&ah,&ar); |
bc = separate_nbm(b,&b0,&bh,&br); |
bc = separate_nbm(b,&b0,&bh,&br); |
mulp(CO,ac,bc,&c); |
mulp(CO,ac,bc,&c); |
shuffle_mulnbp(CO,ar,b0,&t); mulnbp(CO,ah,t,&a1); |
shuffle_mulnbp(CO,ar,b0,&t); mulnbp(CO,ah,t,&a1); |
shuffle_mulnbp(CO,a0,br,&t); mulnbp(CO,bh,t,&b1); |
shuffle_mulnbp(CO,a0,br,&t); mulnbp(CO,bh,t,&b1); |
addnbp(CO,a1,b1,&t); mulnbp(CO,(NBP)c,t,&u); |
addnbp(CO,a1,b1,&t); mulnbp(CO,(NBP)c,t,&u); |
} |
} |
return u; |
return u; |
} |
} |
|
|
NBP harmonic_mul_nbm(NBM a,NBM b) |
NBP harmonic_mul_nbm(NBM a,NBM b) |
{ |
{ |
NBP u,a0,ah,ar,b0,bh,br,a1,b1,t,s,abk,ab1; |
NBP u,a0,ah,ar,b0,bh,br,a1,b1,t,s,abk,ab1; |
P ac,bc,c; |
P ac,bc,c; |
|
|
if ( !a->d || !b->d ) |
if ( !a->d || !b->d ) |
u = nbmtonbp(mul_nbm(a,b)); |
u = nbmtonbp(mul_nbm(a,b)); |
else { |
else { |
mulp(CO,a->c,b->c,&c); |
mulp(CO,a->c,b->c,&c); |
ac = separate_xky_nbm(a,&a0,&ah,&ar); |
ac = separate_xky_nbm(a,&a0,&ah,&ar); |
bc = separate_xky_nbm(b,&b0,&bh,&br); |
bc = separate_xky_nbm(b,&b0,&bh,&br); |
mulp(CO,ac,bc,&c); |
mulp(CO,ac,bc,&c); |
harmonic_mulnbp(CO,ar,b0,&t); mulnbp(CO,ah,t,&a1); |
harmonic_mulnbp(CO,ar,b0,&t); mulnbp(CO,ah,t,&a1); |
harmonic_mulnbp(CO,a0,br,&t); mulnbp(CO,bh,t,&b1); |
harmonic_mulnbp(CO,a0,br,&t); mulnbp(CO,bh,t,&b1); |
abk = make_xky(((NBM)BDY(BDY(ah)))->d+((NBM)BDY(BDY(bh)))->d); |
abk = make_xky(((NBM)BDY(BDY(ah)))->d+((NBM)BDY(BDY(bh)))->d); |
harmonic_mulnbp(CO,ar,br,&t); mulnbp(CO,abk,t,&ab1); |
harmonic_mulnbp(CO,ar,br,&t); mulnbp(CO,abk,t,&ab1); |
addnbp(CO,a1,b1,&t); addnbp(CO,t,ab1,&s); mulnbp(CO,(NBP)c,s,&u); |
addnbp(CO,a1,b1,&t); addnbp(CO,t,ab1,&s); mulnbp(CO,(NBP)c,s,&u); |
} |
} |
return u; |
return u; |
|
|
} |
} |
|
|
void addnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
void addnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
{ |
{ |
NODE b1,b2,br,br0; |
NODE b1,b2,br=0,br0; |
NBM m1,m2,m; |
NBM m1,m2,m; |
P c; |
P c; |
|
|
if ( !p1 ) |
if ( !p1 ) |
*rp = p2; |
*rp = p2; |
else if ( !p2 ) |
else if ( !p2 ) |
*rp = p1; |
*rp = p1; |
else { |
else { |
for ( b1 = BDY(p1), b2 = BDY(p2), br0 = 0; b1 && b2; ) { |
for ( b1 = BDY(p1), b2 = BDY(p2), br0 = 0; b1 && b2; ) { |
m1 = (NBM)BDY(b1); m2 = (NBM)BDY(b2); |
m1 = (NBM)BDY(b1); m2 = (NBM)BDY(b2); |
switch ( comp_nbm(m1,m2) ) { |
switch ( comp_nbm(m1,m2) ) { |
case 0: |
case 0: |
addp(CO,m1->c,m2->c,&c); |
addp(CO,m1->c,m2->c,&c); |
if ( c ) { |
if ( c ) { |
NEXTNODE(br0,br); |
NEXTNODE(br0,br); |
NEWNBM(m); m->d = m1->d; m->c = c; m->b = m1->b; |
NEWNBM(m); m->d = m1->d; m->c = c; m->b = m1->b; |
BDY(br) = (pointer)m; |
BDY(br) = (pointer)m; |
} |
} |
b1 = NEXT(b1); b2 = NEXT(b2); break; |
b1 = NEXT(b1); b2 = NEXT(b2); break; |
case 1: |
case 1: |
NEXTNODE(br0,br); BDY(br) = BDY(b1); |
NEXTNODE(br0,br); BDY(br) = BDY(b1); |
b1 = NEXT(b1); break; |
b1 = NEXT(b1); break; |
case -1: |
case -1: |
NEXTNODE(br0,br); BDY(br) = BDY(b2); |
NEXTNODE(br0,br); BDY(br) = BDY(b2); |
b2 = NEXT(b2); break; |
b2 = NEXT(b2); break; |
} |
} |
} |
} |
if ( !br0 ) |
if ( !br0 ) |
if ( b1 ) |
if ( b1 ) |
br0 = b1; |
br0 = b1; |
else if ( b2 ) |
else if ( b2 ) |
br0 = b2; |
br0 = b2; |
else { |
else { |
*rp = 0; |
*rp = 0; |
return; |
return; |
} |
} |
else if ( b1 ) |
else if ( b1 ) |
NEXT(br) = b1; |
NEXT(br) = b1; |
else if ( b2 ) |
else if ( b2 ) |
NEXT(br) = b2; |
NEXT(br) = b2; |
else |
else |
NEXT(br) = 0; |
NEXT(br) = 0; |
MKNBP(*rp,br0); |
MKNBP(*rp,br0); |
} |
} |
} |
} |
|
|
void subnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
void subnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
{ |
{ |
NBP t; |
NBP t; |
|
|
chsgnnbp(p2,&t); |
chsgnnbp(p2,&t); |
addnbp(vl,p1,t,rp); |
addnbp(vl,p1,t,rp); |
} |
} |
|
|
void chsgnnbp(NBP p,NBP *rp) |
void chsgnnbp(NBP p,NBP *rp) |
{ |
{ |
NODE r0,r,b; |
NODE r0,r=0,b; |
NBM m,m1; |
NBM m,m1; |
|
|
for ( r0 = 0, b = BDY(p); b; b = NEXT(b) ) { |
for ( r0 = 0, b = BDY(p); b; b = NEXT(b) ) { |
NEXTNODE(r0,r); |
NEXTNODE(r0,r); |
m = (NBM)BDY(b); |
m = (NBM)BDY(b); |
NEWNBM(m1); m1->d = m->d; m1->b = m->b; chsgnp(m->c,&m1->c); |
NEWNBM(m1); m1->d = m->d; m1->b = m->b; chsgnp(m->c,&m1->c); |
BDY(r) = m1; |
BDY(r) = m1; |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
MKNBP(*rp,r0); |
MKNBP(*rp,r0); |
} |
} |
|
|
void mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
void mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
{ |
{ |
NODE b,n; |
NODE b,n; |
NBP r,t,s; |
NBP r,t,s; |
NBM m; |
NBM m; |
|
|
if ( !p1 || !p2 ) { |
if ( !p1 || !p2 ) { |
*rp = 0; return; |
*rp = 0; return; |
} |
} |
if ( OID(p1) != O_NBP ) { |
if ( OID(p1) != O_NBP ) { |
if ( !POLY(p1) ) |
if ( !POLY(p1) ) |
error("mulnbp : invalid argument"); |
error("mulnbp : invalid argument"); |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p1; |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p1; |
MKNODE(n,m,0); MKNBP(p1,n); |
MKNODE(n,m,0); MKNBP(p1,n); |
} |
} |
if ( OID(p2) != O_NBP ) { |
if ( OID(p2) != O_NBP ) { |
if ( !POLY(p2) ) |
if ( !POLY(p2) ) |
error("mulnbp : invalid argument"); |
error("mulnbp : invalid argument"); |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p2; |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p2; |
MKNODE(n,m,0); MKNBP(p2,n); |
MKNODE(n,m,0); MKNBP(p2,n); |
} |
} |
if ( length(BDY(p1)) < length(BDY(p2)) ) { |
if ( length(BDY(p1)) < length(BDY(p2)) ) { |
for ( r = 0, b = BDY(p1); b; b = NEXT(b) ) { |
for ( r = 0, b = BDY(p1); b; b = NEXT(b) ) { |
mulnbmnbp(vl,(NBM)BDY(b),p2,&t); |
mulnbmnbp(vl,(NBM)BDY(b),p2,&t); |
addnbp(vl,r,t,&s); r = s; |
addnbp(vl,r,t,&s); r = s; |
} |
} |
*rp = r; |
*rp = r; |
} else { |
} else { |
for ( r = 0, b = BDY(p2); b; b = NEXT(b) ) { |
for ( r = 0, b = BDY(p2); b; b = NEXT(b) ) { |
mulnbpnbm(vl,p1,(NBM)BDY(b),&t); |
mulnbpnbm(vl,p1,(NBM)BDY(b),&t); |
addnbp(vl,r,t,&s); r = s; |
addnbp(vl,r,t,&s); r = s; |
} |
} |
*rp = r; |
*rp = r; |
} |
} |
} |
} |
|
|
void mulnbmnbp(VL vl,NBM m,NBP p, NBP *rp) |
void mulnbmnbp(VL vl,NBM m,NBP p, NBP *rp) |
{ |
{ |
NODE b,r0,r; |
NODE b,r0,r=0; |
|
|
if ( !p ) *rp = 0; |
if ( !p ) *rp = 0; |
else { |
else { |
for ( r0 = 0, b = BDY(p); b; b = NEXT(b) ) { |
for ( r0 = 0, b = BDY(p); b; b = NEXT(b) ) { |
NEXTNODE(r0,r); |
NEXTNODE(r0,r); |
BDY(r) = mul_nbm(m,(NBM)BDY(b)); |
BDY(r) = mul_nbm(m,(NBM)BDY(b)); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
MKNBP(*rp,r0); |
MKNBP(*rp,r0); |
} |
} |
} |
} |
|
|
void mulnbpnbm(VL vl,NBP p,NBM m, NBP *rp) |
void mulnbpnbm(VL vl,NBP p,NBM m, NBP *rp) |
{ |
{ |
NODE b,r0,r; |
NODE b,r0,r=0; |
|
|
if ( !p ) *rp = 0; |
if ( !p ) *rp = 0; |
else { |
else { |
for ( r0 = 0, b = BDY(p); b; b = NEXT(b) ) { |
for ( r0 = 0, b = BDY(p); b; b = NEXT(b) ) { |
NEXTNODE(r0,r); |
NEXTNODE(r0,r); |
BDY(r) = mul_nbm((NBM)BDY(b),m); |
BDY(r) = mul_nbm((NBM)BDY(b),m); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
MKNBP(*rp,r0); |
MKNBP(*rp,r0); |
} |
} |
} |
} |
|
|
void pwrnbp(VL vl,NBP a,Q q,NBP *c) |
void pwrnbp(VL vl,NBP a,Q q,NBP *c) |
{ |
{ |
int t; |
int t; |
NBP a1,a2; |
NBP a1,a2; |
N n1; |
N n1; |
Q q1; |
Q q1; |
NBM m; |
NBM m; |
NODE r; |
NODE r; |
|
|
if ( !q ) { |
if ( !q ) { |
NEWNBM(m); m->d = 0; m->c = (P)ONE; m->b = 0; |
NEWNBM(m); m->d = 0; m->c = (P)ONE; m->b = 0; |
MKNODE(r,m,0); MKNBP(*c,r); |
MKNODE(r,m,0); MKNBP(*c,r); |
} else if ( !a ) |
} else if ( !a ) |
*c = 0; |
*c = 0; |
else if ( UNIQ(q) ) |
else if ( UNIQ(q) ) |
*c = a; |
*c = a; |
else { |
else { |
t = divin(NM(q),2,&n1); NTOQ(n1,1,q1); |
t = divin(NM(q),2,&n1); NTOQ(n1,1,q1); |
pwrnbp(vl,a,q1,&a1); |
pwrnbp(vl,a,q1,&a1); |
mulnbp(vl,a1,a1,&a2); |
mulnbp(vl,a1,a1,&a2); |
if ( t ) |
if ( t ) |
mulnbp(vl,a2,a,c); |
mulnbp(vl,a2,a,c); |
else |
else |
*c = a2; |
*c = a2; |
} |
} |
} |
} |
|
|
int compnbp(VL vl,NBP p1,NBP p2) |
int compnbp(VL vl,NBP p1,NBP p2) |
{ |
{ |
NODE n1,n2; |
NODE n1,n2; |
NBM m1,m2; |
NBM m1,m2; |
int t; |
int t; |
|
|
if ( !p1 ) |
if ( !p1 ) |
return p2 ? -1 : 0; |
return p2 ? -1 : 0; |
else if ( !p2 ) |
else if ( !p2 ) |
return 1; |
return 1; |
else { |
else { |
for ( n1 = BDY(p1), n2 = BDY(p2); |
for ( n1 = BDY(p1), n2 = BDY(p2); |
n1 && n2; n1 = NEXT(n1), n2 = NEXT(n2) ) { |
n1 && n2; n1 = NEXT(n1), n2 = NEXT(n2) ) { |
m1 = (NBM)BDY(n1); m2 = (NBM)BDY(n2); |
m1 = (NBM)BDY(n1); m2 = (NBM)BDY(n2); |
if ( (t = comp_nbm(m1,m2)) || (t = compp(CO,m1->c,m2->c) ) ) |
if ( (t = comp_nbm(m1,m2)) || (t = compp(CO,m1->c,m2->c) ) ) |
return t; |
return t; |
} |
} |
if ( n1 ) |
if ( n1 ) |
return 1; |
return 1; |
else if ( n2 ) |
else if ( n2 ) |
return -1; |
return -1; |
else |
else |
return 0; |
return 0; |
} |
} |
} |
} |
|
|
void shuffle_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
void shuffle_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
{ |
{ |
NODE b1,b2,n; |
NODE b1,b2,n; |
NBP r,t,s; |
NBP r,t,s; |
NBM m; |
NBM m; |
|
|
if ( !p1 || !p2 ) { |
if ( !p1 || !p2 ) { |
*rp = 0; return; |
*rp = 0; return; |
} |
} |
if ( OID(p1) != O_NBP ) { |
if ( OID(p1) != O_NBP ) { |
if ( !POLY(p1) ) |
if ( !POLY(p1) ) |
error("shuffle_mulnbp : invalid argument"); |
error("shuffle_mulnbp : invalid argument"); |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p1; |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p1; |
MKNODE(n,m,0); MKNBP(p1,n); |
MKNODE(n,m,0); MKNBP(p1,n); |
} |
} |
if ( OID(p2) != O_NBP ) { |
if ( OID(p2) != O_NBP ) { |
if ( !POLY(p2) ) |
if ( !POLY(p2) ) |
error("shuffle_mulnbp : invalid argument"); |
error("shuffle_mulnbp : invalid argument"); |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p2; |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p2; |
MKNODE(n,m,0); MKNBP(p2,n); |
MKNODE(n,m,0); MKNBP(p2,n); |
} |
} |
for ( r = 0, b1 = BDY(p1); b1; b1 = NEXT(b1) ) |
for ( r = 0, b1 = BDY(p1); b1; b1 = NEXT(b1) ) |
for ( m = BDY(b1), b2 = BDY(p2); b2; b2 = NEXT(b2) ) { |
for ( m = BDY(b1), b2 = BDY(p2); b2; b2 = NEXT(b2) ) { |
t = shuffle_mul_nbm(m,(NBM)BDY(b2)); |
t = shuffle_mul_nbm(m,(NBM)BDY(b2)); |
addnbp(vl,r,t,&s); r = s; |
addnbp(vl,r,t,&s); r = s; |
} |
} |
*rp = r; |
*rp = r; |
} |
} |
|
|
void harmonic_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
void harmonic_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
{ |
{ |
NODE b1,b2,n; |
NODE b1,b2,n; |
NBP r,t,s; |
NBP r,t,s; |
NBM m; |
NBM m; |
|
|
if ( !p1 || !p2 ) { |
if ( !p1 || !p2 ) { |
*rp = 0; return; |
*rp = 0; return; |
} |
} |
if ( OID(p1) != O_NBP ) { |
if ( OID(p1) != O_NBP ) { |
if ( !POLY(p1) ) |
if ( !POLY(p1) ) |
error("harmonic_mulnbp : invalid argument"); |
error("harmonic_mulnbp : invalid argument"); |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p1; |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p1; |
MKNODE(n,m,0); MKNBP(p1,n); |
MKNODE(n,m,0); MKNBP(p1,n); |
} |
} |
if ( OID(p2) != O_NBP ) { |
if ( OID(p2) != O_NBP ) { |
if ( !POLY(p2) ) |
if ( !POLY(p2) ) |
error("harmonic_mulnbp : invalid argument"); |
error("harmonic_mulnbp : invalid argument"); |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p2; |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (P)p2; |
MKNODE(n,m,0); MKNBP(p2,n); |
MKNODE(n,m,0); MKNBP(p2,n); |
} |
} |
for ( r = 0, b1 = BDY(p1); b1; b1 = NEXT(b1) ) |
for ( r = 0, b1 = BDY(p1); b1; b1 = NEXT(b1) ) |
for ( m = BDY(b1), b2 = BDY(p2); b2; b2 = NEXT(b2) ) { |
for ( m = BDY(b1), b2 = BDY(p2); b2; b2 = NEXT(b2) ) { |
t = harmonic_mul_nbm(m,(NBM)BDY(b2)); |
t = harmonic_mul_nbm(m,(NBM)BDY(b2)); |
addnbp(vl,r,t,&s); r = s; |
addnbp(vl,r,t,&s); r = s; |
} |
} |
*rp = r; |
*rp = r; |
} |
} |
|
|
#if 0 |
#if 0 |
NBP shuffle_mul_nbm(NBM a,NBM b) |
NBP shuffle_mul_nbm(NBM a,NBM b) |
{ |
{ |
int ad,bd,d,i,ai,bi,bit,s; |
int ad,bd,d,i,ai,bi,bit,s; |
int *ab,*bb,*wmb,*w; |
int *ab,*bb,*wmb,*w; |
NBM wm,tm; |
NBM wm,tm; |
P c,c1; |
P c,c1; |
NODE r,t,t1,p; |
NODE r,t,t1,p; |
NBP u; |
NBP u; |
|
|
ad = a->d; bd = b->d; ab = a->b; bb = b->b; |
ad = a->d; bd = b->d; ab = a->b; bb = b->b; |
d = ad + bd; |
d = ad + bd; |
w = (int *)ALLOCA(d*sizeof(int)); |
w = (int *)ALLOCA(d*sizeof(int)); |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
for ( i = 0; i < ad; i++ ) w[i] = 1; |
for ( i = 0; i < ad; i++ ) w[i] = 1; |
for ( ; i < d; i++ ) w[i] = 0; |
for ( ; i < d; i++ ) w[i] = 0; |
mulp(CO,a->c,b->c,&c); |
mulp(CO,a->c,b->c,&c); |
r = 0; |
r = 0; |
do { |
do { |
wm->d = d; wm->c = c; |
wm->d = d; wm->c = c; |
ai = 0; bi = 0; |
ai = 0; bi = 0; |
for ( i = 0; i < d; i++ ) { |
for ( i = 0; i < d; i++ ) { |
if ( w[i] ) { bit = NBM_GET(ab,ai); ai++; } |
if ( w[i] ) { bit = NBM_GET(ab,ai); ai++; } |
else { bit = NBM_GET(bb,bi); bi++; } |
else { bit = NBM_GET(bb,bi); bi++; } |
if ( bit ) NBM_SET(wmb,i); |
if ( bit ) NBM_SET(wmb,i); |
else NBM_CLR(wmb,i); |
else NBM_CLR(wmb,i); |
} |
} |
for ( p = 0, t = r; t; p = t, t = NEXT(t) ) { |
for ( p = 0, t = r; t; p = t, t = NEXT(t) ) { |
tm = (NBM)BDY(t); |
tm = (NBM)BDY(t); |
s = comp_nbm(tm,wm); |
s = comp_nbm(tm,wm); |
if ( s < 0 ) { |
if ( s < 0 ) { |
/* insert */ |
/* insert */ |
MKNODE(t1,wm,t); |
MKNODE(t1,wm,t); |
if ( !p ) r = t1; |
if ( !p ) r = t1; |
else NEXT(p) = t1; |
else NEXT(p) = t1; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
break; |
break; |
} else if ( s == 0 ) { |
} else if ( s == 0 ) { |
/* add coefs */ |
/* add coefs */ |
addp(CO,tm->c,c,&c1); |
addp(CO,tm->c,c,&c1); |
if ( c1 ) tm->c = c1; |
if ( c1 ) tm->c = c1; |
else NEXT(p) = NEXT(t); |
else NEXT(p) = NEXT(t); |
break; |
break; |
} |
} |
} |
} |
if ( !t ) { |
if ( !t ) { |
/* append */ |
/* append */ |
MKNODE(t1,wm,t); |
MKNODE(t1,wm,t); |
if ( !p ) r = t1; |
if ( !p ) r = t1; |
else NEXT(p) = t1; |
else NEXT(p) = t1; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
} |
} |
} while ( ni_next(w,d) ); |
} while ( ni_next(w,d) ); |
MKNBP(u,r); |
MKNBP(u,r); |
return u; |
return u; |
} |
} |
|
|
int nbmtoxky(NBM a,int *b) |
int nbmtoxky(NBM a,int *b) |
{ |
{ |
int d,i,j,k; |
int d,i,j,k; |
int *p; |
int *p; |
|
|
d = a->d; p = a->b; |
d = a->d; p = a->b; |
for ( i = j = 0, k = 1; i < d; i++ ) { |
for ( i = j = 0, k = 1; i < d; i++ ) { |
if ( !NBM_GET(p,i) ) { |
if ( !NBM_GET(p,i) ) { |
b[j++] = k; |
b[j++] = k; |
k = 1; |
k = 1; |
} else k++; |
} else k++; |
} |
} |
return j; |
return j; |
} |
} |
|
|
NBP harmonic_mul_nbm(NBM a,NBM b) |
NBP harmonic_mul_nbm(NBM a,NBM b) |
{ |
{ |
int da,db,d,la,lb,lmax,lmin,l,lab,la1,lb1,lab1; |
int da,db,d,la,lb,lmax,lmin,l,lab,la1,lb1,lab1; |
int i,j,k,ia,ib,s; |
int i,j,k,ia,ib,s; |
int *wa,*wb,*w,*wab,*wa1,*wmb; |
int *wa,*wb,*w,*wab,*wa1,*wmb; |
P c,c1; |
P c,c1; |
NBM wm,tm; |
NBM wm,tm; |
NODE r,t1,t,p; |
NODE r,t1,t,p; |
NBP u; |
NBP u; |
|
|
da = a->d; db = b->d; d = da+db; |
da = a->d; db = b->d; d = da+db; |
wa = (int *)ALLOCA(da*sizeof(int)); |
wa = (int *)ALLOCA(da*sizeof(int)); |
wb = (int *)ALLOCA(db*sizeof(int)); |
wb = (int *)ALLOCA(db*sizeof(int)); |
la = nbmtoxky(a,wa); |
la = nbmtoxky(a,wa); |
lb = nbmtoxky(b,wb); |
lb = nbmtoxky(b,wb); |
mulp(CO,a->c,b->c,&c); |
mulp(CO,a->c,b->c,&c); |
/* wa[0],..,wa[la-1] <-> x^wa[0]y x^wa[1]y .. */ |
/* wa[0],..,wa[la-1] <-> x^wa[0]y x^wa[1]y .. */ |
/* lmax : total length */ |
/* lmax : total length */ |
lmax = la+lb; |
lmax = la+lb; |
lmin = la>lb?la:lb; |
lmin = la>lb?la:lb; |
w = (int *)ALLOCA(lmax*sizeof(int)); |
w = (int *)ALLOCA(lmax*sizeof(int)); |
/* position of a+b */ |
/* position of a+b */ |
wab = (int *)ALLOCA(lmax*sizeof(int)); |
wab = (int *)ALLOCA(lmax*sizeof(int)); |
/* position of a */ |
/* position of a */ |
wa1 = (int *)ALLOCA(lmax*sizeof(int)); |
wa1 = (int *)ALLOCA(lmax*sizeof(int)); |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
for ( l = lmin, r = 0; l <= lmax; l++ ) { |
for ( l = lmin, r = 0; l <= lmax; l++ ) { |
lab = lmax - l; |
lab = lmax - l; |
la1 = la - lab; |
la1 = la - lab; |
lb1 = lb - lab; |
lb1 = lb - lab; |
lab1 = l-lab; |
lab1 = l-lab; |
/* partion l into three parts: a, b, a+b */ |
/* partion l into three parts: a, b, a+b */ |
/* initialize wab */ |
/* initialize wab */ |
for ( i = 0; i < lab; i++ ) wab[i] = 1; |
for ( i = 0; i < lab; i++ ) wab[i] = 1; |
for ( ; i < l; i++ ) wab[i] = 0; |
for ( ; i < l; i++ ) wab[i] = 0; |
do { |
do { |
/* initialize wa1 */ |
/* initialize wa1 */ |
for ( i = 0; i < la1; i++ ) wa1[i] = 1; |
for ( i = 0; i < la1; i++ ) wa1[i] = 1; |
for ( ; i < lab1; i++ ) wa1[i] = 0; |
for ( ; i < lab1; i++ ) wa1[i] = 0; |
do { |
do { |
ia = 0; ib = 0; |
ia = 0; ib = 0; |
for ( i = j = 0; i < l; i++ ) |
for ( i = j = 0; i < l; i++ ) |
if ( wab[i] ) w[i] = wa[ia++]+wb[ib++]; |
if ( wab[i] ) w[i] = wa[ia++]+wb[ib++]; |
else if ( wa1[j++] ) w[i] = wa[ia++]; |
else if ( wa1[j++] ) w[i] = wa[ia++]; |
else w[i] = wb[ib++]; |
else w[i] = wb[ib++]; |
for ( i = j = 0; i < l; i++ ) { |
for ( i = j = 0; i < l; i++ ) { |
for ( k = w[i]-1; k > 0; k--, j++ ) NBM_SET(wmb,j); |
for ( k = w[i]-1; k > 0; k--, j++ ) NBM_SET(wmb,j); |
NBM_CLR(wmb,j); j++; |
NBM_CLR(wmb,j); j++; |
} |
} |
wm->d = j; wm->c = c; |
wm->d = j; wm->c = c; |
for ( p = 0, t = r; t; p = t, t = NEXT(t) ) { |
for ( p = 0, t = r; t; p = t, t = NEXT(t) ) { |
tm = (NBM)BDY(t); |
tm = (NBM)BDY(t); |
s = comp_nbm(tm,wm); |
s = comp_nbm(tm,wm); |
if ( s < 0 ) { |
if ( s < 0 ) { |
/* insert */ |
/* insert */ |
MKNODE(t1,wm,t); |
MKNODE(t1,wm,t); |
if ( !p ) r = t1; |
if ( !p ) r = t1; |
else NEXT(p) = t1; |
else NEXT(p) = t1; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
break; |
break; |
} else if ( s == 0 ) { |
} else if ( s == 0 ) { |
/* add coefs */ |
/* add coefs */ |
addp(CO,tm->c,c,&c1); |
addp(CO,tm->c,c,&c1); |
if ( c1 ) tm->c = c1; |
if ( c1 ) tm->c = c1; |
else NEXT(p) = NEXT(t); |
else NEXT(p) = NEXT(t); |
break; |
break; |
} |
} |
} |
} |
if ( !t ) { |
if ( !t ) { |
/* append */ |
/* append */ |
MKNODE(t1,wm,t); |
MKNODE(t1,wm,t); |
if ( !p ) r = t1; |
if ( !p ) r = t1; |
else NEXT(p) = t1; |
else NEXT(p) = t1; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
} |
} |
} while ( ni_next(wa1,lab1) ); |
} while ( ni_next(wa1,lab1) ); |
} while ( ni_next(wab,l) ); |
} while ( ni_next(wab,l) ); |
} |
} |
MKNBP(u,r); |
MKNBP(u,r); |
return u; |
return u; |
} |
} |
#endif |
#endif |
|
|
|
/* DPM functions */ |
|
|
|
int compdmm(int n,DMM m1,DMM m2) |
|
{ |
|
int t; |
|
|
|
if ( dpm_ispot ) { |
|
if ( m1->pos < m2->pos ) return 1; |
|
else if ( m1->pos > m2->pos ) return -1; |
|
else return (*cmpdl)(n,m1->dl,m2->dl); |
|
} else { |
|
t = (*cmpdl)(n,m1->dl,m2->dl); |
|
if ( t ) return t; |
|
else if ( m1->pos < m2->pos ) return 1; |
|
else if ( m1->pos > m2->pos ) return -1; |
|
else return 0; |
|
} |
|
} |
|
|
|
void adddpm(VL vl,DPM p1,DPM p2,DPM *pr) |
|
{ |
|
int n; |
|
DMM m1,m2,mr=0,mr0; |
|
Obj t; |
|
DL d; |
|
|
|
if ( !p1 ) |
|
*pr = p2; |
|
else if ( !p2 ) |
|
*pr = p1; |
|
else { |
|
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2), mr0 = 0; m1 && m2; ) |
|
switch ( compdmm(n,m1,m2) ) { |
|
case 0: |
|
arf_add(vl,C(m1),C(m2),&t); |
|
if ( t ) { |
|
NEXTDMM(mr0,mr); mr->pos = m1->pos; mr->dl = m1->dl; C(mr) = t; |
|
} |
|
m1 = NEXT(m1); m2 = NEXT(m2); break; |
|
case 1: |
|
NEXTDMM(mr0,mr); mr->pos = m1->pos; mr->dl = m1->dl; C(mr) = C(m1); |
|
m1 = NEXT(m1); break; |
|
case -1: |
|
NEXTDMM(mr0,mr); mr->pos = m2->pos; mr->dl = m2->dl; C(mr) = C(m2); |
|
m2 = NEXT(m2); break; |
|
} |
|
if ( !mr0 ) |
|
if ( m1 ) |
|
mr0 = m1; |
|
else if ( m2 ) |
|
mr0 = m2; |
|
else { |
|
*pr = 0; |
|
return; |
|
} |
|
else if ( m1 ) |
|
NEXT(mr) = m1; |
|
else if ( m2 ) |
|
NEXT(mr) = m2; |
|
else |
|
NEXT(mr) = 0; |
|
MKDPM(NV(p1),mr0,*pr); |
|
if ( *pr ) |
|
(*pr)->sugar = MAX(p1->sugar,p2->sugar); |
|
} |
|
} |
|
|
|
void subdpm(VL vl,DPM p1,DPM p2,DPM *pr) |
|
{ |
|
DPM t; |
|
|
|
if ( !p2 ) |
|
*pr = p1; |
|
else { |
|
chsgndpm(p2,&t); adddpm(vl,p1,t,pr); |
|
} |
|
} |
|
|
|
void chsgndpm(DPM p,DPM *pr) |
|
{ |
|
DMM m,mr=0,mr0; |
|
Obj r; |
|
|
|
if ( !p ) |
|
*pr = 0; |
|
else { |
|
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
|
NEXTDMM(mr0,mr); arf_chsgn(C(m),&C(mr)); mr->pos = m->pos; mr->dl = m->dl; |
|
} |
|
NEXT(mr) = 0; MKDPM(NV(p),mr0,*pr); |
|
if ( *pr ) |
|
(*pr)->sugar = p->sugar; |
|
} |
|
} |
|
|
|
void mulcdpm(VL vl,Obj c,DPM p,DPM *pr) |
|
{ |
|
DMM m,mr=0,mr0; |
|
|
|
if ( !p || !c ) |
|
*pr = 0; |
|
else if ( NUM(c) && UNIQ((Q)c) ) |
|
*pr = p; |
|
else if ( NUM(c) && MUNIQ((Q)c) ) |
|
chsgndpm(p,pr); |
|
else { |
|
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
|
NEXTDMM(mr0,mr); |
|
arf_mul(vl,C(m),c,&C(mr)); |
|
mr->pos = m->pos; |
|
mr->dl = m->dl; |
|
} |
|
NEXT(mr) = 0; MKDPM(NV(p),mr0,*pr); |
|
if ( *pr ) |
|
(*pr)->sugar = p->sugar; |
|
} |
|
} |
|
|
|
void comm_mulmpdpm(VL vl,MP m0,DPM p,DPM *pr) |
|
{ |
|
DMM m,mr=0,mr0; |
|
DL d; |
|
Obj c; |
|
int n; |
|
|
|
if ( !p ) |
|
*pr = 0; |
|
else { |
|
n = NV(p); |
|
d = m0->dl; |
|
c = C(m0); |
|
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
|
NEXTDMM(mr0,mr); |
|
arf_mul(vl,C(m),c,&C(mr)); |
|
mr->pos = m->pos; |
|
adddl(n,m->dl,d,&mr->dl); |
|
} |
|
NEXT(mr) = 0; MKDPM(NV(p),mr0,*pr); |
|
if ( *pr ) |
|
(*pr)->sugar = p->sugar; |
|
} |
|
} |
|
|
|
void weyl_mulmpdpm(VL vl,MP m0,DPM p,DPM *pr) |
|
{ |
|
DPM r,t,t1; |
|
DMM m; |
|
DL d0; |
|
int n,n2,l,i,j,tlen; |
|
struct oMP mp; |
|
static DMM *w,*psum; |
|
static struct cdl *tab; |
|
static int wlen; |
|
static int rtlen; |
|
|
|
if ( !p ) |
|
*pr = 0; |
|
else { |
|
for ( m = BDY(p), l = 0; m; m = NEXT(m), l++ ); |
|
if ( l > wlen ) { |
|
if ( w ) GCFREE(w); |
|
w = (DMM *)MALLOC(l*sizeof(DMM)); |
|
wlen = l; |
|
} |
|
for ( m = BDY(p), i = 0; i < l; m = NEXT(m), i++ ) |
|
w[i] = m; |
|
|
|
n = NV(p); n2 = n>>1; |
|
d0 = m0->dl; |
|
for ( i = 0, tlen = 1; i < n2; i++ ) |
|
tlen *= d0->d[n2+i]+1; |
|
if ( tlen > rtlen ) { |
|
if ( tab ) GCFREE(tab); |
|
if ( psum ) GCFREE(psum); |
|
rtlen = tlen; |
|
tab = (struct cdl *)MALLOC(rtlen*sizeof(struct cdl)); |
|
psum = (DMM *)MALLOC(rtlen*sizeof(DMM)); |
|
} |
|
bzero(psum,tlen*sizeof(DMM)); |
|
for ( i = l-1; i >= 0; i-- ) { |
|
bzero(tab,tlen*sizeof(struct cdl)); |
|
mp.dl = w[i]->dl; mp.c = C(w[i]); mp.next = 0; |
|
weyl_mulmm(vl,m0,&mp,n,tab,tlen); |
|
for ( j = 0; j < tlen; j++ ) { |
|
if ( tab[j].c ) { |
|
NEWDMM(m); m->dl = tab[j].d; m->pos = w[i]->pos; C(m) = (Obj)tab[j].c; NEXT(m) = psum[j]; |
|
psum[j] = m; |
|
} |
|
} |
|
} |
|
for ( j = tlen-1, r = 0; j >= 0; j-- ) |
|
if ( psum[j] ) { |
|
MKDPM(n,psum[j],t); adddpm(vl,r,t,&t1); r = t1; |
|
} |
|
if ( r ) |
|
r->sugar = p->sugar + m0->dl->td; |
|
*pr = r; |
|
} |
|
} |
|
|
|
void mulobjdpm(VL vl,Obj p1,DPM p2,DPM *pr) |
|
{ |
|
MP m; |
|
DPM s,t,u; |
|
|
|
if ( !p1 || !p2 ) |
|
*pr = 0; |
|
else if ( OID(p1) != O_DP ) |
|
mulcdpm(vl,p1,p2,pr); |
|
else { |
|
s = 0; |
|
for ( m = BDY((DP)p1); m; m = NEXT(m) ) { |
|
if ( do_weyl ) |
|
weyl_mulmpdpm(vl,m,p2,&t); |
|
else |
|
comm_mulmpdpm(vl,m,p2,&t); |
|
adddpm(vl,s,t,&u); s = u; |
|
} |
|
*pr = s; |
|
} |
|
} |
|
|
|
int compdpm(VL vl,DPM p1,DPM p2) |
|
{ |
|
int n,t; |
|
DMM m1,m2; |
|
|
|
if ( !p1 ) |
|
return p2 ? -1 : 0; |
|
else if ( !p2 ) |
|
return 1; |
|
else if ( NV(p1) != NV(p2) ) { |
|
error("compdpm : size mismatch"); |
|
return 0; /* XXX */ |
|
} else { |
|
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2); |
|
m1 && m2; m1 = NEXT(m1), m2 = NEXT(m2) ) |
|
if ( (t = compdmm(n,m1,m2)) || |
|
(t = arf_comp(vl,C(m1),C(m2)) ) ) |
|
return t; |
|
if ( m1 ) |
|
return 1; |
|
else if ( m2 ) |
|
return -1; |
|
else |
|
return 0; |
|
} |
|
} |
|
|