version 1.36, 2005/11/25 07:18:32 |
version 1.49, 2014/09/12 06:28:46 |
|
|
* 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.35 2005/11/25 02:43:39 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/dist.c,v 1.48 2014/08/19 06:35:01 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
|
|
|
|
#define ORD_HOMO_WW_DRL_ZIGZAG 13 |
#define ORD_HOMO_WW_DRL_ZIGZAG 13 |
|
|
int cmpdl_drl_zigzag(), cmpdl_homo_ww_drl_zigzag(); |
int cmpdl_drl_zigzag(), cmpdl_homo_ww_drl_zigzag(); |
|
int cmpdl_top_weight(); |
|
|
int (*cmpdl)()=cmpdl_revgradlex; |
int (*cmpdl)()=cmpdl_revgradlex; |
|
int (*cmpdl_tie_breaker)(); |
int (*primitive_cmpdl[3])() = {cmpdl_revgradlex,cmpdl_gradlex,cmpdl_lex}; |
int (*primitive_cmpdl[3])() = {cmpdl_revgradlex,cmpdl_gradlex,cmpdl_lex}; |
|
|
int do_weyl; |
int do_weyl; |
Line 80 void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr); |
|
Line 82 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,P 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() |
{ |
{ |
Line 90 void order_init() |
|
Line 94 void order_init() |
|
create_modorder_spec(0,0,&dp_current_modspec); |
create_modorder_spec(0,0,&dp_current_modspec); |
} |
} |
|
|
|
int has_sfcoef_p(P f); |
|
|
int has_sfcoef(DP f) |
int has_sfcoef(DP f) |
{ |
{ |
MP t; |
MP t; |
Line 118 int has_sfcoef_p(P f) |
|
Line 124 int has_sfcoef_p(P f) |
|
} |
} |
} |
} |
|
|
|
extern Obj current_top_weight; |
|
int current_top_weight_len; |
|
|
void initd(struct order_spec *spec) |
void initd(struct order_spec *spec) |
{ |
{ |
|
int len,i,k,row; |
|
Q **mat; |
|
|
switch ( spec->id ) { |
switch ( spec->id ) { |
case 3: |
case 3: |
cmpdl = cmpdl_composite; |
cmpdl = cmpdl_composite; |
Line 165 void initd(struct order_spec *spec) |
|
Line 177 void initd(struct order_spec *spec) |
|
} |
} |
break; |
break; |
} |
} |
|
if ( current_top_weight ) { |
|
cmpdl_tie_breaker = cmpdl; |
|
cmpdl = cmpdl_top_weight; |
|
if ( OID(current_top_weight) == O_VECT ) { |
|
mat = (Q **)&BDY((VECT)current_top_weight); |
|
row = 1; |
|
} else { |
|
mat = (Q **)BDY((MAT)current_top_weight); |
|
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; |
dp_current_spec = spec; |
} |
} |
|
|
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; |
Line 298 int sugard(MP m) |
|
Line 325 int sugard(MP m) |
|
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; |
P t; |
DL d; |
DL d; |
|
|
Line 358 void addd(VL vl,DP p1,DP p2,DP *pr) |
|
Line 385 void addd(VL vl,DP p1,DP p2,DP *pr) |
|
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; |
Line 409 void symb_addd(DP p1,DP p2,DP *pr) |
|
Line 436 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 ) |
Line 509 NODE symb_mul_merge(NODE m1,DL dl,DP f,int n) |
|
Line 535 NODE symb_mul_merge(NODE m1,DL dl,DP f,int n) |
|
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); |
Line 519 NODE symb_mul_merge(NODE m1,DL dl,DP f,int n) |
|
Line 545 NODE symb_mul_merge(NODE m1,DL dl,DP f,int n) |
|
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: |
Line 595 void subd(VL vl,DP p1,DP p2,DP *pr) |
|
Line 621 void subd(VL vl,DP p1,DP p2,DP *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 ) |
Line 642 void comm_muld(VL vl,DP p1,DP p2,DP *pr) |
|
Line 668 void comm_muld(VL vl,DP p1,DP p2,DP *pr) |
|
l = l1; |
l = l1; |
} |
} |
if ( l > wlen ) { |
if ( l > wlen ) { |
if ( w ) GC_free(w); |
if ( w ) GCFREE(w); |
w = (MP *)MALLOC(l*sizeof(MP)); |
w = (MP *)MALLOC(l*sizeof(MP)); |
wlen = l; |
wlen = l; |
} |
} |
Line 680 void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr) |
|
Line 706 void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr) |
|
l = l1; |
l = l1; |
} |
} |
if ( l > wlen ) { |
if ( l > wlen ) { |
if ( w ) GC_free(w); |
if ( w ) GCFREE(w); |
w = (MP *)MALLOC(l*sizeof(MP)); |
w = (MP *)MALLOC(l*sizeof(MP)); |
wlen = l; |
wlen = l; |
} |
} |
Line 696 void comm_muld_trunc(VL vl,DP p1,DP p2,DL dl,DP *pr) |
|
Line 722 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) |
{ |
{ |
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; |
Line 737 void comm_quod(VL vl,DP p1,DP p2,DP *pr) |
|
Line 763 void comm_quod(VL vl,DP p1,DP p2,DP *pr) |
|
|
|
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; |
P c; |
DL d; |
DL d; |
int n; |
int n; |
Line 762 void muldm(VL vl,DP p,MP m0,DP *pr) |
|
Line 788 void muldm(VL vl,DP p,MP m0,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) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr=0,mr0; |
P c; |
P c; |
DL d,tdl; |
DL d,tdl; |
int n,i; |
int n,i; |
Line 814 void weyl_muld(VL vl,DP p1,DP p2,DP *pr) |
|
Line 840 void weyl_muld(VL vl,DP p1,DP p2,DP *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 ) GC_free(w); |
if ( w ) GCFREE(w); |
w = (MP *)MALLOC(l*sizeof(MP)); |
w = (MP *)MALLOC(l*sizeof(MP)); |
wlen = l; |
wlen = l; |
} |
} |
Line 846 void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
|
Line 872 void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
|
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 ) GC_free(w); |
if ( w ) GCFREE(w); |
w = (MP *)MALLOC(l*sizeof(MP)); |
w = (MP *)MALLOC(l*sizeof(MP)); |
wlen = l; |
wlen = l; |
} |
} |
Line 858 void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
|
Line 884 void weyl_muldm(VL vl,MP m0,DP p,DP *pr) |
|
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 ) GC_free(tab); |
if ( tab ) GCFREE(tab); |
if ( psum ) GC_free(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)); |
Line 921 void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rt |
|
Line 947 void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rt |
|
rtab[0].d = d; |
rtab[0].d = d; |
|
|
if ( rtablen > tmptablen ) { |
if ( rtablen > tmptablen ) { |
if ( tmptab ) GC_free(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; |
} |
} |
Line 947 void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rt |
|
Line 973 void weyl_mulmm(VL vl,MP m0,MP m1,int n,struct cdl *rt |
|
continue; |
continue; |
} |
} |
if ( k+1 > tablen ) { |
if ( k+1 > tablen ) { |
if ( tab ) GC_free(tab); |
if ( tab ) GCFREE(tab); |
if ( ctab ) GC_free(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)); |
Line 1014 void comm_muld_tab(VL vl,int nv,struct cdl *t,int n,st |
|
Line 1040 void comm_muld_tab(VL vl,int nv,struct cdl *t,int n,st |
|
|
|
void muldc(VL vl,DP p,P c,DP *pr) |
void muldc(VL vl,DP p,P c,DP *pr) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr=0,mr0; |
|
|
if ( !p || !c ) |
if ( !p || !c ) |
*pr = 0; |
*pr = 0; |
Line 1039 void muldc(VL vl,DP p,P c,DP *pr) |
|
Line 1065 void muldc(VL vl,DP p,P c,DP *pr) |
|
|
|
void muldc_trunc(VL vl,DP p,P c,DL dl,DP *pr) |
void muldc_trunc(VL vl,DP p,P c,DL dl,DP *pr) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr=0,mr0; |
DL mdl; |
DL mdl; |
int i,n; |
int i,n; |
|
|
Line 1068 void muldc_trunc(VL vl,DP p,P c,DL dl,DP *pr) |
|
Line 1094 void muldc_trunc(VL vl,DP p,P c,DL dl,DP *pr) |
|
|
|
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"); |
Line 1089 void adddl(int n,DL d1,DL d2,DL *dr) |
|
Line 1115 void adddl(int n,DL d1,DL d2,DL *dr) |
|
DL dt; |
DL dt; |
int i; |
int i; |
|
|
if ( !d1->td ) |
*dr = dt = (DL)MALLOC_ATOMIC((n+1)*sizeof(int)); |
*dr = d2; |
dt->td = d1->td + d2->td; |
else if ( !d2->td ) |
for ( i = 0; i < n; i++ ) |
*dr = d1; |
dt->d[i] = d1->d[i]+d2->d[i]; |
else { |
|
*dr = dt = (DL)MALLOC_ATOMIC((n+1)*sizeof(int)); |
|
dt->td = d1->td + d2->td; |
|
for ( i = 0; i < n; i++ ) |
|
dt->d[i] = d1->d[i]+d2->d[i]; |
|
} |
|
} |
} |
|
|
/* d1 += d2 */ |
/* d1 += d2 */ |
Line 1121 int compd(VL vl,DP p1,DP p2) |
|
Line 1141 int compd(VL vl,DP p1,DP p2) |
|
return p2 ? -1 : 0; |
return p2 ? -1 : 0; |
else if ( !p2 ) |
else if ( !p2 ) |
return 1; |
return 1; |
else { |
else if ( NV(p1) != NV(p2) ) { |
|
error("compd : size mismatch"); |
|
return 0; /* XXX */ |
|
} else { |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2); |
for ( n = NV(p1), m1 = BDY(p1), m2 = BDY(p2); |
m1 && m2; m1 = NEXT(m1), m2 = NEXT(m2) ) |
m1 && m2; m1 = NEXT(m1), m2 = NEXT(m2) ) |
if ( (t = (*cmpdl)(n,m1->dl,m2->dl)) || |
if ( (t = (*cmpdl)(n,m1->dl,m2->dl)) || |
Line 1242 int cmpdl_blex(int n,DL d1,DL d2) |
|
Line 1265 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]; |
Line 1447 int cmpdl_drl_zigzag(int n,DL d1,DL d2) |
|
Line 1470 int cmpdl_drl_zigzag(int n,DL d1,DL d2) |
|
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; |
} |
} |
Line 1482 int cmpdl_homo_ww_drl_zigzag(int n,DL d1,DL d2) |
|
Line 1505 int cmpdl_homo_ww_drl_zigzag(int n,DL d1,DL d2) |
|
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; |
} |
} |
Line 1496 int cmpdl_order_pair(int n,DL d1,DL d2) |
|
Line 1519 int cmpdl_order_pair(int n,DL d1,DL d2) |
|
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 ) |
|
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; |
Line 1636 int cmpdl_matrix(int n,DL d1,DL d2) |
|
Line 1661 int cmpdl_matrix(int n,DL d1,DL d2) |
|
return 0; |
return 0; |
} |
} |
|
|
|
int cmpdl_top_weight(int n,DL d1,DL d2) |
|
{ |
|
int *w; |
|
N sum,wm,wma,t; |
|
Q **mat; |
|
Q *a; |
|
struct oN tn; |
|
int len,i,sgn,tsgn,row,k; |
|
int *t1,*t2; |
|
|
|
w = (int *)ALLOCA(n*sizeof(int)); |
|
len = current_top_weight_len+3; |
|
t1 = d1->d; t2 = d2->d; |
|
for ( i = 0; i < n; i++ ) w[i] = t1[i]-t2[i]; |
|
sum = (N)W_ALLOC(len); sgn = 0; |
|
wm = (N)W_ALLOC(len); |
|
wma = (N)W_ALLOC(len); |
|
if ( OID(current_top_weight) == O_VECT ) { |
|
mat = (Q **)&BDY((VECT)current_top_weight); |
|
row = 1; |
|
} else { |
|
mat = (Q **)BDY((MAT)current_top_weight); |
|
row = ((MAT)current_top_weight)->row; |
|
} |
|
for ( k = 0; k < row; k++ ) { |
|
a = mat[k]; |
|
for ( i = 0; i < n; i++ ) { |
|
if ( !a[i] || !w[i] ) continue; |
|
tn.p = 1; |
|
if ( w[i] > 0 ) { |
|
tn.b[0] = w[i]; tsgn = 1; |
|
} else { |
|
tn.b[0] = -w[i]; tsgn = -1; |
|
} |
|
_muln(NM(a[i]),&tn,wm); |
|
if ( !sgn ) { |
|
sgn = tsgn; |
|
t = wm; wm = sum; sum = t; |
|
} else if ( sgn == tsgn ) { |
|
_addn(sum,wm,wma); |
|
if ( !PL(wma) ) |
|
sgn = 0; |
|
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; |
Line 1645 GeoBucket create_bucket() |
|
Line 1724 GeoBucket create_bucket() |
|
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; |
Line 1768 int compdv(VL vl,DPV p1,DPV p2) |
|
Line 1849 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 */ |
|
} else { |
len = p1->len; |
len = p1->len; |
for ( i = 0; i < len; i++ ) |
for ( i = 0; i < len; i++ ) |
if ( t = compd(vl,p1->body[i],p2->body[i]) ) |
if ( (t = compd(vl,p1->body[i],p2->body[i])) ) |
return t; |
return t; |
return 0; |
return 0; |
} |
} |
Line 1799 int ni_next(int *a,int n) |
|
Line 1881 int ni_next(int *a,int n) |
|
|
|
int comp_nbm(NBM a,NBM b) |
int comp_nbm(NBM a,NBM b) |
{ |
{ |
int d,i,w; |
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 |
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 |
|
for ( i = 0; i < d; i++ ) { |
|
ai = NBM_GET(ab,i); |
|
bi = NBM_GET(bb,i); |
|
if ( ai > bi ) return 1; |
|
else if ( ai < bi ) return -1; |
|
} |
|
#endif |
return 0; |
return 0; |
} |
} |
} |
} |
Line 1819 NBM mul_nbm(NBM a,NBM b) |
|
Line 1910 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; |
Q c,c1; |
|
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; mulq(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); |
Line 1837 NBM mul_nbm(NBM a,NBM b) |
|
Line 1925 NBM mul_nbm(NBM a,NBM b) |
|
return m; |
return m; |
} |
} |
|
|
NBP shuffle_mul_nbm(NBM a,NBM b) |
NBP nbmtonbp(NBM m) |
{ |
{ |
int ad,bd,d,i,ai,bi,bit,s; |
NODE n; |
int *ab,*bb,*wmb,*w; |
|
NBM wm,tm; |
|
Q c,c1; |
|
NODE r,t,t1,p; |
|
NBP u; |
NBP u; |
|
|
ad = a->d; bd = b->d; ab = a->b; bb = b->b; |
MKNODE(n,m,0); |
d = ad + bd; |
MKNBP(u,n); |
w = (int *)ALLOCA(d*sizeof(int)); |
return u; |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
} |
for ( i = 0; i < ad; i++ ) w[i] = 1; |
|
for ( ; i < d; i++ ) w[i] = 0; |
/* a=c*x*rest -> a0= x*rest, ah=x, ar=rest */ |
mulq(a->c,b->c,&c); |
|
r = 0; |
P separate_nbm(NBM a,NBP *a0,NBP *ah,NBP *ar) |
do { |
{ |
wm->d = d; wm->c = c; |
int i,d1; |
ai = 0; bi = 0; |
NBM t; |
for ( i = 0; i < d; i++ ) { |
|
if ( w[i] ) { bit = NBM_GET(ab,ai); ai++; } |
if ( !a->d ) error("separate_nbm : invalid argument"); |
else { bit = NBM_GET(bb,bi); bi++; } |
|
if ( bit ) NBM_SET(wmb,i); |
if ( a0 ) { |
else NBM_CLR(wmb,i); |
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
|
*a0 = nbmtonbp(t); |
|
} |
|
|
|
if ( ah ) { |
|
NEWNBM(t); NEWNBMBDY(t,1); t->d = 1; t->c = (P)ONE; |
|
if ( NBM_GET(a->b,0) ) NBM_SET(t->b,0); |
|
else NBM_CLR(t->b,0); |
|
*ah = nbmtonbp(t); |
|
} |
|
|
|
if ( ar ) { |
|
d1 = a->d-1; |
|
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
|
for ( i = 0; i < d1; i++ ) { |
|
if ( NBM_GET(a->b,i+1) ) NBM_SET(t->b,i); |
|
else NBM_CLR(t->b,i); |
} |
} |
for ( p = 0, t = r; t; p = t, t = NEXT(t) ) { |
*ar = nbmtonbp(t); |
tm = (NBM)BDY(t); |
} |
s = comp_nbm(tm,wm); |
|
if ( s < 0 ) { |
return a->c; |
/* insert */ |
} |
MKNODE(t1,wm,t); |
|
if ( !p ) r = t1; |
/* a=c*rest*x -> a0= rest*x, ar=rest, at=x */ |
else NEXT(p) = t1; |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
P separate_tail_nbm(NBM a,NBP *a0,NBP *ar,NBP *at) |
break; |
{ |
} else if ( s == 0 ) { |
int i,d,d1; |
/* add coefs */ |
NBM t; |
addq(tm->c,c,&c1); |
|
if ( c1 ) tm->c = c1; |
if ( !(d=a->d) ) error("separate_tail_nbm : invalid argument"); |
else NEXT(p) = NEXT(t); |
|
break; |
if ( a0 ) { |
} |
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
|
*a0 = nbmtonbp(t); |
|
} |
|
|
|
d1 = a->d-1; |
|
if ( at ) { |
|
NEWNBM(t); NEWNBMBDY(t,1); t->d = 1; t->c = (P)ONE; |
|
if ( NBM_GET(a->b,d1) ) NBM_SET(t->b,0); |
|
else NBM_CLR(t->b,0); |
|
*at = nbmtonbp(t); |
|
} |
|
|
|
if ( ar ) { |
|
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
|
for ( i = 0; i < d1; i++ ) { |
|
if ( NBM_GET(a->b,i) ) NBM_SET(t->b,i); |
|
else NBM_CLR(t->b,i); |
} |
} |
if ( !t ) { |
*ar = nbmtonbp(t); |
/* append */ |
} |
MKNODE(t1,wm,t); |
|
if ( !p ) r = t1; |
return a->c; |
else NEXT(p) = t1; |
} |
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
|
NBP make_xky(int k) |
|
{ |
|
int k1,i; |
|
NBM t; |
|
|
|
NEWNBM(t); NEWNBMBDY(t,k); t->d = k; t->c = (P)ONE; |
|
k1 = k-1; |
|
for ( i = 0; i < k1; i++ ) NBM_SET(t->b,i); |
|
NBM_CLR(t->b,i); |
|
return nbmtonbp(t); |
|
} |
|
|
|
/* 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) |
|
{ |
|
int i,d1,k,k1; |
|
NBM t; |
|
|
|
if ( !a->d ) |
|
error("separate_nbm : invalid argument"); |
|
for ( i = 0; i < a->d && NBM_GET(a->b,i); i++ ); |
|
if ( i == a->d ) |
|
error("separate_nbm : invalid argument"); |
|
k1 = i; |
|
k = i+1; |
|
|
|
if ( a0 ) { |
|
NEWNBM(t); t->d = a->d; t->b = a->b; t->c = (P)ONE; |
|
*a0 = nbmtonbp(t); |
|
} |
|
|
|
if ( ah ) { |
|
NEWNBM(t); NEWNBMBDY(t,k); t->d = k; t->c = (P)ONE; |
|
for ( i = 0; i < k1; i++ ) NBM_SET(t->b,i); |
|
NBM_CLR(t->b,i); |
|
*ah = nbmtonbp(t); |
|
} |
|
|
|
if ( ar ) { |
|
d1 = a->d-k; |
|
NEWNBM(t); NEWNBMBDY(t,d1); t->d = d1; t->c = (P)ONE; |
|
for ( i = 0; i < d1; i++ ) { |
|
if ( NBM_GET(a->b,i+k) ) NBM_SET(t->b,i); |
|
else NBM_CLR(t->b,i); |
} |
} |
} while ( ni_next(w,d) ); |
*ar = nbmtonbp(t); |
MKNBP(u,r); |
} |
return u; |
|
|
return a->c; |
} |
} |
|
|
int nbmtoxky(NBM a,int *b) |
void shuffle_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp); |
|
void harmonic_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp); |
|
void mulnbmnbp(VL vl,NBM m,NBP p, NBP *rp); |
|
void mulnbpnbm(VL vl,NBP p,NBM m, NBP *rp); |
|
|
|
NBP shuffle_mul_nbm(NBM a,NBM b) |
{ |
{ |
int d,i,j,k; |
NBP u,a0,ah,ar,b0,bh,br,a1,b1,t; |
int *p; |
P ac,bc,c; |
|
|
d = a->d; p = a->b; |
if ( !a->d || !b->d ) |
for ( i = j = 0, k = 1; i < d; i++ ) { |
u = nbmtonbp(mul_nbm(a,b)); |
if ( !NBM_GET(p,i) ) { |
else { |
b[j++] = k; |
ac = separate_nbm(a,&a0,&ah,&ar); |
k = 1; |
bc = separate_nbm(b,&b0,&bh,&br); |
} else k++; |
mulp(CO,ac,bc,&c); |
|
shuffle_mulnbp(CO,ar,b0,&t); mulnbp(CO,ah,t,&a1); |
|
shuffle_mulnbp(CO,a0,br,&t); mulnbp(CO,bh,t,&b1); |
|
addnbp(CO,a1,b1,&t); mulnbp(CO,(NBP)c,t,&u); |
} |
} |
return j; |
return u; |
} |
} |
|
|
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; |
NBP u,a0,ah,ar,b0,bh,br,a1,b1,t,s,abk,ab1; |
int i,j,k,ia,ib,s; |
P ac,bc,c; |
int *wa,*wb,*w,*wab,*wa1,*wmb; |
|
Q c,c1; |
|
NBM wm,tm; |
|
NODE r,t1,t,p; |
|
NBP u; |
|
|
|
da = a->d; db = b->d; d = da+db; |
if ( !a->d || !b->d ) |
wa = (int *)ALLOCA(da*sizeof(int)); |
u = nbmtonbp(mul_nbm(a,b)); |
wb = (int *)ALLOCA(db*sizeof(int)); |
else { |
la = nbmtoxky(a,wa); |
mulp(CO,a->c,b->c,&c); |
lb = nbmtoxky(b,wb); |
ac = separate_xky_nbm(a,&a0,&ah,&ar); |
mulq(a->c,b->c,&c); |
bc = separate_xky_nbm(b,&b0,&bh,&br); |
/* wa[0],..,wa[la-1] <-> x^wa[0]y x^wa[1]y .. */ |
mulp(CO,ac,bc,&c); |
/* lmax : total length */ |
harmonic_mulnbp(CO,ar,b0,&t); mulnbp(CO,ah,t,&a1); |
lmax = la+lb; |
harmonic_mulnbp(CO,a0,br,&t); mulnbp(CO,bh,t,&b1); |
lmin = la>lb?la:lb; |
abk = make_xky(((NBM)BDY(BDY(ah)))->d+((NBM)BDY(BDY(bh)))->d); |
w = (int *)ALLOCA(lmax*sizeof(int)); |
harmonic_mulnbp(CO,ar,br,&t); mulnbp(CO,abk,t,&ab1); |
/* position of a+b */ |
addnbp(CO,a1,b1,&t); addnbp(CO,t,ab1,&s); mulnbp(CO,(NBP)c,s,&u); |
wab = (int *)ALLOCA(lmax*sizeof(int)); |
|
/* position of a */ |
|
wa1 = (int *)ALLOCA(lmax*sizeof(int)); |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
for ( l = lmin, r = 0; l <= lmax; l++ ) { |
|
lab = lmax - l; |
|
la1 = la - lab; |
|
lb1 = lb - lab; |
|
lab1 = l-lab; |
|
/* partion l into three parts: a, b, a+b */ |
|
/* initialize wab */ |
|
for ( i = 0; i < lab; i++ ) wab[i] = 1; |
|
for ( ; i < l; i++ ) wab[i] = 0; |
|
do { |
|
/* initialize wa1 */ |
|
for ( i = 0; i < la1; i++ ) wa1[i] = 1; |
|
for ( ; i < lab1; i++ ) wa1[i] = 0; |
|
do { |
|
ia = 0; ib = 0; |
|
for ( i = j = 0; i < l; i++ ) |
|
if ( wab[i] ) w[i] = wa[ia++]+wb[ib++]; |
|
else if ( wa1[j++] ) w[i] = wa[ia++]; |
|
else w[i] = wb[ib++]; |
|
for ( i = j = 0; i < l; i++ ) { |
|
for ( k = w[i]-1; k > 0; k--, j++ ) NBM_SET(wmb,j); |
|
NBM_CLR(wmb,j); j++; |
|
} |
|
wm->d = j; wm->c = c; |
|
for ( p = 0, t = r; t; p = t, t = NEXT(t) ) { |
|
tm = (NBM)BDY(t); |
|
s = comp_nbm(tm,wm); |
|
if ( s < 0 ) { |
|
/* insert */ |
|
MKNODE(t1,wm,t); |
|
if ( !p ) r = t1; |
|
else NEXT(p) = t1; |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
break; |
|
} else if ( s == 0 ) { |
|
/* add coefs */ |
|
addq(tm->c,c,&c1); |
|
if ( c1 ) tm->c = c1; |
|
else NEXT(p) = NEXT(t); |
|
break; |
|
} |
|
} |
|
if ( !t ) { |
|
/* append */ |
|
MKNODE(t1,wm,t); |
|
if ( !p ) r = t1; |
|
else NEXT(p) = t1; |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
} |
|
} while ( ni_next(wa1,lab1) ); |
|
} while ( ni_next(wab,l) ); |
|
} |
} |
MKNBP(u,r); |
|
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; |
Q c; |
P c; |
|
|
if ( !p1 ) |
if ( !p1 ) |
*rp = p2; |
*rp = p2; |
Line 2005 void addnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
Line 2115 void addnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
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: |
addq(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; |
Line 2049 void subnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
Line 2159 void subnbp(VL vl,NBP p1,NBP p2, NBP *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; chsgnq(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 mulnbmnbp(VL vl,NBM m,NBP p, NBP *rp); |
|
void mulnbpnbm(VL vl,NBP p,NBM m, NBP *rp); |
|
|
|
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; |
Line 2075 void mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
Line 2182 void mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
*rp = 0; return; |
*rp = 0; return; |
} |
} |
if ( OID(p1) != O_NBP ) { |
if ( OID(p1) != O_NBP ) { |
if ( !NUM(p1) || !RATN(p1) ) error("mulnbp : invalid argument"); |
if ( !POLY(p1) ) |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (Q)p1; |
error("mulnbp : invalid argument"); |
|
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 ( !NUM(p2) || !RATN(p2) ) error("mulnbp : invalid argument"); |
if ( !POLY(p2) ) |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (Q)p2; |
error("mulnbp : invalid argument"); |
|
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)) ) { |
Line 2101 void mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
Line 2210 void mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
|
|
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 { |
Line 2116 void mulnbmnbp(VL vl,NBM m,NBP p, NBP *rp) |
|
Line 2225 void mulnbmnbp(VL vl,NBM m,NBP p, NBP *rp) |
|
|
|
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 { |
Line 2139 void pwrnbp(VL vl,NBP a,Q q,NBP *c) |
|
Line 2248 void pwrnbp(VL vl,NBP a,Q q,NBP *c) |
|
NODE r; |
NODE r; |
|
|
if ( !q ) { |
if ( !q ) { |
NEWNBM(m); m->d = 0; m->c = 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; |
Line 2156 void pwrnbp(VL vl,NBP a,Q q,NBP *c) |
|
Line 2265 void pwrnbp(VL vl,NBP a,Q q,NBP *c) |
|
} |
} |
} |
} |
|
|
|
int compnbp(VL vl,NBP p1,NBP p2) |
|
{ |
|
NODE n1,n2; |
|
NBM m1,m2; |
|
int t; |
|
|
|
if ( !p1 ) |
|
return p2 ? -1 : 0; |
|
else if ( !p2 ) |
|
return 1; |
|
else { |
|
for ( n1 = BDY(p1), n2 = BDY(p2); |
|
n1 && n2; n1 = NEXT(n1), n2 = NEXT(n2) ) { |
|
m1 = (NBM)BDY(n1); m2 = (NBM)BDY(n2); |
|
if ( (t = comp_nbm(m1,m2)) || (t = compp(CO,m1->c,m2->c) ) ) |
|
return t; |
|
} |
|
if ( n1 ) |
|
return 1; |
|
else if ( n2 ) |
|
return -1; |
|
else |
|
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; |
Line 2166 void shuffle_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
Line 2301 void shuffle_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
*rp = 0; return; |
*rp = 0; return; |
} |
} |
if ( OID(p1) != O_NBP ) { |
if ( OID(p1) != O_NBP ) { |
if ( !NUM(p1) || !RATN(p1) ) error("mulnbp : invalid argument"); |
if ( !POLY(p1) ) |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (Q)p1; |
error("shuffle_mulnbp : invalid argument"); |
|
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 ( !NUM(p2) || !RATN(p2) ) error("mulnbp : invalid argument"); |
if ( !POLY(p2) ) |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (Q)p2; |
error("shuffle_mulnbp : invalid argument"); |
|
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) ) |
Line 2193 void harmonic_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
Line 2330 void harmonic_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
*rp = 0; return; |
*rp = 0; return; |
} |
} |
if ( OID(p1) != O_NBP ) { |
if ( OID(p1) != O_NBP ) { |
if ( !NUM(p1) || !RATN(p1) ) error("mulnbp : invalid argument"); |
if ( !POLY(p1) ) |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (Q)p1; |
error("harmonic_mulnbp : invalid argument"); |
|
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 ( !NUM(p2) || !RATN(p2) ) error("mulnbp : invalid argument"); |
if ( !POLY(p2) ) |
NEWNBM(m); m->d = 0; m->b = 0; m->c = (Q)p2; |
error("harmonic_mulnbp : invalid argument"); |
|
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) ) |
Line 2209 void harmonic_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
Line 2348 void harmonic_mulnbp(VL vl,NBP p1,NBP p2, NBP *rp) |
|
} |
} |
*rp = r; |
*rp = r; |
} |
} |
|
|
|
#if 0 |
|
NBP shuffle_mul_nbm(NBM a,NBM b) |
|
{ |
|
int ad,bd,d,i,ai,bi,bit,s; |
|
int *ab,*bb,*wmb,*w; |
|
NBM wm,tm; |
|
P c,c1; |
|
NODE r,t,t1,p; |
|
NBP u; |
|
|
|
ad = a->d; bd = b->d; ab = a->b; bb = b->b; |
|
d = ad + bd; |
|
w = (int *)ALLOCA(d*sizeof(int)); |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
for ( i = 0; i < ad; i++ ) w[i] = 1; |
|
for ( ; i < d; i++ ) w[i] = 0; |
|
mulp(CO,a->c,b->c,&c); |
|
r = 0; |
|
do { |
|
wm->d = d; wm->c = c; |
|
ai = 0; bi = 0; |
|
for ( i = 0; i < d; i++ ) { |
|
if ( w[i] ) { bit = NBM_GET(ab,ai); ai++; } |
|
else { bit = NBM_GET(bb,bi); bi++; } |
|
if ( bit ) NBM_SET(wmb,i); |
|
else NBM_CLR(wmb,i); |
|
} |
|
for ( p = 0, t = r; t; p = t, t = NEXT(t) ) { |
|
tm = (NBM)BDY(t); |
|
s = comp_nbm(tm,wm); |
|
if ( s < 0 ) { |
|
/* insert */ |
|
MKNODE(t1,wm,t); |
|
if ( !p ) r = t1; |
|
else NEXT(p) = t1; |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
break; |
|
} else if ( s == 0 ) { |
|
/* add coefs */ |
|
addp(CO,tm->c,c,&c1); |
|
if ( c1 ) tm->c = c1; |
|
else NEXT(p) = NEXT(t); |
|
break; |
|
} |
|
} |
|
if ( !t ) { |
|
/* append */ |
|
MKNODE(t1,wm,t); |
|
if ( !p ) r = t1; |
|
else NEXT(p) = t1; |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
} |
|
} while ( ni_next(w,d) ); |
|
MKNBP(u,r); |
|
return u; |
|
} |
|
|
|
int nbmtoxky(NBM a,int *b) |
|
{ |
|
int d,i,j,k; |
|
int *p; |
|
|
|
d = a->d; p = a->b; |
|
for ( i = j = 0, k = 1; i < d; i++ ) { |
|
if ( !NBM_GET(p,i) ) { |
|
b[j++] = k; |
|
k = 1; |
|
} else k++; |
|
} |
|
return j; |
|
} |
|
|
|
NBP harmonic_mul_nbm(NBM a,NBM b) |
|
{ |
|
int da,db,d,la,lb,lmax,lmin,l,lab,la1,lb1,lab1; |
|
int i,j,k,ia,ib,s; |
|
int *wa,*wb,*w,*wab,*wa1,*wmb; |
|
P c,c1; |
|
NBM wm,tm; |
|
NODE r,t1,t,p; |
|
NBP u; |
|
|
|
da = a->d; db = b->d; d = da+db; |
|
wa = (int *)ALLOCA(da*sizeof(int)); |
|
wb = (int *)ALLOCA(db*sizeof(int)); |
|
la = nbmtoxky(a,wa); |
|
lb = nbmtoxky(b,wb); |
|
mulp(CO,a->c,b->c,&c); |
|
/* wa[0],..,wa[la-1] <-> x^wa[0]y x^wa[1]y .. */ |
|
/* lmax : total length */ |
|
lmax = la+lb; |
|
lmin = la>lb?la:lb; |
|
w = (int *)ALLOCA(lmax*sizeof(int)); |
|
/* position of a+b */ |
|
wab = (int *)ALLOCA(lmax*sizeof(int)); |
|
/* position of a */ |
|
wa1 = (int *)ALLOCA(lmax*sizeof(int)); |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
for ( l = lmin, r = 0; l <= lmax; l++ ) { |
|
lab = lmax - l; |
|
la1 = la - lab; |
|
lb1 = lb - lab; |
|
lab1 = l-lab; |
|
/* partion l into three parts: a, b, a+b */ |
|
/* initialize wab */ |
|
for ( i = 0; i < lab; i++ ) wab[i] = 1; |
|
for ( ; i < l; i++ ) wab[i] = 0; |
|
do { |
|
/* initialize wa1 */ |
|
for ( i = 0; i < la1; i++ ) wa1[i] = 1; |
|
for ( ; i < lab1; i++ ) wa1[i] = 0; |
|
do { |
|
ia = 0; ib = 0; |
|
for ( i = j = 0; i < l; i++ ) |
|
if ( wab[i] ) w[i] = wa[ia++]+wb[ib++]; |
|
else if ( wa1[j++] ) w[i] = wa[ia++]; |
|
else w[i] = wb[ib++]; |
|
for ( i = j = 0; i < l; i++ ) { |
|
for ( k = w[i]-1; k > 0; k--, j++ ) NBM_SET(wmb,j); |
|
NBM_CLR(wmb,j); j++; |
|
} |
|
wm->d = j; wm->c = c; |
|
for ( p = 0, t = r; t; p = t, t = NEXT(t) ) { |
|
tm = (NBM)BDY(t); |
|
s = comp_nbm(tm,wm); |
|
if ( s < 0 ) { |
|
/* insert */ |
|
MKNODE(t1,wm,t); |
|
if ( !p ) r = t1; |
|
else NEXT(p) = t1; |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
break; |
|
} else if ( s == 0 ) { |
|
/* add coefs */ |
|
addp(CO,tm->c,c,&c1); |
|
if ( c1 ) tm->c = c1; |
|
else NEXT(p) = NEXT(t); |
|
break; |
|
} |
|
} |
|
if ( !t ) { |
|
/* append */ |
|
MKNODE(t1,wm,t); |
|
if ( !p ) r = t1; |
|
else NEXT(p) = t1; |
|
NEWNBM(wm); NEWNBMBDY(wm,d); wmb = wm->b; |
|
} |
|
} while ( ni_next(wa1,lab1) ); |
|
} while ( ni_next(wab,l) ); |
|
} |
|
MKNBP(u,r); |
|
return u; |
|
} |
|
#endif |