version 1.30, 2020/07/03 03:37:59 |
version 1.40, 2020/11/02 08:30:55 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.29 2020/07/02 09:24:17 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2018/engine/nd.c,v 1.39 2020/10/29 01:50:35 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
Line 18 NM _nm_free_list; |
|
Line 18 NM _nm_free_list; |
|
ND _nd_free_list; |
ND _nd_free_list; |
ND_pairs _ndp_free_list; |
ND_pairs _ndp_free_list; |
NODE nd_hcf; |
NODE nd_hcf; |
int Nsyz; |
int Nsyz,Nsamesig; |
|
|
Obj nd_top_weight; |
Obj nd_top_weight; |
|
|
Line 66 static int *nd_poly_weight,*nd_module_weight; |
|
Line 66 static int *nd_poly_weight,*nd_module_weight; |
|
static NODE nd_tracelist; |
static NODE nd_tracelist; |
static NODE nd_alltracelist; |
static NODE nd_alltracelist; |
static int nd_gentrace,nd_gensyz,nd_nora,nd_newelim,nd_intersect,nd_lf; |
static int nd_gentrace,nd_gensyz,nd_nora,nd_newelim,nd_intersect,nd_lf; |
|
static int nd_f4_td,nd_sba_f4step,nd_sba_pot,nd_sba_largelcm,nd_sba_dontsort; |
|
static int nd_top; |
static int *nd_gbblock; |
static int *nd_gbblock; |
static NODE nd_nzlist,nd_check_splist; |
static NODE nd_nzlist,nd_check_splist; |
static int nd_splist; |
static int nd_splist; |
Line 114 NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,U |
|
Line 116 NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,U |
|
NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int trace,UINT *s0vect,int col, |
NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int trace,UINT *s0vect,int col, |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred); |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred); |
int nd_gauss_elim_lf(mpz_t **mat0,int *sugar,int row,int col,int *colstat); |
int nd_gauss_elim_lf(mpz_t **mat0,int *sugar,int row,int col,int *colstat); |
|
int nd_gauss_elim_mod_s(UINT **mat,int *sugar,ND_pairs *spactive,int row,int col,int md,int *colstat,SIG *sig); |
NODE nd_f4_lf_trace_main(int m,int **indp); |
NODE nd_f4_lf_trace_main(int m,int **indp); |
void nd_f4_lf_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp); |
void nd_f4_lf_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp); |
|
|
Line 786 int ndl_module_compare(UINT *d1,UINT *d2) |
|
Line 789 int ndl_module_compare(UINT *d1,UINT *d2) |
|
|
|
extern DMMstack dmm_stack; |
extern DMMstack dmm_stack; |
void _addtodl(int n,DL d1,DL d2); |
void _addtodl(int n,DL d1,DL d2); |
|
void _adddl(int n,DL d1,DL d2,DL d3); |
int _eqdl(int n,DL d1,DL d2); |
int _eqdl(int n,DL d1,DL d2); |
|
|
int ndl_module_schreyer_compare(UINT *m1,UINT *m2) |
int ndl_module_schreyer_compare(UINT *m1,UINT *m2) |
Line 1222 void print_sig(SIG s) |
|
Line 1226 void print_sig(SIG s) |
|
fprintf(asir_out,">>*e%d",s->pos); |
fprintf(asir_out,">>*e%d",s->pos); |
} |
} |
|
|
|
// assuming increasing order wrt signature |
|
|
INLINE int ndl_find_reducer_s(UINT *dg,SIG sig) |
INLINE int ndl_find_reducer_s(UINT *dg,SIG sig) |
{ |
{ |
RHist r; |
RHist r; |
Line 1236 INLINE int ndl_find_reducer_s(UINT *dg,SIG sig) |
|
Line 1242 INLINE int ndl_find_reducer_s(UINT *dg,SIG sig) |
|
tmp = (UINT *)MALLOC(wpd*sizeof(UINT)); |
tmp = (UINT *)MALLOC(wpd*sizeof(UINT)); |
} |
} |
d = ndl_hash_value(dg); |
d = ndl_hash_value(dg); |
|
#if 1 |
for ( r = nd_red[d], k = 0; r; r = NEXT(r), k++ ) { |
for ( r = nd_red[d], k = 0; r; r = NEXT(r), k++ ) { |
if ( ndl_equal(dg,DL(r)) ) { |
if ( ndl_equal(dg,DL(r)) ) { |
return r->index; |
return r->index; |
} |
} |
} |
} |
|
#endif |
singular = 0; |
singular = 0; |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
r = nd_psh[i]; |
r = nd_psh[i]; |
Line 1251 INLINE int ndl_find_reducer_s(UINT *dg,SIG sig) |
|
Line 1259 INLINE int ndl_find_reducer_s(UINT *dg,SIG sig) |
|
quo->pos = nd_psh[i]->sig->pos; |
quo->pos = nd_psh[i]->sig->pos; |
ret = comp_sig(sig,quo); |
ret = comp_sig(sig,quo); |
if ( ret > 0 ) { singular = 0; break; } |
if ( ret > 0 ) { singular = 0; break; } |
if ( ret == 0 ) { fprintf(asir_out,"s"); fflush(asir_out); singular = 1; } |
if ( ret == 0 ) { /* fprintf(asir_out,"s"); fflush(asir_out); */ singular = 1; } |
} |
} |
} |
} |
if ( singular ) return -1; |
if ( singular ) return -1; |
Line 2023 void free_pbucket(PGeoBucket b) { |
|
Line 2031 void free_pbucket(PGeoBucket b) { |
|
GCFREE(b); |
GCFREE(b); |
} |
} |
|
|
|
#if 0 |
void add_pbucket_symbolic(PGeoBucket g,ND d) |
void add_pbucket_symbolic(PGeoBucket g,ND d) |
{ |
{ |
int l,i,k,m; |
int l,i,k,m; |
Line 2040 void add_pbucket_symbolic(PGeoBucket g,ND d) |
|
Line 2049 void add_pbucket_symbolic(PGeoBucket g,ND d) |
|
g->body[k] = d; |
g->body[k] = d; |
g->m = MAX(g->m,k); |
g->m = MAX(g->m,k); |
} |
} |
|
#else |
|
void add_pbucket_symbolic(PGeoBucket g,ND d) |
|
{ |
|
int l,i,k,m,m0; |
|
|
|
if ( !d ) |
|
return; |
|
m0 = g->m; |
|
while ( 1 ) { |
|
l = LEN(d); |
|
for ( k = 0, m = 1; l > m; k++, m <<= 1 ); |
|
/* 2^(k-1) < l <= 2^k (=m) */ |
|
if ( g->body[k] == 0 ) { |
|
g->body[k] = d; |
|
m0 = MAX(k,m0); |
|
break; |
|
} else { |
|
d = nd_merge(g->body[k],d); |
|
g->body[k] = 0; |
|
} |
|
} |
|
g->m = m0; |
|
} |
|
#endif |
|
|
|
#if 0 |
void add_pbucket(int mod,PGeoBucket g,ND d) |
void add_pbucket(int mod,PGeoBucket g,ND d) |
{ |
{ |
int l,i,k,m; |
int l,i,k,m; |
Line 2058 void add_pbucket(int mod,PGeoBucket g,ND d) |
|
Line 2092 void add_pbucket(int mod,PGeoBucket g,ND d) |
|
g->body[k] = d; |
g->body[k] = d; |
g->m = MAX(g->m,k); |
g->m = MAX(g->m,k); |
} |
} |
|
#else |
|
void add_pbucket(int mod,PGeoBucket g,ND d) |
|
{ |
|
int l,i,k,m,m0; |
|
|
|
m0 = g->m; |
|
while ( d != 0 ) { |
|
l = LEN(d); |
|
for ( k = 0, m = 1; l > m; k++, m <<= 1 ); |
|
/* 2^(k-1) < l <= 2^k (=m) */ |
|
if ( g->body[k] == 0 ) { |
|
g->body[k] = d; |
|
m0 = MAX(k,m0); |
|
break; |
|
} else { |
|
d = nd_add(mod,g->body[k],d); |
|
g->body[k] = 0; |
|
} |
|
} |
|
g->m = m0; |
|
} |
|
#endif |
|
|
void mulq_pbucket(PGeoBucket g,Z c) |
void mulq_pbucket(PGeoBucket g,Z c) |
{ |
{ |
int k; |
int k; |
|
|
goto again; |
goto again; |
} |
} |
#if USE_GEOBUCKET |
#if USE_GEOBUCKET |
stat = (m&&!nd_gentrace)?nd_nf_pbucket(m,h,nd_ps,!Top,&nf) |
stat = (m&&!nd_gentrace)?nd_nf_pbucket(m,h,nd_ps,!nd_top&&!Top,&nf) |
:nd_nf(m,0,h,nd_ps,!Top,&nf); |
:nd_nf(m,0,h,nd_ps,!nd_top&&!Top,&nf); |
#else |
#else |
stat = nd_nf(m,0,h,nd_ps,!Top,&nf); |
stat = nd_nf(m,0,h,nd_ps,!nd_top&&!Top,&nf); |
#endif |
#endif |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
Line 2476 get_eg(&eg2); add_eg(&eg_update,&eg1,&eg2); |
|
Line 2532 get_eg(&eg2); add_eg(&eg_update,&eg1,&eg2); |
|
} |
} |
if ( DP_Print ) { printf("."); fflush(stdout); } |
if ( DP_Print ) { printf("."); fflush(stdout); } |
FREENDP(l); |
FREENDP(l); |
} |
} |
} |
} |
conv_ilist(nd_demand,0,g,indp); |
conv_ilist(nd_demand,0,g,indp); |
if ( !checkonly && DP_Print ) { printf("nd_gb done. Number of nd_add=%d\n",Nnd_add); fflush(stdout); } |
if ( !checkonly && DP_Print ) { printf("nd_gb done. Number of nd_add=%d\n",Nnd_add); fflush(stdout); } |
print_eg("update",&eg_update); |
|
return g; |
if ( DP_Print ) |
|
print_eg("update",&eg_update); |
|
return g; |
} |
} |
|
|
ND_pairs update_pairs_s(ND_pairs d,int t,NODE *syz); |
ND_pairs update_pairs_s(ND_pairs d,int t,NODE *syz); |
Line 2554 int small_lcm(ND_pairs l) |
|
Line 2612 int small_lcm(ND_pairs l) |
|
static DL lcm,mul,quo; |
static DL lcm,mul,quo; |
static int nvar; |
static int nvar; |
|
|
|
if ( nd_sba_largelcm ) return 0; |
if ( nvar < nd_nvar ) { |
if ( nvar < nd_nvar ) { |
nvar = nd_nvar; NEWDL(lcm,nvar); NEWDL(quo,nvar); NEWDL(mul,nvar); |
nvar = nd_nvar; NEWDL(lcm,nvar); NEWDL(quo,nvar); NEWDL(mul,nvar); |
} |
} |
Line 2610 NODE conv_ilist_s(int demand,int trace,int **indp); |
|
Line 2669 NODE conv_ilist_s(int demand,int trace,int **indp); |
|
|
|
NODE nd_sba_buch(int m,int ishomo,int **indp) |
NODE nd_sba_buch(int m,int ishomo,int **indp) |
{ |
{ |
int i,j,nh,sugar,stat; |
int i,j,nh,sugar,stat,pos; |
NODE r,t,g; |
NODE r,t,g; |
ND_pairs d; |
ND_pairs d; |
ND_pairs l; |
ND_pairs l; |
Line 2624 NODE nd_sba_buch(int m,int ishomo,int **indp) |
|
Line 2683 NODE nd_sba_buch(int m,int ishomo,int **indp) |
|
NODE *syzlist; |
NODE *syzlist; |
int Nredundant; |
int Nredundant; |
DL lcm,quo,mul; |
DL lcm,quo,mul; |
struct oEGT eg1,eg2,eg_update,eg_remove,eg_large; |
struct oEGT eg1,eg2,eg_update,eg_remove,eg_large,eg_nf,eg_nfzero; |
|
|
init_eg(&eg_remove); |
init_eg(&eg_remove); |
syzlist = (NODE *)MALLOC(nd_psn*sizeof(NODE)); |
syzlist = (NODE *)MALLOC(nd_psn*sizeof(NODE)); |
Line 2642 init_eg(&eg_remove); |
|
Line 2701 init_eg(&eg_remove); |
|
syzlist[sig->pos] = insert_sig(syzlist[sig->pos],sig); |
syzlist[sig->pos] = insert_sig(syzlist[sig->pos],sig); |
} |
} |
sugar = 0; |
sugar = 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_large); |
init_eg(&eg_large); |
|
init_eg(&eg_nf); |
|
init_eg(&eg_nfzero); |
while ( d ) { |
while ( d ) { |
again: |
again: |
if ( DP_Print ) { |
if ( DP_Print ) { |
|
|
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
} |
} |
sig = l->sig; |
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); |
stat = nd_sp(m,0,l,&h); |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(0,d); |
d = nd_reconstruct(0,d); |
goto again; |
goto again; |
} |
} |
|
get_eg(&eg1); |
#if USE_GEOBUCKET |
#if USE_GEOBUCKET |
stat = m?nd_nf_pbucket_s(m,h,nd_ps,!Top,&nf):nd_nf_s(m,0,h,nd_ps,!Top,&nf); |
stat = m?nd_nf_pbucket_s(m,h,nd_ps,!nd_top&&!Top,&nf):nd_nf_s(m,0,h,nd_ps,!nd_top&&!Top,&nf); |
#else |
#else |
stat = nd_nf_s(m,0,h,nd_ps,!Top,&nf); |
stat = nd_nf_s(m,0,h,nd_ps,!nd_top&&!Top,&nf); |
#endif |
#endif |
|
get_eg(&eg2); |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(0,d); |
d = nd_reconstruct(0,d); |
|
|
FREENDP(l); |
FREENDP(l); |
} else if ( nf ) { |
} else if ( nf ) { |
if ( DP_Print ) { printf("+"); fflush(stdout); } |
if ( DP_Print ) { printf("+"); fflush(stdout); } |
|
add_eg(&eg_nf,&eg1,&eg2); |
hc = HCU(nf); |
hc = HCU(nf); |
nd_removecont(m,nf); |
nd_removecont(m,nf); |
nfv = ndtondv(m,nf); nd_free(nf); |
nfv = ndtondv(m,nf); nd_free(nf); |
|
|
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); |
FREENDP(l); |
} else { |
} else { |
|
add_eg(&eg_nfzero,&eg1,&eg2); |
// syzygy |
// syzygy |
get_eg(&eg1); |
get_eg(&eg1); |
d = remove_spair_s(d,sig); |
d = remove_spair_s(d,sig); |
Line 2706 get_eg(&eg2); add_eg(&eg_remove,&eg1,&eg2); |
|
Line 2778 get_eg(&eg2); add_eg(&eg_remove,&eg1,&eg2); |
|
} |
} |
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,Nredundant=%d\n",Nnd_add,Nsyz,Nredundant); |
printf("\nnd_sba done. nd_add=%d,Nsyz=%d,Nsamesig=%d,Nredundant=%d\n",Nnd_add,Nsyz,Nsamesig,Nredundant); |
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("remove",&eg_remove); |
print_eg("remove",&eg_remove); |
|
print_eg("nf",&eg_nf); |
|
print_eg("nfzero",&eg_nfzero); |
printf("\n"); |
printf("\n"); |
} |
} |
return g; |
return g; |
|
|
d = nd_reconstruct(0,d); |
d = nd_reconstruct(0,d); |
goto again; |
goto again; |
} |
} |
stat = nd_nf(m,0,h,nd_ps,!Top,&nf); |
stat = nd_nf(m,0,h,nd_ps,!nd_top&&!Top,&nf); |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(0,d); |
d = nd_reconstruct(0,d); |
|
|
goto again; |
goto again; |
} |
} |
#if USE_GEOBUCKET |
#if USE_GEOBUCKET |
stat = nd_nf_pbucket(m,h,nd_ps,!Top,&nf); |
stat = nd_nf_pbucket(m,h,nd_ps,!nd_top&&!Top,&nf); |
#else |
#else |
stat = nd_nf(m,0,h,nd_ps,!Top,&nf); |
stat = nd_nf(m,0,h,nd_ps,!nd_top&&!Top,&nf); |
#endif |
#endif |
if ( !stat ) { |
if ( !stat ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
|
|
} else |
} else |
nfq = 0; |
nfq = 0; |
if ( !nfq ) { |
if ( !nfq ) { |
if ( !nd_sp(0,1,l,&h) || !nd_nf(0,0,h,nd_ps_trace,!Top,&nfq) ) { |
if ( !nd_sp(0,1,l,&h) || !nd_nf(0,0,h,nd_ps_trace,!nd_top&&!Top,&nfq) ) { |
NEXT(l) = d; d = l; |
NEXT(l) = d; d = l; |
d = nd_reconstruct(1,d); |
d = nd_reconstruct(1,d); |
goto again; |
goto again; |
Line 3188 ND_pairs nd_newpairs( NODE g, int t ) |
|
Line 3262 ND_pairs nd_newpairs( NODE g, int t ) |
|
|
|
int comp_sig(SIG s1,SIG s2) |
int comp_sig(SIG s1,SIG s2) |
{ |
{ |
#if 0 |
if ( nd_sba_pot ) { |
if ( s1->pos > s2->pos ) return 1; |
if ( s1->pos > s2->pos ) return 1; |
else if ( s1->pos < s2->pos ) return -1; |
else if ( s1->pos < s2->pos ) return -1; |
else return (*cmpdl)(nd_nvar,s1->dl,s2->dl); |
else return (*cmpdl)(nd_nvar,s1->dl,s2->dl); |
#else |
} else { |
static DL m1,m2; |
static DL m1,m2; |
static int nvar; |
static int nvar; |
int ret; |
int ret; |
|
|
if ( nvar != nd_nvar ) { |
if ( nvar != nd_nvar ) { |
nvar = nd_nvar; NEWDL(m1,nvar); NEWDL(m2,nvar); |
nvar = nd_nvar; NEWDL(m1,nvar); NEWDL(m2,nvar); |
|
} |
|
_adddl(nd_nvar,s1->dl,nd_sba_hm[s1->pos],m1); |
|
_adddl(nd_nvar,s2->dl,nd_sba_hm[s2->pos],m2); |
|
ret = (*cmpdl)(nd_nvar,m1,m2); |
|
if ( ret != 0 ) return ret; |
|
else if ( s1->pos > s2->pos ) return 1; |
|
else if ( s1->pos < s2->pos ) return -1; |
|
else return 0; |
} |
} |
// _ndltodl(DL(nd_psh[s1->pos]),m1); |
|
// _ndltodl(DL(nd_psh[s2->pos]),m2); |
|
_copydl(nd_nvar,nd_sba_hm[s1->pos],m1); |
|
_copydl(nd_nvar,nd_sba_hm[s2->pos],m2); |
|
_addtodl(nd_nvar,s1->dl,m1); |
|
_addtodl(nd_nvar,s2->dl,m2); |
|
ret = (*cmpdl)(nd_nvar,m1,m2); |
|
if ( ret != 0 ) return ret; |
|
else if ( s1->pos > s2->pos ) return 1; |
|
else if ( s1->pos < s2->pos ) return -1; |
|
else return 0; |
|
#endif |
|
} |
} |
|
|
int _create_spair_s(int i1,int i2,ND_pairs sp,SIG sig1,SIG sig2) |
int _create_spair_s(int i1,int i2,ND_pairs sp,SIG sig1,SIG sig2) |
Line 3295 ND_pairs merge_pairs_s(ND_pairs p1,ND_pairs p2) |
|
Line 3365 ND_pairs merge_pairs_s(ND_pairs p1,ND_pairs p2) |
|
r->next = q2; r = q2; q2 = q2->next; |
r->next = q2; r = q2; q2 = q2->next; |
} else { |
} else { |
ret = DL_COMPARE(q1->lcm,q2->lcm); |
ret = DL_COMPARE(q1->lcm,q2->lcm); |
|
Nsamesig++; |
if ( ret < 0 ) { |
if ( ret < 0 ) { |
r->next = q1; r = q1; q1 = q1->next; |
r->next = q1; r = q1; q1 = q1->next; |
q2 = q2->next; |
q2 = q2->next; |
Line 3679 ND_pairs nd_minsugarp_s( ND_pairs d, ND_pairs *prest ) |
|
Line 3750 ND_pairs nd_minsugarp_s( ND_pairs d, ND_pairs *prest ) |
|
int msugar; |
int msugar; |
ND_pairs t,last; |
ND_pairs t,last; |
|
|
#if 0 |
|
for ( msugar = SG(d), t = d; t; t = NEXT(t) ) |
for ( msugar = SG(d), t = d; t; t = NEXT(t) ) |
if ( SG(t) == msugar ) last = t; |
if ( SG(t) == msugar ) last = t; |
#else |
|
msugar = (d->sig->dl->td)+nd_sba_hm[d->sig->pos]->td; |
|
for ( t = d; t; t = NEXT(t) ) |
|
if ( ((t->sig->dl->td)+nd_sba_hm[t->sig->pos]->td) == msugar ) last = t; |
|
#endif |
|
*prest = last->next; |
*prest = last->next; |
last->next = 0; |
last->next = 0; |
return d; |
return d; |
Line 4260 void nd_sba(LIST f,LIST v,int m,int homo,int retdp,int |
|
Line 4325 void nd_sba(LIST f,LIST v,int m,int homo,int retdp,int |
|
nd_module = 0; |
nd_module = 0; |
nd_demand = 0; |
nd_demand = 0; |
parse_nd_option(current_option); |
parse_nd_option(current_option); |
|
Nsamesig = 0; |
if ( DP_Multiple ) |
if ( DP_Multiple ) |
nd_scale = ((double)DP_Multiple)/(double)(Denominator?Denominator:1); |
nd_scale = ((double)DP_Multiple)/(double)(Denominator?Denominator:1); |
get_vars((Obj)f,&fv); pltovl(v,&vv); vlminus(fv,vv,&nd_vc); |
get_vars((Obj)f,&fv); pltovl(v,&vv); vlminus(fv,vv,&nd_vc); |
Line 4312 void nd_sba(LIST f,LIST v,int m,int homo,int retdp,int |
|
Line 4377 void nd_sba(LIST f,LIST v,int m,int homo,int retdp,int |
|
ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos,ompos); |
ndv_homogenize((NDV)BDY(t),obpe,oadv,oepos,ompos); |
} |
} |
|
|
ndv_setup(m,0,fd0,0,0,1); |
ndv_setup(m,0,fd0,nd_sba_dontsort,0,1); |
x = f4 ? nd_sba_f4(m,&perm) : nd_sba_buch(m,ishomo || homo,&perm); |
x = f4 ? nd_sba_f4(m,&perm) : nd_sba_buch(m,ishomo || homo,&perm); |
if ( !x ) { |
if ( !x ) { |
*rp = 0; return; |
*rp = 0; return; |
Line 4331 void nd_sba(LIST f,LIST v,int m,int homo,int retdp,int |
|
Line 4396 void nd_sba(LIST f,LIST v,int m,int homo,int retdp,int |
|
for ( r0 = 0, t = x; t; t = NEXT(t) ) { |
for ( r0 = 0, t = x; t; t = NEXT(t) ) { |
NEXTNODE(r0,r); |
NEXTNODE(r0,r); |
if ( retdp ) BDY(r) = ndvtodp(m,BDY(t)); |
if ( retdp ) BDY(r) = ndvtodp(m,BDY(t)); |
BDY(r) = ndvtop(m,CO,vv,BDY(t)); |
else BDY(r) = ndvtop(m,CO,vv,BDY(t)); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
MKLIST(*rp,r0); |
MKLIST(*rp,r0); |
Line 4852 DL ndltodl(int n,UINT *ndl) |
|
Line 4917 DL ndltodl(int n,UINT *ndl) |
|
int i,j,l,s,ord_l; |
int i,j,l,s,ord_l; |
struct order_pair *op; |
struct order_pair *op; |
|
|
NEWDL(dl,n); |
NEWDL_NOINIT(dl,n); |
dl->td = TD(ndl); |
dl->td = TD(ndl); |
d = dl->d; |
d = dl->d; |
if ( nd_blockmask ) { |
if ( nd_blockmask ) { |
Line 7394 int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndA |
|
Line 7459 int ndv_reduce_vect_q(Z *svect0,int trace,int col,IndA |
|
} |
} |
#endif |
#endif |
|
|
int ndv_reduce_vect(int m,UINT *svect,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
int ndv_reduce_vect(int m,UINT *svect,int col,IndArray *imat,NM_ind_pair *rp0,int nred,SIG sig) |
{ |
{ |
int i,j,k,len,pos,prev; |
int i,j,k,len,pos,prev; |
UINT c,c1,c2,c3,up,lo,dmy; |
UINT c,c1,c2,c3,up,lo,dmy; |
Line 7411 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
Line 7476 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
for ( i = 0; i < nred; i++ ) { |
for ( i = 0; i < nred; i++ ) { |
ivect = imat[i]; |
ivect = imat[i]; |
k = ivect->head; svect[k] %= m; |
k = ivect->head; svect[k] %= m; |
if ( (c = svect[k]) != 0 ) { |
if ( (c = svect[k]) != 0 && (sig == 0 || comp_sig(sig,rp0[i]->sig) > 0 ) ) { |
maxrs = MAX(maxrs,rp0[i]->sugar); |
maxrs = MAX(maxrs,rp0[i]->sugar); |
c = m-c; redv = nd_ps[rp0[i]->index]; |
c = m-c; redv = nd_ps[rp0[i]->index]; |
len = LEN(redv); mr = BDY(redv); |
len = LEN(redv); mr = BDY(redv); |
Line 7421 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
Line 7486 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
ivc = ivect->index.c; |
ivc = ivect->index.c; |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
pos = prev+ivc[j]; c1 = CM(mr); prev = pos; |
pos = prev+ivc[j]; c1 = CM(mr); prev = pos; |
if ( c1 ) { |
if ( c1 ) { |
c2 = svect[pos]; |
c2 = svect[pos]; |
DMA(c1,c,c2,up,lo); |
DMA(c1,c,c2,up,lo); |
if ( up ) { DSAB(m,up,lo,dmy,c3); svect[pos] = c3; |
if ( up ) { DSAB(m,up,lo,dmy,c3); svect[pos] = c3; |
} else svect[pos] = lo; |
} else svect[pos] = lo; |
} |
} |
} |
} |
break; |
break; |
case 2: |
case 2: |
Line 7434 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
Line 7499 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
pos = prev+ivs[j]; c1 = CM(mr); |
pos = prev+ivs[j]; c1 = CM(mr); |
prev = pos; |
prev = pos; |
if ( c1 ) { |
if ( c1 ) { |
c2 = svect[pos]; |
c2 = svect[pos]; |
DMA(c1,c,c2,up,lo); |
DMA(c1,c,c2,up,lo); |
if ( up ) { DSAB(m,up,lo,dmy,c3); svect[pos] = c3; |
if ( up ) { DSAB(m,up,lo,dmy,c3); svect[pos] = c3; |
} else svect[pos] = lo; |
} else svect[pos] = lo; |
} |
} |
} |
} |
break; |
break; |
case 4: |
case 4: |
Line 7447 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
Line 7512 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
pos = prev+ivi[j]; c1 = CM(mr); |
pos = prev+ivi[j]; c1 = CM(mr); |
prev = pos; |
prev = pos; |
if ( c1 ) { |
if ( c1 ) { |
c2 = svect[pos]; |
c2 = svect[pos]; |
DMA(c1,c,c2,up,lo); |
DMA(c1,c,c2,up,lo); |
if ( up ) { DSAB(m,up,lo,dmy,c3); svect[pos] = c3; |
if ( up ) { DSAB(m,up,lo,dmy,c3); svect[pos] = c3; |
} else svect[pos] = lo; |
} else svect[pos] = lo; |
} |
} |
} |
} |
break; |
break; |
} |
} |
Line 7720 NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea |
|
Line 7785 NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea |
|
} |
} |
} |
} |
|
|
|
NDV vect_to_ndv_s(UINT *vect,int col,UINT *s0vect) |
|
{ |
|
int j,k,len; |
|
UINT *p; |
|
UINT c; |
|
NDV r; |
|
NMV mr0,mr; |
|
|
|
for ( j = 0, len = 0; j < col; j++ ) if ( vect[j] ) len++; |
|
if ( !len ) return 0; |
|
else { |
|
mr0 = (NMV)MALLOC_ATOMIC_IGNORE_OFF_PAGE(nmv_adv*len); |
|
mr = mr0; |
|
p = s0vect; |
|
for ( j = k = 0; j < col; j++, p += nd_wpd ) |
|
if ( (c = vect[k++]) != 0 ) { |
|
ndl_copy(p,DL(mr)); CM(mr) = c; NMV_ADV(mr); |
|
} |
|
MKNDV(nd_nvar,mr0,len,r); |
|
return r; |
|
} |
|
} |
|
|
NDV vect_to_ndv_2(unsigned long *vect,int col,UINT *s0vect) |
NDV vect_to_ndv_2(unsigned long *vect,int col,UINT *s0vect) |
{ |
{ |
int j,k,len; |
int j,k,len; |
Line 7986 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 8074 NODE nd_f4(int m,int checkonly,int **indp) |
|
if ( nflist ) nd_last_nonzero = f4red; |
if ( nflist ) nd_last_nonzero = f4red; |
for ( r = nflist; r; r = NEXT(r) ) { |
for ( r = nflist; r; r = NEXT(r) ) { |
nf = (NDV)BDY(r); |
nf = (NDV)BDY(r); |
|
if ( nd_f4_td ) SG(nf) = nd_tdeg(nf); |
ndv_removecont(m,nf); |
ndv_removecont(m,nf); |
if ( !m && nd_nalg ) { |
if ( !m && nd_nalg ) { |
ND nf1; |
ND nf1; |
Line 8390 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 8479 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
if ( m == -1 ) |
if ( m == -1 ) |
maxrs = ndv_reduce_vect_sf(m,svect,col,imat,rvect,nred); |
maxrs = ndv_reduce_vect_sf(m,svect,col,imat,rvect,nred); |
else |
else |
maxrs = ndv_reduce_vect(m,svect,col,imat,rvect,nred); |
maxrs = ndv_reduce_vect(m,svect,col,imat,rvect,nred,0); |
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
if ( i < col ) { |
if ( i < col ) { |
spmat[sprow] = v = (UINT *)MALLOC_ATOMIC(spcol*sizeof(UINT)); |
spmat[sprow] = v = (UINT *)MALLOC_ATOMIC(spcol*sizeof(UINT)); |
Line 8446 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 8535 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
return r0; |
return r0; |
} |
} |
|
|
|
NODE nd_f4_red_main_s(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
|
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,NODE *syzlistp) |
|
{ |
|
int spcol,sprow,a; |
|
int i,j,k,l,rank; |
|
NODE r0,r; |
|
ND_pairs sp; |
|
ND spol; |
|
UINT **spmat; |
|
UINT *svect,*cvect; |
|
UINT *v; |
|
int *colstat; |
|
struct oEGT eg0,eg1,eg2,eg_f4,eg_f4_1,eg_f4_2; |
|
int maxrs; |
|
int *spsugar; |
|
ND_pairs *spactive; |
|
SIG *spsig; |
|
|
|
get_eg(&eg0); |
|
/* elimination (1st step) */ |
|
spmat = (UINT **)MALLOC(nsp*sizeof(UINT *)); |
|
spsugar = (int *)MALLOC(nsp*sizeof(int)); |
|
spsig = (SIG *)MALLOC(nsp*sizeof(SIG)); |
|
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
|
nd_sp(m,0,sp,&spol); |
|
if ( !spol ) { |
|
syzlistp[sp->sig->pos] = insert_sig(syzlistp[sp->sig->pos],sp->sig); |
|
continue; |
|
} |
|
svect = (UINT *)MALLOC(col*sizeof(UINT)); |
|
nd_to_vect(m,s0vect,col,spol,svect); |
|
maxrs = ndv_reduce_vect(m,svect,col,imat,rvect,nred,spol->sig); |
|
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
|
if ( i < col ) { |
|
spmat[sprow] = svect; |
|
spsugar[sprow] = MAX(maxrs,SG(spol)); |
|
spsig[sprow] = sp->sig; |
|
sprow++; |
|
} else { |
|
syzlistp[sp->sig->pos] = insert_sig(syzlistp[sp->sig->pos],sp->sig); |
|
} |
|
nd_free(spol); |
|
} |
|
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); add_eg(&f4_elim1,&eg0,&eg1); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime); |
|
fflush(asir_out); |
|
} |
|
/* free index arrays */ |
|
for ( i = 0; i < nred; i++ ) GCFREE(imat[i]->index.c); |
|
|
|
/* elimination (2nd step) */ |
|
colstat = (int *)MALLOC(col*sizeof(int)); |
|
rank = nd_gauss_elim_mod_s(spmat,spsugar,0,sprow,col,m,colstat,spsig); |
|
r0 = 0; |
|
for ( i = 0; i < sprow; i++ ) { |
|
if ( spsugar[i] >= 0 ) { |
|
NEXTNODE(r0,r); |
|
BDY(r) = vect_to_ndv_s(spmat[i],col,s0vect); |
|
SG((NDV)BDY(r)) = spsugar[i]; |
|
((NDV)BDY(r))->sig = spsig[i]; |
|
} else |
|
syzlistp[spsig[i]->pos] = insert_sig(syzlistp[spsig[i]->pos],spsig[i]); |
|
GCFREE(spmat[i]); |
|
} |
|
if ( r0 ) NEXT(r) = 0; |
|
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); add_eg(&f4_elim2,&eg1,&eg2); |
|
init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime); |
|
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
|
nsp,nred,sprow,col,rank); |
|
fprintf(asir_out,"%.3fsec,",eg_f4.exectime); |
|
} |
|
return r0; |
|
} |
|
|
|
|
/* for small finite fields */ |
/* for small finite fields */ |
|
|
NODE nd_f4_red_sf_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NODE nd_f4_red_sf_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
Line 8858 int nd_gauss_elim_mod(UINT **mat0,int *sugar,ND_pairs |
|
Line 9024 int nd_gauss_elim_mod(UINT **mat0,int *sugar,ND_pairs |
|
return rank; |
return rank; |
} |
} |
|
|
|
int nd_gauss_elim_mod_s(UINT **mat,int *sugar,ND_pairs *spactive,int row,int col,int md,int *colstat,SIG *sig) |
|
{ |
|
int i,j,k,l,rank,s,imin; |
|
UINT inv; |
|
UINT a; |
|
UINT *t,*pivot,*pk; |
|
UINT *ck; |
|
UINT *ct; |
|
ND_pairs pair; |
|
SIG sg; |
|
int *used; |
|
|
|
used = (int *)MALLOC(row*sizeof(int)); |
|
for ( j = 0; j < col; j++ ) { |
|
for ( i = 0; i < row; i++ ) |
|
a = mat[i][j] %= md; |
|
for ( i = 0; i < row; i++ ) |
|
if ( !used[i] && mat[i][j] ) break; |
|
if ( i == row ) { |
|
colstat[j] = 0; |
|
continue; |
|
} else { |
|
colstat[j] = 1; |
|
used[i] = 1; |
|
} |
|
/* column j is normalized */ |
|
s = sugar[i]; |
|
inv = invm(mat[i][j],md); |
|
/* normalize pivot row */ |
|
for ( k = j, pk = mat[i]+j; k < col; k++, pk++, ck++ ) { |
|
DMAR(*pk,inv,0,md,*pk); |
|
} |
|
for ( k = i+1; k < row; k++ ) { |
|
if ( (a = mat[k][j]) != 0 ) { |
|
sugar[k] = MAX(sugar[k],s); |
|
red_by_vect(md,mat[k]+j,mat[i]+j,(int)(md-a),col-j); |
|
Nf4_red++; |
|
} |
|
} |
|
} |
|
rank = 0; |
|
for ( i = 0; i < row; i++ ) { |
|
for ( j = 0; j < col; j++ ) |
|
if ( mat[i][j] ) break; |
|
if ( j == col ) sugar[i] = -1; |
|
else rank++; |
|
} |
|
return rank; |
|
} |
|
|
|
|
int nd_gauss_elim_sf(UINT **mat0,int *sugar,int row,int col,int md,int *colstat) |
int nd_gauss_elim_sf(UINT **mat0,int *sugar,int row,int col,int md,int *colstat) |
{ |
{ |
int i,j,k,l,inv,a,rank,s; |
int i,j,k,l,inv,a,rank,s; |
Line 9555 NODE conv_ilist_s(int demand,int trace,int **indp) |
|
Line 9771 NODE conv_ilist_s(int demand,int trace,int **indp) |
|
|
|
void parse_nd_option(NODE opt) |
void parse_nd_option(NODE opt) |
{ |
{ |
NODE t,p,u; |
NODE t,p,u; |
int i,s,n; |
int i,s,n; |
char *key; |
char *key; |
Obj value; |
Obj value; |
|
|
nd_gentrace = 0; nd_gensyz = 0; nd_nora = 0; nd_gbblock = 0; |
nd_gentrace = 0; nd_gensyz = 0; nd_nora = 0; nd_gbblock = 0; |
nd_newelim = 0; nd_intersect = 0; nd_nzlist = 0; |
nd_newelim = 0; nd_intersect = 0; nd_nzlist = 0; |
nd_splist = 0; nd_check_splist = 0; |
nd_splist = 0; nd_check_splist = 0; |
nd_sugarweight = 0; |
nd_sugarweight = 0; nd_f4red =0; nd_rank0 = 0; |
nd_f4red =0; |
nd_f4_td = 0; nd_sba_f4step = 2; nd_sba_pot = 0; nd_sba_largelcm = 0; |
nd_rank0 = 0; |
nd_sba_dontsort = 0; nd_top = 0; |
for ( t = opt; t; t = NEXT(t) ) { |
|
p = BDY((LIST)BDY(t)); |
for ( t = opt; t; t = NEXT(t) ) { |
key = BDY((STRING)BDY(p)); |
p = BDY((LIST)BDY(t)); |
value = (Obj)BDY(NEXT(p)); |
key = BDY((STRING)BDY(p)); |
if ( !strcmp(key,"gentrace") ) |
value = (Obj)BDY(NEXT(p)); |
nd_gentrace = value?1:0; |
if ( !strcmp(key,"gentrace") ) |
else if ( !strcmp(key,"gensyz") ) |
nd_gentrace = value?1:0; |
nd_gensyz = value?1:0; |
else if ( !strcmp(key,"gensyz") ) |
else if ( !strcmp(key,"nora") ) |
nd_gensyz = value?1:0; |
nd_nora = value?1:0; |
else if ( !strcmp(key,"nora") ) |
else if ( !strcmp(key,"gbblock") ) { |
nd_nora = value?1:0; |
if ( value && OID(value) == O_LIST ) { |
else if ( !strcmp(key,"gbblock") ) { |
|
if ( value && OID(value) == O_LIST ) { |
u = BDY((LIST)value); |
u = BDY((LIST)value); |
nd_gbblock = MALLOC((2*length(u)+1)*sizeof(int)); |
nd_gbblock = MALLOC((2*length(u)+1)*sizeof(int)); |
for ( i = 0; u; u = NEXT(u) ) { |
for ( i = 0; u; u = NEXT(u) ) { |
p = BDY((LIST)BDY(u)); |
p = BDY((LIST)BDY(u)); |
s = nd_gbblock[i++] = ZTOS((Q)BDY(p)); |
s = nd_gbblock[i++] = ZTOS((Q)BDY(p)); |
nd_gbblock[i++] = s+ZTOS((Q)BDY(NEXT(p)))-1; |
nd_gbblock[i++] = s+ZTOS((Q)BDY(NEXT(p)))-1; |
} |
} |
nd_gbblock[i] = -1; |
nd_gbblock[i] = -1; |
} else |
} else |
nd_gbblock = 0; |
nd_gbblock = 0; |
} else if ( !strcmp(key,"newelim") ) |
} else if ( !strcmp(key,"newelim") ) |
nd_newelim = value?1:0; |
nd_newelim = value?1:0; |
else if ( !strcmp(key,"intersect") ) |
else if ( !strcmp(key,"intersect") ) |
Line 9597 void parse_nd_option(NODE opt) |
|
Line 9814 void parse_nd_option(NODE opt) |
|
else if ( !strcmp(key,"lf") ) |
else if ( !strcmp(key,"lf") ) |
nd_lf = value?1:0; |
nd_lf = value?1:0; |
else if ( !strcmp(key,"trace") ) { |
else if ( !strcmp(key,"trace") ) { |
if ( value ) { |
if ( value ) { |
u = BDY((LIST)value); |
u = BDY((LIST)value); |
nd_nzlist = BDY((LIST)ARG2(u)); |
nd_nzlist = BDY((LIST)ARG2(u)); |
nd_bpe = ZTOS((Q)ARG3(u)); |
nd_bpe = ZTOS((Q)ARG3(u)); |
} |
} |
} else if ( !strcmp(key,"f4red") ) { |
} else if ( !strcmp(key,"f4red") ) { |
nd_f4red = ZTOS((Q)value); |
nd_f4red = ZTOS((Q)value); |
} else if ( !strcmp(key,"rank0") ) { |
} else if ( !strcmp(key,"rank0") ) { |
nd_rank0 = value?1:0; |
nd_rank0 = value?1:0; |
} else if ( !strcmp(key,"splist") ) { |
} else if ( !strcmp(key,"splist") ) { |
nd_splist = value?1:0; |
nd_splist = value?1:0; |
} else if ( !strcmp(key,"check_splist") ) { |
} else if ( !strcmp(key,"check_splist") ) { |
nd_check_splist = BDY((LIST)value); |
nd_check_splist = BDY((LIST)value); |
} else if ( !strcmp(key,"sugarweight") ) { |
} else if ( !strcmp(key,"sugarweight") ) { |
u = BDY((LIST)value); |
u = BDY((LIST)value); |
n = length(u); |
n = length(u); |
nd_sugarweight = MALLOC(n*sizeof(int)); |
nd_sugarweight = MALLOC(n*sizeof(int)); |
for ( i = 0; i < n; i++, u = NEXT(u) ) |
for ( i = 0; i < n; i++, u = NEXT(u) ) |
nd_sugarweight[i] = ZTOS((Q)BDY(u)); |
nd_sugarweight[i] = ZTOS((Q)BDY(u)); |
|
} else if ( !strcmp(key,"f4_td") ) { |
|
nd_f4_td = value?1:0; |
|
} else if ( !strcmp(key,"sba_f4step") ) { |
|
nd_sba_f4step = value?ZTOS((Q)value):0; |
|
} else if ( !strcmp(key,"sba_pot") ) { |
|
nd_sba_pot = value?1:0; |
|
} else if ( !strcmp(key,"sba_largelcm") ) { |
|
nd_sba_largelcm = value?1:0; |
|
} else if ( !strcmp(key,"sba_dontsort") ) { |
|
nd_sba_dontsort = value?1:0; |
|
} else if ( !strcmp(key,"top") ) { |
|
nd_top = value?1:0; |
} |
} |
} |
} |
} |
} |
|
|
ND mdptond(DP d); |
ND mdptond(DP d); |
Line 10582 int nd_gauss_elim_mod64(mp_limb_t **mat,int *sugar,ND_ |
|
Line 10811 int nd_gauss_elim_mod64(mp_limb_t **mat,int *sugar,ND_ |
|
GCFREE(cmat); |
GCFREE(cmat); |
return rank; |
return rank; |
} |
} |
#endif |
|
|
|
int nd_gauss_elim_mod64_s(mp_limb_t **mat,int *sugar,ND_pairs *spactive,int row,int col,int md,int *colstat,SIG *sig) |
int nd_gauss_elim_mod64_s(mp_limb_t **mat,int *sugar,ND_pairs *spactive,int row,int col,int md,int *colstat,SIG *sig) |
{ |
{ |
Line 10596 int nd_gauss_elim_mod64_s(mp_limb_t **mat,int *sugar,N |
|
Line 10824 int nd_gauss_elim_mod64_s(mp_limb_t **mat,int *sugar,N |
|
UINT *ct; |
UINT *ct; |
ND_pairs pair; |
ND_pairs pair; |
SIG sg; |
SIG sg; |
|
int *used; |
|
|
|
used = (int *)MALLOC(row*sizeof(int)); |
cmat = (UINT **)MALLOC(row*sizeof(UINT *)); |
cmat = (UINT **)MALLOC(row*sizeof(UINT *)); |
for ( i = 0; i < row; i++ ) { |
for ( i = 0; i < row; i++ ) { |
cmat[i] = MALLOC_ATOMIC(col*sizeof(UINT)); |
cmat[i] = MALLOC_ATOMIC(col*sizeof(UINT)); |
bzero(cmat[i],col*sizeof(UINT)); |
bzero(cmat[i],col*sizeof(UINT)); |
} |
} |
|
|
for ( rank = 0, j = 0; j < col; j++ ) { |
for ( j = 0; j < col; j++ ) { |
for ( i = rank; i < row; i++ ) { |
for ( i = 0; i < row; i++ ) { |
a = mat[i][j]; c = cmat[i][j]; |
a = mat[i][j]; c = cmat[i][j]; |
MOD128(a,c,md); |
MOD128(a,c,md); |
mat[i][j] = a; cmat[i][j] = 0; |
mat[i][j] = a; cmat[i][j] = 0; |
} |
} |
imin = -1; |
for ( i = 0; i < row; i++ ) |
for ( i = rank; i < row; i++ ) |
if ( !used[i] && mat[i][j] ) break; |
if ( mat[i][j] && (imin < 0 || comp_sig(sig[imin],sig[i]) > 0) ) imin = i; |
if ( i == row ) { |
if ( imin == -1 ) { |
|
colstat[j] = 0; |
colstat[j] = 0; |
continue; |
continue; |
} else |
} else { |
colstat[j] = 1; |
colstat[j] = 1; |
if ( imin != rank ) { |
used[i] = 1; |
t = mat[imin]; mat[imin] = mat[rank]; mat[rank] = t; |
|
ct = cmat[imin]; cmat[imin] = cmat[rank]; cmat[rank] = ct; |
|
s = sugar[imin]; sugar[imin] = sugar[rank]; sugar[rank] = s; |
|
sg = sig[imin]; sig[imin] = sig[rank]; sig[rank] = sg; |
|
if ( spactive ) { |
|
pair = spactive[imin]; spactive[imin] = spactive[rank]; |
|
spactive[rank] = pair; |
|
} |
|
} |
} |
/* column j is normalized */ |
/* column j is normalized */ |
s = sugar[rank]; |
s = sugar[i]; |
inv = invm((UINT)mat[rank][j],md); |
inv = invm((UINT)mat[i][j],md); |
/* normalize pivot row */ |
/* normalize pivot row */ |
for ( k = j, pk = mat[rank]+j, ck = cmat[rank]+j; k < col; k++, pk++, ck++ ) { |
for ( k = j, pk = mat[i]+j, ck = cmat[i]+j; k < col; k++, pk++, ck++ ) { |
a = *pk; c = *ck; MOD128(a,c,md); *pk = (a*inv)%md; *ck = 0; |
a = *pk; c = *ck; MOD128(a,c,md); *pk = (a*inv)%md; *ck = 0; |
} |
} |
for ( i = rank+1; i < row; i++ ) { |
for ( k = i+1; k < row; k++ ) { |
if ( (a = mat[i][j]) != 0 ) { |
if ( (a = mat[k][j]) != 0 ) { |
sugar[i] = MAX(sugar[i],s); |
sugar[k] = MAX(sugar[k],s); |
red_by_vect64(md,mat[i]+j,cmat[i]+j,mat[rank]+j,(int)(md-a),col-j); |
red_by_vect64(md,mat[k]+j,cmat[k]+j,mat[i]+j,(int)(md-a),col-j); |
Nf4_red++; |
Nf4_red++; |
} |
} |
} |
} |
rank++; |
|
} |
} |
#if 1 |
rank = 0; |
for ( j = col-1, l = rank-1; j >= 0; j-- ) |
for ( i = 0; i < row; i++ ) { |
if ( colstat[j] ) { |
for ( j = 0; j < col; j++ ) |
for ( k = j, pk = mat[l]+j, ck = cmat[l]+j; k < col; k++, pk++, ck++ ) { |
if ( mat[i][j] ) break; |
a = *pk; c = *ck; MOD128(a,c,md); *pk = a; *ck = 0; |
if ( j == col ) sugar[i] = -1; |
} |
else rank++; |
s = sugar[l]; |
} |
for ( i = 0; i < l; i++ ) { |
|
a = mat[i][j]; c = cmat[i][j]; MOD128(a,c,md); mat[i][j] = a; cmat[i][j] = 0; |
|
if ( a && comp_sig(sig[i],sig[l]) > 0 ) { |
|
sugar[i] = MAX(sugar[i],s); |
|
red_by_vect64(md,mat[i]+j,cmat[i]+j,mat[l]+j,(int)(md-a),col-j); |
|
Nf4_red++; |
|
} |
|
} |
|
l--; |
|
} |
|
#endif |
|
for ( i = 0; i < row; i++ ) GCFREE(cmat[i]); |
for ( i = 0; i < row; i++ ) GCFREE(cmat[i]); |
GCFREE(cmat); |
GCFREE(cmat); |
return rank; |
return rank; |
Line 10722 NODE nd_f4_red_mod64_main_s(int m,ND_pairs sp0,int nsp |
|
Line 10931 NODE nd_f4_red_mod64_main_s(int m,ND_pairs sp0,int nsp |
|
colstat = (int *)MALLOC(col*sizeof(int)); |
colstat = (int *)MALLOC(col*sizeof(int)); |
rank = nd_gauss_elim_mod64_s(spmat,spsugar,0,sprow,col,m,colstat,spsig); |
rank = nd_gauss_elim_mod64_s(spmat,spsugar,0,sprow,col,m,colstat,spsig); |
r0 = 0; |
r0 = 0; |
for ( i = 0; i < rank; i++ ) { |
for ( i = 0; i < sprow; i++ ) { |
NEXTNODE(r0,r); |
if ( spsugar[i] >= 0 ) { |
BDY(r) = vect64_to_ndv_s(spmat[i],col,s0vect); |
NEXTNODE(r0,r); |
SG((NDV)BDY(r)) = spsugar[i]; |
BDY(r) = vect64_to_ndv_s(spmat[i],col,s0vect); |
((NDV)BDY(r))->sig = spsig[i]; |
SG((NDV)BDY(r)) = spsugar[i]; |
|
((NDV)BDY(r))->sig = spsig[i]; |
|
} else |
|
syzlistp[spsig[i]->pos] = insert_sig(syzlistp[spsig[i]->pos],spsig[i]); |
GCFREE(spmat[i]); |
GCFREE(spmat[i]); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
|
|
for ( ; i < sprow; i++ ) { |
|
GCFREE(spmat[i]); |
|
syzlistp[spsig[i]->pos] = insert_sig(syzlistp[spsig[i]->pos],spsig[i]); |
|
} |
|
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); add_eg(&f4_elim2,&eg1,&eg2); |
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); add_eg(&f4_elim2,&eg1,&eg2); |
init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); |
init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); |
if ( DP_Print ) { |
if ( DP_Print ) { |
Line 10745 NODE nd_f4_red_mod64_main_s(int m,ND_pairs sp0,int nsp |
|
Line 10952 NODE nd_f4_red_mod64_main_s(int m,ND_pairs sp0,int nsp |
|
} |
} |
return r0; |
return r0; |
} |
} |
|
#endif |
|
|
NODE nd_f4_red_s(int m,ND_pairs sp0,int trace,UINT *s0vect,int col,NODE rp0,NODE *syzlistp) |
NODE nd_f4_red_s(int m,ND_pairs sp0,int trace,UINT *s0vect,int col,NODE rp0,NODE *syzlistp) |
{ |
{ |
Line 10783 NODE nd_f4_red_s(int m,ND_pairs sp0,int trace,UINT *s0 |
|
Line 10991 NODE nd_f4_red_s(int m,ND_pairs sp0,int trace,UINT *s0 |
|
fflush(asir_out); |
fflush(asir_out); |
} |
} |
if ( m > 0 ) |
if ( m > 0 ) |
|
#if SIZEOF_LONG==8 |
r0 = nd_f4_red_mod64_main_s(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,syzlistp); |
r0 = nd_f4_red_mod64_main_s(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,syzlistp); |
|
#else |
|
r0 = nd_f4_red_main_s(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,syzlistp); |
|
#endif |
else |
else |
// r0 = nd_f4_red_q_main_s(sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
// r0 = nd_f4_red_q_main_s(sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
error("nd_f4_red_q_main_s : not implemented yet"); |
error("nd_f4_red_q_main_s : not implemented yet"); |
Line 10890 int nd_symbolic_preproc_s(PGeoBucket bucket,int trace, |
|
Line 11102 int nd_symbolic_preproc_s(PGeoBucket bucket,int trace, |
|
|
|
NODE nd_sba_f4(int m,int **indp) |
NODE nd_sba_f4(int m,int **indp) |
{ |
{ |
int i,nh,stat,index,f4red; |
int i,nh,stat,index,f4red,f4step; |
NODE r,g,tn0,tn,node; |
int col,rank,len,k,j,a,sugar,nbase,psugar,ms; |
ND_pairs d,l,t,ll0,ll,lh; |
NODE r,g,rp0,nflist; |
LIST l0,l1; |
ND_pairs d,l,t; |
ND spol,red; |
ND h,nf; |
NDV nf,redv; |
NDV nfv; |
NM s0,s; |
union oNDC hc; |
NODE rp0,srp0,nflist; |
UINT *s0vect; |
int nsp,nred,col,rank,len,k,j,a,i1s,i2s; |
|
UINT c; |
UINT c; |
UINT **spmat; |
|
UINT *s0vect,*svect,*p,*v; |
|
int *colstat; |
|
IndArray *imat; |
|
int *rhead; |
|
int spcol,sprow; |
|
int sugar,sugarh; |
|
int nbase; |
|
PGeoBucket bucket; |
PGeoBucket bucket; |
struct oEGT eg0,eg1,eg_f4; |
|
Z i1,i2,sugarq; |
|
NODE *syzlist; |
NODE *syzlist; |
|
SIG sig; |
|
struct oEGT eg0,eg1,eg_f4; |
|
struct oEGT eg2,eg_update,eg_remove,eg_large,eg_nf,eg_nfzero; |
|
|
Nf4_red=0; |
Nf4_red=0; |
d = 0; |
d = 0; |
Line 10921 NODE nd_sba_f4(int m,int **indp) |
|
Line 11125 NODE nd_sba_f4(int m,int **indp) |
|
} |
} |
nd_nbase = nd_psn; |
nd_nbase = nd_psn; |
f4red = 1; |
f4red = 1; |
|
psugar = 0; |
|
f4step = 0; |
while ( d ) { |
while ( d ) { |
l = nd_minsugarp_s(d,&d); |
for ( t = d, ms = SG(d); t; t = NEXT(t) ) |
if ( !l ) continue; |
if ( SG(t) < ms ) ms = SG(t); |
sugar = nd_sugarweight?l->sugar2:SG(l); |
if ( ms == psugar && f4step >= nd_sba_f4step ) { |
if ( MaxDeg > 0 && sugar > MaxDeg ) break; |
again: |
bucket = create_pbucket(); |
l = d; d = d->next; |
stat = nd_sp_f4(m,0,l,bucket); |
if ( small_lcm(l) ) { |
if ( !stat ) { |
if ( DP_Print ) fprintf(asir_out,"M"); |
for ( t = l; NEXT(t); t = NEXT(t) ); |
continue; |
NEXT(t) = d; d = l; |
} |
d = nd_reconstruct(0,d); |
sig = l->sig; |
continue; |
stat = nd_sp(m,0,l,&h); |
} |
if ( !stat ) { |
if ( bucket->m < 0 ) continue; |
NEXT(l) = d; d = l; |
col = nd_symbolic_preproc_s(bucket,0,&s0vect,&rp0); |
d = nd_reconstruct(0,d); |
if ( !col ) { |
goto again; |
for ( t = l; NEXT(t); t = NEXT(t) ); |
} |
NEXT(t) = d; d = l; |
get_eg(&eg1); |
d = nd_reconstruct(0,d); |
#if USE_GEOBUCKET |
continue; |
stat = m?nd_nf_pbucket_s(m,h,nd_ps,!nd_top&&!Top,&nf):nd_nf_s(m,0,h,nd_ps,!nd_top&&!Top,&nf); |
} |
#else |
if ( DP_Print ) fprintf(asir_out,"sugar=%d,",sugar); |
stat = nd_nf_s(m,0,h,nd_ps,!nd_top&&!Top,&nf); |
l = remove_large_lcm(l); |
#endif |
nflist = nd_f4_red_s(m,l,0,s0vect,col,rp0,syzlist); |
get_eg(&eg2); |
/* adding new bases */ |
if ( !stat ) { |
for ( r = nflist; r; r = NEXT(r) ) { |
NEXT(l) = d; d = l; |
ND tmp,tmpred; |
d = nd_reconstruct(0,d); |
SIG sig; |
goto again; |
|
} else if ( stat == -1 ) { |
nf = (NDV)BDY(r); |
if ( DP_Print ) { printf("S"); fflush(stdout); } |
sig = nf->sig; |
FREENDP(l); |
tmp = ndvtond(m,nf); |
} else if ( nf ) { |
stat = nd_nf_s(m,0,tmp,nd_ps,!Top,&tmpred); |
if ( DP_Print ) { printf("+"); fflush(stdout); } |
if ( stat < 0 ) { |
add_eg(&eg_nf,&eg1,&eg2); |
// top reducible |
hc = HCU(nf); |
if ( DP_Print ) { fprintf(asir_out,"S"); fflush(asir_out); } |
nd_removecont(m,nf); |
} else if ( tmpred ) { |
nfv = ndtondv(m,nf); nd_free(nf); |
nf = ndtondv(m,tmpred); |
nh = ndv_newps(m,nfv,0); |
ndv_removecont(m,nf); |
|
nh = ndv_newps(m,nf,0); |
|
d = update_pairs_s(d,nh,syzlist); |
d = update_pairs_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 { |
|
add_eg(&eg_nfzero,&eg1,&eg2); |
|
// syzygy |
|
get_eg(&eg1); |
|
d = remove_spair_s(d,sig); |
|
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); } |
|
FREENDP(l); |
|
} |
|
} else { |
|
if ( ms != psugar ) f4step = 1; |
|
else f4step++; |
|
again2: |
|
psugar = ms; |
|
l = nd_minsugarp_s(d,&d); |
|
sugar = nd_sugarweight?d->sugar2:SG(d); |
|
bucket = create_pbucket(); |
|
stat = nd_sp_f4(m,0,l,bucket); |
|
if ( !stat ) { |
|
for ( t = l; NEXT(t); t = NEXT(t) ); |
|
NEXT(t) = d; d = l; |
|
d = nd_reconstruct(0,d); |
|
goto again2; |
|
} |
|
if ( bucket->m < 0 ) continue; |
|
col = nd_symbolic_preproc_s(bucket,0,&s0vect,&rp0); |
|
if ( !col ) { |
|
for ( t = l; NEXT(t); t = NEXT(t) ) |
|
; |
|
NEXT(t) = d; d = l; |
|
d = nd_reconstruct(0,d); |
|
goto again2; |
|
} |
|
if ( DP_Print ) fprintf(asir_out,"\nsugar=%d,",psugar); |
|
nflist = nd_f4_red_s(m,l,0,s0vect,col,rp0,syzlist); |
|
/* adding new bases */ |
|
for ( r = nflist; r; r = NEXT(r) ) { |
|
nfv = (NDV)BDY(r); |
|
if ( nd_f4_td ) SG(nfv) = nd_tdeg(nfv); |
|
ndv_removecont(m,nfv); |
|
nh = ndv_newps(m,nfv,0); |
|
d = update_pairs_s(d,nh,syzlist); |
|
nd_sba_pos[nfv->sig->pos] = append_one(nd_sba_pos[nfv->sig->pos],nh); |
|
} |
|
for ( i = 0; i < nd_nbase; i++ ) |
|
for ( r = syzlist[i]; r; r = NEXT(r) ) |
|
d = remove_spair_s(d,(SIG)BDY(r)); |
|
d = remove_large_lcm(d); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"f4red=%d,gblen=%d",f4red,nd_psn); fflush(asir_out); |
|
} |
|
f4red++; |
} |
} |
for ( i = 0; i < nd_nbase; i++ ) |
|
for ( r = syzlist[i]; r; r = NEXT(r) ) |
|
d = remove_spair_s(d,(SIG)BDY(r)); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"f4red=%d,gblen=%d\n",f4red,length(g)); fflush(asir_out); |
|
} |
|
f4red++; |
|
if ( nd_f4red && f4red > nd_f4red ) break; |
|
if ( nd_rank0 && !nflist ) break; |
|
} |
} |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"number of red=%d,",Nf4_red); |
fprintf(asir_out,"\nnumber of red=%d,",Nf4_red); |
} |
} |
g = conv_ilist_s(nd_demand,0,indp); |
g = conv_ilist_s(nd_demand,0,indp); |
return g; |
return g; |