version 1.120, 2004/12/07 15:15:52 |
version 1.123, 2005/01/23 14:03:48 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.119 2004/12/06 09:29:34 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.122 2004/12/09 13:20:33 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; |
static int nd_nalg; |
#if 0 |
#if 0 |
static int ndv_alloc; |
static int ndv_alloc; |
Line 1536 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 1552 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 1573 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 1598 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); |
} |
} |
|
|
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 1658 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 1671 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 1690 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; |
static struct oEGT eg_invdalg; |
Line 1720 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); |
} |
} |
Line 2214 void ndv_setup(int mod,int trace,NODE f) |
|
Line 2233 void ndv_setup(int mod,int trace,NODE f) |
|
struct order_spec *append_block(struct order_spec *spec, |
struct order_spec *append_block(struct order_spec *spec, |
int nv,int nalg,int ord); |
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, |
void preprocess_algcoef(VL vv,VL av,struct order_spec *ord,LIST f, |
struct order_spec **ord1p,LIST *f1p,NODE *alistp) |
struct order_spec **ord1p,LIST *f1p,NODE *alistp) |
{ |
{ |
NODE alist,t,s,r0,r; |
NODE alist,t,s,r0,r,arg; |
VL tv; |
VL tv; |
P poly; |
P poly; |
DP d; |
DP d; |
Alg alpha,dp; |
Alg alpha,dp; |
DAlg inv,da,hc; |
DAlg inv,da,hc; |
MP m; |
MP m; |
int i,nvar,nalg; |
int i,nvar,nalg,n; |
NumberField nf; |
NumberField nf; |
LIST f1,f2; |
LIST f1,f2; |
struct order_spec *current_spec; |
struct order_spec *current_spec; |
|
VECT obj,obj0; |
|
Obj tmp; |
|
|
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++); |
for ( nvar = 0, tv = vv; tv; tv = NEXT(tv), nvar++); |
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++); |
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++); |
Line 2271 void preprocess_algcoef(VL vv,VL av,struct order_spec |
|
Line 2295 void preprocess_algcoef(VL vv,VL av,struct order_spec |
|
MKLIST(f1,t); |
MKLIST(f1,t); |
*alistp = alist; |
*alistp = alist; |
algobjtorat(f1,f1p); |
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,av; |
VL tv,fv,vv,vc,av; |
Line 2304 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 2366 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
break; |
break; |
} |
} |
nd_nalg = 0; |
nd_nalg = 0; |
|
av = 0; |
if ( !m ) { |
if ( !m ) { |
get_algtree((Obj)f,&av); |
get_algtree((Obj)f,&av); |
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ ); |
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ ); |
|
nd_ntrans = nvar; |
nd_nalg = nalg; |
nd_nalg = nalg; |
/* #i -> t#i */ |
/* #i -> t#i */ |
if ( nalg ) { |
if ( nalg ) { |
Line 2340 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
Line 2404 void nd_gr(LIST f,LIST v,int m,int f4,struct order_spe |
|
for ( r0 = 0, t = x; t; t = NEXT(t) ) { |
for ( r0 = 0, t = x; t; t = NEXT(t) ) { |
NEXTNODE(r0,r); |
NEXTNODE(r0,r); |
BDY(r) = ndvtop(m,CO,vv,BDY(t)); |
BDY(r) = ndvtop(m,CO,vv,BDY(t)); |
if ( nalg ) { |
|
p = BDY(r); |
|
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; |
|
} |
|
BDY(r) = p; |
|
} |
|
} |
} |
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); |
Line 2385 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2444 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
|
|
get_algtree((Obj)f,&av); |
get_algtree((Obj)f,&av); |
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ ); |
for ( nalg = 0, tv = av; tv; tv = NEXT(tv), nalg++ ); |
|
nd_ntrans = nvar; |
nd_nalg = nalg; |
nd_nalg = nalg; |
/* #i -> t#i */ |
/* #i -> t#i */ |
if ( nalg ) { |
if ( nalg ) { |
Line 2427 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2487 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 2483 void nd_gr_trace(LIST f,LIST v,int trace,int homo,stru |
|
Line 2543 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) ) { |
for ( r = cand; r; r = NEXT(r) ) |
BDY(r) = (pointer)ndvtop(0,CO,vv,BDY(r)); |
BDY(r) = (pointer)ndvtop(0,CO,vv,BDY(r)); |
if ( nalg ) { |
if ( nalg ) |
poly = BDY(r); |
cand = postprocess_algcoef(av,alist,cand); |
for ( tv = av, s = alist; tv; tv = NEXT(tv), s = NEXT(s) ) { |
|
substr(CO,0,(Obj)poly,tv->v,(Obj)BDY(s),&obj); poly = (P)obj; |
|
} |
|
BDY(r) = poly; |
|
} |
|
} |
|
MKLIST(*rp,cand); |
MKLIST(*rp,cand); |
} |
} |
|
|
Line 5241 UINT *nd_det_compute_bound(NDV **dm,int n,int j) |
|
Line 5295 UINT *nd_det_compute_bound(NDV **dm,int n,int j) |
|
|
|
DL nd_separate_d(UINT *d,UINT *trans) |
DL nd_separate_d(UINT *d,UINT *trans) |
{ |
{ |
int n,ntrans,td,i,e; |
int n,td,i,e,j; |
DL a; |
DL a; |
|
|
n = nd_nvar; ntrans = n-nd_nalg; |
|
ndl_zero(trans); |
ndl_zero(trans); |
td = 0; |
td = 0; |
for ( i = 0; i < ntrans; i++ ) { |
for ( i = 0; i < nd_ntrans; i++ ) { |
e = GET_EXP(d,i); |
e = GET_EXP(d,i); |
PUT_EXP(trans,i,e); |
PUT_EXP(trans,i,e); |
td += MUL_WEIGHT(e,i); |
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; |
TD(trans) = td; |
if ( nd_blockmask) ndl_weight_mask(trans); |
if ( nd_blockmask) ndl_weight_mask(trans); |
NEWDL(a,nd_nalg); |
NEWDL(a,nd_nalg); |
td = 0; |
td = 0; |
for ( ; i < n; i++ ) { |
for ( i = 0; i < nd_nalg; i++ ) { |
e = GET_EXP(d,i); |
j = nd_ntrans+i; |
a->d[i-ntrans] = e; |
e = GET_EXP(d,j); |
|
a->d[i] = e; |
td += e; |
td += e; |
} |
} |
a->td = td; |
a->td = td; |
Line 5286 int nd_monic(int mod,ND *p) |
|
Line 5347 int nd_monic(int mod,ND *p) |
|
if ( !(nf = get_numberfield()) ) |
if ( !(nf = get_numberfield()) ) |
error("nd_monic : current_numberfield is not set"); |
error("nd_monic : current_numberfield is not set"); |
|
|
n = nd_nvar; ntrans = n-nd_nalg; |
|
/* Q coef -> DAlg coef */ |
/* Q coef -> DAlg coef */ |
NEWNM(ma0); ma = ma0; |
NEWNM(ma0); ma = ma0; |
m = BDY(*p); |
m = BDY(*p); |
Line 5340 int nd_monic(int mod,ND *p) |
|
Line 5400 int nd_monic(int mod,ND *p) |
|
dl = mp->dl; |
dl = mp->dl; |
td = TD(DL(m)); |
td = TD(DL(m)); |
ndl_copy(DL(m),DL(mr)); |
ndl_copy(DL(m),DL(mr)); |
for ( i = ntrans; i < n; i++ ) { |
for ( i = 0; i < nd_nalg; i++ ) { |
e = dl->d[i-ntrans]; |
e = dl->d[i]; |
PUT_EXP(DL(mr),i,e); |
PUT_EXP(DL(mr),i+nd_ntrans,e); |
td += MUL_WEIGHT(e,i); |
td += MUL_WEIGHT(e,i+nd_ntrans); |
} |
} |
TD(DL(mr)) = td; |
TD(DL(mr)) = td; |
if ( nd_blockmask) ndl_weight_mask(DL(mr)); |
if ( nd_blockmask) ndl_weight_mask(DL(mr)); |