version 1.2, 2018/09/28 08:20:27 |
version 1.8, 2019/03/18 10:30:41 |
|
|
* 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.c,v 1.1 2018/09/19 05:45:05 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2018/builtin/dp.c,v 1.7 2019/03/18 07:09:58 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
Line 61 extern int nd_rref2; |
|
Line 61 extern int nd_rref2; |
|
|
|
int do_weyl; |
int do_weyl; |
|
|
|
void Pdp_monomial_hilbert_poincare(); |
void Pdp_sort(); |
void Pdp_sort(); |
void Pdp_mul_trunc(),Pdp_quo(); |
void Pdp_mul_trunc(),Pdp_quo(); |
void Pdp_ord(), Pdp_ptod(), Pdp_dtop(), Phomogenize(); |
void Pdp_ord(), Pdp_ptod(), Pdp_dtop(), Phomogenize(); |
Line 233 struct ftab dp_tab[] = { |
|
Line 234 struct ftab dp_tab[] = { |
|
{"dp_weyl_f4_main",Pdp_weyl_f4_main,3}, |
{"dp_weyl_f4_main",Pdp_weyl_f4_main,3}, |
{"dp_weyl_f4_mod_main",Pdp_weyl_f4_mod_main,4}, |
{"dp_weyl_f4_mod_main",Pdp_weyl_f4_mod_main,4}, |
|
|
|
/* Hilbert function */ |
|
{"dp_monomial_hilbert_poincare",Pdp_monomial_hilbert_poincare,2}, |
|
|
/* misc */ |
/* misc */ |
{"dp_inv_or_split",Pdp_inv_or_split,3}, |
{"dp_inv_or_split",Pdp_inv_or_split,3}, |
{"dp_set_weight",Pdp_set_weight,-1}, |
{"dp_set_weight",Pdp_set_weight,-1}, |
Line 322 struct ftab dp_supp_tab[] = { |
|
Line 326 struct ftab dp_supp_tab[] = { |
|
|
|
NODE compute_last_w(NODE g,NODE gh,int n,int **v,int row1,int **m1,int row2,int **m2); |
NODE compute_last_w(NODE g,NODE gh,int n,int **v,int row1,int **m1,int row2,int **m2); |
Q compute_last_t(NODE g,NODE gh,Q t,VECT w1,VECT w2,NODE *homo,VECT *wp); |
Q compute_last_t(NODE g,NODE gh,Q t,VECT w1,VECT w2,NODE *homo,VECT *wp); |
|
|
|
int comp_by_tdeg(DP *a,DP *b) |
|
{ |
|
int da,db; |
|
|
|
da = BDY(*a)->dl->td; |
|
db = BDY(*b)->dl->td; |
|
if ( da>db ) return 1; |
|
else if ( da<db ) return -1; |
|
else return 0; |
|
} |
|
|
|
void dl_print(DL d,int n) |
|
{ |
|
int i; |
|
|
|
printf("<<"); |
|
for ( i = 0; i < n; i++ ) |
|
printf("%d ",d->d[i]); |
|
printf(">>\n"); |
|
} |
|
|
|
int simple_check(VECT b,int nv) |
|
{ |
|
int n,i,j; |
|
DL *p; |
|
|
|
n = b->len; p = (DL *)b->body; |
|
for ( i = 0; i < n; i++ ) { |
|
for ( j = 0; j < nv; j++ ) { |
|
if ( p[i]->d[j] ) break; |
|
} |
|
if ( p[i]->d[j] != p[i]->td ) return 0; |
|
} |
|
return 1; |
|
} |
|
|
|
void make_reduced(VECT b,int nv) |
|
{ |
|
int n,i,j; |
|
DL *p; |
|
DL pi; |
|
|
|
n = b->len; |
|
p = (DL *)BDY(b); |
|
for ( i = 0; i < n; i++ ) { |
|
pi = p[i]; |
|
if ( !pi ) continue; |
|
for ( j = 0; j < n; j++ ) |
|
if ( i != j && p[j] && _dl_redble(pi,p[j],nv) ) p[j] = 0; |
|
} |
|
for ( i = j = 0; i < n; i++ ) |
|
if ( p[i] ) p[j++] = p[i]; |
|
b->len = j; |
|
} |
|
|
|
void make_reduced2(VECT b,int k,int nv) |
|
{ |
|
int n,i,j,l; |
|
DL *p; |
|
DL pi; |
|
|
|
n = b->len; |
|
p = (DL *)BDY(b); |
|
for ( i = l = k; i < n; i++ ) { |
|
pi = p[i]; |
|
for ( j = 0; j < k; j++ ) |
|
if ( _dl_redble(p[j],pi,nv) ) break; |
|
if ( j == k ) |
|
p[l++] = pi; |
|
} |
|
b->len = l; |
|
} |
|
|
|
int i_all,i_simple; |
|
|
|
P mhp_simple(VECT b,VECT x,P t) |
|
{ |
|
int n,i,j,nv; |
|
DL *p; |
|
P hp,mt,s,w; |
|
Z z; |
|
|
|
n = b->len; nv = x->len; p = (DL *)BDY(b); |
|
hp = (P)ONE; |
|
for ( i = 0; i < n; i++ ) { |
|
for ( j = 0; j < nv; j++ ) |
|
if ( p[i]->d[j] ) break; |
|
STOZ(p[i]->d[j],z); |
|
chsgnp(t,&mt); mt->dc->d =z; |
|
addp(CO,mt,(P)ONE,&s); mulp(CO,hp,s,&w); hp = w; |
|
} |
|
return hp; |
|
} |
|
|
|
struct oEGT eg_comp; |
|
|
|
void mhp_rec(VECT b,VECT x,P t,P *r) |
|
{ |
|
int n,i,j,k,l,i2,nv,len; |
|
int *d; |
|
Z mone,z; |
|
DCP dc,dc1; |
|
P s; |
|
P *r2; |
|
DL *p,*q; |
|
DL pi,xj,d1; |
|
VECT c; |
|
struct oEGT eg0,eg1; |
|
|
|
i_all++; |
|
n = b->len; nv = x->len; p = (DL *)BDY(b); |
|
if ( !n ) { |
|
r[0] = (P)ONE; |
|
return; |
|
} |
|
if ( n == 1 && p[0]->td == 0 ) |
|
return; |
|
for ( i = 0; i < n; i++ ) |
|
if ( p[i]->td > 1 ) break; |
|
if ( i == n ) { |
|
r[n] = (P)ONE; |
|
return; |
|
} |
|
#if 0 |
|
if ( simple_check(b,nv) ) { |
|
i_simple++; |
|
r[0] = mhp_simple(b,x,t); |
|
return; |
|
} |
|
#endif |
|
for ( j = 0, d = p[i]->d; j < nv; j++ ) |
|
if ( d[j] ) break; |
|
xj = BDY(x)[j]; |
|
MKVECT(c,n); q = (DL *)BDY(c); |
|
for ( i = k = l = 0; i < n; i++ ) |
|
if ( p[i]->d[j] ) { |
|
pi = p[i]; |
|
NEWDL(d1,nv); d1->td =pi->td - 1; |
|
memcpy(d1->d,pi->d,nv*sizeof(int)); |
|
d1->d[j]--; |
|
p[k++] = d1; |
|
} else |
|
q[l++] = p[i]; |
|
for ( i = k, i2 = 0; i2 < l; i++, i2++ ) |
|
p[i] = q[i2]; |
|
/* b=(b[0]/xj,...,b[k-1]/xj,b[k],...b[n-1]) where |
|
b[0],...,b[k-1] are divisible by k */ |
|
make_reduced2(b,k,nv); |
|
mhp_rec(b,x,t,r); |
|
/* c = (b[0],...,b[l-1],xj) */ |
|
q[l] = xj; c->len = l+1; |
|
r2 = (P *)CALLOC(nv+1,sizeof(P)); |
|
mhp_rec(c,x,t,r2); |
|
// get_eg(&eg0); |
|
for ( i = 0; i <= nv; i++ ) { |
|
mulp(CO,r[i],t,&s); addp(CO,s,r2[i],&r[i]); |
|
} |
|
// get_eg(&eg1); add_eg(&eg_comp,&eg0,&eg1); |
|
} |
|
|
|
/* (n+a)Cb as a polynomial of n; return (n+a)*...*(n+a-b+1) */ |
|
|
|
P binpoly(P n,int a,int b) |
|
{ |
|
Z z; |
|
P s,r,t; |
|
int i; |
|
|
|
STOZ(a,z); addp(CO,n,(P)z,&s); r = (P)ONE; |
|
for ( i = 0; i < b; i++ ) { |
|
mulp(CO,r,s,&t); r = t; |
|
subp(CO,s,(P)ONE,&t); s = t; |
|
} |
|
return r; |
|
} |
|
|
|
void mhp_to_hf(VL vl,P hp,int n,P *plist,VECT *head,P *hf) |
|
{ |
|
P tv,gcd,q,h,hphead,tt,ai,hpoly,nv,bp,w; |
|
Z d,z; |
|
DCP dc,topdc; |
|
VECT hfhead; |
|
int i,s,qd; |
|
|
|
if ( !hp ) { |
|
MKVECT(hfhead,0); *head = hfhead; |
|
*hf = 0; |
|
} else { |
|
makevar("t",&tv); |
|
ezgcdp(CO,hp,plist[n],&gcd); |
|
if ( NUM(gcd) ) { |
|
s = n; |
|
q = hp; |
|
} else { |
|
s = n-ZTOS(DEG(DC(gcd))); |
|
divsp(CO,hp,plist[n-s],&q); |
|
} |
|
if ( NUM(q) ) qd = 0; |
|
else qd = ZTOS(DEG(DC(q))); |
|
if ( s == 0 ) { |
|
MKVECT(hfhead,qd+1); |
|
for ( i = 0; i <= qd; i++ ) { |
|
coefp(q,i,(P *)&BDY(hfhead)[i]); |
|
} |
|
*head = hfhead; |
|
*hf = 0; |
|
} else { |
|
if ( qd ) { |
|
topdc = 0; |
|
for ( i = 0; i < qd; i++ ) { |
|
NEWDC(dc); NEXT(dc) = topdc; |
|
ibin(i+s-1,s-1,&COEF(dc)); |
|
STOZ(i,d); DEG(dc) = d; |
|
topdc = dc; |
|
} |
|
MKP(VR(tv),topdc,h); |
|
mulp(CO,h,q,&hphead); |
|
} |
|
MKVECT(hfhead,qd); |
|
for ( i = 0; i < qd; i++ ) |
|
coefp(hphead,i,(P *)&BDY(hfhead)[i]); |
|
*head = hfhead; |
|
hpoly = 0; |
|
makevar("n",&nv); |
|
for ( i = 0; i <= qd; i++ ) { |
|
coefp(q,i,&ai); |
|
bp = binpoly(nv,s-i-1,s-1); |
|
mulp(CO,ai,bp,&tt); |
|
addp(CO,hpoly,tt,&w); |
|
hpoly = w; |
|
} |
|
if ( s > 2 ) { |
|
factorialz(s-1,&z); |
|
divsp(CO,hpoly,(P)z,&tt); hpoly = tt; |
|
} |
|
*hf = hpoly; |
|
for ( i = qd-1; i >= 0; i-- ) { |
|
UTOZ(i,z); |
|
substp(CO,hpoly,VR(nv),(P)z,&tt); |
|
if ( cmpz((Z)tt,(Z)BDY(hfhead)[i]) ) break; |
|
} |
|
hfhead->len = i+1; |
|
} |
|
} |
|
} |
|
|
|
/* create (1,1-t,...,(1-t)^n) */ |
|
|
|
P *mhp_prep(int n,P *tv) { |
|
P *plist; |
|
P mt,t1; |
|
int i; |
|
|
|
plist = (P *)MALLOC((n+1)*sizeof(P)); |
|
/* t1 = 1-t */ |
|
makevar("t",tv); chsgnp(*tv,&mt); addp(CO,mt,(P)ONE,&t1); |
|
for ( plist[0] = (P)ONE, i = 1; i <= n; i++ ) |
|
mulp(CO,plist[i-1],t1,&plist[i]); |
|
return plist; |
|
} |
|
|
|
P mhp_ctop(P *r,P *plist,int n) |
|
{ |
|
int i; |
|
P hp,u,w; |
|
|
|
for ( hp = 0, i = 0; i <= n; i++ ) { |
|
mulp(CO,plist[i],r[i],&u); addp(CO,u,hp,&w); hp = w; |
|
} |
|
return hp; |
|
} |
|
|
|
void Pdp_monomial_hilbert_poincare(NODE arg,LIST *rp) |
|
{ |
|
LIST g,v; |
|
VL vl; |
|
int m,n,i; |
|
VECT b,x,hfhead; |
|
NODE t,nd; |
|
Z z,den; |
|
P hp,tv,mt,t1,u,w,hpoly; |
|
DP a; |
|
DL *p; |
|
P *plist,*r; |
|
Obj val; |
|
|
|
i_simple = i_all = 0; |
|
g = (LIST)ARG0(arg); v = (LIST)ARG1(arg); |
|
pltovl(v,&vl); |
|
m = length(BDY(g)); MKVECT(b,m); p = (DL *)BDY(b); |
|
for ( t = BDY(g), i = 0; t; t = NEXT(t), i++ ) { |
|
if ( !BDY(t) ) |
|
p[i] = 0; |
|
else { |
|
ptod(CO,vl,(P)BDY(t),&a); p[i] = BDY(a)->dl; |
|
} |
|
} |
|
n = length(BDY(v)); MKVECT(x,n); p = (DL *)BDY(x); |
|
for ( t = BDY(v), i = 0; t; t = NEXT(t), i++ ) { |
|
ptod(CO,vl,(P)BDY(t),&a); p[i] = BDY(a)->dl; |
|
} |
|
|
|
r = (P *)CALLOC(n+1,sizeof(P)); |
|
plist = mhp_prep(n,&tv); |
|
make_reduced(b,n); |
|
mhp_rec(b,x,tv,r); |
|
hp = mhp_ctop(r,plist,n); |
|
mhp_to_hf(CO,hp,n,plist,&hfhead,&hpoly); |
|
UTOZ(n,z); |
|
nd = mknode(4,hp,z,hfhead,hpoly); |
|
MKLIST(*rp,nd); |
|
} |
|
|
void Pdp_compute_last_t(NODE arg,LIST *rp) |
void Pdp_compute_last_t(NODE arg,LIST *rp) |
{ |
{ |