version 1.107, 2004/09/21 02:34:12 |
version 1.127, 2005/08/03 05:01:01 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.106 2004/09/21 02:23:49 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.126 2005/02/09 14:30:47 noro Exp $ */ |
|
|
#include "nd.h" |
#include "nd.h" |
|
|
|
|
ND _nd_free_list; |
ND _nd_free_list; |
ND_pairs _ndp_free_list; |
ND_pairs _ndp_free_list; |
|
|
|
static int nd_ntrans; |
|
static int nd_nalg; |
#if 0 |
#if 0 |
static int ndv_alloc; |
static int ndv_alloc; |
#endif |
#endif |
Line 41 static int nd_found,nd_create,nd_notfirst; |
|
Line 43 static int nd_found,nd_create,nd_notfirst; |
|
static int nmv_adv; |
static int nmv_adv; |
static int nd_demand; |
static int nd_demand; |
|
|
|
NumberField get_numberfield(); |
|
UINT *nd_det_compute_bound(NDV **dm,int n,int j); |
|
void nd_det_reconstruct(NDV **dm,int n,int j,NDV d); |
|
int nd_monic(int m,ND *p); |
|
|
void nd_free_private_storage() |
void nd_free_private_storage() |
{ |
{ |
_nm_free_list = 0; |
_nm_free_list = 0; |
Line 724 int ndl_disjoint(UINT *d1,UINT *d2) |
|
Line 731 int ndl_disjoint(UINT *d1,UINT *d2) |
|
#endif |
#endif |
} |
} |
|
|
int ndl_check_bound2(int index,UINT *d2) |
int ndl_check_bound(UINT *d1,UINT *d2) |
{ |
{ |
UINT u2; |
UINT u2; |
UINT *d1; |
|
int i,j,ind,k; |
int i,j,ind,k; |
|
|
d1 = nd_bound[index]; |
|
ind = 0; |
ind = 0; |
#if USE_UNROLL |
#if USE_UNROLL |
switch ( nd_bpe ) { |
switch ( nd_bpe ) { |
Line 819 int ndl_check_bound2(int index,UINT *d2) |
|
Line 824 int ndl_check_bound2(int index,UINT *d2) |
|
#endif |
#endif |
} |
} |
|
|
|
int ndl_check_bound2(int index,UINT *d2) |
|
{ |
|
return ndl_check_bound(nd_bound[index],d2); |
|
} |
|
|
INLINE int ndl_hash_value(UINT *d) |
INLINE int ndl_hash_value(UINT *d) |
{ |
{ |
int i; |
int i; |
Line 1527 ND normalize_pbucket(int mod,PGeoBucket g) |
|
Line 1537 ND normalize_pbucket(int mod,PGeoBucket g) |
|
return r; |
return r; |
} |
} |
|
|
void do_diagonalize(int sugar,int m) |
int do_diagonalize(int sugar,int m) |
{ |
{ |
int i,nh,stat; |
int i,nh,stat; |
NODE r,g,t; |
NODE r,g,t; |
Line 1543 void do_diagonalize(int sugar,int m) |
|
Line 1553 void do_diagonalize(int sugar,int m) |
|
nfv = nd_ps[i]; |
nfv = nd_ps[i]; |
s = ndvtond(m,nfv); |
s = ndvtond(m,nfv); |
s = nd_separate_head(s,&head); |
s = nd_separate_head(s,&head); |
nd_nf(m,s,nd_ps,1,&dn,&nf); |
stat = nd_nf(m,s,nd_ps,1,&dn,&nf); |
|
if ( !stat ) return 0; |
if ( !m ) { |
if ( !m ) { |
NTOQ(NM(dn.z),SGN(dn.z),num); |
NTOQ(NM(dn.z),SGN(dn.z),num); |
mulq(HCQ(head),num,&q); HCQ(head) = q; |
mulq(HCQ(head),num,&q); HCQ(head) = q; |
Line 1564 void do_diagonalize(int sugar,int m) |
|
Line 1575 void do_diagonalize(int sugar,int m) |
|
} else |
} else |
nd_ps[i] = nfv; |
nd_ps[i] = nfv; |
} |
} |
|
return 1; |
} |
} |
|
|
/* return value = 0 => input is not a GB */ |
/* return value = 0 => input is not a GB */ |
Line 1574 NODE nd_gb(int m,int ishomo,int checkonly) |
|
Line 1586 NODE nd_gb(int m,int ishomo,int checkonly) |
|
NODE r,g,t; |
NODE r,g,t; |
ND_pairs d; |
ND_pairs d; |
ND_pairs l; |
ND_pairs l; |
ND h,nf,s,head; |
ND h,nf,s,head,nf1; |
NDV nfv; |
NDV nfv; |
Q q,num,den; |
Q q,num,den; |
union oNDC dn; |
union oNDC dn; |
Line 1589 NODE nd_gb(int m,int ishomo,int checkonly) |
|
Line 1601 NODE nd_gb(int m,int ishomo,int checkonly) |
|
again: |
again: |
l = nd_minp(d,&d); |
l = nd_minp(d,&d); |
if ( SG(l) != sugar ) { |
if ( SG(l) != sugar ) { |
if ( ishomo ) do_diagonalize(sugar,m); |
if ( ishomo ) { |
|
stat = do_diagonalize(sugar,m); |
|
if ( !stat ) { |
|
NEXT(l) = d; d = l; |
|
d = nd_reconstruct(0,d); |
|
goto again; |
|
} |
|
} |
sugar = SG(l); |
sugar = SG(l); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
} |
} |
|
|
if ( checkonly ) return 0; |
if ( checkonly ) return 0; |
if ( DP_Print ) { printf("+"); fflush(stdout); } |
if ( DP_Print ) { printf("+"); fflush(stdout); } |
nd_removecont(m,nf); |
nd_removecont(m,nf); |
|
if ( !m && nd_nalg ) { |
|
nd_monic(0,&nf); |
|
nd_removecont(m,nf); |
|
} |
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(d,g,nh); |
d = update_pairs(d,g,nh); |
|
|
return g; |
return g; |
} |
} |
|
|
void do_diagonalize_trace(int sugar,int m) |
int do_diagonalize_trace(int sugar,int m) |
{ |
{ |
int i,nh,stat; |
int i,nh,stat; |
NODE r,g,t; |
NODE r,g,t; |
Line 1645 void do_diagonalize_trace(int sugar,int m) |
|
Line 1667 void do_diagonalize_trace(int sugar,int m) |
|
/* for nd_ps */ |
/* for nd_ps */ |
s = ndvtond(m,nd_ps[i]); |
s = ndvtond(m,nd_ps[i]); |
s = nd_separate_head(s,&head); |
s = nd_separate_head(s,&head); |
nd_nf_pbucket(m,s,nd_ps,1,&nf); |
stat = nd_nf_pbucket(m,s,nd_ps,1,&nf); |
|
if ( !stat ) return 0; |
nf = nd_add(m,head,nf); |
nf = nd_add(m,head,nf); |
ndv_free(nd_ps[i]); |
ndv_free(nd_ps[i]); |
nd_ps[i] = ndtondv(m,nf); |
nd_ps[i] = ndtondv(m,nf); |
Line 1658 void do_diagonalize_trace(int sugar,int m) |
|
Line 1681 void do_diagonalize_trace(int sugar,int m) |
|
nfv = nd_ps_trace[i]; |
nfv = nd_ps_trace[i]; |
s = ndvtond(0,nfv); |
s = ndvtond(0,nfv); |
s = nd_separate_head(s,&head); |
s = nd_separate_head(s,&head); |
nd_nf(0,s,nd_ps_trace,1,&dn,&nf); |
stat = nd_nf(0,s,nd_ps_trace,1,&dn,&nf); |
|
if ( !stat ) return 0; |
NTOQ(NM(dn.z),SGN(dn.z),num); |
NTOQ(NM(dn.z),SGN(dn.z),num); |
mulq(HCQ(head),num,&q); HCQ(head) = q; |
mulq(HCQ(head),num,&q); HCQ(head) = q; |
if ( DN(dn.z) ) { |
if ( DN(dn.z) ) { |
Line 1677 void do_diagonalize_trace(int sugar,int m) |
|
Line 1701 void do_diagonalize_trace(int sugar,int m) |
|
} else |
} else |
nd_ps_trace[i] = nfv; |
nd_ps_trace[i] = nfv; |
} |
} |
|
return 1; |
} |
} |
|
|
|
static struct oEGT eg_invdalg; |
|
struct oEGT eg_le; |
|
|
NODE nd_gb_trace(int m,int ishomo) |
NODE nd_gb_trace(int m,int ishomo) |
{ |
{ |
int i,nh,sugar,stat; |
int i,nh,sugar,stat; |
Line 1689 NODE nd_gb_trace(int m,int ishomo) |
|
Line 1717 NODE nd_gb_trace(int m,int ishomo) |
|
NDV nfv,nfqv; |
NDV nfv,nfqv; |
Q q,den,num; |
Q q,den,num; |
union oNDC dn; |
union oNDC dn; |
|
struct oEGT eg_monic,egm0,egm1; |
|
|
|
init_eg(&eg_monic); |
|
init_eg(&eg_invdalg); |
|
init_eg(&eg_le); |
g = 0; d = 0; |
g = 0; d = 0; |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = 0; i < nd_psn; i++ ) { |
d = update_pairs(d,g,i); |
d = update_pairs(d,g,i); |
Line 1700 NODE nd_gb_trace(int m,int ishomo) |
|
Line 1732 NODE nd_gb_trace(int m,int ishomo) |
|
again: |
again: |
l = nd_minp(d,&d); |
l = nd_minp(d,&d); |
if ( SG(l) != sugar ) { |
if ( SG(l) != sugar ) { |
if ( ishomo ) do_diagonalize_trace(sugar,m); |
if ( ishomo ) { |
|
stat = do_diagonalize_trace(sugar,m); |
|
if ( !stat ) { |
|
NEXT(l) = d; d = l; |
|
d = nd_reconstruct(1,d); |
|
goto again; |
|
} |
|
} |
sugar = SG(l); |
sugar = SG(l); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
if ( DP_Print ) fprintf(asir_out,"%d",sugar); |
} |
} |
|
|
if ( !rem(NM(HCQ(nfq)),m) ) return 0; |
if ( !rem(NM(HCQ(nfq)),m) ) return 0; |
|
|
if ( DP_Print ) { printf("+"); fflush(stdout); } |
if ( DP_Print ) { printf("+"); fflush(stdout); } |
nd_removecont(m,nf); nfv = ndtondv(m,nf); nd_free(nf); |
if ( nd_nalg ) { |
nd_removecont(0,nfq); nfqv = ndtondv(0,nfq); nd_free(nfq); |
/* m|DN(HC(nf)^(-1)) => failure */ |
|
get_eg(&egm0); |
|
if ( !nd_monic(m,&nfq) ) return 0; |
|
get_eg(&egm1); add_eg(&eg_monic,&egm0,&egm1); |
|
nd_removecont(0,nfq); nfqv = ndtondv(0,nfq); nd_free(nfq); |
|
nfv = ndv_dup(0,nfqv); ndv_mod(m,nfv); nd_free(nf); |
|
} else { |
|
nd_removecont(0,nfq); nfqv = ndtondv(0,nfq); nd_free(nfq); |
|
nd_removecont(m,nf); nfv = ndtondv(m,nf); nd_free(nf); |
|
} |
nh = ndv_newps(0,nfv,nfqv); |
nh = ndv_newps(0,nfv,nfqv); |
d = update_pairs(d,g,nh); |
d = update_pairs(d,g,nh); |
g = update_base(g,nh); |
g = update_base(g,nh); |
|
|
else |
else |
for ( t = g; t; t = NEXT(t) ) |
for ( t = g; t; t = NEXT(t) ) |
BDY(t) = (pointer)nd_ps_trace[(int)BDY(t)]; |
BDY(t) = (pointer)nd_ps_trace[(int)BDY(t)]; |
|
if ( nd_nalg ) { |
|
print_eg("monic",&eg_monic); |
|
print_eg("invdalg",&eg_invdalg); |
|
print_eg("le",&eg_le); |
|
} |
return g; |
return g; |
} |
} |
|
|
Line 2177 void ndv_setup(int mod,int trace,NODE f) |
|
Line 2230 void ndv_setup(int mod,int trace,NODE f) |
|
} |
} |
} |
} |
|
|
|
struct order_spec *append_block(struct order_spec *spec, |
|
int nv,int nalg,int ord); |
|
|
|
extern VECT current_dl_weight_vector_obj; |
|
static VECT prev_weight_vector_obj; |
|
|
|
void preprocess_algcoef(VL vv,VL av,struct order_spec *ord,LIST f, |
|
struct order_spec **ord1p,LIST *f1p,NODE *alistp) |
|
{ |
|
NODE alist,t,s,r0,r,arg; |
|
VL tv; |
|
P poly; |
|
DP d; |
|
Alg alpha,dp; |
|
DAlg inv,da,hc; |
|
MP m; |
|
int i,nvar,nalg,n; |
|
NumberField nf; |
|
LIST f1,f2; |
|
struct order_spec *current_spec; |
|
VECT obj,obj0; |
|
Obj tmp; |
|
|
|
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++); |
|
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++); |
|
|
|
for ( alist = 0, tv = av; tv; tv = NEXT(tv) ) { |
|
NEXTNODE(alist,t); MKV(tv->v,poly); |
|
MKAlg(poly,alpha); BDY(t) = (pointer)alpha; |
|
tv->v = tv->v->priv; |
|
} |
|
NEXT(t) = 0; |
|
|
|
/* simplification, makeing polynomials monic */ |
|
setfield_dalg(alist); |
|
obj_algtodalg(f,&f1); |
|
for ( t = BDY(f); t; t = NEXT(t) ) { |
|
initd(ord); ptod(vv,vv,(P)BDY(t),&d); |
|
hc = (DAlg)BDY(d)->c; |
|
if ( NID(hc) == N_DA ) { |
|
invdalg(hc,&inv); |
|
for ( m = BDY(d); m; m = NEXT(m) ) { |
|
muldalg(inv,(DAlg)m->c,&da); m->c = (P)da; |
|
} |
|
} |
|
initd(ord); dtop(vv,vv,d,&poly); BDY(f) = (pointer)poly; |
|
} |
|
obj_dalgtoalg(f1,&f); |
|
|
|
/* append alg vars to the var list */ |
|
for ( tv = vv; NEXT(tv); tv = NEXT(tv) ); |
|
NEXT(tv) = av; |
|
|
|
/* append a block to ord */ |
|
*ord1p = append_block(ord,nvar,nalg,2); |
|
|
|
/* create generator list */ |
|
nf = get_numberfield(); |
|
for ( i = nalg-1, t = BDY(f); i >= 0; i-- ) { |
|
MKAlg(nf->defpoly[i],dp); |
|
MKNODE(s,dp,t); t = s; |
|
} |
|
MKLIST(f1,t); |
|
*alistp = alist; |
|
algobjtorat(f1,f1p); |
|
|
|
/* creating a new weight vector */ |
|
prev_weight_vector_obj = obj0 = current_dl_weight_vector_obj; |
|
n = nvar+nalg+1; |
|
MKVECT(obj,n); |
|
if ( obj0 && obj0->len == nvar ) |
|
for ( i = 0; i < nvar; i++ ) BDY(obj)[i] = BDY(obj0)[i]; |
|
else |
|
for ( i = 0; i < nvar; i++ ) BDY(obj)[i] = (pointer)ONE; |
|
for ( i = 0; i < nalg; i++ ) BDY(obj)[i+nvar] = 0; |
|
BDY(obj)[n-1] = (pointer)ONE; |
|
arg = mknode(1,obj); |
|
Pdp_set_weight(arg,&tmp); |
|
} |
|
|
|
NODE postprocess_algcoef(VL av,NODE alist,NODE r) |
|
{ |
|
NODE s,t,u0,u; |
|
P p; |
|
VL tv; |
|
Obj obj,tmp; |
|
NODE arg; |
|
|
|
u0 = 0; |
|
for ( t = r; t; t = NEXT(t) ) { |
|
p = (P)BDY(t); |
|
for ( tv = av, s = alist; tv; tv = NEXT(tv), s = NEXT(s) ) { |
|
substr(CO,0,(Obj)p,tv->v,(Obj)BDY(s),&obj); p = (P)obj; |
|
} |
|
if ( OID(p) == O_P || (OID(p) == O_N && NID((Num)p) != N_A) ) { |
|
NEXTNODE(u0,u); |
|
BDY(u) = (pointer)p; |
|
} |
|
} |
|
arg = mknode(1,prev_weight_vector_obj); |
|
Pdp_set_weight(arg,&tmp); |
|
|
|
return u0; |
|
} |
|
|
void nd_gr(LIST f,LIST v,int m,int f4,struct order_spec *ord,LIST *rp) |
void nd_gr(LIST f,LIST v,int m,int f4,struct order_spec *ord,LIST *rp) |
{ |
{ |
VL tv,fv,vv,vc; |
VL tv,fv,vv,vc,av; |
NODE fd,fd0,r,r0,t,x,s,xx; |
NODE fd,fd0,r,r0,t,x,s,xx,alist; |
int e,max,nvar; |
int e,max,nvar,i; |
NDV b; |
NDV b; |
int ishomo; |
int ishomo,nalg; |
|
Alg alpha,dp; |
|
P p; |
|
LIST f1,f2; |
|
Obj obj; |
|
NumberField nf; |
|
struct order_spec *ord1; |
|
|
if ( !m && Demand ) nd_demand = 1; |
if ( !m && Demand ) nd_demand = 1; |
else nd_demand = 0; |
else nd_demand = 0; |
Line 2201 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 2365 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
default: |
default: |
break; |
break; |
} |
} |
|
nd_nalg = 0; |
|
av = 0; |
|
if ( !m ) { |
|
get_algtree((Obj)f,&av); |
|
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ ); |
|
nd_ntrans = nvar; |
|
nd_nalg = nalg; |
|
/* #i -> t#i */ |
|
if ( nalg ) { |
|
preprocess_algcoef(vv,av,ord,f,&ord1,&f1,&alist); |
|
ord = ord1; |
|
f = f1; |
|
} |
|
nvar += nalg; |
|
} |
nd_init_ord(ord); |
nd_init_ord(ord); |
for ( t = BDY(f), max = 0; t; t = NEXT(t) ) |
for ( t = BDY(f), max = 0; t; t = NEXT(t) ) |
for ( tv = vv; tv; tv = NEXT(tv) ) { |
for ( tv = vv; tv; tv = NEXT(tv) ) { |
Line 2227 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 2406 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
BDY(r) = ndvtop(m,CO,vv,BDY(t)); |
BDY(r) = ndvtop(m,CO,vv,BDY(t)); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
|
if ( nalg ) |
|
r0 = postprocess_algcoef(av,alist,r0); |
MKLIST(*rp,r0); |
MKLIST(*rp,r0); |
#if 0 |
#if 0 |
fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); |
fprintf(asir_out,"ndv_alloc=%d\n",ndv_alloc); |
#endif |
#endif |
} |
} |
|
|
void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp) |
void nd_gr_postproc(LIST f,LIST v,int m,struct order_spec *ord,int do_check,LIST *rp) |
{ |
{ |
|
VL tv,fv,vv,vc,av; |
|
NODE fd,fd0,r,r0,t,x,s,xx,alist; |
|
int e,max,nvar,i; |
|
NDV b; |
|
int ishomo,nalg; |
|
Alg alpha,dp; |
|
P p; |
|
LIST f1,f2; |
|
Obj obj; |
|
NumberField nf; |
struct order_spec *ord1; |
struct order_spec *ord1; |
VL tv,fv,vv,vc; |
|
NODE fd,fd0,in0,in,r,r0,t,s,cand; |
get_vars((Obj)f,&fv); pltovl(v,&vv); |
|
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
|
switch ( ord->id ) { |
|
case 1: |
|
if ( ord->nv != nvar ) |
|
error("nd_check : invalid order specification"); |
|
break; |
|
default: |
|
break; |
|
} |
|
nd_nalg = 0; |
|
av = 0; |
|
if ( !m ) { |
|
get_algtree((Obj)f,&av); |
|
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ ); |
|
nd_ntrans = nvar; |
|
nd_nalg = nalg; |
|
/* #i -> t#i */ |
|
if ( nalg ) { |
|
preprocess_algcoef(vv,av,ord,f,&ord1,&f1,&alist); |
|
ord = ord1; |
|
f = f1; |
|
} |
|
nvar += nalg; |
|
} |
|
nd_init_ord(ord); |
|
for ( t = BDY(f), max = 0; t; t = NEXT(t) ) |
|
for ( tv = vv; tv; tv = NEXT(tv) ) { |
|
e = getdeg(tv->v,(P)BDY(t)); |
|
max = MAX(e,max); |
|
} |
|
nd_setup_parameters(nvar,max); |
|
ishomo = 1; |
|
for ( fd0 = 0, t = BDY(f); t; t = NEXT(t) ) { |
|
b = (pointer)ptondv(CO,vv,(P)BDY(t)); |
|
if ( ishomo ) |
|
ishomo = ishomo && ndv_ishomo(b); |
|
if ( m ) ndv_mod(m,b); |
|
if ( b ) { NEXTNODE(fd0,fd); BDY(fd) = (pointer)b; } |
|
} |
|
if ( fd0 ) NEXT(fd) = 0; |
|
ndv_setup(m,0,fd0); |
|
for ( x = 0, i = 0; i < nd_psn; i++ ) |
|
x = update_base(x,i); |
|
if ( do_check ) { |
|
x = nd_gb(m,ishomo,1); |
|
if ( !x ) { |
|
*rp = 0; |
|
return; |
|
} |
|
} else { |
|
for ( t = x; t; t = NEXT(t) ) |
|
BDY(t) = (pointer)nd_ps[(int)BDY(t)]; |
|
} |
|
x = ndv_reducebase(x); |
|
x = ndv_reduceall(m,x); |
|
for ( r0 = 0, t = x; t; t = NEXT(t) ) { |
|
NEXTNODE(r0,r); |
|
BDY(r) = ndvtop(m,CO,vv,BDY(t)); |
|
} |
|
if ( r0 ) NEXT(r) = 0; |
|
if ( nalg ) |
|
r0 = postprocess_algcoef(av,alist,r0); |
|
MKLIST(*rp,r0); |
|
} |
|
|
|
void nd_gr_trace(LIST f,LIST v,int trace,int homo,struct order_spec *ord,LIST *rp) |
|
{ |
|
VL tv,fv,vv,vc,av; |
|
NODE fd,fd0,in0,in,r,r0,t,s,cand,alist; |
int m,nocheck,nvar,mindex,e,max; |
int m,nocheck,nvar,mindex,e,max; |
NDV c; |
NDV c; |
NMV a; |
NMV a; |
P p; |
P p; |
EPOS oepos; |
EPOS oepos; |
int obpe,oadv,wmax,i,len,cbpe,ishomo; |
int obpe,oadv,wmax,i,len,cbpe,ishomo,nalg; |
|
Alg alpha,dp; |
|
P poly; |
|
LIST f1,f2; |
|
Obj obj; |
|
NumberField nf; |
|
struct order_spec *ord1; |
|
|
get_vars((Obj)f,&fv); pltovl(v,&vv); |
get_vars((Obj)f,&fv); pltovl(v,&vv); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
Line 2255 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2521 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
default: |
default: |
break; |
break; |
} |
} |
|
|
|
get_algtree((Obj)f,&av); |
|
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ ); |
|
nd_ntrans = nvar; |
|
nd_nalg = nalg; |
|
/* #i -> t#i */ |
|
if ( nalg ) { |
|
preprocess_algcoef(vv,av,ord,f,&ord1,&f1,&alist); |
|
ord = ord1; |
|
f = f1; |
|
} |
|
nvar += nalg; |
|
|
nocheck = 0; |
nocheck = 0; |
mindex = 0; |
mindex = 0; |
|
|
Line 2288 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2567 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
if ( in0 ) NEXT(in) = 0; |
if ( in0 ) NEXT(in) = 0; |
if ( fd0 ) NEXT(fd) = 0; |
if ( fd0 ) NEXT(fd) = 0; |
if ( !ishomo && homo ) { |
if ( !ishomo && homo ) { |
for ( t = in0, wmax = 0; t; t = NEXT(t) ) { |
for ( t = in0, wmax = max; t; t = NEXT(t) ) { |
c = (NDV)BDY(t); len = LEN(c); |
c = (NDV)BDY(t); len = LEN(c); |
for ( a = BDY(c), i = 0; i < len; i++, NMV_ADV(a) ) |
for ( a = BDY(c), i = 0; i < len; i++, NMV_ADV(a) ) |
wmax = MAX(TD(DL(a)),wmax); |
wmax = MAX(TD(DL(a)),wmax); |
Line 2344 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2623 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
/* dp->p */ |
/* dp->p */ |
nd_bpe = cbpe; |
nd_bpe = cbpe; |
nd_setup_parameters(nd_nvar,0); |
nd_setup_parameters(nd_nvar,0); |
for ( r = cand; r; r = NEXT(r) ) BDY(r) = (pointer)ndvtop(0,CO,vv,BDY(r)); |
for ( r = cand; r; r = NEXT(r) ) |
|
BDY(r) = (pointer)ndvtop(0,CO,vv,BDY(r)); |
|
if ( nalg ) |
|
cand = postprocess_algcoef(av,alist,cand); |
MKLIST(*rp,cand); |
MKLIST(*rp,cand); |
} |
} |
|
|
Line 2579 void removecont_array(Q *c,int n) |
|
Line 2861 void removecont_array(Q *c,int n) |
|
{ |
{ |
struct oVECT v; |
struct oVECT v; |
Q d0,d1,a,u,u1,gcd; |
Q d0,d1,a,u,u1,gcd; |
int i; |
int i,j; |
N qn,rn,gn; |
N qn,rn,gn; |
Q *q,*r; |
Q *q,*r; |
|
|
Line 2616 void nd_mul_c(int mod,ND p,int mul) |
|
Line 2898 void nd_mul_c(int mod,ND p,int mul) |
|
int c,c1; |
int c,c1; |
|
|
if ( !p ) return; |
if ( !p ) return; |
|
if ( mul == 1 ) return; |
if ( mod == -1 ) |
if ( mod == -1 ) |
for ( m = BDY(p); m; m = NEXT(m) ) |
for ( m = BDY(p); m; m = NEXT(m) ) |
CM(m) = _mulsf(CM(m),mul); |
CM(m) = _mulsf(CM(m),mul); |
Line 2631 void nd_mul_c_q(ND p,Q mul) |
|
Line 2914 void nd_mul_c_q(ND p,Q mul) |
|
Q c; |
Q c; |
|
|
if ( !p ) return; |
if ( !p ) return; |
|
if ( UNIQ(mul) ) return; |
for ( m = BDY(p); m; m = NEXT(m) ) { |
for ( m = BDY(p); m; m = NEXT(m) ) { |
mulq(CQ(m),mul,&c); CQ(m) = c; |
mulq(CQ(m),mul,&c); CQ(m) = c; |
} |
} |
Line 3211 ND nd_quo(int mod,PGeoBucket bucket,NDV d) |
|
Line 3495 ND nd_quo(int mod,PGeoBucket bucket,NDV d) |
|
ND p,t,r; |
ND p,t,r; |
N tnm; |
N tnm; |
|
|
if ( !p ) return 0; |
if ( bucket->m < 0 ) return 0; |
else { |
else { |
nv = NV(d); |
nv = NV(d); |
mq0 = 0; |
mq0 = 0; |
Line 3332 ND nd_dup(ND p) |
|
Line 3616 ND nd_dup(ND p) |
|
void ndv_mod(int mod,NDV p) |
void ndv_mod(int mod,NDV p) |
{ |
{ |
NMV t,d; |
NMV t,d; |
int r; |
int r,s,u; |
int i,len,dlen; |
int i,len,dlen; |
Obj gfs; |
Obj gfs; |
|
|
Line 3354 void ndv_mod(int mod,NDV p) |
|
Line 3638 void ndv_mod(int mod,NDV p) |
|
if ( r ) { |
if ( r ) { |
if ( SGN(CQ(t)) < 0 ) |
if ( SGN(CQ(t)) < 0 ) |
r = mod-r; |
r = mod-r; |
|
if ( DN(CQ(t)) ) { |
|
s = rem(DN(CQ(t)),mod); |
|
if ( !s ) |
|
error("ndv_mod : division by 0"); |
|
s = invm(s,mod); |
|
DMAR(r,s,0,mod,u); r = u; |
|
} |
CM(d) = r; |
CM(d) = r; |
ndl_copy(DL(t),DL(d)); |
ndl_copy(DL(t),DL(d)); |
NMV_ADV(d); |
NMV_ADV(d); |
Line 3709 void nd_nf_p(P f,LIST g,LIST v,int m,struct order_spec |
|
Line 4000 void nd_nf_p(P f,LIST g,LIST v,int m,struct order_spec |
|
int stat,nvar,max,e; |
int stat,nvar,max,e; |
union oNDC dn; |
union oNDC dn; |
|
|
|
if ( !f ) { |
|
*rp = 0; |
|
return; |
|
} |
pltovl(v,&vv); |
pltovl(v,&vv); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++ ); |
|
|
Line 3785 int nd_to_vect_q(UINT *s0,int n,ND d,Q *r) |
|
Line 4080 int nd_to_vect_q(UINT *s0,int n,ND d,Q *r) |
|
return i; |
return i; |
} |
} |
|
|
int nm_ind_pair_to_vect(int mod,UINT *s0,int n,NM_ind_pair pair,UINT *r) |
|
{ |
|
NM m; |
|
NMV mr; |
|
UINT *d,*t,*s; |
|
NDV p; |
|
int i,j,len; |
|
|
|
m = pair->mul; |
|
d = DL(m); |
|
p = nd_ps[pair->index]; |
|
t = (UINT *)ALLOCA(nd_wpd*sizeof(UINT)); |
|
for ( i = 0; i < n; i++ ) r[i] = 0; |
|
len = LEN(p); |
|
for ( i = j = 0, s = s0, mr = BDY(p); j < len; j++, NMV_ADV(mr) ) { |
|
ndl_add(d,DL(mr),t); |
|
for ( ; !ndl_equal(t,s); s += nd_wpd, i++ ); |
|
r[i] = CM(mr); |
|
} |
|
for ( i = 0; !r[i]; i++ ); |
|
return i; |
|
} |
|
|
|
IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0,int n,NM_ind_pair pair) |
IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0,int n,NM_ind_pair pair) |
{ |
{ |
NM m; |
NM m; |
Line 3860 IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0 |
|
Line 4132 IndArray nm_ind_pair_to_vect_compress(int mod,UINT *s0 |
|
int ndv_reduce_vect_q(Q *svect,int col,IndArray *imat,NM_ind_pair *rp0,int nred) |
int ndv_reduce_vect_q(Q *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; |
Q cs,mcs,c1,c2,cr,gcd; |
Q cs,mcs,c1,c2,cr,gcd,t; |
IndArray ivect; |
IndArray ivect; |
unsigned char *ivc; |
unsigned char *ivc; |
unsigned short *ivs; |
unsigned short *ivs; |
Line 3880 int ndv_reduce_vect_q(Q *svect,int col,IndArray *imat, |
|
Line 4152 int ndv_reduce_vect_q(Q *svect,int col,IndArray *imat, |
|
len = LEN(redv); mr = BDY(redv); |
len = LEN(redv); mr = BDY(redv); |
igcd_cofactor(svect[k],CQ(mr),&gcd,&cs,&cr); |
igcd_cofactor(svect[k],CQ(mr),&gcd,&cs,&cr); |
chsgnq(cs,&mcs); |
chsgnq(cs,&mcs); |
|
if ( !UNIQ(cr) ) { |
|
for ( j = 0; j < col; j++ ) { |
|
mulq(svect[j],cr,&c1); svect[j] = c1; |
|
} |
|
} |
svect[k] = 0; prev = k; |
svect[k] = 0; prev = k; |
switch ( ivect->width ) { |
switch ( ivect->width ) { |
case 1: |
case 1: |
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]; prev = pos; |
pos = prev+ivc[j]; prev = pos; |
mulq(svect[pos],cr,&c1); mulq(CQ(mr),mcs,&c2); addq(c1,c2,&svect[pos]); |
mulq(CQ(mr),mcs,&c2); addq(svect[pos],c2,&t); svect[pos] = t; |
} |
} |
break; |
break; |
case 2: |
case 2: |
ivs = ivect->index.s; |
ivs = ivect->index.s; |
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]; prev = pos; |
pos = prev+ivs[j]; prev = pos; |
mulq(svect[pos],cr,&c1); mulq(CQ(mr),mcs,&c2); addq(c1,c2,&svect[pos]); |
mulq(CQ(mr),mcs,&c2); addq(svect[pos],c2,&t); svect[pos] = t; |
} |
} |
break; |
break; |
case 4: |
case 4: |
ivi = ivect->index.i; |
ivi = ivect->index.i; |
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]; prev = pos; |
pos = prev+ivi[j]; prev = pos; |
mulq(svect[pos],cr,&c1); mulq(CQ(mr),mcs,&c2); addq(c1,c2,&svect[pos]); |
mulq(CQ(mr),mcs,&c2); addq(svect[pos],c2,&t); svect[pos] = t; |
} |
} |
break; |
break; |
} |
} |
Line 4059 NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead |
|
Line 4336 NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead |
|
for ( j = 0, len = 0; j < spcol; j++ ) if ( vect[j] ) len++; |
for ( j = 0, len = 0; j < spcol; j++ ) if ( vect[j] ) len++; |
if ( !len ) return 0; |
if ( !len ) return 0; |
else { |
else { |
mr0 = (NMV)GC_malloc_atomic_ignore_off_page(nmv_adv*len); |
mr0 = (NMV)GC_malloc(nmv_adv*len); |
#if 0 |
#if 0 |
ndv_alloc += nmv_adv*len; |
ndv_alloc += nmv_adv*len; |
#endif |
#endif |
Line 4068 NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead |
|
Line 4345 NDV vect_to_ndv_q(Q *vect,int spcol,int col,int *rhead |
|
for ( j = k = 0; j < col; j++, p += nd_wpd ) |
for ( j = k = 0; j < col; j++, p += nd_wpd ) |
if ( !rhead[j] ) { |
if ( !rhead[j] ) { |
if ( c = vect[k++] ) { |
if ( c = vect[k++] ) { |
|
if ( DN(c) ) |
|
error("afo"); |
ndl_copy(p,DL(mr)); CQ(mr) = c; NMV_ADV(mr); |
ndl_copy(p,DL(mr)); CQ(mr) = c; NMV_ADV(mr); |
} |
} |
} |
} |
Line 4155 NODE nd_f4(int m) |
|
Line 4434 NODE nd_f4(int m) |
|
PGeoBucket bucket; |
PGeoBucket bucket; |
struct oEGT eg0,eg1,eg_f4; |
struct oEGT eg0,eg1,eg_f4; |
|
|
if ( !m ) |
|
error("nd_f4 : not implemented"); |
|
#if 0 |
#if 0 |
ndv_alloc = 0; |
ndv_alloc = 0; |
#endif |
#endif |
Line 4298 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
Line 4575 NODE nd_f4_red_main(int m,ND_pairs sp0,int nsp,UINT *s |
|
SG((NDV)BDY(r)) = spsugar[i]; |
SG((NDV)BDY(r)) = spsugar[i]; |
GC_free(spmat[i]); |
GC_free(spmat[i]); |
} |
} |
|
if ( r0 ) NEXT(r) = 0; |
for ( ; i < sprow; i++ ) GC_free(spmat[i]); |
for ( ; i < sprow; i++ ) GC_free(spmat[i]); |
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); |
Line 4328 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec |
|
Line 4606 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec |
|
spcol = col-nred; |
spcol = col-nred; |
get_eg(&eg0); |
get_eg(&eg0); |
/* elimination (1st step) */ |
/* elimination (1st step) */ |
spmat = (Q **)ALLOCA(nsp*sizeof(UINT *)); |
spmat = (Q **)ALLOCA(nsp*sizeof(Q *)); |
svect = (Q *)ALLOCA(col*sizeof(UINT)); |
svect = (Q *)ALLOCA(col*sizeof(Q)); |
spsugar = (int *)ALLOCA(nsp*sizeof(UINT)); |
spsugar = (int *)ALLOCA(nsp*sizeof(Q)); |
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
for ( a = sprow = 0, sp = sp0; a < nsp; a++, sp = NEXT(sp) ) { |
nd_sp(0,0,sp,&spol); |
nd_sp(0,0,sp,&spol); |
if ( !spol ) continue; |
if ( !spol ) continue; |
Line 4338 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec |
|
Line 4616 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec |
|
maxrs = ndv_reduce_vect_q(svect,col,imat,rvect,nred); |
maxrs = ndv_reduce_vect_q(svect,col,imat,rvect,nred); |
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 = (Q *)MALLOC_ATOMIC(spcol*sizeof(Q)); |
spmat[sprow] = v = (Q *)MALLOC(spcol*sizeof(Q)); |
for ( j = k = 0; j < col; j++ ) |
for ( j = k = 0; j < col; j++ ) |
if ( !rhead[j] ) v[k++] = svect[j]; |
if ( !rhead[j] ) v[k++] = svect[j]; |
spsugar[sprow] = MAX(maxrs,SG(spol)); |
spsugar[sprow] = MAX(maxrs,SG(spol)); |
sprow++; |
sprow++; |
} |
} |
nd_free(spol); |
/* nd_free(spol); */ |
} |
} |
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 ) { |
Line 4352 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec |
|
Line 4630 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec |
|
fflush(asir_out); |
fflush(asir_out); |
} |
} |
/* free index arrays */ |
/* free index arrays */ |
for ( i = 0; i < nred; i++ ) GC_free(imat[i]->index.c); |
/* for ( i = 0; i < nred; i++ ) GC_free(imat[i]->index.c); */ |
|
|
/* elimination (2nd step) */ |
/* elimination (2nd step) */ |
colstat = (int *)ALLOCA(spcol*sizeof(int)); |
colstat = (int *)ALLOCA(spcol*sizeof(int)); |
Line 4362 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec |
|
Line 4640 NODE nd_f4_red_q_main(ND_pairs sp0,int nsp,UINT *s0vec |
|
NEXTNODE(r0,r); BDY(r) = |
NEXTNODE(r0,r); BDY(r) = |
(pointer)vect_to_ndv_q(spmat[i],spcol,col,rhead,s0vect); |
(pointer)vect_to_ndv_q(spmat[i],spcol,col,rhead,s0vect); |
SG((NDV)BDY(r)) = spsugar[i]; |
SG((NDV)BDY(r)) = spsugar[i]; |
GC_free(spmat[i]); |
/* GC_free(spmat[i]); */ |
} |
} |
for ( ; i < sprow; i++ ) GC_free(spmat[i]); |
if ( r0 ) NEXT(r) = 0; |
|
|
|
/* for ( ; i < sprow; i++ ) GC_free(spmat[i]); */ |
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 ) { |
Line 4634 void nd_exec_f4_red_dist() |
|
Line 4914 void nd_exec_f4_red_dist() |
|
|
|
int nd_gauss_elim_q(Q **mat0,int *sugar,int row,int col,int *colstat) |
int nd_gauss_elim_q(Q **mat0,int *sugar,int row,int col,int *colstat) |
{ |
{ |
|
int mod,i,j,t,c,rank,rank0,inv; |
|
int *ci,*ri; |
|
Q dn; |
|
MAT m,nm; |
|
int **wmat; |
|
|
|
/* XXX */ |
|
mod = 99999989; |
|
wmat = (int **)ALLOCA(row*sizeof(int *)); |
|
for ( i = 0; i < row; i++ ) { |
|
wmat[i] = (int *)ALLOCA(col*sizeof(int)); |
|
for ( j = 0; j < col; j++ ) { |
|
if ( mat0[i][j] ) { |
|
t = rem(NM(mat0[i][j]),mod); |
|
if ( SGN(mat0[i][j]) < 0 ) t = mod-t; |
|
wmat[i][j] = t; |
|
} else |
|
wmat[i][j] = 0; |
|
} |
|
} |
|
rank0 = nd_gauss_elim_mod(wmat,sugar,row,col,mod,colstat); |
|
NEWMAT(m); m->row = row; m->col = col; m->body = (pointer **)mat0; |
|
rank = generic_gauss_elim(m,&nm,&dn,&ri,&ci); |
|
if ( rank != rank0 ) |
|
error("afo"); |
|
for ( i = 0; i < row; i++ ) |
|
for ( j = 0; j < col; j++ ) |
|
mat0[i][j] = 0; |
|
c = col-rank; |
|
for ( i = 0; i < rank; i++ ) { |
|
mat0[i][ri[i]] = dn; |
|
for ( j = 0; j < c; j++ ) |
|
mat0[i][ci[j]] = (Q)BDY(nm)[i][j]; |
|
} |
|
inv = invm(rem(NM(dn),mod),mod); |
|
if ( SGN(dn) < 0 ) inv = mod-inv; |
|
for ( i = 0; i < row; i++ ) |
|
for ( j = 0; j < col; j++ ) { |
|
if ( mat0[i][j] ) { |
|
t = rem(NM(mat0[i][j]),mod); |
|
if ( SGN(mat0[i][j]) < 0 ) t = mod-t; |
|
} else |
|
t = 0; |
|
c = dmar(t,inv,0,mod); |
|
if ( wmat[i][j] != c ) |
|
error("afo"); |
|
} |
|
return rank; |
} |
} |
|
|
int nd_gauss_elim_mod(int **mat0,int *sugar,int row,int col,int md,int *colstat) |
int nd_gauss_elim_mod(int **mat0,int *sugar,int row,int col,int md,int *colstat) |
Line 4849 void nd_det(int mod,MAT f,P *rp) |
|
Line 5177 void nd_det(int mod,MAT f,P *rp) |
|
int n,i,j,max,e,nvar,sgn,k0,l0,len0,len,k,l,a; |
int n,i,j,max,e,nvar,sgn,k0,l0,len0,len,k,l,a; |
pointer **m; |
pointer **m; |
Q mone; |
Q mone; |
|
P **w; |
|
P mp,r; |
NDV **dm; |
NDV **dm; |
NDV *t,*mi,*mj; |
NDV *t,*mi,*mj; |
NDV d,s,mij,mjj; |
NDV d,s,mij,mjj; |
ND u; |
ND u; |
NMV nmv; |
NMV nmv; |
|
UINT *bound; |
PGeoBucket bucket; |
PGeoBucket bucket; |
struct order_spec *ord; |
struct order_spec *ord; |
|
Q dq,dt,ds; |
|
N gn,qn,dn0,nm,dn; |
|
|
create_order_spec(0,0,&ord); |
create_order_spec(0,0,&ord); |
nd_init_ord(ord); |
nd_init_ord(ord); |
Line 4863 void nd_det(int mod,MAT f,P *rp) |
|
Line 5196 void nd_det(int mod,MAT f,P *rp) |
|
if ( f->row != f->col ) |
if ( f->row != f->col ) |
error("nd_det : non-square matrix"); |
error("nd_det : non-square matrix"); |
n = f->row; |
n = f->row; |
for ( nvar = 0, tv = fv; tv; tv = NEXT(tv), nvar++ ); |
|
m = f->body; |
m = f->body; |
|
for ( nvar = 0, tv = fv; tv; tv = NEXT(tv), nvar++ ); |
|
|
|
if ( !nvar ) { |
|
if ( !mod ) |
|
detp(CO,(P **)m,n,rp); |
|
else { |
|
w = (P **)almat_pointer(n,n); |
|
for ( i = 0; i < n; i++ ) |
|
for ( j = 0; j < n; j++ ) |
|
ptomp(mod,(P)m[i][j],&w[i][j]); |
|
detmp(CO,mod,w,n,&mp); |
|
mptop(mp,rp); |
|
} |
|
return; |
|
} |
|
|
|
if ( !mod ) { |
|
w = (P **)almat_pointer(n,n); |
|
dq = ONE; |
|
for ( i = 0; i < n; i++ ) { |
|
dn0 = ONEN; |
|
for ( j = 0; j < n; j++ ) { |
|
if ( !m[i][j] ) continue; |
|
lgp(m[i][j],&nm,&dn); |
|
gcdn(dn0,dn,&gn); divsn(dn0,gn,&qn); muln(qn,dn,&dn0); |
|
} |
|
if ( !UNIN(dn0) ) { |
|
NTOQ(dn0,1,ds); |
|
for ( j = 0; j < n; j++ ) |
|
mulp(CO,(P)m[i][j],(P)ds,&w[i][j]); |
|
mulq(dq,ds,&dt); dq = dt; |
|
} else |
|
for ( j = 0; j < n; j++ ) |
|
w[i][j] = (P)m[i][j]; |
|
} |
|
m = (pointer **)w; |
|
} |
|
|
for ( i = 0, max = 0; i < n; i++ ) |
for ( i = 0, max = 0; i < n; i++ ) |
for ( j = 0; j < n; j++ ) |
for ( j = 0; j < n; j++ ) |
for ( tv = fv; tv; tv = NEXT(tv) ) { |
for ( tv = fv; tv; tv = NEXT(tv) ) { |
e = getdeg(tv->v,(P)m[i][j]); |
e = getdeg(tv->v,(P)m[i][j]); |
max = MAX(e,max); |
max = MAX(e,max); |
} |
} |
nd_setup_parameters(nvar,1024); |
nd_setup_parameters(nvar,max); |
dm = (NDV **)almat_pointer(n,n); |
dm = (NDV **)almat_pointer(n,n); |
for ( i = 0, max = 0; i < n; i++ ) |
for ( i = 0, max = 0; i < n; i++ ) |
for ( j = 0; j < n; j++ ) { |
for ( j = 0; j < n; j++ ) { |
Line 4883 void nd_det(int mod,MAT f,P *rp) |
|
Line 5253 void nd_det(int mod,MAT f,P *rp) |
|
if ( mod ) ndv_mod(mod,d); |
if ( mod ) ndv_mod(mod,d); |
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 ) fprintf(stderr,"j=%d\n",j); |
if ( DP_Print ) fprintf(stderr,".",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 ) { |
*rp = 0; |
*rp = 0; |
Line 4905 void nd_det(int mod,MAT f,P *rp) |
|
Line 5275 void nd_det(int mod,MAT f,P *rp) |
|
} |
} |
sgn = -sgn; |
sgn = -sgn; |
} |
} |
|
bound = nd_det_compute_bound(dm,n,j); |
|
if ( ndl_check_bound(bound,bound) ) |
|
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(stderr," 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(stderr,"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 4932 void nd_det(int mod,MAT f,P *rp) |
|
Line 5306 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(stderr,"\n",k); */ |
} |
} |
d = mjj; |
d = mjj; |
} |
} |
|
if ( DP_Print ) fprintf(stderr,"\n",k); |
if ( sgn < 0 ) |
if ( sgn < 0 ) |
if ( mod ) |
if ( mod ) |
ndv_mul_c(mod,d,mod-1); |
ndv_mul_c(mod,d,mod-1); |
else |
else |
ndv_mul_c_q(d,mone); |
ndv_mul_c_q(d,mone); |
*rp = ndvtop(mod,CO,fv,d); |
r = ndvtop(mod,CO,fv,d); |
|
if ( !mod && !UNIQ(dq) ) |
|
divsp(CO,r,(P)dq,rp); |
|
else |
|
*rp = r; |
} |
} |
|
|
ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
Line 4992 ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
|
Line 5371 ND ndv_mul_nmv_trunc(int mod,NMV m0,NDV p,UINT *d) |
|
return r; |
return r; |
} |
} |
} |
} |
|
} |
|
|
|
void nd_det_reconstruct(NDV **dm,int n,int j,NDV d) |
|
{ |
|
int i,obpe,oadv,h,k,l; |
|
static NM prev_nm_free_list; |
|
EPOS oepos; |
|
|
|
obpe = nd_bpe; |
|
oadv = nmv_adv; |
|
oepos = nd_epos; |
|
if ( obpe < 2 ) nd_bpe = 2; |
|
else if ( obpe < 3 ) nd_bpe = 3; |
|
else if ( obpe < 4 ) nd_bpe = 4; |
|
else if ( obpe < 5 ) nd_bpe = 5; |
|
else if ( obpe < 6 ) nd_bpe = 6; |
|
else if ( obpe < 8 ) nd_bpe = 8; |
|
else if ( obpe < 10 ) nd_bpe = 10; |
|
else if ( obpe < 16 ) nd_bpe = 16; |
|
else if ( obpe < 32 ) nd_bpe = 32; |
|
else error("nd_det_reconstruct : exponent too large"); |
|
|
|
nd_setup_parameters(nd_nvar,0); |
|
prev_nm_free_list = _nm_free_list; |
|
_nm_free_list = 0; |
|
for ( k = j; k < n; k++ ) |
|
for (l = j; l < n; l++ ) |
|
ndv_realloc(dm[k][l],obpe,oadv,oepos); |
|
ndv_realloc(d,obpe,oadv,oepos); |
|
prev_nm_free_list = 0; |
|
#if 0 |
|
GC_gcollect(); |
|
#endif |
|
} |
|
|
|
UINT *nd_det_compute_bound(NDV **dm,int n,int j) |
|
{ |
|
UINT *d0,*d1,*d,*t,*r; |
|
int k,l; |
|
|
|
d0 = (UINT *)ALLOCA(nd_wpd*sizeof(UINT)); |
|
d1 = (UINT *)ALLOCA(nd_wpd*sizeof(UINT)); |
|
for ( k = 0; k < nd_wpd; k++ ) d0[k] = 0; |
|
for ( k = j; k < n; k++ ) |
|
for ( l = j; l < n; l++ ) |
|
if ( dm[k][l] ) { |
|
d = ndv_compute_bound(dm[k][l]); |
|
ndl_lcm(d,d0,d1); |
|
t = d1; d1 = d0; d0 = t; |
|
} |
|
r = (UINT *)ALLOCA(nd_wpd*sizeof(UINT)); |
|
for ( k = 0; k < nd_wpd; k++ ) r[k] = d0[k]; |
|
return r; |
|
} |
|
|
|
DL nd_separate_d(UINT *d,UINT *trans) |
|
{ |
|
int n,td,i,e,j; |
|
DL a; |
|
|
|
ndl_zero(trans); |
|
td = 0; |
|
for ( i = 0; i < nd_ntrans; i++ ) { |
|
e = GET_EXP(d,i); |
|
PUT_EXP(trans,i,e); |
|
td += MUL_WEIGHT(e,i); |
|
} |
|
if ( nd_ntrans+nd_nalg < nd_nvar ) { |
|
/* homogenized */ |
|
i = nd_nvar-1; |
|
e = GET_EXP(d,i); |
|
PUT_EXP(trans,i,e); |
|
td += MUL_WEIGHT(e,i); |
|
} |
|
TD(trans) = td; |
|
if ( nd_blockmask) ndl_weight_mask(trans); |
|
NEWDL(a,nd_nalg); |
|
td = 0; |
|
for ( i = 0; i < nd_nalg; i++ ) { |
|
j = nd_ntrans+i; |
|
e = GET_EXP(d,j); |
|
a->d[i] = e; |
|
td += e; |
|
} |
|
a->td = td; |
|
return a; |
|
} |
|
|
|
int nd_monic(int mod,ND *p) |
|
{ |
|
UINT *trans,*t; |
|
DL alg; |
|
MP mp0,mp; |
|
NM m,m0,m1,ma0,ma,mb,mr0,mr; |
|
ND r; |
|
DL dl; |
|
DP nm; |
|
NDV ndv; |
|
DAlg inv,cd; |
|
ND s,c; |
|
Q l,mul; |
|
N ln; |
|
int n,ntrans,i,e,td,is_lc,len; |
|
NumberField nf; |
|
struct oEGT eg0,eg1; |
|
|
|
if ( !(nf = get_numberfield()) ) |
|
error("nd_monic : current_numberfield is not set"); |
|
|
|
/* Q coef -> DAlg coef */ |
|
NEWNM(ma0); ma = ma0; |
|
m = BDY(*p); |
|
is_lc = 1; |
|
while ( 1 ) { |
|
NEWMP(mp0); mp = mp0; |
|
mp->c = (P)CQ(m); |
|
mp->dl = nd_separate_d(DL(m),DL(ma)); |
|
NEWNM(mb); |
|
for ( m = NEXT(m); m; m = NEXT(m) ) { |
|
alg = nd_separate_d(DL(m),DL(mb)); |
|
if ( !ndl_equal(DL(ma),DL(mb)) ) |
|
break; |
|
NEXTMP(mp0,mp); mp->c = (P)CQ(m); mp->dl = alg; |
|
} |
|
NEXT(mp) = 0; |
|
MKDP(nd_nalg,mp0,nm); |
|
MKDAlg(nm,ONE,cd); |
|
if ( is_lc == 1 ) { |
|
/* if the lc is a rational number, we have nothing to do */ |
|
if ( !mp0->dl->td ) |
|
return 1; |
|
|
|
get_eg(&eg0); |
|
invdalg(cd,&inv); |
|
get_eg(&eg1); add_eg(&eg_invdalg,&eg0,&eg1); |
|
/* check the validity of inv */ |
|
if ( mod && !rem(NM(inv->dn),mod) ) |
|
return 0; |
|
CA(ma) = nf->one; |
|
is_lc = 0; |
|
ln = ONEN; |
|
} else { |
|
muldalg(cd,inv,&CA(ma)); |
|
lcmn(ln,NM(CA(ma)->dn),&ln); |
|
} |
|
if ( m ) { |
|
NEXT(ma) = mb; ma = mb; |
|
} else { |
|
NEXT(ma) = 0; |
|
break; |
|
} |
|
} |
|
/* l = lcm(denoms) */ |
|
NTOQ(ln,1,l); |
|
for ( mr0 = 0, m = ma0; m; m = NEXT(m) ) { |
|
divq(l,CA(m)->dn,&mul); |
|
for ( mp = BDY(CA(m)->nm); mp; mp = NEXT(mp) ) { |
|
NEXTNM(mr0,mr); |
|
mulq((Q)mp->c,mul,&CQ(mr)); |
|
dl = mp->dl; |
|
td = TD(DL(m)); |
|
ndl_copy(DL(m),DL(mr)); |
|
for ( i = 0; i < nd_nalg; i++ ) { |
|
e = dl->d[i]; |
|
PUT_EXP(DL(mr),i+nd_ntrans,e); |
|
td += MUL_WEIGHT(e,i+nd_ntrans); |
|
} |
|
TD(DL(mr)) = td; |
|
if ( nd_blockmask) ndl_weight_mask(DL(mr)); |
|
} |
|
} |
|
NEXT(mr) = 0; |
|
for ( len = 0, mr = mr0; mr; mr = NEXT(mr), len++ ); |
|
MKND(NV(*p),mr0,len,r); |
|
/* XXX */ |
|
SG(r) = SG(*p); |
|
nd_free(*p); |
|
*p = r; |
|
return 1; |
} |
} |