version 1.18, 2019/12/12 04:44:59 |
version 1.21, 2020/02/05 04:56:10 |
|
|
* 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/engine/dist.c,v 1.17 2019/11/21 04:03:16 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2018/engine/dist.c,v 1.20 2020/02/03 05:51:52 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
|
|
Line 353 void nodetodpm(NODE node,Obj pos,DPM *dp) |
|
Line 353 void nodetodpm(NODE node,Obj pos,DPM *dp) |
|
} |
} |
d->td = td; |
d->td = td; |
p = ZTOS((Q)pos); |
p = ZTOS((Q)pos); |
if ( dp_current_spec->module_rank ) { |
if ( dp_current_spec->module_top_weight ) { |
if ( p > dp_current_spec->module_rank ) |
if ( p > dp_current_spec->module_rank ) |
error("nodetodpm : inconsistent order spec"); |
error("nodetodpm : inconsistent order spec"); |
d->td += dp_current_spec->module_top_weight[p-1]; |
d->td += dp_current_spec->module_top_weight[p-1]; |
Line 371 void dtodpm(DP d,int pos,DPM *dp) |
|
Line 371 void dtodpm(DP d,int pos,DPM *dp) |
|
if ( !d ) *dp = 0; |
if ( !d ) *dp = 0; |
else { |
else { |
shift = 0; |
shift = 0; |
if ( dp_current_spec->module_rank ) { |
if ( dp_current_spec->module_top_weight ) { |
if ( pos > dp_current_spec->module_rank ) |
if ( pos > dp_current_spec->module_rank ) |
error("nodetodpm : inconsistent order spec"); |
error("nodetodpm : inconsistent order spec"); |
shift = dp_current_spec->module_top_weight[pos-1]; |
shift = dp_current_spec->module_top_weight[pos-1]; |
Line 2750 void dpm_sp(DPM p1,DPM p2,DPM *sp,DP *t1,DP *t2); |
|
Line 2750 void dpm_sp(DPM p1,DPM p2,DPM *sp,DP *t1,DP *t2); |
|
DPM dpm_nf_and_quotient3(DPM sp,VECT psv,DPM *nf,P *dn); |
DPM dpm_nf_and_quotient3(DPM sp,VECT psv,DPM *nf,P *dn); |
DPM dpm_nf_and_quotient4(DPM sp,DPM *ps,VECT psiv,DPM head,DPM *nf,P *dn); |
DPM dpm_nf_and_quotient4(DPM sp,DPM *ps,VECT psiv,DPM head,DPM *nf,P *dn); |
DPM dpm_sp_nf(VECT psv,VECT psiv,int i,int j,DPM *nf); |
DPM dpm_sp_nf(VECT psv,VECT psiv,int i,int j,DPM *nf); |
DPM dpm_sp_nf_zlist(VECT psv,VECT psiv,int i,int j,DPM *nf); |
DPM dpm_sp_nf_zlist(VECT psv,VECT psiv,int i,int j,int top,DPM *nf); |
DPM dpm_sp_nf_asir(VECT psv,int i,int j,DPM *nf); |
DPM dpm_sp_nf_asir(VECT psv,int i,int j,DPM *nf); |
void dpm_sort(DPM p,DPM *r); |
void dpm_sort(DPM p,DPM *r); |
|
|
Line 2907 void dpm_list_to_array(LIST g,VECT *psvect,VECT *psind |
|
Line 2907 void dpm_list_to_array(LIST g,VECT *psvect,VECT *psind |
|
*psvect = psv; *psindvect = psiv; |
*psvect = psv; *psindvect = psiv; |
} |
} |
|
|
|
#if 0 |
void dpm_insert_to_zlist(VECT psiv,int pos,int i) |
void dpm_insert_to_zlist(VECT psiv,int pos,int i) |
{ |
{ |
LIST l; |
LIST l; |
Line 2926 void dpm_insert_to_zlist(VECT psiv,int pos,int i) |
|
Line 2927 void dpm_insert_to_zlist(VECT psiv,int pos,int i) |
|
if ( prev == 0 ) BDY(l) = nd; |
if ( prev == 0 ) BDY(l) = nd; |
else NEXT(prev) = nd; |
else NEXT(prev) = nd; |
} |
} |
|
#else |
|
void dpm_insert_to_zlist(VECT psiv,int pos,int i) |
|
{ |
|
LIST l; |
|
NODE prev,cur,nd; |
|
int curi; |
|
Z iz; |
|
|
|
l = (LIST)BDY(psiv)[pos]; |
|
for ( prev = 0, cur = BDY(l); cur; cur = NEXT(cur) ) { |
|
curi = ZTOS((Q)BDY(cur)); |
|
if ( curi == i ) |
|
error("dpm_insert_to_list : invalid index"); |
|
prev = cur; |
|
} |
|
STOZ(i,iz); MKNODE(nd,iz,cur); |
|
if ( prev == 0 ) BDY(l) = nd; |
|
else NEXT(prev) = nd; |
|
} |
|
#endif |
|
|
void dpm_schreyer_base_zlist(LIST g,LIST *s) |
void dpm_schreyer_base_zlist(LIST g,LIST *s) |
{ |
{ |
NODE nd,t0,t,b0,b; |
NODE nd,t0,t,b0,b; |
Line 2979 void dpm_schreyer_base_zlist(LIST g,LIST *s) |
|
Line 3000 void dpm_schreyer_base_zlist(LIST g,LIST *s) |
|
} |
} |
for ( j = p1+1; j <= n; j++ ) { |
for ( j = p1+1; j <= n; j++ ) { |
if ( mm[j] ) { |
if ( mm[j] ) { |
quo = dpm_sp_nf_zlist(psv,psiv,p1,j,&nf); |
quo = dpm_sp_nf_zlist(psv,psiv,p1,j,0,&nf); |
if ( nf ) |
if ( nf ) |
error("dpm_schreyer_base : cannot happen"); |
error("dpm_schreyer_base : cannot happen"); |
NEXTNODE(b0,b); BDY(b) = (pointer)quo; |
NEXTNODE(b0,b); BDY(b) = (pointer)quo; |
Line 3006 void dpm_schreyer_base_zlist(LIST g,LIST *s) |
|
Line 3027 void dpm_schreyer_base_zlist(LIST g,LIST *s) |
|
printf("sch_count=%d, schlast_count=%d\n",sch_count,schlast_count); |
printf("sch_count=%d, schlast_count=%d\n",sch_count,schlast_count); |
} |
} |
|
|
|
static int compdp_nv; |
|
|
|
int compdp_revgradlex(DP *a,DP *b) |
|
{ |
|
return -cmpdl_revgradlex(compdp_nv,BDY(*a)->dl,BDY(*b)->dl); |
|
} |
|
|
|
int compdp_lex(DP *a,DP *b) |
|
{ |
|
return -cmpdl_lex(compdp_nv,BDY(*a)->dl,BDY(*b)->dl); |
|
} |
|
|
DMMstack_array dpm_schreyer_frame(NODE g) |
DMMstack_array dpm_schreyer_frame(NODE g) |
{ |
{ |
LIST l; |
LIST l; |
NODE nd,in,b0,b,n1,n2,n3,t; |
NODE nd,in,b0,b,n1,n2,n3,t; |
NODE *psi; |
NODE *psi; |
long p1,p2,p3; |
long p1,p2,p3; |
int nv,n,i,max,pos,level; |
int nv,n,i,j,k,max,pos,level; |
DMMstack s,s1; |
DMMstack s,s1; |
DMM m1,m0,dmm; |
DMM m1,m0,dmm; |
MP mp; |
MP mp; |
DP dp,h; |
DP dp,h; |
DP *m; |
DP *m,*m2; |
DPM dpm,dpm0,dpm1; |
DPM dpm,dpm0,dpm1; |
VECT psv,psiv; |
VECT psv,psiv; |
DPM *ps; |
DPM *ps; |
DMMstack_array dmmstack_array; |
DMMstack_array dmmstack_array; |
|
|
nd = g; |
nd = g; |
nv = ((DPM)BDY(nd))->nv; |
compdp_nv = nv = ((DPM)BDY(nd))->nv; |
s = 0; |
s = 0; |
level = 0; |
level = 0; |
while ( 1 ) { |
while ( 1 ) { |
Line 3069 DMMstack_array dpm_schreyer_frame(NODE g) |
|
Line 3102 DMMstack_array dpm_schreyer_frame(NODE g) |
|
MKNODE(nd,(long)i,psi[pos]); psi[pos] = nd; |
MKNODE(nd,(long)i,psi[pos]); psi[pos] = nd; |
} |
} |
m = (DP *)MALLOC((n+1)*sizeof(DP)); |
m = (DP *)MALLOC((n+1)*sizeof(DP)); |
|
m2 = (DP *)MALLOC((n+1)*sizeof(DP)); |
b0 = 0; |
b0 = 0; |
for ( i = 1; i <= max; i++ ) { |
for ( i = 1; i <= max; i++ ) { |
for ( n1 = psi[i]; n1; n1 = NEXT(n1) ) { |
for ( n1 = psi[i]; n1; n1 = NEXT(n1) ) { |
Line 3088 DMMstack_array dpm_schreyer_frame(NODE g) |
|
Line 3122 DMMstack_array dpm_schreyer_frame(NODE g) |
|
} |
} |
if ( h ) m[p2] = h; |
if ( h ) m[p2] = h; |
} |
} |
|
#if 0 |
|
// compress m to m2 |
|
for ( j = 0, n2 = NEXT(n1); n2; n2 = NEXT(n2) ) { |
|
p2 = (long)BDY(n2); |
|
if ( m[p2] ) m2[j++] = m[p2]; |
|
} |
|
qsort(m2,j,sizeof(DP),(int (*)(const void *,const void *))compdp_lex); |
|
for ( k = 0; k < j; k++ ) { |
|
NEWDMM(dmm); dmm->dl = BDY(m2[k])->dl; dmm->pos = p1; dmm->c = (Obj)ONE; |
|
MKDPM(nv,dmm,dpm); |
|
NEXTNODE(b0,b); BDY(b) = (pointer)dpm; |
|
} |
|
#else |
for ( n2 = NEXT(n1); n2; n2 = NEXT(n2) ) { |
for ( n2 = NEXT(n1); n2; n2 = NEXT(n2) ) { |
p2 = (long)BDY(n2); |
p2 = (long)BDY(n2); |
if ( m[p2] ) { |
if ( m[p2] ) { |
Line 3096 DMMstack_array dpm_schreyer_frame(NODE g) |
|
Line 3143 DMMstack_array dpm_schreyer_frame(NODE g) |
|
NEXTNODE(b0,b); BDY(b) = (pointer)dpm; |
NEXTNODE(b0,b); BDY(b) = (pointer)dpm; |
} |
} |
} |
} |
|
#endif |
} |
} |
} |
} |
if ( !b0 ) { |
if ( !b0 ) { |
Line 3164 int compdmm_schreyer(int n,DMM m1,DMM m2) |
|
Line 3212 int compdmm_schreyer(int n,DMM m1,DMM m2) |
|
} |
} |
} |
} |
|
|
|
int compdmm_schreyer_old(int n,DMM m1,DMM m2) |
|
{ |
|
int pos1,pos2,t,npos1,npos2; |
|
DMM *in,*sum; |
|
DMMstack s; |
|
static DL d1=0,d2=0; |
|
static int dlen=0; |
|
|
|
sch_count++; |
|
pos1 = m1->pos; pos2 = m2->pos; |
|
if ( pos1 == pos2 ) return (*cmpdl)(n,m1->dl,m2->dl); |
|
if ( n > dlen ) { |
|
NEWDL(d1,n); NEWDL(d2,n); dlen = n; |
|
} |
|
sum = dmm_stack->sum; |
|
_copydl(n,m1->dl,d1); |
|
_copydl(n,m2->dl,d2); |
|
for ( s = dmm_stack; s; s = NEXT(s) ) { |
|
in = s->in; |
|
_addtodl(n,in[pos1]->dl,d1); |
|
_addtodl(n,in[pos2]->dl,d2); |
|
if ( in[pos1]->pos == in[pos2]->pos && _eqdl(n,d1,d2)) { |
|
if ( pos1 < pos2 ) return 1; |
|
else if ( pos1 > pos2 ) return -1; |
|
else return 0; |
|
} |
|
pos1 = in[pos1]->pos; |
|
pos2 = in[pos2]->pos; |
|
if ( pos1 == pos2 ) return (*cmpdl)(n,d1,d2); |
|
} |
|
if ( dpm_base_ordtype == 1 ) { |
|
if ( pos1 < pos2 ) return 1; |
|
else if ( pos1 > pos2 ) return -1; |
|
else return (*cmpdl)(n,d1,d2); |
|
} else { |
|
t = (*cmpdl)(n,d1,d2); |
|
if ( t ) return t; |
|
else if ( pos1 < pos2 ) return 1; |
|
else if ( pos1 > pos2 ) return -1; |
|
else return 0; |
|
} |
|
} |
|
|
|
extern int NaiveSchreyer; |
|
|
int compdmm(int n,DMM m1,DMM m2) |
int compdmm(int n,DMM m1,DMM m2) |
{ |
{ |
int t; |
int t,t1; |
|
int *base_ord; |
|
|
switch ( dpm_ordtype ) { |
switch ( dpm_ordtype ) { |
case 0: /* TOP ord->pos */ |
case 0: /* TOP ord->pos */ |
Line 3186 int compdmm(int n,DMM m1,DMM m2) |
|
Line 3280 int compdmm(int n,DMM m1,DMM m2) |
|
else if ( m1->pos > m2->pos ) return -1; |
else if ( m1->pos > m2->pos ) return -1; |
else return (*cmpdl)(n,m1->dl,m2->dl); |
else return (*cmpdl)(n,m1->dl,m2->dl); |
case 3: /* Schreyer */ |
case 3: /* Schreyer */ |
return compdmm_schreyer(n,m1,m2); |
if ( NaiveSchreyer ) |
|
t = compdmm_schreyer_old(n,m1,m2); |
|
else |
|
t = compdmm_schreyer(n,m1,m2); |
|
return t; |
|
case 4: /* POT with base_ord */ |
|
base_ord = dp_current_spec->module_base_ord; |
|
if ( base_ord[m1->pos] < base_ord[m2->pos] ) return 1; |
|
else if ( base_ord[m1->pos] > base_ord[m2->pos] ) return -1; |
|
else return (*cmpdl)(n,m1->dl,m2->dl); |
default: |
default: |
error("compdmm : invalid dpm_ordtype"); |
error("compdmm : invalid dpm_ordtype"); |
} |
} |
Line 3462 DPM dpm_eliminate_term(DPM a,DPM p,Obj c,int pos) |
|
Line 3565 DPM dpm_eliminate_term(DPM a,DPM p,Obj c,int pos) |
|
if ( m->pos == pos ) { |
if ( m->pos == pos ) { |
NEXTMP(d0,d); |
NEXTMP(d0,d); |
arf_chsgn(m->c,&d->c); |
arf_chsgn(m->c,&d->c); |
if ( !dp_current_spec || !dp_current_spec->module_rank ) |
if ( !dp_current_spec || !dp_current_spec->module_top_weight ) |
d->dl = m->dl; |
d->dl = m->dl; |
else { |
else { |
NEWDL(dl,NV(a)); |
NEWDL(dl,NV(a)); |
Line 3503 DPM dpm_compress(DPM p,int *tab) |
|
Line 3606 DPM dpm_compress(DPM p,int *tab) |
|
} |
} |
|
|
// input : s, s = syz(m) output simplified s, m |
// input : s, s = syz(m) output simplified s, m |
|
// assuming the term order is POT |
void dpm_simplify_syz(LIST s,LIST m,LIST *s1,LIST *m1,LIST *w1) |
void dpm_simplify_syz(LIST s,LIST m,LIST *s1,LIST *m1,LIST *w1) |
{ |
{ |
int lm,ls,i,j,k,pos,nv; |
int lm,ls,i,j,k,pos,nv; |
Line 3525 void dpm_simplify_syz(LIST s,LIST m,LIST *s1,LIST *m1, |
|
Line 3629 void dpm_simplify_syz(LIST s,LIST m,LIST *s1,LIST *m1, |
|
p = as[i]; |
p = as[i]; |
if ( p == 0 ) continue; |
if ( p == 0 ) continue; |
nv = NV(p); |
nv = NV(p); |
for ( d = BDY(p); d; d = NEXT(d) ) { |
for ( d = BDY(p); d; ) { |
dd = d->dl->d; |
dd = d->dl->d; |
for ( k = 0; k < nv; k++ ) if ( dd[k] ) break; |
for ( k = 0; k < nv; k++ ) if ( dd[k] ) break; |
if ( k == nv ) break; |
if ( k == nv ) break; |
|
pos = d->pos; |
|
while ( d && d->pos == pos ) d = NEXT(d); |
} |
} |
if ( d ) { |
if ( d ) { |
c = d->c; pos = d->pos; |
c = d->c; pos = d->pos; |
Line 3557 void dpm_simplify_syz(LIST s,LIST m,LIST *s1,LIST *m1, |
|
Line 3663 void dpm_simplify_syz(LIST s,LIST m,LIST *s1,LIST *m1, |
|
} |
} |
MKLIST(*s1,t); |
MKLIST(*s1,t); |
|
|
if ( dp_current_spec && dp_current_spec->module_rank ) { |
if ( dp_current_spec && dp_current_spec->module_top_weight ) { |
new_w = (int *)MALLOC(j*sizeof(int)); |
new_w = (int *)MALLOC(j*sizeof(int)); |
for ( j = 0, i = 1; i <= lm; i++ ) |
for ( j = 0, i = 1; i <= lm; i++ ) |
if ( tab[i] ) { new_w[j++] = dp_current_spec->module_top_weight[i-1]; } |
if ( tab[i] ) { new_w[j++] = dp_current_spec->module_top_weight[i-1]; } |