version 1.27, 2021/01/25 00:39:51 |
version 1.31, 2021/12/05 22:41:03 |
|
|
* 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.26 2020/10/26 02:41:05 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2018/builtin/dp.c,v 1.30 2021/03/10 06:36:20 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; |
|
|
|
extern int do_weyl; |
extern int do_weyl; |
|
|
void Pdp_monomial_hilbert_poincare(); |
void Pdp_monomial_hilbert_poincare(),Pdp_monomial_hilbert_poincare_incremental(); |
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 133 void Pdp_rref2(),Psumi_updatepairs(),Psumi_symbolic(); |
|
Line 133 void Pdp_rref2(),Psumi_updatepairs(),Psumi_symbolic(); |
|
|
|
LIST dp_initial_term(); |
LIST dp_initial_term(); |
LIST dp_order(); |
LIST dp_order(); |
|
int peek_option(NODE opt,char *find,Obj *ret); |
void parse_gr_option(LIST f,NODE opt,LIST *v,Num *homo, |
void parse_gr_option(LIST f,NODE opt,LIST *v,Num *homo, |
int *modular,struct order_spec **ord); |
int *modular,struct order_spec **ord); |
NODE dp_inv_or_split(NODE gb,DP f,struct order_spec *spec, DP *inv); |
NODE dp_inv_or_split(NODE gb,DP f,struct order_spec *spec, DP *inv); |
Line 249 struct ftab dp_tab[] = { |
|
Line 250 struct ftab dp_tab[] = { |
|
|
|
/* Hilbert function */ |
/* Hilbert function */ |
{"dp_monomial_hilbert_poincare",Pdp_monomial_hilbert_poincare,2}, |
{"dp_monomial_hilbert_poincare",Pdp_monomial_hilbert_poincare,2}, |
|
{"dp_monomial_hilbert_poincare_incremental",Pdp_monomial_hilbert_poincare_incremental,3}, |
|
|
/* misc */ |
/* misc */ |
{"dp_inv_or_split",Pdp_inv_or_split,3}, |
{"dp_inv_or_split",Pdp_inv_or_split,3}, |
Line 466 void mhp_rec(VECT b,VECT x,P t,P *r) |
|
Line 468 void mhp_rec(VECT b,VECT x,P t,P *r) |
|
DL *p,*q; |
DL *p,*q; |
DL pi,xj,d1; |
DL pi,xj,d1; |
VECT c; |
VECT c; |
struct oEGT eg0,eg1; |
struct oEGT eg0,eg1; |
|
|
i_all++; |
i_all++; |
n = b->len; nv = x->len; p = (DL *)BDY(b); |
n = b->len; nv = x->len; p = (DL *)BDY(b); |
Line 519 struct oEGT eg0,eg1; |
|
Line 521 struct oEGT eg0,eg1; |
|
// get_eg(&eg1); add_eg(&eg_comp,&eg0,&eg1); |
// get_eg(&eg1); add_eg(&eg_comp,&eg0,&eg1); |
} |
} |
|
|
|
P mhp_rec_weight(VECT b,VECT x,P t,int *w) |
|
{ |
|
int n,i,j,k,l,i2,nv,len,td; |
|
int *d; |
|
Z wj; |
|
P twj,tmp,tmp2,ret,qadd,qcolon; |
|
DL *p,*q; |
|
DL pi,xj,d1; |
|
VECT c; |
|
|
|
i_all++; |
|
n = b->len; nv = x->len; p = (DL *)BDY(b); |
|
if ( !n ) { |
|
// I=<0> => HP(t)=1/(1-t^w1)...(1-t^wn) => Q(t)=1 |
|
return (P)ONE; |
|
} |
|
if ( n == 1 && p[0]->td == 0 ) { |
|
// I=<1> => HP(t)=0 => Q(t)=0 |
|
return 0; |
|
} |
|
for ( i = 0; i < n; i++ ) { |
|
d = p[i]->d; |
|
for ( td = 0, j = 0; j < nv; j++ ) td += d[j]; |
|
if (td > 1 ) break; |
|
} |
|
if ( i == n ) { |
|
// I=<xi1,...,xin> => Q(t)=(1-t^wi1)...(1-t^win) |
|
for ( ret = (P)ONE, i = 0; i < n; i++ ) { |
|
d = p[i]->d; |
|
for ( j = 0; j < nv; j++ ) if ( d[j] ) break; |
|
STOZ(w[j],wj); pwrp(CO,t,wj,&tmp); |
|
subp(CO,(P)ONE,tmp,&tmp2); mulp(CO,ret,tmp2,&tmp); ret = tmp; |
|
} |
|
return ret; |
|
} |
|
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); |
|
qcolon = mhp_rec_weight(b,x,t,w); |
|
/* c = (b[0],...,b[l-1],xj) */ |
|
q[l] = xj; c->len = l+1; |
|
qadd = mhp_rec_weight(c,x,t,w); |
|
// Q(t)=Qadd+t^wj*Qcolon |
|
STOZ(w[j],wj); pwrp(CO,t,wj,&twj); |
|
mulp(CO,twj,qcolon,&tmp); addp(CO,qadd,tmp,&ret); |
|
return ret; |
|
} |
|
|
/* (n+a)Cb as a polynomial of n; return (n+a)*...*(n+a-b+1) */ |
/* (n+a)Cb as a polynomial of n; return (n+a)*...*(n+a-b+1) */ |
|
|
P binpoly(P n,int a,int b) |
P binpoly(P n,int a,int b) |
Line 613 P *mhp_prep(int n,P *tv) { |
|
Line 678 P *mhp_prep(int n,P *tv) { |
|
P *plist; |
P *plist; |
P mt,t1; |
P mt,t1; |
int i; |
int i; |
|
VECT list; |
|
|
plist = (P *)MALLOC((n+1)*sizeof(P)); |
plist = (P *)MALLOC((n+1)*sizeof(P)); |
/* t1 = 1-t */ |
/* t1 = 1-t */ |
Line 633 P mhp_ctop(P *r,P *plist,int n) |
|
Line 699 P mhp_ctop(P *r,P *plist,int n) |
|
return hp; |
return hp; |
} |
} |
|
|
|
LIST dp_monomial_hilbert_poincare(VECT b,VECT x) |
|
{ |
|
int n; |
|
P *r,*plist; |
|
P tv; |
|
P hp,hpoly; |
|
VECT hfhead; |
|
Z z; |
|
NODE nd; |
|
VECT vect; |
|
LIST list; |
|
|
|
n = x->len; |
|
plist = mhp_prep(n,&tv); |
|
r = (P *)CALLOC(n+1,sizeof(P)); |
|
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); |
|
NEWVECT(vect); vect->len = n+1; BDY(vect) = (pointer)plist; |
|
nd = mknode(5,hp,z,hfhead,hpoly,vect); |
|
MKLIST(list,nd); |
|
return list; |
|
} |
|
|
|
LIST dp_monomial_hilbert_poincare_weight(VECT b,VECT x,int *w) |
|
{ |
|
int n,i; |
|
NODE nd; |
|
LIST list; |
|
P tv,ret; |
|
|
|
n = x->len; |
|
make_reduced(b,n); |
|
makevar("t",&tv); |
|
ret = mhp_rec_weight(b,x,tv,w); |
|
nd = mknode(1,ret); |
|
MKLIST(list,nd); |
|
return list; |
|
} |
|
|
void Pdp_monomial_hilbert_poincare(NODE arg,LIST *rp) |
void Pdp_monomial_hilbert_poincare(NODE arg,LIST *rp) |
{ |
{ |
LIST g,v; |
LIST g,v; |
VL vl; |
VL vl; |
int m,n,i; |
int m,n,i,wlen; |
VECT b,x,hfhead; |
VECT b,x,hfhead,prep; |
NODE t,nd; |
NODE t,nd; |
Z z,den; |
Z z,den; |
P hp,tv,mt,t1,u,w,hpoly; |
P hp,tv,mt,t1,u,hpoly; |
DP a; |
DP a; |
DL *p; |
DL *p; |
P *plist,*r; |
Obj val,ord,weight; |
Obj val; |
int *w; |
|
struct order_spec *current_spec=0,*spec; |
|
|
|
weight = 0; |
|
if ( current_option ) { |
|
if ( peek_option(current_option,"ord",&ord) ) { |
|
current_spec = dp_current_spec; |
|
create_order_spec(0,ord,&spec); |
|
initd(spec); |
|
} |
|
peek_option(current_option,"weight",&weight); |
|
} |
i_simple = i_all = 0; |
i_simple = i_all = 0; |
g = (LIST)ARG0(arg); v = (LIST)ARG1(arg); |
g = (LIST)ARG0(arg); v = (LIST)ARG1(arg); |
pltovl(v,&vl); |
pltovl(v,&vl); |
Line 662 void Pdp_monomial_hilbert_poincare(NODE arg,LIST *rp) |
|
Line 780 void Pdp_monomial_hilbert_poincare(NODE arg,LIST *rp) |
|
for ( t = BDY(v), i = 0; t; t = NEXT(t), i++ ) { |
for ( t = BDY(v), i = 0; t; t = NEXT(t), i++ ) { |
ptod(CO,vl,(P)BDY(t),&a); p[i] = BDY(a)->dl; |
ptod(CO,vl,(P)BDY(t),&a); p[i] = BDY(a)->dl; |
} |
} |
|
if ( weight ) { |
|
wlen = length(BDY((LIST)weight)); |
|
if ( n != wlen ) |
|
error("dp_monomial_hilbert_poincare: inconsistent weight length"); |
|
w = (int *)MALLOC(n*sizeof(int)); |
|
for ( i = 0, nd = BDY((LIST)weight); i < n; i++, nd = NEXT(nd) ) |
|
w[i] = ZTOS((Z)BDY(nd)); |
|
} else if ( current_dl_weight_vector ) |
|
w = current_dl_weight_vector; |
|
else |
|
w = 0; |
|
if ( w ) { |
|
*rp = dp_monomial_hilbert_poincare_weight(b,x,w); |
|
} else { |
|
*rp = dp_monomial_hilbert_poincare(b,x); |
|
} |
|
if ( current_spec ) |
|
initd(current_spec); |
|
} |
|
|
|
DL monomial_colon(DL a,DL b,int n) |
|
{ |
|
int i,d,td; |
|
DL r; |
|
|
|
NEWDL(r,n); |
|
td = 0; |
|
for ( i = 0; i < n; i++ ) { |
|
d = a->d[i]-b->d[i]; |
|
r->d[i] = MAX(d,0); |
|
td += r->d[i]; |
|
} |
|
r->td = td; |
|
return r; |
|
} |
|
|
|
// arguments : DPlist, Xlist, Mono, [HN(t),NV,Head,HP(n),Plist] |
|
void Pdp_monomial_hilbert_poincare_incremental(NODE arg,LIST *rp) |
|
{ |
|
NODE g,data,data1,nd,t; |
|
LIST list,list1; |
|
DL new,dl; |
|
int len,i,n; |
|
Z dz; |
|
DL *p; |
|
P hn,hn1,newhn,tv,newhpoly,td,s; |
|
VECT b,x,newhfhead; |
|
P *plist; |
|
Obj ord; |
|
struct order_spec *current_spec=0,*spec; |
|
|
r = (P *)CALLOC(n+1,sizeof(P)); |
if ( current_option ) { |
|
if ( peek_option(current_option,"ord",&ord) ) { |
|
current_spec = dp_current_spec; |
|
create_order_spec(0,ord,&spec); |
|
initd(spec); |
|
} |
|
} |
|
g = BDY((LIST)ARG0(arg)); new = BDY((DP)ARG1(arg))->dl; |
|
data = BDY((LIST)ARG2(arg)); |
|
hn = (P)ARG0(data); n = ZTOS((Z)ARG1(data)); |
|
len = length(g); MKVECT(b,len); p = (DL *)BDY(b); |
|
for ( t = g, i = 0; t; t = NEXT(t), i++ ) |
|
p[i] = monomial_colon(BDY((DP)BDY(t))->dl,new,n); |
|
MKVECT(x,n); |
|
for ( i = 0; i < n; i++ ) { |
|
NEWDL(dl,n); dl->d[i] = 1; dl->td = 1; BDY(x)[i] = dl; |
|
} |
|
// compute HP(I:new) |
|
list1 = dp_monomial_hilbert_poincare(b,x); |
|
data1 = BDY((LIST)list1); |
|
hn1 = (P)ARG0(data1); |
|
// HP(I+<new>) = H(I)-t^d*H(I:new), d=tdeg(new) |
plist = mhp_prep(n,&tv); |
plist = mhp_prep(n,&tv); |
make_reduced(b,n); |
UTOZ(new->td,dz); |
mhp_rec(b,x,tv,r); |
pwrp(CO,tv,dz,&td); |
hp = mhp_ctop(r,plist,n); |
mulp(CO,hn1,td,&s); |
mhp_to_hf(CO,hp,n,plist,&hfhead,&hpoly); |
subp(CO,hn,s,&newhn); |
UTOZ(n,z); |
mhp_to_hf(CO,newhn,n,plist,&newhfhead,&newhpoly); |
nd = mknode(4,hp,z,hfhead,hpoly); |
nd = mknode(5,newhn,ARG1(data),newhfhead,newhpoly,(VECT)ARG4(data)); |
MKLIST(*rp,nd); |
MKLIST(list,nd); |
|
*rp = list; |
|
if ( current_spec ) |
|
initd(current_spec); |
} |
} |
|
|
void Pdp_compute_last_t(NODE arg,LIST *rp) |
void Pdp_compute_last_t(NODE arg,LIST *rp) |
Line 2753 void parse_gr_option(LIST f,NODE opt,LIST *v,Num *homo |
|
Line 2945 void parse_gr_option(LIST f,NODE opt,LIST *v,Num *homo |
|
if ( !homo_is_set ) *homo = 0; |
if ( !homo_is_set ) *homo = 0; |
} |
} |
|
|
|
int peek_option(NODE opt,char *find,Obj *retp) |
|
{ |
|
NODE t,p; |
|
char *key; |
|
Obj value; |
|
|
|
for ( t = opt; t; t = NEXT(t) ) { |
|
p = BDY((LIST)BDY(t)); |
|
key = BDY((STRING)BDY(p)); |
|
value = (Obj)BDY(NEXT(p)); |
|
if ( !strcmp(key,find) ) { |
|
*retp = value; |
|
return 1; |
|
} |
|
} |
|
return 0; |
|
} |
|
|
void Pdp_gr_main(NODE arg,LIST *rp) |
void Pdp_gr_main(NODE arg,LIST *rp) |
{ |
{ |
LIST f,v; |
LIST f,v; |
Line 3039 void Pnd_sba(NODE arg,LIST *rp) |
|
Line 3249 void Pnd_sba(NODE arg,LIST *rp) |
|
Z mq,z; |
Z mq,z; |
Num nhomo; |
Num nhomo; |
NODE node; |
NODE node; |
struct order_spec *ord; |
struct order_spec *ord,*current_spec; |
|
|
|
current_spec = dp_current_spec; |
do_weyl = 0; |
do_weyl = 0; |
retdp = 0; |
retdp = 0; |
if ( (ac=argc(arg)) == 4 ) { |
if ( (ac=argc(arg)) == 4 ) { |
Line 3072 void Pnd_sba(NODE arg,LIST *rp) |
|
Line 3283 void Pnd_sba(NODE arg,LIST *rp) |
|
} else |
} else |
error("nd_gr : invalid argument"); |
error("nd_gr : invalid argument"); |
nd_sba(f,v,m,homo,retdp,0,ord,rp); |
nd_sba(f,v,m,homo,retdp,0,ord,rp); |
|
initd(current_spec); |
} |
} |
|
|
void Pnd_weyl_sba(NODE arg,LIST *rp) |
void Pnd_weyl_sba(NODE arg,LIST *rp) |