version 1.46, 2021/01/25 00:39:52 |
version 1.47, 2021/02/01 08:06:33 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.45 2021/01/11 08:37:44 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.46 2021/01/25 00:39:52 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
void print_siglist(NODE l); |
void print_siglist(NODE l); |
|
|
int Nnd_add,Nf4_red,NcriB,NcriMF,Ncri2,Npairs; |
int Nnd_add,Nf4_red,NcriB,NcriMF,Ncri2,Npairs,Nnewpair; |
struct oEGT eg_search,f4_symb,f4_conv,f4_elim1,f4_elim2; |
struct oEGT eg_search,f4_symb,f4_conv,f4_elim1,f4_elim2; |
|
|
int diag_period = 6; |
int diag_period = 6; |
Line 2592 get_eg(&eg2); add_eg(&eg_update,&eg1,&eg2); |
|
Line 2592 get_eg(&eg2); add_eg(&eg_update,&eg1,&eg2); |
|
} |
} |
|
|
ND_pairs update_pairs_s(ND_pairs d,int t,NODE *syz); |
ND_pairs update_pairs_s(ND_pairs d,int t,NODE *syz); |
|
int update_pairs_array_s(ND_pairs *d,int t,NODE *syz); |
ND_pairs nd_newpairs_s(int t ,NODE *syz); |
ND_pairs nd_newpairs_s(int t ,NODE *syz); |
|
ND_pairs *nd_newpairs_array_s(int t ,NODE *syz); |
|
|
int nd_nf_pbucket_s(int mod,ND g,NDV *ps,int full,ND *nf); |
int nd_nf_pbucket_s(int mod,ND g,NDV *ps,int full,ND *nf); |
int nd_nf_s(int mod,ND d,ND g,NDV *ps,int full,ND *nf); |
int nd_nf_s(int mod,ND d,ND g,NDV *ps,int full,ND *nf); |
Line 2721 ND_pairs find_smallest_lcm(ND_pairs l) |
|
Line 2723 ND_pairs find_smallest_lcm(ND_pairs l) |
|
_addtodl(nd_nvar,quo,mul); |
_addtodl(nd_nvar,quo,mul); |
if ( (*cmpdl)(nd_nvar,minlm,mul) > 0 ) { |
if ( (*cmpdl)(nd_nvar,minlm,mul) > 0 ) { |
minindex = i; |
minindex = i; |
|
break; |
_copydl(nd_nvar,mul,minlm); |
_copydl(nd_nvar,mul,minlm); |
} |
} |
} |
} |
} |
} |
// l->lcm is minimal; return l itself |
// l->lcm is minimal; return l itself |
if ( minindex < 0 ) return l; |
if ( minindex < 0 ) return l; |
|
else return 0; |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
if ( i == minindex ) continue; |
if ( i == minindex ) continue; |
_ndltodl(DL(nd_psh[i]),mul); |
_ndltodl(DL(nd_psh[i]),mul); |
Line 2808 SIG trivial_sig(int i,int j) |
|
Line 2812 SIG trivial_sig(int i,int j) |
|
return sig; |
return sig; |
} |
} |
|
|
|
int nd_minsig(ND_pairs *d) |
|
{ |
|
int min,i,ret; |
|
|
|
min = -1; |
|
for ( i = 0; i < nd_nbase; i++ ) { |
|
if ( d[i] != 0 ) { |
|
if ( min < 0 ) min = i; |
|
else { |
|
ret = comp_sig(d[i]->sig,d[min]->sig); |
|
if ( ret < 0 ) min = i; |
|
} |
|
} |
|
} |
|
return min; |
|
} |
|
|
|
int dlength(ND_pairs d) |
|
{ |
|
int i; |
|
for ( i = 0; d; d = d->next, i++ ); |
|
return i; |
|
} |
|
|
NODE nd_sba_buch(int m,int ishomo,int **indp,NODE *syzp) |
NODE nd_sba_buch(int m,int ishomo,int **indp,NODE *syzp) |
{ |
{ |
int i,j,nh,sugar,stat,pos; |
int i,j,nh,sugar,stat,pos; |
NODE r,t,g; |
NODE r,t,g; |
ND_pairs d; |
ND_pairs *d; |
ND_pairs l,l1; |
ND_pairs l,l1; |
ND h,nf,s,head,nf1; |
ND h,nf,s,head,nf1; |
NDV nfv; |
NDV nfv; |
Line 2822 NODE nd_sba_buch(int m,int ishomo,int **indp,NODE *syz |
|
Line 2850 NODE nd_sba_buch(int m,int ishomo,int **indp,NODE *syz |
|
LIST list; |
LIST list; |
SIG sig; |
SIG sig; |
NODE *syzlist; |
NODE *syzlist; |
int ngen; |
int ngen,ind; |
int Nnominimal,Nredundant; |
int Nnominimal,Nredundant; |
DL lcm,quo,mul; |
DL lcm,quo,mul; |
struct oEGT eg1,eg2,eg_update,eg_remove,eg_large,eg_nf,eg_nfzero; |
struct oEGT eg1,eg2,eg_update,eg_remove,eg_large,eg_nf,eg_nfzero,eg_minsig,eg_smallest; |
int Nnfs=0,Nnfz=0,Nnfnz=0; |
int Nnfs=0,Nnfz=0,Nnfnz=0,dlen,nsyz; |
|
|
init_eg(&eg_remove); |
init_eg(&eg_remove); |
syzlist = (NODE *)MALLOC(nd_psn*sizeof(NODE)); |
syzlist = (NODE *)MALLOC(nd_psn*sizeof(NODE)); |
|
d = (ND_pairs *)MALLOC(nd_psn*sizeof(ND_pairs)); |
|
nd_nbase = nd_psn; |
Nsyz = 0; |
Nsyz = 0; |
Nnd_add = 0; |
Nnd_add = 0; |
Nnominimal = 0; |
Nnominimal = 0; |
Nredundant = 0; |
Nredundant = 0; |
d = 0; |
|
ngen = nd_psn; |
ngen = nd_psn; |
for ( i = 0; i < nd_psn; i++ ) |
for ( i = 0; i < nd_psn; i++ ) |
for ( j = i+1; j < nd_psn; j++ ) { |
for ( j = i+1; j < nd_psn; j++ ) { |
sig = trivial_sig(i,j); |
sig = trivial_sig(i,j); |
syzlist[sig->pos] = insert_sig(syzlist[sig->pos],sig); |
syzlist[sig->pos] = insert_sig(syzlist[sig->pos],sig); |
} |
} |
|
dlen = 0; |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
d = update_pairs_s(d,i,syzlist); |
dlen += update_pairs_array_s(d,i,syzlist); |
} |
} |
sugar = 0; |
sugar = 0; |
pos = 0; |
pos = 0; |
NEWDL(lcm,nd_nvar); NEWDL(quo,nd_nvar); NEWDL(mul,nd_nvar); |
NEWDL(lcm,nd_nvar); NEWDL(quo,nd_nvar); NEWDL(mul,nd_nvar); |
init_eg(&eg_create); |
init_eg(&eg_create); |
init_eg(&eg_merge); |
init_eg(&eg_merge); |
|
init_eg(&eg_minsig); |
|
init_eg(&eg_smallest); |
init_eg(&eg_large); |
init_eg(&eg_large); |
init_eg(&eg_nf); |
init_eg(&eg_nf); |
init_eg(&eg_nfzero); |
init_eg(&eg_nfzero); |
while ( d ) { |
while ( 1 ) { |
again: |
if ( DP_Print && dlen%100 == 0 ) fprintf(asir_out,"(%d)",dlen); |
if ( DP_Print ) { |
again : |
int len; |
get_eg(&eg1); |
ND_pairs td; |
ind = nd_minsig(d); |
for ( td = d, len=0; td; td = td->next, len++) |
get_eg(&eg2); add_eg(&eg_minsig,&eg1,&eg2); |
; |
if ( ind < 0 ) break; |
if ( !(len%100) ) fprintf(asir_out,"(%d)",len); |
l = d[ind]; |
} |
// printf("(%d,%d)",l->i1,l->i2); print_sig(l->sig); printf("\n"); |
l = d; d = d->next; |
get_eg(&eg1); |
#if 0 |
|
if ( small_lcm(l) ) { |
|
if ( DP_Print ) fprintf(asir_out,"M"); |
|
Nnominimal++; |
|
continue; |
|
} |
|
if ( SG(l) != sugar ) { |
|
sugar = SG(l); |
|
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
|
} |
|
sig = l->sig; |
|
if ( DP_Print && nd_sba_pot ) { |
|
if ( sig->pos != pos ) { |
|
fprintf(asir_out,"[%d]",sig->pos); |
|
pos = sig->pos; |
|
} |
|
} |
|
stat = nd_sp(m,0,l,&h); |
|
#else |
|
// if ( l->sig->dl->td == 0 ) |
|
// if ( DP_Print ) print_sig(l->sig); |
|
l1 = find_smallest_lcm(l); |
l1 = find_smallest_lcm(l); |
|
get_eg(&eg2); add_eg(&eg_smallest,&eg1,&eg2); |
if ( l1 == 0 ) { |
if ( l1 == 0 ) { |
|
d[ind] = d[ind]->next; dlen--; |
if ( DP_Print ) fprintf(asir_out,"M"); |
if ( DP_Print ) fprintf(asir_out,"M"); |
Nnominimal++; |
Nnominimal++; |
continue; |
continue; |
|
|
} |
} |
} |
} |
stat = nd_sp(m,0,l1,&h); |
stat = nd_sp(m,0,l1,&h); |
#endif |
|
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
nd_reconstruct_s(0,d); |
d = nd_reconstruct(0,d); |
|
goto again; |
goto again; |
} |
} |
get_eg(&eg1); |
get_eg(&eg1); |
|
|
#endif |
#endif |
get_eg(&eg2); |
get_eg(&eg2); |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
nd_reconstruct_s(0,d); |
d = nd_reconstruct(0,d); |
|
goto again; |
goto again; |
} else if ( stat == -1 ) { |
} else if ( stat == -1 ) { |
|
d[ind] = d[ind]->next; dlen--; |
Nnfs++; |
Nnfs++; |
if ( DP_Print ) { printf("S"); fflush(stdout); } |
if ( DP_Print ) { printf("S"); fflush(stdout); } |
FREENDP(l); |
|
} else if ( nf ) { |
} else if ( nf ) { |
|
d[ind] = d[ind]->next; dlen--; |
Nnfnz++; |
Nnfnz++; |
if ( DP_Print ) { |
if ( DP_Print ) { |
if ( nd_sba_redundant_check ) { |
if ( nd_sba_redundant_check ) { |
|
|
nfv = ndtondv(m,nf); nd_free(nf); |
nfv = ndtondv(m,nf); nd_free(nf); |
nh = ndv_newps(m,nfv,0); |
nh = ndv_newps(m,nfv,0); |
|
|
d = update_pairs_s(d,nh,syzlist); |
dlen += update_pairs_array_s(d,nh,syzlist); |
nd_sba_pos[sig->pos] = append_one(nd_sba_pos[sig->pos],nh); |
nd_sba_pos[sig->pos] = append_one(nd_sba_pos[sig->pos],nh); |
FREENDP(l); |
|
} else { |
} else { |
|
d[ind] = d[ind]->next; dlen--; |
Nnfz++; |
Nnfz++; |
add_eg(&eg_nfzero,&eg1,&eg2); |
add_eg(&eg_nfzero,&eg1,&eg2); |
// syzygy |
// syzygy |
get_eg(&eg1); |
get_eg(&eg1); |
d = remove_spair_s(d,sig); |
nsyz = Nsyz; |
|
d[sig->pos] = remove_spair_s(d[sig->pos],sig); |
|
dlen -= Nsyz-nsyz; |
get_eg(&eg2); add_eg(&eg_remove,&eg1,&eg2); |
get_eg(&eg2); add_eg(&eg_remove,&eg1,&eg2); |
syzlist[sig->pos] = insert_sig(syzlist[sig->pos],sig); |
syzlist[sig->pos] = insert_sig(syzlist[sig->pos],sig); |
if ( DP_Print ) { printf("."); fflush(stdout); } |
if ( DP_Print ) { printf("."); fflush(stdout); } |
FREENDP(l); |
|
} |
} |
} |
} |
g = conv_ilist_s(nd_demand,0,indp); |
g = conv_ilist_s(nd_demand,0,indp); |
if ( DP_Print ) { |
if ( DP_Print ) { |
printf("\nnd_sba done. nd_add=%d,Nsyz=%d,Nsamesig=%d,Nnominimal=%d\n",Nnd_add,Nsyz,Nsamesig,Nnominimal); |
printf("\ndlen=%d,nd_sba done. nd_add=%d,Nsyz=%d,Nsamesig=%d,Nnominimal=%d\n",dlen,Nnd_add,Nsyz,Nsamesig,Nnominimal); |
printf("Nnfnz=%d,Nnfz=%d,Nnfsingular=%d\n",Nnfnz,Nnfz,Nnfs); |
printf("Nnfnz=%d,Nnfz=%d,Nnfsingular=%d\n",Nnfnz,Nnfz,Nnfs); |
fflush(stdout); |
fflush(stdout); |
if ( nd_sba_redundant_check ) |
if ( nd_sba_redundant_check ) |
Line 2966 get_eg(&eg2); add_eg(&eg_remove,&eg1,&eg2); |
|
Line 2978 get_eg(&eg2); add_eg(&eg_remove,&eg1,&eg2); |
|
fflush(stdout); |
fflush(stdout); |
print_eg("create",&eg_create); |
print_eg("create",&eg_create); |
print_eg("merge",&eg_merge); |
print_eg("merge",&eg_merge); |
|
print_eg("minsig",&eg_minsig); |
|
print_eg("smallest",&eg_smallest); |
print_eg("remove",&eg_remove); |
print_eg("remove",&eg_remove); |
print_eg("nf",&eg_nf); |
print_eg("nf",&eg_nf); |
print_eg("nfzero",&eg_nfzero); |
print_eg("nfzero",&eg_nfzero); |
printf("\n"); |
printf("\n"); |
} |
} |
if ( nd_sba_syz ) { |
if ( nd_sba_syz ) { |
|
print_eg("remove",&eg_remove); |
|
print_eg("nf",&eg_nf); |
|
print_eg("nfzero",&eg_nfzero); |
|
printf("\n"); |
|
} |
|
if ( nd_sba_syz ) { |
NODE hsyz,tsyz,prev; |
NODE hsyz,tsyz,prev; |
|
|
hsyz = 0; |
hsyz = 0; |
Line 3431 get_eg(&eg3); add_eg(&eg_merge,&eg2,&eg3); |
|
Line 3451 get_eg(&eg3); add_eg(&eg_merge,&eg2,&eg3); |
|
return d; |
return d; |
} |
} |
|
|
|
int update_pairs_array_s( ND_pairs *d, int t,NODE *syz) |
|
{ |
|
ND_pairs *d1; |
|
struct oEGT eg1,eg2,eg3; |
|
int i; |
|
|
|
if ( !t ) return 0; |
|
get_eg(&eg1); |
|
Nnewpair = 0; |
|
d1 = nd_newpairs_array_s(t,syz); |
|
get_eg(&eg2); add_eg(&eg_create,&eg1,&eg2); |
|
for ( i = 0; i < nd_nbase; i++ ) |
|
d[i] = merge_pairs_s(d[i],d1[i]); |
|
get_eg(&eg3); add_eg(&eg_merge,&eg2,&eg3); |
|
return Nnewpair; |
|
} |
|
|
ND_pairs nd_newpairs( NODE g, int t ) |
ND_pairs nd_newpairs( NODE g, int t ) |
{ |
{ |
NODE h; |
NODE h; |
Line 3677 int comp_sig(SIG s1,SIG s2) |
|
Line 3714 int comp_sig(SIG s1,SIG s2) |
|
} |
} |
_adddl(nd_nvar,s1->dl,nd_sba_hm[s1->pos],m1); |
_adddl(nd_nvar,s1->dl,nd_sba_hm[s1->pos],m1); |
_adddl(nd_nvar,s2->dl,nd_sba_hm[s2->pos],m2); |
_adddl(nd_nvar,s2->dl,nd_sba_hm[s2->pos],m2); |
ret = comp_sig_monomial(nd_nvar,m1,m2); |
if ( !nd_sba_modord ) |
|
ret = (*cmpdl)(nd_nvar,m1,m2); |
|
else |
|
ret = comp_sig_monomial(nd_nvar,m1,m2); |
if ( ret != 0 ) return ret; |
if ( ret != 0 ) return ret; |
else if ( s1->pos > s2->pos ) return 1; |
else if ( s1->pos > s2->pos ) return 1; |
else if ( s1->pos < s2->pos ) return -1; |
else if ( s1->pos < s2->pos ) return -1; |
Line 3765 ND_pairs merge_pairs_s(ND_pairs p1,ND_pairs p2) |
|
Line 3805 ND_pairs merge_pairs_s(ND_pairs p1,ND_pairs p2) |
|
} else if ( ret > 0 ) { |
} else if ( ret > 0 ) { |
r->next = q2; r = q2; q2 = q2->next; |
r->next = q2; r = q2; q2 = q2->next; |
} else { |
} else { |
|
Nnewpair--; |
ret = DL_COMPARE(q1->lcm,q2->lcm); |
ret = DL_COMPARE(q1->lcm,q2->lcm); |
Nsamesig++; |
Nsamesig++; |
if ( ret < 0 ) { |
if ( ret < 0 ) { |
Line 3787 ND_pairs merge_pairs_s(ND_pairs p1,ND_pairs p2) |
|
Line 3828 ND_pairs merge_pairs_s(ND_pairs p1,ND_pairs p2) |
|
ND_pairs insert_pair_s(ND_pairs l,ND_pairs s) |
ND_pairs insert_pair_s(ND_pairs l,ND_pairs s) |
{ |
{ |
ND_pairs p,prev; |
ND_pairs p,prev; |
int ret; |
int ret=1; |
|
|
for ( p = l, prev = 0; p != 0; prev = p, p = p->next ) { |
for ( p = l, prev = 0; p != 0; prev = p, p = p->next ) { |
if ( (ret = comp_sig(s->sig,p->sig)) <= 0 ) |
if ( (ret = comp_sig(s->sig,p->sig)) <= 0 ) |
Line 3808 ND_pairs insert_pair_s(ND_pairs l,ND_pairs s) |
|
Line 3849 ND_pairs insert_pair_s(ND_pairs l,ND_pairs s) |
|
return l; |
return l; |
} else { |
} else { |
// insert s between prev and p |
// insert s between prev and p |
|
Nnewpair++; |
s->next = p; |
s->next = p; |
if ( prev == 0 ) { |
if ( prev == 0 ) { |
return s; |
return s; |
Line 3869 ND_pairs nd_newpairs_s(int t, NODE *syz) |
|
Line 3911 ND_pairs nd_newpairs_s(int t, NODE *syz) |
|
return r0; |
return r0; |
} |
} |
|
|
|
ND_pairs *nd_newpairs_array_s(int t, NODE *syz) |
|
{ |
|
NODE h,s; |
|
UINT *dl; |
|
int ts,ret,i; |
|
ND_pairs r,r0,_sp,sp; |
|
ND_pairs *d; |
|
SIG spsig,tsig; |
|
static int nvar = 0; |
|
static SIG _sig1,_sig2; |
|
struct oEGT eg1,eg2,eg3,eg4; |
|
|
|
NEWND_pairs(_sp); |
|
if ( !_sig1 || nvar != nd_nvar ) { |
|
nvar = nd_nvar; NEWSIG(_sig1); NEWSIG(_sig2); |
|
} |
|
d = (ND_pairs *)MALLOC(nd_nbase*sizeof(ND_pairs)); |
|
Nnewpair = 0; |
|
for ( i = 0; i < t; i++ ) { |
|
ret = _create_spair_s(i,t,_sp,_sig1,_sig2); |
|
if ( ret ) { |
|
spsig = _sp->sig; |
|
for ( s = syz[spsig->pos]; s; s = s->next ) { |
|
tsig = (SIG)s->body; |
|
if ( _dl_redble(DL(tsig),DL(spsig),nd_nvar) ) |
|
break; |
|
} |
|
if ( s == 0 ) { |
|
NEWND_pairs(sp); |
|
dup_ND_pairs(sp,_sp); |
|
d[spsig->pos] = insert_pair_s(d[spsig->pos],sp); |
|
} else |
|
Nsyz++; |
|
} |
|
} |
|
return d; |
|
} |
|
|
/* ipair = [i1,i2],[i1,i2],... */ |
/* ipair = [i1,i2],[i1,i2],... */ |
ND_pairs nd_ipairtospair(NODE ipair) |
ND_pairs nd_ipairtospair(NODE ipair) |
{ |
{ |
Line 6172 void nd_reconstruct_s(int trace,ND_pairs *d) |
|
Line 6252 void nd_reconstruct_s(int trace,ND_pairs *d) |
|
SG(s) = SG(t); |
SG(s) = SG(t); |
ndl_reconstruct(LCM(t),LCM(s),obpe,oepos); |
ndl_reconstruct(LCM(t),LCM(s),obpe,oepos); |
} |
} |
|
if ( s0 ) NEXT(s) = 0; |
d[i] = s0; |
d[i] = s0; |
} |
} |
|
|