version 1.236, 2017/03/27 09:05:46 |
version 1.242, 2017/09/17 02:34:02 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.235 2017/02/28 07:06:28 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.241 2017/09/16 08:02:35 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
Line 65 static int *nd_gbblock; |
|
Line 65 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; |
static int *nd_sugarweight; |
static int *nd_sugarweight; |
static int nd_f4red,nd_rank0; |
static int nd_f4red,nd_rank0,nd_last_nonzero; |
|
|
NumberField get_numberfield(); |
NumberField get_numberfield(); |
UINT *nd_det_compute_bound(NDV **dm,int n,int j); |
UINT *nd_det_compute_bound(NDV **dm,int n,int j); |
Line 98 void Pox_cmo_rpc(NODE,Obj *); |
|
Line 98 void Pox_cmo_rpc(NODE,Obj *); |
|
ND nd_add_lf(ND p1,ND p2); |
ND nd_add_lf(ND p1,ND p2); |
void nd_mul_c_lf(ND p,GZ mul); |
void nd_mul_c_lf(ND p,GZ mul); |
void ndv_mul_c_lf(NDV p,GZ mul); |
void ndv_mul_c_lf(NDV p,GZ mul); |
|
NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
|
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz); |
|
NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
|
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz); |
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); |
Line 2909 ND_pairs nd_minsugarp( ND_pairs d, ND_pairs *prest ) |
|
Line 2913 ND_pairs nd_minsugarp( ND_pairs d, ND_pairs *prest ) |
|
return dm0; |
return dm0; |
} |
} |
|
|
|
int nd_tdeg(NDV c) |
|
{ |
|
int wmax = 0; |
|
int i,len; |
|
NMV a; |
|
|
|
len = LEN(c); |
|
for ( a = BDY(c), i = 0; i < len; i++, NMV_ADV(a) ) |
|
wmax = MAX(TD(DL(a)),wmax); |
|
return wmax; |
|
} |
|
|
int ndv_newps(int m,NDV a,NDV aq,int f4) |
int ndv_newps(int m,NDV a,NDV aq,int f4) |
{ |
{ |
int len; |
int len; |
Line 2941 int ndv_newps(int m,NDV a,NDV aq,int f4) |
|
Line 2957 int ndv_newps(int m,NDV a,NDV aq,int f4) |
|
} else |
} else |
error("ndv_newps : invalud modulus"); |
error("ndv_newps : invalud modulus"); |
nd_bound[nd_psn] = ndv_compute_bound(aq); |
nd_bound[nd_psn] = ndv_compute_bound(aq); |
SG(r) = SG(aq); ndl_copy(HDL(aq),DL(r)); |
#if 1 |
|
SG(r) = SG(aq); |
|
#else |
|
SG(r) = nd_tdeg(aq); |
|
#endif |
|
ndl_copy(HDL(aq),DL(r)); |
} else { |
} else { |
if ( !m ) register_hcf(a); |
if ( !m ) register_hcf(a); |
nd_bound[nd_psn] = ndv_compute_bound(a); |
nd_bound[nd_psn] = ndv_compute_bound(a); |
SG(r) = SG(a); ndl_copy(HDL(a),DL(r)); |
#if 1 |
|
SG(r) = SG(a); |
|
#else |
|
SG(r) = nd_tdeg(a); |
|
#endif |
|
ndl_copy(HDL(a),DL(r)); |
if ( !m && !nd_vc ) nd_ps_gz[nd_psn] = ndvtondvgz(a); |
if ( !m && !nd_vc ) nd_ps_gz[nd_psn] = ndvtondvgz(a); |
} |
} |
if ( nd_demand ) { |
if ( nd_demand ) { |
Line 3120 void preprocess_algcoef(VL vv,VL av,struct order_spec |
|
Line 3146 void preprocess_algcoef(VL vv,VL av,struct order_spec |
|
if ( NID(hc) == N_DA ) { |
if ( NID(hc) == N_DA ) { |
invdalg(hc,&inv); |
invdalg(hc,&inv); |
for ( m = BDY(d); m; m = NEXT(m) ) { |
for ( m = BDY(d); m; m = NEXT(m) ) { |
muldalg(inv,(DAlg)m->c,&da); m->c = (P)da; |
muldalg(inv,(DAlg)m->c,&da); m->c = (Obj)da; |
} |
} |
} |
} |
initd(ord); dtop(vv,vv,d,&poly); BDY(f) = (pointer)poly; |
initd(ord); dtop(vv,vv,d,(Obj *)&poly); BDY(f) = (pointer)poly; |
} |
} |
obj_dalgtoalg((Obj)f1,(Obj *)&f); |
obj_dalgtoalg((Obj)f1,(Obj *)&f); |
|
|
Line 3202 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
Line 3228 void nd_gr(LIST f,LIST v,int m,int homo,int retdp,int |
|
NODE tr,tl1,tl2,tl3,tl4,nzlist; |
NODE tr,tl1,tl2,tl3,tl4,nzlist; |
LIST l1,l2,l3,l4,l5; |
LIST l1,l2,l3,l4,l5; |
int j; |
int j; |
Q jq,bpe; |
Q jq,bpe,last_nonzero; |
int *perm; |
int *perm; |
EPOS oepos; |
EPOS oepos; |
int obpe,oadv,ompos,cbpe; |
int obpe,oadv,ompos,cbpe; |
|
|
if ( nd_gentrace ) { |
if ( nd_gentrace ) { |
if ( f4 ) { |
if ( f4 ) { |
STOQ(16,bpe); |
STOQ(16,bpe); |
tr = mknode(4,*rp,(!ishomo&&homo)?ONE:0,BDY(nzlist),bpe); MKLIST(*rp,tr); |
STOQ(nd_last_nonzero,last_nonzero); |
|
tr = mknode(5,*rp,(!ishomo&&homo)?ONE:0,BDY(nzlist),bpe,last_nonzero); MKLIST(*rp,tr); |
|
|
} else { |
} else { |
tl1 = reverse_node(tl1); tl2 = reverse_node(tl2); |
tl1 = reverse_node(tl1); tl2 = reverse_node(tl2); |
tl3 = reverse_node(tl3); |
tl3 = reverse_node(tl3); |
Line 3814 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
Line 3842 void nd_gr_trace(LIST f,LIST v,int trace,int homo,int |
|
} |
} |
get_eg(&eg1); init_eg(&eg_check); add_eg(&eg_check,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_check); add_eg(&eg_check,&eg0,&eg1); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"check=%fsec\n",eg_check.exectime+eg_check.gctime); |
fprintf(asir_out,"check=%.3fsec,",eg_check.exectime+eg_check.gctime); |
/* dp->p */ |
/* dp->p */ |
nd_bpe = cbpe; |
nd_bpe = cbpe; |
nd_setup_parameters(nd_nvar,0); |
nd_setup_parameters(nd_nvar,0); |
Line 3903 void nmtodp(int mod,NM m,DP *r) |
|
Line 3931 void nmtodp(int mod,NM m,DP *r) |
|
|
|
NEWMP(mr); |
NEWMP(mr); |
mr->dl = ndltodl(nd_nvar,DL(m)); |
mr->dl = ndltodl(nd_nvar,DL(m)); |
mr->c = ndctop(mod,m->c); |
mr->c = (Obj)ndctop(mod,m->c); |
NEXT(mr) = 0; MKDP(nd_nvar,mr,dp); dp->sugar = mr->dl->td; |
NEXT(mr) = 0; MKDP(nd_nvar,mr,dp); dp->sugar = mr->dl->td; |
*r = dp; |
*r = dp; |
} |
} |
Line 5317 P ndvtop(int mod,VL vl,VL dvl,NDV p) |
|
Line 5345 P ndvtop(int mod,VL vl,VL dvl,NDV p) |
|
if ( mod == -1 ) { |
if ( mod == -1 ) { |
e = IFTOF(CM(m)); MKGFS(e,gfs); c = (P)gfs; |
e = IFTOF(CM(m)); MKGFS(e,gfs); c = (P)gfs; |
} else if ( mod == -2 ) { |
} else if ( mod == -2 ) { |
c = gztoz(CZ(m)); |
c = (P)gztoz(CZ(m)); |
} else if ( mod > 0 ) { |
} else if ( mod > 0 ) { |
STOQ(CM(m),q); c = (P)q; |
STOQ(CM(m),q); c = (P)q; |
} else |
} else |
Line 5436 DP ndvtodp(int mod,NDV p) |
|
Line 5464 DP ndvtodp(int mod,NDV p) |
|
for ( t = BDY(p), i = 0; i < len; NMV_ADV(t), i++ ) { |
for ( t = BDY(p), i = 0; i < len; NMV_ADV(t), i++ ) { |
NEXTMP(m0,m); |
NEXTMP(m0,m); |
m->dl = ndltodl(nd_nvar,DL(t)); |
m->dl = ndltodl(nd_nvar,DL(t)); |
m->c = ndctop(mod,t->c); |
m->c = (Obj)ndctop(mod,t->c); |
} |
} |
NEXT(m) = 0; |
NEXT(m) = 0; |
MKDP(nd_nvar,m0,d); |
MKDP(nd_nvar,m0,d); |
Line 5457 DP ndtodp(int mod,ND p) |
|
Line 5485 DP ndtodp(int mod,ND p) |
|
for ( t = BDY(p); t; t = NEXT(t) ) { |
for ( t = BDY(p); t; t = NEXT(t) ) { |
NEXTMP(m0,m); |
NEXTMP(m0,m); |
m->dl = ndltodl(nd_nvar,DL(t)); |
m->dl = ndltodl(nd_nvar,DL(t)); |
m->c = ndctop(mod,t->c); |
m->c = (Obj)ndctop(mod,t->c); |
} |
} |
NEXT(m) = 0; |
NEXT(m) = 0; |
MKDP(nd_nvar,m0,d); |
MKDP(nd_nvar,m0,d); |
Line 5796 int nd_to_vect(int mod,UINT *s0,int n,ND d,UINT *r) |
|
Line 5824 int nd_to_vect(int mod,UINT *s0,int n,ND d,UINT *r) |
|
return i; |
return i; |
} |
} |
|
|
|
#if defined(__GNUC__) && SIZEOF_LONG==8 |
|
|
|
#define MOD128(a,c,m) ((a)=(((c)!=0||((a)>=(m)))?(((((U128)(c))<<64)+(a))%(m)):(a))) |
|
|
|
int nd_to_vect64(int mod,UINT *s0,int n,ND d,U64 *r) |
|
{ |
|
NM m; |
|
UINT *t,*s; |
|
int i; |
|
|
|
for ( i = 0; i < n; i++ ) r[i] = 0; |
|
for ( i = 0, s = s0, m = BDY(d); m; m = NEXT(m) ) { |
|
t = DL(m); |
|
for ( ; !ndl_equal(t,s); s += nd_wpd, i++ ); |
|
r[i] = (U64)CM(m); |
|
} |
|
for ( i = 0; !r[i]; i++ ); |
|
return i; |
|
} |
|
#endif |
|
|
int nd_to_vect_q(UINT *s0,int n,ND d,Q *r) |
int nd_to_vect_q(UINT *s0,int n,ND d,Q *r) |
{ |
{ |
NM m; |
NM m; |
Line 6121 int ndv_reduce_vect_gz(GZ *gvect,int trace,int col,Ind |
|
Line 6170 int ndv_reduce_vect_gz(GZ *gvect,int trace,int col,Ind |
|
return maxrs; |
return maxrs; |
} |
} |
|
|
|
|
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) |
{ |
{ |
int i,j,k,len,pos,prev; |
int i,j,k,len,pos,prev; |
Line 6191 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
Line 6239 int ndv_reduce_vect(int m,UINT *svect,int col,IndArray |
|
return maxrs; |
return maxrs; |
} |
} |
|
|
|
#if defined(__GNUC__) && SIZEOF_LONG==8 |
|
|
|
int ndv_reduce_vect64(int m,U64 *svect,U64 *cvect,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
|
{ |
|
int i,j,k,len,pos,prev; |
|
U64 a,c,c1,c2; |
|
IndArray ivect; |
|
unsigned char *ivc; |
|
unsigned short *ivs; |
|
unsigned int *ivi; |
|
NDV redv; |
|
NMV mr; |
|
NODE rp; |
|
int maxrs; |
|
|
|
for ( i = 0; i < col; i++ ) cvect[i] = 0; |
|
maxrs = 0; |
|
for ( i = 0; i < nred; i++ ) { |
|
ivect = imat[i]; |
|
k = ivect->head; |
|
a = svect[k]; c = cvect[k]; |
|
MOD128(a,c,m); |
|
svect[k] = a; cvect[k] = 0; |
|
if ( c = svect[k] ) { |
|
maxrs = MAX(maxrs,rp0[i]->sugar); |
|
c = m-c; redv = nd_ps[rp0[i]->index]; |
|
len = LEN(redv); mr = BDY(redv); |
|
svect[k] = 0; prev = k; |
|
switch ( ivect->width ) { |
|
case 1: |
|
ivc = ivect->index.c; |
|
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
|
pos = prev+ivc[j]; c1 = CM(mr); prev = pos; |
|
if ( c1 ) { |
|
c2 = svect[pos]+c1*c; |
|
if ( c2 < svect[pos] ) cvect[pos]++; |
|
svect[pos] = c2; |
|
} |
|
} |
|
break; |
|
case 2: |
|
ivs = ivect->index.s; |
|
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
|
pos = prev+ivs[j]; c1 = CM(mr); prev = pos; |
|
if ( c1 ) { |
|
c2 = svect[pos]+c1*c; |
|
if ( c2 < svect[pos] ) cvect[pos]++; |
|
svect[pos] = c2; |
|
} |
|
} |
|
break; |
|
case 4: |
|
ivi = ivect->index.i; |
|
for ( j = 1, NMV_ADV(mr); j < len; j++, NMV_ADV(mr) ) { |
|
pos = prev+ivi[j]; c1 = CM(mr); prev = pos; |
|
if ( c1 ) { |
|
c2 = svect[pos]+c1*c; |
|
if ( c2 < svect[pos] ) cvect[pos]++; |
|
svect[pos] = c2; |
|
} |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
for ( i = 0; i < col; i++ ) { |
|
a = svect[i]; c = cvect[i]; MOD128(a,c,m); svect[i] = a; |
|
} |
|
return maxrs; |
|
} |
|
#endif |
|
|
int ndv_reduce_vect_sf(int m,UINT *svect,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
int ndv_reduce_vect_sf(int m,UINT *svect,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
{ |
{ |
int i,j,k,len,pos,prev; |
int i,j,k,len,pos,prev; |
Line 6448 NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea |
|
Line 6568 NDV vect_to_ndv(UINT *vect,int spcol,int col,int *rhea |
|
} |
} |
} |
} |
|
|
|
#if defined(__GNUC__) && SIZEOF_LONG==8 |
|
NDV vect64_to_ndv(U64 *vect,int spcol,int col,int *rhead,UINT *s0vect) |
|
{ |
|
int j,k,len; |
|
UINT *p; |
|
UINT c; |
|
NDV r; |
|
NMV mr0,mr; |
|
|
|
for ( j = 0, len = 0; j < spcol; j++ ) if ( vect[j] ) len++; |
|
if ( !len ) return 0; |
|
else { |
|
mr0 = (NMV)MALLOC_ATOMIC_IGNORE_OFF_PAGE(nmv_adv*len); |
|
#if 0 |
|
ndv_alloc += nmv_adv*len; |
|
#endif |
|
mr = mr0; |
|
p = s0vect; |
|
for ( j = k = 0; j < col; j++, p += nd_wpd ) |
|
if ( !rhead[j] ) { |
|
if ( c = (UINT)vect[k++] ) { |
|
ndl_copy(p,DL(mr)); CM(mr) = c; NMV_ADV(mr); |
|
} |
|
} |
|
MKNDV(nd_nvar,mr0,len,r); |
|
return r; |
|
} |
|
} |
|
#endif |
|
|
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 6686 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6836 NODE nd_f4(int m,int checkonly,int **indp) |
|
} |
} |
nzlist = 0; |
nzlist = 0; |
nzlist_t = nd_nzlist; |
nzlist_t = nd_nzlist; |
f4red = 0; |
f4red = 1; |
|
nd_last_nonzero = 0; |
while ( d || nzlist_t ) { |
while ( d || nzlist_t ) { |
get_eg(&eg0); |
get_eg(&eg0); |
if ( nd_nzlist ) { |
if ( nd_nzlist ) { |
node = BDY((LIST)BDY(nzlist_t)); |
node = BDY((LIST)BDY(nzlist_t)); |
sugar = (int)ARG0(node); |
sugar = QTOS((Q)ARG0(node)); |
tn = BDY((LIST)ARG1(node)); |
tn = BDY((LIST)ARG1(node)); |
if ( !tn ) { |
if ( !tn ) { |
nzlist_t = NEXT(nzlist_t); |
nzlist_t = NEXT(nzlist_t); |
Line 6724 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6875 NODE nd_f4(int m,int checkonly,int **indp) |
|
} |
} |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"sugar=%d,symb=%fsec,", |
fprintf(asir_out,"sugar=%d,symb=%.3fsec,", |
sugar,eg_f4.exectime+eg_f4.gctime); |
sugar,eg_f4.exectime+eg_f4.gctime); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,nd_gentrace?&ll:0); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,nd_gentrace?&ll:0); |
if ( checkonly && nflist ) return 0; |
if ( checkonly && nflist ) return 0; |
/* adding new bases */ |
/* adding new bases */ |
|
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); |
ndv_removecont(m,nf); |
ndv_removecont(m,nf); |
Line 6745 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6897 NODE nd_f4(int m,int checkonly,int **indp) |
|
g = update_base(g,nh); |
g = update_base(g,nh); |
} |
} |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"f4red=%d,gblen=%d,",f4red,length(g)); fflush(asir_out); |
fprintf(asir_out,"f4red=%d,gblen=%d\n",f4red,length(g)); fflush(asir_out); |
} |
} |
if ( nd_gentrace ) { |
if ( nd_gentrace ) { |
for ( t = ll, tn0 = 0; t; t = NEXT(t) ) { |
for ( t = ll, tn0 = 0; t; t = NEXT(t) ) { |
Line 6760 NODE nd_f4(int m,int checkonly,int **indp) |
|
Line 6912 NODE nd_f4(int m,int checkonly,int **indp) |
|
} |
} |
if ( nd_nzlist ) nzlist_t = NEXT(nzlist_t); |
if ( nd_nzlist ) nzlist_t = NEXT(nzlist_t); |
f4red++; |
f4red++; |
if ( nd_f4red && f4red >= nd_f4red ) break; |
if ( nd_f4red && f4red > nd_f4red ) break; |
if ( nd_rank0 && !nflist ) break; |
if ( nd_rank0 && !nflist ) break; |
} |
} |
if ( nd_gentrace ) { |
if ( nd_gentrace ) { |
Line 6823 NODE nd_f4_trace(int m,int **indp) |
|
Line 6975 NODE nd_f4_trace(int m,int **indp) |
|
} |
} |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"sugar=%d,symb=%fsec,", |
fprintf(asir_out,"sugar=%d,symb=%.3fsec,", |
sugar,eg_f4.exectime+eg_f4.gctime); |
sugar,eg_f4.exectime+eg_f4.gctime); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,&l0); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,&l0); |
if ( !l0 ) continue; |
if ( !l0 ) continue; |
Line 7037 init_eg(&eg_search); |
|
Line 7189 init_eg(&eg_search); |
|
get_eg(&eg2); |
get_eg(&eg2); |
init_eg(&eg_elim2); add_eg(&eg_elim2,&eg1,&eg2); |
init_eg(&eg_elim2); add_eg(&eg_elim2,&eg1,&eg2); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,elim2=%fsec\n", |
fprintf(asir_out,"elim1=%.3fsec,elim2=%.3fsec,", |
eg_elim1.exectime+eg_elim1.gctime,eg_elim2.exectime+eg_elim2.gctime); |
eg_elim1.exectime+eg_elim1.gctime,eg_elim2.exectime+eg_elim2.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
Line 7068 init_eg(&eg_search); |
|
Line 7220 init_eg(&eg_search); |
|
|
|
/* construction of index arrays */ |
/* construction of index arrays */ |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(stderr,"%dx%d,",nsp+nred,col); |
fprintf(asir_out,"%dx%d,",nsp+nred,col); |
} |
} |
rvect = (NM_ind_pair *)MALLOC(nred*sizeof(NM_ind_pair)); |
rvect = (NM_ind_pair *)MALLOC(nred*sizeof(NM_ind_pair)); |
s0hash = (int *)MALLOC(col*sizeof(int)); |
s0hash = (int *)MALLOC(col*sizeof(int)); |
Line 7079 init_eg(&eg_search); |
|
Line 7231 init_eg(&eg_search); |
|
imat[i] = nm_ind_pair_to_vect_compress(trace,s0vect,col,s0hash,rvect[i]); |
imat[i] = nm_ind_pair_to_vect_compress(trace,s0vect,col,s0hash,rvect[i]); |
rhead[imat[i]->head] = 1; |
rhead[imat[i]->head] = 1; |
} |
} |
if ( m > 0 || m == -1 ) |
if ( m > 0 ) |
|
#if defined(__GNUC__) && SIZEOF_LONG==8 |
|
r0 = nd_f4_red_mod64_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
|
#else |
r0 = nd_f4_red_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
r0 = nd_f4_red_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
|
#endif |
|
else if ( m == -1 ) |
|
r0 = nd_f4_red_sf_main(m,sp0,nsp,s0vect,col,rvect,rhead,imat,nred,nz); |
else if ( m == -2 ) |
else if ( m == -2 ) |
r0 = nd_f4_red_lf_main(m,sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
r0 = nd_f4_red_lf_main(m,sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
else |
else |
|
#if defined(VISUAL) |
|
r0 = nd_f4_red_q_main(sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
|
#else |
r0 = nd_f4_red_gz_main(sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
r0 = nd_f4_red_gz_main(sp0,nsp,trace,s0vect,col,rvect,rhead,imat,nred); |
|
#endif |
|
#if 0 |
if ( DP_Print ) print_eg("search",&eg_search); |
if ( DP_Print ) print_eg("search",&eg_search); |
|
#endif |
return r0; |
return r0; |
} |
} |
|
|
/* for small finite fields */ |
/* for Fp, 2<=p<2^16 */ |
|
|
NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz) |
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz) |
{ |
{ |
Line 7135 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 7300 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
} |
} |
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7160 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 7325 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); |
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&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 ) { |
fprintf(asir_out,"elim2=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
nsp,nred,sprow,spcol,rank); |
nsp,nred,sprow,spcol,rank); |
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
fprintf(asir_out,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
if ( nz ) { |
if ( nz ) { |
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
Line 7176 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 7341 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
return r0; |
return r0; |
} |
} |
|
|
|
#if defined(__GNUC__) && SIZEOF_LONG==8 |
|
/* for Fp, 2^15=<p<2^29 */ |
|
|
|
NODE nd_f4_red_mod64_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
|
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz) |
|
{ |
|
int spcol,sprow,a; |
|
int i,j,k,l,rank; |
|
NODE r0,r; |
|
ND_pairs sp; |
|
ND spol; |
|
U64 **spmat; |
|
U64 *svect,*cvect; |
|
U64 *v; |
|
int *colstat; |
|
struct oEGT eg0,eg1,eg2,eg_f4,eg_f4_1,eg_f4_2; |
|
int maxrs; |
|
int *spsugar; |
|
ND_pairs *spactive; |
|
|
|
spcol = col-nred; |
|
get_eg(&eg0); |
|
/* elimination (1st step) */ |
|
spmat = (U64 **)MALLOC(nsp*sizeof(U64 *)); |
|
svect = (U64 *)MALLOC(col*sizeof(U64)); |
|
cvect = (U64 *)MALLOC(col*sizeof(U64)); |
|
spsugar = (int *)MALLOC(nsp*sizeof(int)); |
|
spactive = !nz?0:(ND_pairs *)MALLOC(nsp*sizeof(ND_pairs)); |
|
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
|
nd_sp(m,0,sp,&spol); |
|
if ( !spol ) continue; |
|
nd_to_vect64(m,s0vect,col,spol,svect); |
|
maxrs = ndv_reduce_vect64(m,svect,cvect,col,imat,rvect,nred); |
|
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
|
if ( i < col ) { |
|
spmat[sprow] = v = (U64 *)MALLOC_ATOMIC(spcol*sizeof(U64)); |
|
for ( j = k = 0; j < col; j++ ) |
|
if ( !rhead[j] ) v[k++] = (UINT)svect[j]; |
|
spsugar[sprow] = MAX(maxrs,SG(spol)); |
|
if ( nz ) |
|
spactive[sprow] = sp; |
|
sprow++; |
|
} |
|
nd_free(spol); |
|
} |
|
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
|
fflush(asir_out); |
|
} |
|
/* free index arrays */ |
|
for ( i = 0; i < nred; i++ ) GCFREE(imat[i]->index.c); |
|
|
|
/* elimination (2nd step) */ |
|
colstat = (int *)MALLOC(spcol*sizeof(int)); |
|
rank = nd_gauss_elim_mod64(spmat,spsugar,spactive,sprow,spcol,m,colstat); |
|
r0 = 0; |
|
for ( i = 0; i < rank; i++ ) { |
|
NEXTNODE(r0,r); BDY(r) = |
|
(pointer)vect64_to_ndv(spmat[i],spcol,col,rhead,s0vect); |
|
SG((NDV)BDY(r)) = spsugar[i]; |
|
GCFREE(spmat[i]); |
|
} |
|
if ( r0 ) NEXT(r) = 0; |
|
|
|
for ( ; i < sprow; i++ ) GCFREE(spmat[i]); |
|
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); |
|
init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime+eg_f4_2.gctime); |
|
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
|
nsp,nred,sprow,spcol,rank); |
|
fprintf(asir_out,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
|
} |
|
if ( nz ) { |
|
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
|
if ( rank > 0 ) { |
|
NEXT(spactive[rank-1]) = 0; |
|
*nz = spactive[0]; |
|
} else |
|
*nz = 0; |
|
} |
|
return r0; |
|
} |
|
#endif |
|
|
|
/* for small finite fields */ |
|
|
|
NODE nd_f4_red_sf_main(int m,ND_pairs sp0,int nsp,UINT *s0vect,int col, |
|
NM_ind_pair *rvect,int *rhead,IndArray *imat,int nred,ND_pairs *nz) |
|
{ |
|
int spcol,sprow,a; |
|
int i,j,k,l,rank; |
|
NODE r0,r; |
|
ND_pairs sp; |
|
ND spol; |
|
int **spmat; |
|
UINT *svect,*v; |
|
int *colstat; |
|
struct oEGT eg0,eg1,eg2,eg_f4,eg_f4_1,eg_f4_2; |
|
int maxrs; |
|
int *spsugar; |
|
ND_pairs *spactive; |
|
|
|
spcol = col-nred; |
|
get_eg(&eg0); |
|
/* elimination (1st step) */ |
|
spmat = (int **)MALLOC(nsp*sizeof(UINT *)); |
|
svect = (UINT *)MALLOC(col*sizeof(UINT)); |
|
spsugar = (int *)MALLOC(nsp*sizeof(int)); |
|
spactive = !nz?0:(ND_pairs *)MALLOC(nsp*sizeof(ND_pairs)); |
|
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
|
nd_sp(m,0,sp,&spol); |
|
if ( !spol ) continue; |
|
nd_to_vect(m,s0vect,col,spol,svect); |
|
maxrs = ndv_reduce_vect_sf(m,svect,col,imat,rvect,nred); |
|
for ( i = 0; i < col; i++ ) if ( svect[i] ) break; |
|
if ( i < col ) { |
|
spmat[sprow] = v = (UINT *)MALLOC_ATOMIC(spcol*sizeof(UINT)); |
|
for ( j = k = 0; j < col; j++ ) |
|
if ( !rhead[j] ) v[k++] = svect[j]; |
|
spsugar[sprow] = MAX(maxrs,SG(spol)); |
|
if ( nz ) |
|
spactive[sprow] = sp; |
|
sprow++; |
|
} |
|
nd_free(spol); |
|
} |
|
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
|
fflush(asir_out); |
|
} |
|
/* free index arrays */ |
|
for ( i = 0; i < nred; i++ ) GCFREE(imat[i]->index.c); |
|
|
|
/* elimination (2nd step) */ |
|
colstat = (int *)MALLOC(spcol*sizeof(int)); |
|
rank = nd_gauss_elim_sf(spmat,spsugar,sprow,spcol,m,colstat); |
|
r0 = 0; |
|
for ( i = 0; i < rank; i++ ) { |
|
NEXTNODE(r0,r); BDY(r) = |
|
(pointer)vect_to_ndv(spmat[i],spcol,col,rhead,s0vect); |
|
SG((NDV)BDY(r)) = spsugar[i]; |
|
GCFREE(spmat[i]); |
|
} |
|
if ( r0 ) NEXT(r) = 0; |
|
|
|
for ( ; i < sprow; i++ ) GCFREE(spmat[i]); |
|
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); |
|
init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg2); |
|
if ( DP_Print ) { |
|
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime+eg_f4_2.gctime); |
|
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
|
nsp,nred,sprow,spcol,rank); |
|
fprintf(asir_out,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
|
} |
|
if ( nz ) { |
|
for ( i = 0; i < rank-1; i++ ) NEXT(spactive[i]) = spactive[i+1]; |
|
if ( rank > 0 ) { |
|
NEXT(spactive[rank-1]) = 0; |
|
*nz = spactive[0]; |
|
} else |
|
*nz = 0; |
|
} |
|
return r0; |
|
} |
|
|
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) |
{ |
{ |
Line 7215 NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int |
|
Line 7548 NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int |
|
} |
} |
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7250 NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int |
|
Line 7583 NODE nd_f4_red_lf_main(int m,ND_pairs sp0,int nsp,int |
|
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); |
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&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 ) { |
fprintf(asir_out,"elim2=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
nsp,nred,sprow,spcol,rank); |
nsp,nred,sprow,spcol,rank); |
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
fprintf(asir_out,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
return r0; |
return r0; |
} |
} |
Line 7298 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U |
|
Line 7631 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U |
|
} |
} |
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7332 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U |
|
Line 7665 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,int trace,U |
|
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); |
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&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 ) { |
fprintf(asir_out,"elim2=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
nsp,nred,sprow,spcol,rank); |
nsp,nred,sprow,spcol,rank); |
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
fprintf(asir_out,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
return r0; |
return r0; |
} |
} |
Line 7380 NODE nd_f4_red_gz_main(ND_pairs sp0,int nsp,int trace, |
|
Line 7713 NODE nd_f4_red_gz_main(ND_pairs sp0,int nsp,int trace, |
|
} |
} |
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4_1); add_eg(&eg_f4_1,&eg0,&eg1); |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"elim1=%fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fprintf(asir_out,"elim1=%.3fsec,",eg_f4_1.exectime+eg_f4_1.gctime); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
Line 7417 NODE nd_f4_red_gz_main(ND_pairs sp0,int nsp,int trace, |
|
Line 7750 NODE nd_f4_red_gz_main(ND_pairs sp0,int nsp,int trace, |
|
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&eg1,&eg2); |
get_eg(&eg2); init_eg(&eg_f4_2); add_eg(&eg_f4_2,&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 ) { |
fprintf(asir_out,"elim2=%fsec\n",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"elim2=%.3fsec,",eg_f4_2.exectime+eg_f4_2.gctime); |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
fprintf(asir_out,"nsp=%d,nred=%d,spmat=(%d,%d),rank=%d ", |
nsp,nred,sprow,spcol,rank); |
nsp,nred,sprow,spcol,rank); |
fprintf(asir_out,"%fsec\n",eg_f4.exectime+eg_f4.gctime); |
fprintf(asir_out,"%.3fsec,",eg_f4.exectime+eg_f4.gctime); |
} |
} |
return r0; |
return r0; |
} |
} |
Line 7670 int nd_gauss_elim_mod(int **mat0,int *sugar,ND_pairs * |
|
Line 8003 int nd_gauss_elim_mod(int **mat0,int *sugar,ND_pairs * |
|
return rank; |
return rank; |
} |
} |
|
|
|
#if defined(__GNUC__) && SIZEOF_LONG==8 |
|
|
|
int nd_gauss_elim_mod64(U64 **mat,int *sugar,ND_pairs *spactive,int row,int col,int md,int *colstat) |
|
{ |
|
int i,j,k,l,rank,s; |
|
U64 inv; |
|
U64 a; |
|
UINT c; |
|
U64 *t,*pivot,*pk; |
|
UINT *ck; |
|
UINT **cmat; |
|
UINT *ct; |
|
ND_pairs pair; |
|
|
|
cmat = (UINT **)MALLOC(row*sizeof(UINT *)); |
|
for ( i = 0; i < row; i++ ) { |
|
cmat[i] = MALLOC_ATOMIC(col*sizeof(UINT)); |
|
bzero(cmat[i],col*sizeof(UINT)); |
|
} |
|
|
|
for ( rank = 0, j = 0; j < col; j++ ) { |
|
for ( i = rank; i < row; i++ ) { |
|
a = mat[i][j]; c = cmat[i][j]; |
|
MOD128(a,c,md); |
|
mat[i][j] = a; cmat[i][j] = 0; |
|
} |
|
for ( i = rank; i < row; i++ ) |
|
if ( mat[i][j] ) |
|
break; |
|
if ( i == row ) { |
|
colstat[j] = 0; |
|
continue; |
|
} else |
|
colstat[j] = 1; |
|
if ( i != rank ) { |
|
t = mat[i]; mat[i] = mat[rank]; mat[rank] = t; |
|
ct = cmat[i]; cmat[i] = cmat[rank]; cmat[rank] = ct; |
|
s = sugar[i]; sugar[i] = sugar[rank]; sugar[rank] = s; |
|
if ( spactive ) { |
|
pair = spactive[i]; spactive[i] = spactive[rank]; |
|
spactive[rank] = pair; |
|
} |
|
} |
|
/* column j is normalized */ |
|
s = sugar[rank]; |
|
inv = invm((UINT)mat[rank][j],md); |
|
/* normalize pivot row */ |
|
for ( k = j, pk = mat[rank]+j, ck = cmat[rank]+j; k < col; k++, pk++, ck++ ) { |
|
a = *pk; c = *ck; MOD128(a,c,md); *pk = (a*inv)%md; *ck = 0; |
|
} |
|
for ( i = rank+1; i < row; i++ ) { |
|
if ( a = mat[i][j] ) { |
|
sugar[i] = MAX(sugar[i],s); |
|
red_by_vect64(md,mat[i]+j,cmat[i]+j,mat[rank]+j,(int)(md-a),col-j); |
|
} |
|
} |
|
rank++; |
|
} |
|
for ( j = col-1, l = rank-1; j >= 0; j-- ) |
|
if ( colstat[j] ) { |
|
for ( k = j, pk = mat[l]+j, ck = cmat[l]+j; k < col; k++, pk++, ck++ ) { |
|
a = *pk; c = *ck; MOD128(a,c,md); *pk = a; *ck = 0; |
|
} |
|
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 ) { |
|
sugar[i] = MAX(sugar[i],s); |
|
red_by_vect64(md,mat[i]+j,cmat[i]+j,mat[l]+j,(int)(md-a),col-j); |
|
} |
|
} |
|
l--; |
|
} |
|
for ( i = 0; i < row; i++ ) GCFREE(cmat[i]); |
|
GCFREE(cmat); |
|
return rank; |
|
} |
|
#endif |
|
|
int nd_gauss_elim_sf(int **mat0,int *sugar,int row,int col,int md,int *colstat) |
int nd_gauss_elim_sf(int **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 7959 void nd_det(int mod,MAT f,P *rp) |
|
Line 8371 void nd_det(int mod,MAT f,P *rp) |
|
chsgnq(ONE,&mone); |
chsgnq(ONE,&mone); |
for ( j = 0, sgn = 1; j < n; j++ ) { |
for ( j = 0, sgn = 1; j < n; j++ ) { |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(stderr,".",j); |
fprintf(asir_out,".",j); |
} |
} |
for ( i = j; i < n && !dm[i][j]; i++ ); |
for ( i = j; i < n && !dm[i][j]; i++ ); |
if ( i == n ) { |
if ( i == n ) { |
Line 7989 void nd_det(int mod,MAT f,P *rp) |
|
Line 8401 void nd_det(int mod,MAT f,P *rp) |
|
nd_det_reconstruct(dm,n,j,d); |
nd_det_reconstruct(dm,n,j,d); |
|
|
for ( i = j+1, mj = dm[j], mjj = mj[j]; i < n; i++ ) { |
for ( i = j+1, mj = dm[j], mjj = mj[j]; i < n; i++ ) { |
/* if ( DP_Print ) fprintf(stderr," i=%d\n ",i); */ |
/* if ( DP_Print ) fprintf(asir_out," i=%d\n ",i); */ |
mi = dm[i]; mij = mi[j]; |
mi = dm[i]; mij = mi[j]; |
if ( mod ) |
if ( mod ) |
ndv_mul_c(mod,mij,mod-1); |
ndv_mul_c(mod,mij,mod-1); |
else |
else |
ndv_mul_c_q(mij,mone); |
ndv_mul_c_q(mij,mone); |
for ( k = j+1; k < n; k++ ) { |
for ( k = j+1; k < n; k++ ) { |
/* if ( DP_Print ) fprintf(stderr,"k=%d ",k); */ |
/* if ( DP_Print ) fprintf(asir_out,"k=%d ",k); */ |
bucket = create_pbucket(); |
bucket = create_pbucket(); |
if ( mi[k] ) { |
if ( mi[k] ) { |
nmv = BDY(mjj); len = LEN(mjj); |
nmv = BDY(mjj); len = LEN(mjj); |
Line 8015 void nd_det(int mod,MAT f,P *rp) |
|
Line 8427 void nd_det(int mod,MAT f,P *rp) |
|
u = nd_quo(mod,bucket,d); |
u = nd_quo(mod,bucket,d); |
mi[k] = ndtondv(mod,u); |
mi[k] = ndtondv(mod,u); |
} |
} |
/* if ( DP_Print ) fprintf(stderr,"\n",k); */ |
/* if ( DP_Print ) fprintf(asir_out,"\n",k); */ |
} |
} |
d = mjj; |
d = mjj; |
} |
} |
if ( DP_Print ) { |
if ( DP_Print ) { |
fprintf(stderr,"\n",k); |
fprintf(asir_out,"\n",k); |
} |
} |
if ( sgn < 0 ) |
if ( sgn < 0 ) |
if ( mod ) |
if ( mod ) |
Line 8196 int nd_monic(int mod,ND *p) |
|
Line 8608 int nd_monic(int mod,ND *p) |
|
is_lc = 1; |
is_lc = 1; |
while ( 1 ) { |
while ( 1 ) { |
NEWMP(mp0); mp = mp0; |
NEWMP(mp0); mp = mp0; |
mp->c = (P)CQ(m); |
mp->c = (Obj)CQ(m); |
mp->dl = nd_separate_d(DL(m),DL(ma)); |
mp->dl = nd_separate_d(DL(m),DL(ma)); |
NEWNM(mb); |
NEWNM(mb); |
for ( m = NEXT(m); m; m = NEXT(m) ) { |
for ( m = NEXT(m); m; m = NEXT(m) ) { |
alg = nd_separate_d(DL(m),DL(mb)); |
alg = nd_separate_d(DL(m),DL(mb)); |
if ( !ndl_equal(DL(ma),DL(mb)) ) |
if ( !ndl_equal(DL(ma),DL(mb)) ) |
break; |
break; |
NEXTMP(mp0,mp); mp->c = (P)CQ(m); mp->dl = alg; |
NEXTMP(mp0,mp); mp->c = (Obj)CQ(m); mp->dl = alg; |
} |
} |
NEXT(mp) = 0; |
NEXT(mp) = 0; |
MKDP(nd_nalg,mp0,nm); |
MKDP(nd_nalg,mp0,nm); |
Line 8819 void nd_f4_lf_trace(LIST f,LIST v,int trace,int homo,s |
|
Line 9231 void nd_f4_lf_trace(LIST f,LIST v,int trace,int homo,s |
|
} |
} |
get_eg(&eg1); init_eg(&eg_check); add_eg(&eg_check,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_check); add_eg(&eg_check,&eg0,&eg1); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"check=%fsec\n",eg_check.exectime+eg_check.gctime); |
fprintf(asir_out,"check=%.3fsec\n",eg_check.exectime+eg_check.gctime); |
/* dp->p */ |
/* dp->p */ |
nd_bpe = cbpe; |
nd_bpe = cbpe; |
nd_setup_parameters(nd_nvar,0); |
nd_setup_parameters(nd_nvar,0); |
Line 8879 NODE nd_f4_lf_trace_main(int m,int **indp) |
|
Line 9291 NODE nd_f4_lf_trace_main(int m,int **indp) |
|
} |
} |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
get_eg(&eg1); init_eg(&eg_f4); add_eg(&eg_f4,&eg0,&eg1); |
if ( DP_Print ) |
if ( DP_Print ) |
fprintf(asir_out,"sugar=%d,symb=%fsec,", |
fprintf(asir_out,"sugar=%d,symb=%.3fsec,", |
sugar,eg_f4.exectime+eg_f4.gctime); |
sugar,eg_f4.exectime+eg_f4.gctime); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,&l0); |
nflist = nd_f4_red(m,l,0,s0vect,col,rp0,&l0); |
if ( !l0 ) continue; |
if ( !l0 ) continue; |