version 1.3, 2019/08/21 00:37:47 |
version 1.5, 2019/09/13 02:04:42 |
|
|
* 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/asir2018/builtin/dp-supp.c,v 1.2 2018/09/28 08:20:27 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2018/builtin/dp-supp.c,v 1.4 2019/09/04 01:12:02 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
Line 657 void dpm_sp(DPM p1,DPM p2,DPM *rp,DP *mul1,DP *mul2) |
|
Line 657 void dpm_sp(DPM p1,DPM p2,DPM *rp,DP *mul1,DP *mul2) |
|
} |
} |
} |
} |
|
|
|
DP dpm_sp_hm(DPM p1,DPM p2) |
|
{ |
|
int i,n,td; |
|
int *w; |
|
DL d1,d2,d; |
|
MP m; |
|
DP s1; |
|
|
|
n = p1->nv; d1 = BDY(p1)->dl; d2 = BDY(p2)->dl; |
|
if ( BDY(p1)->pos != BDY(p2)->pos ) { |
|
return 0; |
|
} |
|
w = (int *)ALLOCA(n*sizeof(int)); |
|
for ( i = 0, td = 0; i < n; i++ ) { |
|
w[i] = MAX(d1->d[i],d2->d[i]); td += MUL_WEIGHT(w[i],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 = (Obj)ONE; NEXT(m) = 0; |
|
MKDP(n,m,s1); s1->sugar = d->td; |
|
return s1; |
|
} |
|
|
void _dp_sp_dup(DP p1,DP p2,DP *rp) |
void _dp_sp_dup(DP p1,DP p2,DP *rp) |
{ |
{ |
int i,n,td; |
int i,n,td; |
Line 841 void dpm_red(DPM p0,DPM p1,DPM p2,DPM *head,DPM *rest, |
|
Line 867 void dpm_red(DPM p0,DPM p1,DPM p2,DPM *head,DPM *rest, |
|
int i,n,pos; |
int i,n,pos; |
DL d1,d2,d; |
DL d1,d2,d; |
MP m; |
MP m; |
DP s; |
DP s,ms; |
DPM t,r,h,u,w; |
DPM t,r,h,u,w; |
Z c,c1,c2,gn; |
Z c,c1,c2,gn; |
P g,a; |
P g,a; |
Line 873 void dpm_red(DPM p0,DPM p1,DPM p2,DPM *head,DPM *rest, |
|
Line 899 void dpm_red(DPM p0,DPM p1,DPM p2,DPM *head,DPM *rest, |
|
} |
} |
NEWMP(m); m->dl = d; m->c = (Obj)c1; NEXT(m) = 0; MKDP(n,m,s); s->sugar = d->td; |
NEWMP(m); m->dl = d; m->c = (Obj)c1; NEXT(m) = 0; MKDP(n,m,s); s->sugar = d->td; |
*multp = s; |
*multp = s; |
mulobjdpm(CO,(Obj)s,p2,&u); mulobjdpm(CO,(Obj)c2,p1,&w); subdpm(CO,w,u,&r); |
chsgnd(s,&ms); mulobjdpm(CO,(Obj)ms,p2,&u); mulobjdpm(CO,(Obj)c2,p1,&w); adddpm(CO,w,u,&r); |
mulobjdpm(CO,(Obj)c2,p0,&h); |
mulobjdpm(CO,(Obj)c2,p0,&h); |
*head = h; *rest = r; *dnp = (P)c2; |
*head = h; *rest = r; *dnp = (P)c2; |
} |
} |
|
|
|
void dpm_red2(DPM p1,DPM p2,DPM *rest,P *dnp,DP *multp) |
|
{ |
|
int i,n,pos; |
|
DL d1,d2,d; |
|
MP m; |
|
DP s,ms; |
|
DPM t,r,h,u,w; |
|
Z c,c1,c2,gn; |
|
P g,a; |
|
P p[2]; |
|
|
|
n = p1->nv; d1 = BDY(p1)->dl; d2 = BDY(p2)->dl; pos = BDY(p1)->pos; |
|
if ( pos != BDY(p2)->pos ) |
|
error("dpm_red : cannot happen"); |
|
NEWDL(d,n); d->td = d1->td - d2->td; |
|
for ( i = 0; i < n; i++ ) |
|
d->d[i] = d1->d[i]-d2->d[i]; |
|
c1 = (Z)BDY(p1)->c; c2 = (Z)BDY(p2)->c; |
|
if ( dp_fcoeffs == N_GFS ) { |
|
p[0] = (P)c1; p[1] = (P)c2; |
|
gcdsf(CO,p,2,&g); |
|
divsp(CO,(P)c1,g,&a); c1 = (Z)a; divsp(CO,(P)c2,g,&a); c2 = (Z)a; |
|
} else if ( dp_fcoeffs ) { |
|
/* do nothing */ |
|
} else if ( INT(c1) && INT(c2) ) { |
|
gcdz(c1,c2,&gn); |
|
if ( !UNIQ(gn) ) { |
|
divsz(c1,gn,&c); c1 = c; |
|
divsz(c2,gn,&c); c2 = c; |
|
} |
|
} else { |
|
ezgcdpz(CO,(P)c1,(P)c2,&g); |
|
divsp(CO,(P)c1,g,&a); c1 = (Z)a; divsp(CO,(P)c2,g,&a); c2 = (Z)a; |
|
add_denomlist(g); |
|
} |
|
NEWMP(m); m->dl = d; m->c = (Obj)c1; NEXT(m) = 0; MKDP(n,m,s); s->sugar = d->td; |
|
*multp = s; |
|
chsgnd(s,&ms); mulobjdpm(CO,(Obj)ms,p2,&u); mulobjdpm(CO,(Obj)c2,p1,&w); adddpm(CO,w,u,&r); |
|
*rest = r; *dnp = (P)c2; |
|
} |
|
|
/* |
/* |
* m-reduction by a marked poly |
* m-reduction by a marked poly |
* do content reduction over Z or Q(x,...) |
* do content reduction over Z or Q(x,...) |
|
|
return q; |
return q; |
} |
} |
|
|
|
struct oEGT egred; |
|
|
|
void mulcmp(Obj c,MP m); |
|
void mulcdmm(Obj c,DMM m); |
|
|
|
DP appendd(DP d,DP m) |
|
{ |
|
MP t; |
|
|
|
if ( !d ) return m; |
|
for ( t = BDY(d); NEXT(t); t = NEXT(t) ); |
|
NEXT(t) = BDY(m); |
|
return d; |
|
} |
|
|
|
DPM appenddpm(DPM d,DPM m) |
|
{ |
|
DMM t; |
|
|
|
if ( !d ) return m; |
|
for ( t = BDY(d); NEXT(t); t = NEXT(t) ); |
|
NEXT(t) = BDY(m); |
|
return d; |
|
} |
|
|
DP *dpm_nf_and_quotient(NODE b,DPM g,VECT psv,DPM *rp,P *dnp) |
DP *dpm_nf_and_quotient(NODE b,DPM g,VECT psv,DPM *rp,P *dnp) |
{ |
{ |
DPM u,p,d,s,t; |
DPM u,p,s,t,d; |
DP dmy,mult; |
DP dmy,mult,zzz; |
DPM *ps; |
DPM *ps; |
DP *q; |
DP *q; |
NODE l; |
NODE l; |
DMM m,mr; |
DMM m,mr; |
int i,n,j,len; |
MP mp; |
|
int i,n,j,len,nv; |
int *wb; |
int *wb; |
int sugar,psugar,multiple; |
int sugar,psugar,multiple; |
P nm,tnm1,dn,tdn,tdn1; |
P nm,tnm1,dn,tdn,tdn1; |
Q cont; |
Q cont; |
|
struct oEGT eg0,eg1; |
|
|
dn = (P)ONE; |
dn = (P)ONE; |
if ( !g ) { |
if ( !g ) { |
*rp = 0; *dnp = dn; return 0; |
*rp = 0; *dnp = dn; return 0; |
} |
} |
|
nv = NV(g); |
ps = (DPM *)BDY(psv); |
ps = (DPM *)BDY(psv); |
len = psv->len; |
len = psv->len; |
if ( b ) { |
if ( b ) { |
Line 1392 DP *dpm_nf_and_quotient(NODE b,DPM g,VECT psv,DPM *rp, |
|
Line 1486 DP *dpm_nf_and_quotient(NODE b,DPM g,VECT psv,DPM *rp, |
|
for ( d = 0; g; ) { |
for ( d = 0; g; ) { |
for ( u = 0, i = 0; i < n; i++ ) { |
for ( u = 0, i = 0; i < n; i++ ) { |
if ( dpm_redble(g,p = ps[wb[i]]) ) { |
if ( dpm_redble(g,p = ps[wb[i]]) ) { |
dpm_red(d,g,p,&t,&u,&tdn,&mult); |
// get_eg(&eg0); |
|
dpm_red2(g,p,&u,&tdn,&mult); |
|
// get_eg(&eg1); add_eg(&egred,&eg0,&eg1); |
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
sugar = MAX(sugar,psugar); |
sugar = MAX(sugar,psugar); |
for ( j = 0; j < len; j++ ) { |
for ( j = 0; j < len; j++ ) { |
muldc(CO,q[j],(Obj)tdn,&dmy); q[j] = dmy; |
if ( q[j] ) { mulcmp((Obj)tdn,BDY(q[j])); } |
} |
} |
addd(CO,q[wb[i]],mult,&dmy); q[wb[i]] = dmy; |
q[wb[i]] = appendd(q[wb[i]],mult); |
mulp(CO,dn,tdn,&tdn1); dn = tdn1; |
mulp(CO,dn,tdn,&tdn1); dn = tdn1; |
d = t; |
if ( d ) mulcdmm((Obj)tdn,BDY(d)); |
if ( !u ) goto last; |
if ( !u ) goto last; |
break; |
break; |
} |
} |
Line 1410 DP *dpm_nf_and_quotient(NODE b,DPM g,VECT psv,DPM *rp, |
|
Line 1506 DP *dpm_nf_and_quotient(NODE b,DPM g,VECT psv,DPM *rp, |
|
} else { |
} else { |
m = BDY(g); NEWDMM(mr); mr->dl = m->dl; mr->c = m->c; mr->pos = m->pos; |
m = BDY(g); NEWDMM(mr); mr->dl = m->dl; mr->c = m->c; mr->pos = m->pos; |
NEXT(mr) = 0; MKDPM(g->nv,mr,t); t->sugar = mr->dl->td; |
NEXT(mr) = 0; MKDPM(g->nv,mr,t); t->sugar = mr->dl->td; |
adddpm(CO,d,t,&s); d = s; |
d = appenddpm(d,t); |
dpm_rest(g,&t); g = t; |
dpm_rest(g,&t); g = t; |
} |
} |
} |
} |
Line 1546 void dp_nf_z(NODE b,DP g,DP *ps,int full,int multiple, |
|
Line 1642 void dp_nf_z(NODE b,DP g,DP *ps,int full,int multiple, |
|
*rp = d; |
*rp = d; |
} |
} |
|
|
void dpm_nf_z(NODE b,DPM g,DPM *ps,int full,int multiple,DPM *rp) |
void dpm_nf_z(NODE b,DPM g,VECT psv,int full,int multiple,DPM *rp) |
{ |
{ |
|
DPM *ps; |
DPM u,p,d,s,t; |
DPM u,p,d,s,t; |
DP dmy1; |
DP dmy1; |
P dmy; |
P dmy; |
Line 1562 void dpm_nf_z(NODE b,DPM g,DPM *ps,int full,int multip |
|
Line 1659 void dpm_nf_z(NODE b,DPM g,DPM *ps,int full,int multip |
|
if ( !g ) { |
if ( !g ) { |
*rp = 0; return; |
*rp = 0; return; |
} |
} |
for ( n = 0, l = b; l; l = NEXT(l), n++ ); |
if ( b ) { |
wb = (int *)ALLOCA(n*sizeof(int)); |
for ( n = 0, l = b; l; l = NEXT(l), n++ ); |
for ( i = 0, l = b; i < n; l = NEXT(l), i++ ) |
wb = (int *)ALLOCA(n*sizeof(int)); |
wb[i] = ZTOS((Q)BDY(l)); |
for ( i = 0, l = b; i < n; l = NEXT(l), i++ ) |
|
wb[i] = ZTOS((Q)BDY(l)); |
|
ps = (DPM *)BDY(psv); |
|
} else { |
|
n = psv->len; |
|
wb = (int *)MALLOC(n*sizeof(int)); |
|
for ( i = 0; i < n; i++ ) wb[i] = i; |
|
ps = (DPM *)BDY(psv); |
|
} |
|
|
hmag = multiple*HMAG(g); |
hmag = multiple*HMAG(g); |
sugar = g->sugar; |
sugar = g->sugar; |
|
|
for ( d = 0; g; ) { |
for ( d = 0; g; ) { |
for ( u = 0, i = 0; i < n; i++ ) { |
for ( u = 0, i = 0; i < n; i++ ) { |
if ( dpm_redble(g,p = ps[wb[i]]) ) { |
if ( (p=ps[wb[i]])!=0 && dpm_redble(g,p) ) { |
dpm_red(d,g,p,&t,&u,&dmy,&dmy1); |
dpm_red2(g,p,&u,&dmy,&dmy1); |
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
sugar = MAX(sugar,psugar); |
sugar = MAX(sugar,psugar); |
|
if ( d ) mulcdmm((Obj)dmy,BDY(d)); |
if ( !u ) { |
if ( !u ) { |
if ( d ) |
if ( d ) |
d->sugar = sugar; |
d->sugar = sugar; |
*rp = d; return; |
*rp = d; return; |
} |
} |
d = t; |
|
break; |
break; |
} |
} |
} |
} |
Line 1607 void dpm_nf_z(NODE b,DPM g,DPM *ps,int full,int multip |
|
Line 1712 void dpm_nf_z(NODE b,DPM g,DPM *ps,int full,int multip |
|
} else { |
} else { |
m = BDY(g); NEWDMM(mr); mr->dl = m->dl; mr->c = m->c; mr->pos = m->pos; |
m = BDY(g); NEWDMM(mr); mr->dl = m->dl; mr->c = m->c; mr->pos = m->pos; |
NEXT(mr) = 0; MKDPM(g->nv,mr,t); t->sugar = mr->dl->td; |
NEXT(mr) = 0; MKDPM(g->nv,mr,t); t->sugar = mr->dl->td; |
adddpm(CO,d,t,&s); d = s; |
d = appenddpm(d,t); |
dpm_rest(g,&t); g = t; |
dpm_rest(g,&t); g = t; |
} |
} |
} |
} |
Line 1720 void dp_nf_f(NODE b,DP g,DP *ps,int full,DP *rp) |
|
Line 1825 void dp_nf_f(NODE b,DP g,DP *ps,int full,DP *rp) |
|
*rp = d; |
*rp = d; |
} |
} |
|
|
void dpm_nf_f(NODE b,DPM g,DPM *ps,int full,DPM *rp) |
void dpm_nf_f(NODE b,DPM g,VECT psv,int full,DPM *rp) |
{ |
{ |
|
DPM *ps; |
DPM u,p,d,s,t; |
DPM u,p,d,s,t; |
NODE l; |
NODE l; |
DMM m,mr; |
DMM m,mr; |
Line 1732 void dpm_nf_f(NODE b,DPM g,DPM *ps,int full,DPM *rp) |
|
Line 1838 void dpm_nf_f(NODE b,DPM g,DPM *ps,int full,DPM *rp) |
|
if ( !g ) { |
if ( !g ) { |
*rp = 0; return; |
*rp = 0; return; |
} |
} |
for ( n = 0, l = b; l; l = NEXT(l), n++ ); |
if ( b ) { |
wb = (int *)ALLOCA(n*sizeof(int)); |
for ( n = 0, l = b; l; l = NEXT(l), n++ ); |
for ( i = 0, l = b; i < n; l = NEXT(l), i++ ) |
wb = (int *)ALLOCA(n*sizeof(int)); |
wb[i] = ZTOS((Q)BDY(l)); |
for ( i = 0, l = b; i < n; l = NEXT(l), i++ ) |
|
wb[i] = ZTOS((Q)BDY(l)); |
|
ps = (DPM *)BDY(psv); |
|
} else { |
|
n = psv->len; |
|
wb = (int *)MALLOC(n*sizeof(int)); |
|
for ( i = 0; i < n; i++ ) wb[i] = i; |
|
ps = (DPM *)BDY(psv); |
|
} |
|
|
sugar = g->sugar; |
sugar = g->sugar; |
for ( d = 0; g; ) { |
for ( d = 0; g; ) { |
for ( u = 0, i = 0; i < n; i++ ) { |
for ( u = 0, i = 0; i < n; i++ ) { |
if ( dpm_redble(g,p = ps[wb[i]]) ) { |
if ( ( (p=ps[wb[i]]) != 0 ) && dpm_redble(g,p) ) { |
dpm_red_f(g,p,&u); |
dpm_red_f(g,p,&u); |
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
sugar = MAX(sugar,psugar); |
sugar = MAX(sugar,psugar); |