version 1.5, 2000/08/21 08:31:27 |
version 1.8, 2000/12/05 08:29:44 |
|
|
* shall be made on your publication or presentation in any form of the |
* shall be made on your publication or presentation in any form of the |
* results obtained by use of the SOFTWARE. |
* results obtained by use of the SOFTWARE. |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification |
* e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification |
* for such modification or the source code of the modified part of the |
* for such modification or the source code of the modified part of the |
* SOFTWARE. |
* SOFTWARE. |
* |
* |
|
|
* 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/distm.c,v 1.4 2000/07/13 05:09:01 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/distm.c,v 1.7 2000/12/05 06:59:16 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
|
|
#define NV(p) ((p)->nv) |
|
#define C(p) ((p)->c) |
|
#if 0 |
|
#define ITOS(p) (((unsigned int)(p))>>1) |
|
#define STOI(i) ((P)((((unsigned int)(i))<<1)|1)) |
|
#else |
|
#define ITOS(p) (((unsigned int)(p))&0x7fffffff) |
|
#define STOI(i) ((P)((unsigned int)(i)|0x80000000)) |
|
#endif |
|
|
|
extern int (*cmpdl)(); |
extern int (*cmpdl)(); |
extern int do_weyl; |
extern int do_weyl; |
|
|
Line 67 void comm_mulmd(); |
|
Line 57 void comm_mulmd(); |
|
void weyl_mulmd(); |
void weyl_mulmd(); |
void weyl_mulmdm(); |
void weyl_mulmdm(); |
void weyl_mulmmm(); |
void weyl_mulmmm(); |
void _comm_mulmd(); |
|
void _weyl_mulmd(); |
|
void _weyl_mulmmm(); |
|
void _weyl_mulmdm(); |
|
|
|
|
void mulmdm_dup(); |
|
void comm_mulmd_dup(); |
|
void weyl_mulmd_dup(); |
|
void weyl_mulmdm_dup(); |
|
void weyl_mulmmm_dup(); |
|
void comm_mulmd_tab_destructive(); |
|
void adddl_dup(); |
void ptomd(vl,mod,dvl,p,pr) |
void ptomd(vl,mod,dvl,p,pr) |
VL vl,dvl; |
VL vl,dvl; |
int mod; |
int mod; |
|
|
} |
} |
} |
} |
|
|
void _mdtop(vl,mod,dvl,p,pr) |
void _dtop_mod(vl,dvl,p,pr) |
VL vl,dvl; |
VL vl,dvl; |
int mod; |
|
DP p; |
DP p; |
P *pr; |
P *pr; |
{ |
{ |
|
|
MP m; |
MP m; |
P r,s,t,u,w; |
P r,s,t,u,w; |
Q q; |
Q q; |
MQ tq; |
|
VL tvl; |
VL tvl; |
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
else { |
else { |
for ( n = p->nv, m = BDY(p), s = 0; m; m = NEXT(m) ) { |
for ( n = p->nv, m = BDY(p), s = 0; m; m = NEXT(m) ) { |
STOMQ(ITOS(C(m)),tq); t = (P)tq; |
i = ITOS(m->c); STOQ(i,q); t = (P)q; |
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); pwrmp(vl,mod,r,q,&u); |
MKV(tvl->v,r); STOQ(d->d[i],q); pwrp(vl,r,q,&u); |
mulmp(vl,mod,t,u,&w); t = w; |
mulp(vl,t,u,&w); t = w; |
} |
} |
addmp(vl,mod,s,t,&u); s = u; |
addp(vl,s,t,&u); s = u; |
} |
} |
mptop(s,pr); |
*pr = s; |
} |
} |
} |
} |
|
|
void _addmd(vl,mod,p1,p2,pr) |
void _dp_mod(p,mod,subst,rp) |
VL vl; |
DP p; |
int mod; |
int mod; |
|
NODE subst; |
|
DP *rp; |
|
{ |
|
MP m,mr,mr0; |
|
P t,s; |
|
NODE tn; |
|
|
|
if ( !p ) |
|
*rp = 0; |
|
else { |
|
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
|
for ( tn = subst, s = m->c; tn; tn = NEXT(NEXT(tn)) ) { |
|
substp(CO,s,BDY(tn),BDY(NEXT(tn)),&t); |
|
s = t; |
|
} |
|
ptomp(mod,s,&t); |
|
if ( t ) { |
|
NEXTMP(mr0,mr); mr->c = STOI(CONT((MQ)t)); mr->dl = m->dl; |
|
} |
|
} |
|
if ( mr0 ) { |
|
NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar; |
|
} else |
|
*rp = 0; |
|
} |
|
} |
|
|
|
void _dp_monic(p,mod,rp) |
|
DP p; |
|
int mod; |
|
DP *rp; |
|
{ |
|
MP m,mr,mr0; |
|
int c,c1; |
|
NODE tn; |
|
|
|
if ( !p ) |
|
*rp = 0; |
|
else { |
|
c = invm(ITOS(BDY(p)->c),mod); |
|
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
|
c1 = dmar(ITOS(m->c),c,0,mod); |
|
NEXTMP(mr0,mr); mr->c = STOI(c1); mr->dl = m->dl; |
|
} |
|
NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar; |
|
} |
|
} |
|
|
|
void _printdp(d) |
|
DP d; |
|
{ |
|
int n,i; |
|
MP m; |
|
DL dl; |
|
|
|
if ( !d ) { |
|
printf("0"); return; |
|
} |
|
for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) { |
|
printf("%d*<<",ITOS(m->c)); |
|
for ( i = 0, dl = m->dl; i < n-1; i++ ) |
|
printf("%d,",dl->d[i]); |
|
printf("%d",dl->d[i]); |
|
printf(">>"); |
|
if ( NEXT(m) ) |
|
printf("+"); |
|
} |
|
} |
|
|
|
/* merge p1 and p2 into pr */ |
|
|
|
void addmd_destructive(mod,p1,p2,pr) |
|
int mod; |
DP p1,p2,*pr; |
DP p1,p2,*pr; |
{ |
{ |
int n; |
int n; |
MP m1,m2,mr,mr0; |
MP m1,m2,mr,mr0,s; |
int t; |
int t; |
|
|
if ( !p1 ) |
if ( !p1 ) |
|
|
t = (ITOS(C(m1))+ITOS(C(m2))) - mod; |
t = (ITOS(C(m1))+ITOS(C(m2))) - mod; |
if ( t < 0 ) |
if ( t < 0 ) |
t += mod; |
t += mod; |
|
s = m1; m1 = NEXT(m1); |
if ( t ) { |
if ( t ) { |
NEXTMP(mr0,mr); mr->dl = m1->dl; C(mr) = STOI(t); |
NEXTMP2(mr0,mr,s); C(mr) = STOI(t); |
} |
} |
m1 = NEXT(m1); m2 = NEXT(m2); break; |
s = m2; m2 = NEXT(m2); |
|
break; |
case 1: |
case 1: |
NEXTMP(mr0,mr); mr->dl = m1->dl; C(mr) = C(m1); |
s = m1; m1 = NEXT(m1); NEXTMP2(mr0,mr,s); |
m1 = NEXT(m1); break; |
break; |
case -1: |
case -1: |
NEXTMP(mr0,mr); mr->dl = m2->dl; C(mr) = C(m2); |
s = m2; m2 = NEXT(m2); NEXTMP2(mr0,mr,s); |
m2 = NEXT(m2); break; |
break; |
} |
} |
if ( !mr0 ) |
if ( !mr0 ) |
if ( m1 ) |
if ( m1 ) |
|
|
} |
} |
} |
} |
|
|
void _submd(vl,mod,p1,p2,pr) |
void mulmd_dup(mod,p1,p2,pr) |
VL vl; |
|
int mod; |
int mod; |
DP p1,p2,*pr; |
DP p1,p2,*pr; |
{ |
{ |
DP t; |
|
|
|
if ( !p2 ) |
|
*pr = p1; |
|
else { |
|
_chsgnmd(mod,p2,&t); _addmd(vl,mod,p1,t,pr); |
|
} |
|
} |
|
|
|
void _chsgnmd(mod,p,pr) |
|
int mod; |
|
DP p,*pr; |
|
{ |
|
MP m,mr,mr0; |
|
|
|
if ( !p ) |
|
*pr = 0; |
|
else { |
|
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
|
NEXTMP(mr0,mr); C(mr) = STOI(mod - ITOS(C(m))); mr->dl = m->dl; |
|
} |
|
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
|
if ( *pr ) |
|
(*pr)->sugar = p->sugar; |
|
} |
|
} |
|
|
|
void _mulmd(vl,mod,p1,p2,pr) |
|
VL vl; |
|
int mod; |
|
DP p1,p2,*pr; |
|
{ |
|
if ( !do_weyl ) |
if ( !do_weyl ) |
_comm_mulmd(vl,mod,p1,p2,pr); |
comm_mulmd_dup(mod,p1,p2,pr); |
else |
else |
_weyl_mulmd(vl,mod,p1,p2,pr); |
weyl_mulmd_dup(mod,p1,p2,pr); |
} |
} |
|
|
void _comm_mulmd(vl,mod,p1,p2,pr) |
void comm_mulmd_dup(mod,p1,p2,pr) |
VL vl; |
|
int mod; |
int mod; |
DP p1,p2,*pr; |
DP p1,p2,*pr; |
{ |
{ |
|
|
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-- ) { |
_mulmdm(vl,mod,p1,w[i],&t); _addmd(vl,mod,s,t,&u); s = u; |
mulmdm_dup(mod,p1,w[i],&t); addmd_destructive(mod,s,t,&u); s = u; |
} |
} |
bzero(w,l*sizeof(MP)); |
bzero(w,l*sizeof(MP)); |
*pr = s; |
*pr = s; |
} |
} |
} |
} |
|
|
void _weyl_mulmd(vl,mod,p1,p2,pr) |
void weyl_mulmd_dup(mod,p1,p2,pr) |
VL vl; |
|
int mod; |
int mod; |
DP p1,p2,*pr; |
DP p1,p2,*pr; |
{ |
{ |
|
|
if ( !p1 || !p2 ) |
if ( !p1 || !p2 ) |
*pr = 0; |
*pr = 0; |
else { |
else { |
for ( m = BDY(p2), 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 ) GC_free(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(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_mulmdm(vl,mod,p1,w[i],&t); _addmd(vl,mod,s,t,&u); s = u; |
weyl_mulmdm_dup(mod,w[i],p2,&t); addmd_destructive(mod,s,t,&u); s = u; |
} |
} |
bzero(w,l*sizeof(MP)); |
bzero(w,l*sizeof(MP)); |
*pr = s; |
*pr = s; |
} |
} |
} |
} |
|
|
void _mulmdm(vl,mod,p,m0,pr) |
void mulmdm_dup(mod,p,m0,pr) |
VL vl; |
|
int mod; |
int mod; |
DP p; |
DP p; |
MP m0; |
MP m0; |
DP *pr; |
DP *pr; |
{ |
{ |
MP m,mr,mr0; |
MP m,mr,mr0; |
DL d; |
DL d,dt,dm; |
int c,n,r; |
int c,n,r,i; |
|
int *pt,*p1,*p2; |
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
|
|
m; m = NEXT(m) ) { |
m; m = NEXT(m) ) { |
NEXTMP(mr0,mr); |
NEXTMP(mr0,mr); |
C(mr) = STOI(dmar(ITOS(C(m)),c,0,mod)); |
C(mr) = STOI(dmar(ITOS(C(m)),c,0,mod)); |
adddl(n,m->dl,d,&mr->dl); |
NEWDL_NOINIT(dt,n); mr->dl = dt; |
|
dm = m->dl; |
|
dt->td = d->td + dm->td; |
|
for ( i = 0, pt = dt->d, p1=d->d, p2 = dm->d; i < n; i++ ) |
|
*pt++ = *p1++ + *p2++; |
} |
} |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
NEXT(mr) = 0; MKDP(NV(p),mr0,*pr); |
if ( *pr ) |
if ( *pr ) |
|
|
} |
} |
} |
} |
|
|
void _weyl_mulmdm(vl,mod,p,m0,pr) |
void weyl_mulmdm_dup(mod,m0,p,pr) |
VL vl; |
|
int mod; |
int mod; |
DP p; |
|
MP m0; |
MP m0; |
|
DP p; |
DP *pr; |
DP *pr; |
{ |
{ |
DP r,t,t1; |
DP r,t,t1; |
MP m; |
MP m; |
int n,l,i; |
DL d0; |
static MP *w; |
int n,n2,l,i,j,tlen; |
|
static MP *w,*psum; |
|
static struct cdlm *tab; |
static int wlen; |
static int wlen; |
|
static int rtlen; |
|
|
if ( !p ) |
if ( !p ) |
*pr = 0; |
*pr = 0; |
|
|
} |
} |
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; |
for ( r = 0, i = l-1, n = NV(p); i >= 0; i-- ) { |
n = NV(p); n2 = n>>1; |
_weyl_mulmmm(vl,mod,w[i],m0,n,&t); |
d0 = m0->dl; |
_addmd(vl,mod,r,t,&t1); r = t1; |
|
|
for ( i = 0, tlen = 1; i < n2; i++ ) |
|
tlen *= d0->d[n2+i]+1; |
|
if ( tlen > rtlen ) { |
|
if ( tab ) GC_free(tab); |
|
if ( psum ) GC_free(psum); |
|
rtlen = tlen; |
|
tab = (struct cdlm *)MALLOC(rtlen*sizeof(struct cdlm)); |
|
psum = (MP *)MALLOC(rtlen*sizeof(MP)); |
} |
} |
bzero(w,l*sizeof(MP)); |
bzero(psum,tlen*sizeof(MP)); |
|
for ( i = l-1; i >= 0; i-- ) { |
|
bzero(tab,tlen*sizeof(struct cdlm)); |
|
weyl_mulmmm_dup(mod,m0,w[i],n,tab,tlen); |
|
for ( j = 0; j < tlen; j++ ) { |
|
if ( tab[j].c ) { |
|
NEWMP(m); m->dl = tab[j].d; |
|
C(m) = STOI(tab[j].c); NEXT(m) = psum[j]; |
|
psum[j] = m; |
|
} |
|
} |
|
} |
|
for ( j = tlen-1, r = 0; j >= 0; j-- ) |
|
if ( psum[j] ) { |
|
MKDP(n,psum[j],t); addmd_destructive(mod,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^d(n/2)*dx1^d(n/2+1)*... */ |
/* m0 = x0^d0*x1^d1*... * dx0^d(n/2)*dx1^d(n/2+1)*... */ |
|
|
void _weyl_mulmmm(vl,mod,m0,m1,n,pr) |
void weyl_mulmmm_dup(mod,m0,m1,n,rtab,rtablen) |
VL vl; |
|
int mod; |
int mod; |
MP m0,m1; |
MP m0,m1; |
int n; |
int n; |
DP *pr; |
struct cdlm *rtab; |
|
int rtablen; |
{ |
{ |
MP m,mr,mr0; |
MP m,mr,mr0; |
DP r,t,t1; |
DP r,t,t1; |
int c,c0,c1,cc; |
int c,c0,c1,cc; |
DL d,d0,d1; |
DL d,d0,d1,dt; |
int i,j,a,b,k,l,n2,s,min,h; |
int i,j,a,b,k,l,n2,s,min,h,curlen; |
static int *tab; |
struct cdlm *p; |
|
static int *ctab; |
|
static struct cdlm *tab; |
static int tablen; |
static int tablen; |
|
static struct cdlm *tmptab; |
|
static int tmptablen; |
|
|
if ( !m0 || !m1 ) |
if ( !m0 || !m1 ) { |
*pr = 0; |
rtab[0].c = 0; |
else { |
rtab[0].d = 0; |
c0 = ITOS(C(m0)); c1 = ITOS(C(m1)); |
return; |
c = dmar(c0,c1,0,mod); |
} |
d0 = m0->dl; d1 = m1->dl; |
c0 = ITOS(C(m0)); c1 = ITOS(C(m1)); |
n2 = n>>1; |
c = dmar(c0,c1,0,mod); |
|
d0 = m0->dl; d1 = m1->dl; |
|
n2 = n>>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; |
NEWMP(mr); mr->c = STOI(c); mr->dl = d; NEXT(mr) = 0; |
rtab[0].c = c; |
MKDP(n,mr,r); r->sugar = d->td; |
rtab[0].d = d; |
|
|
/* homogenized computation; dx-xd=h^2 */ |
if ( rtablen > tmptablen ) { |
for ( i = 0; i < n2; i++ ) { |
if ( tmptab ) GC_free(tmptab); |
a = d0->d[i]; b = d1->d[n2+i]; |
tmptab = (struct cdlm *)MALLOC(rtablen*sizeof(struct cdlm)); |
k = d0->d[n2+i]; l = d1->d[i]; |
tmptablen = rtablen; |
/* degree of xi^a*(Di^k*xi^l)*Di^b */ |
|
s = a+k+l+b; |
|
/* compute xi^a*(Di^k*xi^l)*Di^b */ |
|
min = MIN(k,l); |
|
|
|
if ( min+1 > tablen ) { |
|
if ( tab ) GC_free(tab); |
|
tab = (int *)MALLOC((min+1)*sizeof(int)); |
|
tablen = min+1; |
|
} |
|
mkwcm(k,l,mod,tab); |
|
if ( n & 1 ) |
|
for ( mr0 = 0, j = 0; j <= min; j++ ) { |
|
NEXTMP(mr0,mr); NEWDL(d,n); |
|
d->d[i] = l-j+a; d->d[n2+i] = k-j+b; |
|
d->td = s; |
|
d->d[n-1] = s-(d->d[i]+d->d[n2+i]); |
|
mr->c = STOI(tab[j]); mr->dl = d; |
|
} |
|
else |
|
for ( mr0 = 0, s = 0, j = 0; j <= min; j++ ) { |
|
NEXTMP(mr0,mr); NEWDL(d,n); |
|
d->d[i] = l-j+a; d->d[n2+i] = k-j+b; |
|
d->td = d->d[i]+d->d[n2+i]; /* XXX */ |
|
s = MAX(s,d->td); /* XXX */ |
|
mr->c = STOI(tab[j]); mr->dl = d; |
|
} |
|
bzero(tab,(min+1)*sizeof(int)); |
|
if ( mr0 ) |
|
NEXT(mr) = 0; |
|
MKDP(n,mr0,t); |
|
if ( t ) |
|
t->sugar = s; |
|
_comm_mulmd(vl,mod,r,t,&t1); r = t1; |
|
} |
|
*pr = r; |
|
} |
} |
} |
|
|
|
void _dtop_mod(vl,dvl,p,pr) |
for ( i = 0; i < n2; i++ ) { |
VL vl,dvl; |
a = d0->d[i]; b = d1->d[n2+i]; |
DP p; |
k = d0->d[n2+i]; l = d1->d[i]; |
P *pr; |
if ( !k || !l ) { |
{ |
a += l; |
int n,i; |
b += k; |
DL d; |
s = a+b; |
MP m; |
for ( j = 0, p = rtab; j < curlen; j++, p++ ) { |
P r,s,t,u,w; |
if ( p->c ) { |
Q q; |
dt = p->d; |
VL tvl; |
dt->d[i] = a; |
|
dt->d[n2+i] = b; |
if ( !p ) |
dt->td += s; |
*pr = 0; |
} |
else { |
|
for ( n = p->nv, m = BDY(p), s = 0; m; m = NEXT(m) ) { |
|
i = ITOS(m->c); STOQ(i,q); t = (P)q; |
|
for ( i = 0, d = m->dl, tvl = dvl; |
|
i < n; tvl = NEXT(tvl), i++ ) { |
|
MKV(tvl->v,r); STOQ(d->d[i],q); pwrp(vl,r,q,&u); |
|
mulp(vl,t,u,&w); t = w; |
|
} |
} |
addp(vl,s,t,&u); s = u; |
curlen *= k+1; |
|
continue; |
} |
} |
*pr = s; |
if ( k+1 > tablen ) { |
} |
if ( tab ) GC_free(tab); |
} |
if ( ctab ) GC_free(ctab); |
|
tablen = k+1; |
void _dp_red_mod(p1,p2,mod,rp) |
tab = (struct cdlm *)MALLOC(tablen*sizeof(struct cdlm)); |
DP p1,p2; |
ctab = (int *)MALLOC(tablen*sizeof(int)); |
int mod; |
} |
DP *rp; |
/* degree of xi^a*(Di^k*xi^l)*Di^b */ |
{ |
s = a+k+l+b; |
int i,n; |
/* compute xi^a*(Di^k*xi^l)*Di^b */ |
DL d1,d2,d; |
min = MIN(k,l); |
MP m; |
mkwcm(k,l,mod,ctab); |
DP t,s; |
bzero(tab,(k+1)*sizeof(struct cdlm)); |
int c,c1; |
/* n&1 != 0 => homogenized computation; dx-xd=h^2 */ |
|
if ( n & 1 ) |
n = p1->nv; d1 = BDY(p1)->dl; d2 = BDY(p2)->dl; |
for ( j = 0; j <= min; j++ ) { |
NEWDL(d,n); d->td = d1->td - d2->td; |
NEWDL(d,n); |
for ( i = 0; i < n; i++ ) |
d->d[i] = l-j+a; d->d[n2+i] = k-j+b; |
d->d[i] = d1->d[i]-d2->d[i]; |
d->td = s; |
c = invm(ITOS(BDY(p2)->c),mod); c1 = dmar(c,ITOS(BDY(p1)->c),0,mod); |
d->d[n-1] = s-(d->d[i]+d->d[n2+i]); |
NEWMP(m); m->dl = d; m->c = STOI(mod-c1); NEXT(m) = 0; |
tab[j].d = d; |
MKDP(n,m,s); s->sugar = d->td; |
tab[j].c = ctab[j]; |
_mulmd(CO,mod,s,p2,&t); _addmd(CO,mod,p1,t,rp); |
|
} |
|
|
|
void _dp_mod(p,mod,subst,rp) |
|
DP p; |
|
int mod; |
|
NODE subst; |
|
DP *rp; |
|
{ |
|
MP m,mr,mr0; |
|
P t,s; |
|
NODE tn; |
|
|
|
if ( !p ) |
|
*rp = 0; |
|
else { |
|
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
|
for ( tn = subst, s = m->c; tn; tn = NEXT(NEXT(tn)) ) { |
|
substp(CO,s,BDY(tn),BDY(NEXT(tn)),&t); |
|
s = t; |
|
} |
} |
ptomp(mod,s,&t); |
else |
if ( t ) { |
for ( j = 0; j <= min; j++ ) { |
NEXTMP(mr0,mr); mr->c = STOI(CONT((MQ)t)); mr->dl = m->dl; |
NEWDL(d,n); |
|
d->d[i] = l-j+a; d->d[n2+i] = k-j+b; |
|
d->td = d->d[i]+d->d[n2+i]; /* XXX */ |
|
tab[j].d = d; |
|
tab[j].c = ctab[j]; |
} |
} |
} |
comm_mulmd_tab_destructive(mod,n,rtab,curlen,tab,k+1); |
if ( mr0 ) { |
curlen *= k+1; |
NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar; |
|
} else |
|
*rp = 0; |
|
} |
} |
} |
} |
|
|
void _dp_monic(p,mod,rp) |
void comm_mulmd_tab_destructive(mod,nv,t,n,t1,n1) |
DP p; |
|
int mod; |
int mod; |
DP *rp; |
int nv; |
|
struct cdlm *t; |
|
int n; |
|
struct cdlm *t1; |
|
int n1; |
{ |
{ |
MP m,mr,mr0; |
int i,j; |
int c,c1; |
struct cdlm *p; |
NODE tn; |
int c; |
|
DL d; |
|
|
if ( !p ) |
for ( j = 1, p = t+n; j < n1; j++ ) { |
*rp = 0; |
c = t1[j].c; |
else { |
d = t1[j].d; |
c = invm(ITOS(BDY(p)->c),mod); |
if ( !c ) |
for ( mr0 = 0, m = BDY(p); m; m = NEXT(m) ) { |
break; |
c1 = dmar(ITOS(m->c),c,0,mod); |
for ( i = 0; i < n; i++, p++ ) { |
NEXTMP(mr0,mr); mr->c = STOI(c1); mr->dl = m->dl; |
if ( t[i].c ) { |
|
p->c = dmar(t[i].c,c,0,mod); |
|
adddl_dup(nv,t[i].d,d,&p->d); |
|
} |
} |
} |
NEXT(mr) = 0; MKDP(p->nv,mr0,*rp); (*rp)->sugar = p->sugar; |
|
} |
} |
|
c = t1[0].c; |
|
d = t1[0].d; |
|
for ( i = 0, p = t; i < n; i++, p++ ) |
|
if ( t[i].c ) { |
|
p->c = dmar(t[i].c,c,0,mod); |
|
/* t[i].d += d */ |
|
adddl_destructive(nv,t[i].d,d); |
|
} |
} |
} |
|
|
void _dp_sp_mod(p1,p2,mod,rp) |
void adddl_dup(n,d1,d2,dr) |
DP p1,p2; |
int n; |
int mod; |
DL d1,d2; |
DP *rp; |
DL *dr; |
{ |
{ |
int i,n,td; |
DL dt; |
int *w; |
int i; |
DL d1,d2,d; |
|
MP m; |
|
DP t,s,u; |
|
|
|
n = p1->nv; d1 = BDY(p1)->dl; d2 = BDY(p2)->dl; |
NEWDL(dt,n); |
w = (int *)ALLOCA(n*sizeof(int)); |
*dr = dt; |
for ( i = 0, td = 0; i < n; i++ ) { |
dt->td = d1->td + d2->td; |
w[i] = MAX(d1->d[i],d2->d[i]); td += w[i]; |
|
} |
|
NEWDL(d,n); d->td = td - d1->td; |
|
for ( i = 0; i < n; i++ ) |
for ( i = 0; i < n; i++ ) |
d->d[i] = w[i] - d1->d[i]; |
dt->d[i] = d1->d[i]+d2->d[i]; |
NEWMP(m); m->dl = d; m->c = BDY(p2)->c; NEXT(m) = 0; |
|
MKDP(n,m,s); s->sugar = d->td; _mulmd(CO,mod,s,p1,&t); |
|
NEWDL(d,n); d->td = td - d2->td; |
|
for ( i = 0; i < n; i++ ) |
|
d->d[i] = w[i] - d2->d[i]; |
|
NEWMP(m); m->dl = d; m->c = STOI(mod - ITOS(BDY(p1)->c)); NEXT(m) = 0; |
|
MKDP(n,m,s); s->sugar = d->td; _mulmd(CO,mod,s,p2,&u); |
|
_addmd(CO,mod,t,u,rp); |
|
} |
|
|
|
void _dp_sp_component_mod(p1,p2,mod,f1,f2) |
|
DP p1,p2; |
|
int mod; |
|
DP *f1,*f2; |
|
{ |
|
int i,n,td; |
|
int *w; |
|
DL d1,d2,d; |
|
MP m; |
|
DP t,s,u; |
|
|
|
n = p1->nv; d1 = BDY(p1)->dl; d2 = BDY(p2)->dl; |
|
w = (int *)ALLOCA(n*sizeof(int)); |
|
for ( i = 0, td = 0; i < n; i++ ) { |
|
w[i] = MAX(d1->d[i],d2->d[i]); td += w[i]; |
|
} |
|
NEWDL(d,n); d->td = td - d1->td; |
|
for ( i = 0; i < n; i++ ) |
|
d->d[i] = w[i] - d1->d[i]; |
|
NEWMP(m); m->dl = d; m->c = BDY(p2)->c; NEXT(m) = 0; |
|
MKDP(n,m,s); s->sugar = d->td; _mulmd(CO,mod,s,p1,f1); |
|
NEWDL(d,n); d->td = td - d2->td; |
|
for ( i = 0; i < n; i++ ) |
|
d->d[i] = w[i] - d2->d[i]; |
|
NEWMP(m); m->dl = d; m->c = BDY(p1)->c; NEXT(m) = 0; |
|
MKDP(n,m,s); s->sugar = d->td; _mulmd(CO,mod,s,p2,f2); |
|
} |
|
|
|
void _printdp(d) |
|
DP d; |
|
{ |
|
int n,i; |
|
MP m; |
|
DL dl; |
|
|
|
if ( !d ) { |
|
printf("0"); return; |
|
} |
|
for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) { |
|
printf("%d*<<",ITOS(m->c)); |
|
for ( i = 0, dl = m->dl; i < n-1; i++ ) |
|
printf("%d,",dl->d[i]); |
|
printf("%d",dl->d[i]); |
|
printf(">>"); |
|
if ( NEXT(m) ) |
|
printf("+"); |
|
} |
|
} |
} |