version 1.6, 2003/07/25 04:19:54 |
version 1.13, 2003/07/30 00:55:41 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.5 2003/07/24 03:45:41 noro Exp $ */ |
/* $OpenXM$ */ |
|
|
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
Line 35 typedef struct oNDV { |
|
Line 35 typedef struct oNDV { |
|
|
|
typedef struct oNM { |
typedef struct oNM { |
struct oNM *next; |
struct oNM *next; |
int td; |
|
int c; |
int c; |
|
int td; |
unsigned int dl[1]; |
unsigned int dl[1]; |
} *NM; |
} *NM; |
|
|
typedef struct oNMV { |
typedef struct oNMV { |
int td; |
|
int c; |
int c; |
|
int td; |
unsigned int dl[1]; |
unsigned int dl[1]; |
} *NMV; |
} *NMV; |
|
|
|
typedef struct oRHist { |
|
struct oRHist *next; |
|
int index; |
|
int td; |
|
unsigned int dl[1]; |
|
} *RHist; |
|
|
typedef struct oND_pairs { |
typedef struct oND_pairs { |
struct oND_pairs *next; |
struct oND_pairs *next; |
int i1,i2; |
int i1,i2; |
Line 53 typedef struct oND_pairs { |
|
Line 60 typedef struct oND_pairs { |
|
unsigned int lcm[1]; |
unsigned int lcm[1]; |
} *ND_pairs; |
} *ND_pairs; |
|
|
static ND *nd_ps; |
|
static NDV *nd_psv; |
|
static unsigned int **nd_bound; |
static unsigned int **nd_bound; |
int nd_mod,nd_nvar; |
int nd_mod,nd_nvar; |
int is_rlex; |
int is_rlex; |
Line 64 unsigned int nd_mask0,nd_mask1; |
|
Line 69 unsigned int nd_mask0,nd_mask1; |
|
NM _nm_free_list; |
NM _nm_free_list; |
ND _nd_free_list; |
ND _nd_free_list; |
ND_pairs _ndp_free_list; |
ND_pairs _ndp_free_list; |
NM *nd_red; |
RHist *nd_red; |
int nd_red_len; |
int nd_red_len; |
|
|
extern int Top,Reverse; |
extern int Top,Reverse; |
int nd_psn,nd_pslen; |
int nd_psn,nd_pslen; |
int nd_found,nd_create,nd_notfirst; |
int nd_found,nd_create,nd_notfirst; |
int *nd_psl; |
int *nd_psl; |
|
RHist *nd_psh; |
|
int nm_adv; |
|
#define NM_ADV(m) (m = (NM)(((char *)m)+nm_adv)) |
|
|
void GC_gcollect(); |
void GC_gcollect(); |
NODE append_one(NODE,int); |
NODE append_one(NODE,int); |
Line 79 NODE append_one(NODE,int); |
|
Line 87 NODE append_one(NODE,int); |
|
#define HDL(d) ((d)->body->dl) |
#define HDL(d) ((d)->body->dl) |
#define HC(d) ((d)->body->c) |
#define HC(d) ((d)->body->c) |
|
|
|
#define NEWRHist(r) ((r)=(RHist)MALLOC(sizeof(struct oRHist))) |
#define NEWND_pairs(m) if(!_ndp_free_list)_NDP_alloc(); (m)=_ndp_free_list; _ndp_free_list = NEXT(_ndp_free_list) |
#define NEWND_pairs(m) if(!_ndp_free_list)_NDP_alloc(); (m)=_ndp_free_list; _ndp_free_list = NEXT(_ndp_free_list) |
#define NEWNM(m) if(!_nm_free_list)_NM_alloc(); (m)=_nm_free_list; _nm_free_list = NEXT(_nm_free_list) |
#define NEWNM(m) if(!_nm_free_list)_NM_alloc(); (m)=_nm_free_list; _nm_free_list = NEXT(_nm_free_list) |
#define MKND(n,m,d) if(!_nd_free_list)_ND_alloc(); (d)=_nd_free_list; _nd_free_list = (ND)BDY(_nd_free_list); (d)->nv=(n); BDY(d)=(m) |
#define MKND(n,m,d) if(!_nd_free_list)_ND_alloc(); (d)=_nd_free_list; _nd_free_list = (ND)BDY(_nd_free_list); (d)->nv=(n); BDY(d)=(m) |
|
|
|
#define NEXTRHist(r,c) \ |
|
if(!(r)){NEWRHist(r);(c)=(r);}else{NEWRHist(NEXT(c));(c)=NEXT(c);} |
#define NEXTNM(r,c) \ |
#define NEXTNM(r,c) \ |
if(!(r)){NEWNM(r);(c)=(r);}else{NEWNM(NEXT(c));(c)=NEXT(c);} |
if(!(r)){NEWNM(r);(c)=(r);}else{NEWNM(NEXT(c));(c)=NEXT(c);} |
#define NEXTNM2(r,c,s) \ |
#define NEXTNM2(r,c,s) \ |
Line 133 unsigned int *nd_compute_bound(ND p); |
|
Line 144 unsigned int *nd_compute_bound(ND p); |
|
unsigned int *dp_compute_bound(DP p); |
unsigned int *dp_compute_bound(DP p); |
ND_pairs nd_reconstruct(ND_pairs); |
ND_pairs nd_reconstruct(ND_pairs); |
void nd_setup_parameters(); |
void nd_setup_parameters(); |
ND nd_dup(ND p,int obpe); |
void nd_realloc(ND p,int obpe); |
ND nd_copy(ND p); |
ND nd_copy(ND p); |
void ndl_dup(int obpe,unsigned int *d,unsigned int *r); |
void ndl_dup(int obpe,unsigned int *d,unsigned int *r); |
|
|
#if USE_NDV |
#if USE_NDV |
|
static NDV *nd_ps; |
|
|
#define NMV_ADV(m) (m = (NMV)(((char *)m)+nmv_adv)) |
#define NMV_ADV(m) (m = (NMV)(((char *)m)+nmv_adv)) |
#define NEWNDV(d) ((d)=(NDV)MALLOC(sizeof(struct oNDV))) |
#define NEWNDV(d) ((d)=(NDV)MALLOC(sizeof(struct oNDV))) |
#define MKNDV(n,m,l,d) NEWNDV(d); (d)->nv=(n); BDY(d)=(m); (d)->len = l; |
#define MKNDV(n,m,l,d) NEWNDV(d); (d)->nv=(n); BDY(d)=(m); (d)->len = l; |
|
|
int nmv_len; |
int nmv_len; |
NDV ndv_red; |
NDV ndv_red; |
|
|
|
void ndv_mul_c(NDV p,int mul); |
ND ndv_add(ND p1,NDV p2); |
ND ndv_add(ND p1,NDV p2); |
NDV ndtondv(ND p); |
NDV ndtondv(ND p); |
void ndv_mul_nm(NDV pv,NM m,NDV r); |
void ndv_mul_nm(NDV pv,NM m,NDV r); |
|
ND ndv_mul_nm_create(NDV p,NM m0); |
|
void ndv_realloc(NDV p,int obpe,int oadv); |
|
NDV dptondv(DP); |
|
DP ndvtodp(NDV); |
|
#else |
|
static ND *nd_ps; |
|
ND dptond(DP); |
|
DP ndtodp(ND); |
#endif |
#endif |
|
|
void nd_free_private_storage() |
void nd_free_private_storage() |
Line 156 void nd_free_private_storage() |
|
Line 178 void nd_free_private_storage() |
|
_nd_free_list = 0; |
_nd_free_list = 0; |
_nm_free_list = 0; |
_nm_free_list = 0; |
_ndp_free_list = 0; |
_ndp_free_list = 0; |
nd_red = 0; |
bzero(nd_red,sizeof(REDTAB_LEN*sizeof(RHist))); |
GC_gcollect(); |
GC_gcollect(); |
} |
} |
|
|
Line 165 void _NM_alloc() |
|
Line 187 void _NM_alloc() |
|
NM p; |
NM p; |
int i; |
int i; |
|
|
for ( i = 0; i < 16; i++ ) { |
for ( i = 0; i < 1024; i++ ) { |
p = (NM)GC_malloc(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int)); |
p = (NM)GC_malloc(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int)); |
p->next = _nm_free_list; _nm_free_list = p; |
p->next = _nm_free_list; _nm_free_list = p; |
} |
} |
Line 187 void _NDP_alloc() |
|
Line 209 void _NDP_alloc() |
|
ND_pairs p; |
ND_pairs p; |
int i; |
int i; |
|
|
for ( i = 0; i < 10240; i++ ) { |
for ( i = 0; i < 1024; i++ ) { |
p = (ND_pairs)GC_malloc(sizeof(struct oND_pairs) |
p = (ND_pairs)GC_malloc(sizeof(struct oND_pairs) |
+(nd_wpd-1)*sizeof(unsigned int)); |
+(nd_wpd-1)*sizeof(unsigned int)); |
p->next = _ndp_free_list; _ndp_free_list = p; |
p->next = _ndp_free_list; _ndp_free_list = p; |
Line 773 int ndl_check_bound2(int index,unsigned int *d2) |
|
Line 795 int ndl_check_bound2(int index,unsigned int *d2) |
|
} |
} |
} |
} |
|
|
int nd_sp(ND_pairs p,ND *rp) |
|
{ |
|
NM m; |
|
ND p1,p2,t1,t2; |
|
unsigned int *lcm; |
|
int td; |
|
|
|
p1 = nd_ps[p->i1]; |
|
p2 = nd_ps[p->i2]; |
|
lcm = p->lcm; |
|
td = p->td; |
|
NEWNM(m); |
|
C(m) = HC(p2); m->td = td-HTD(p1); ndl_sub(lcm,HDL(p1),m->dl); NEXT(m) = 0; |
|
if ( ndl_check_bound2(p->i1,m->dl) ) |
|
return 0; |
|
t1 = nd_mul_nm(p1,m); |
|
C(m) = nd_mod-HC(p1); m->td = td-HTD(p2); ndl_sub(lcm,HDL(p2),m->dl); |
|
if ( ndl_check_bound2(p->i2,m->dl) ) { |
|
nd_free(t1); |
|
return 0; |
|
} |
|
t2 = nd_mul_nm(p2,m); |
|
FREENM(m); |
|
*rp = nd_add(t1,t2); |
|
return 1; |
|
} |
|
|
|
INLINE int ndl_hash_value(int td,unsigned int *d) |
INLINE int ndl_hash_value(int td,unsigned int *d) |
{ |
{ |
int i; |
int i; |
Line 813 INLINE int ndl_hash_value(int td,unsigned int *d) |
|
Line 808 INLINE int ndl_hash_value(int td,unsigned int *d) |
|
|
|
INLINE int nd_find_reducer(ND g) |
INLINE int nd_find_reducer(ND g) |
{ |
{ |
NM m; |
RHist r; |
ND p; |
|
int d,k,i; |
int d,k,i; |
|
|
d = ndl_hash_value(HTD(g),HDL(g)); |
d = ndl_hash_value(HTD(g),HDL(g)); |
for ( m = nd_red[d], k = 0; m; m = NEXT(m), k++ ) { |
for ( r = nd_red[d], k = 0; r; r = NEXT(r), k++ ) { |
if ( HTD(g) == m->td && ndl_equal(HDL(g),m->dl) ) { |
if ( HTD(g) == r->td && ndl_equal(HDL(g),r->dl) ) { |
if ( k > 0 ) nd_notfirst++; |
if ( k > 0 ) nd_notfirst++; |
nd_found++; |
nd_found++; |
return m->c; |
return r->index; |
} |
} |
} |
} |
|
|
for ( i = 0; i < nd_psn; i++ ) { |
if ( Reverse ) |
p = nd_ps[i]; |
for ( i = nd_psn-1; i >= 0; i-- ) { |
if ( HTD(g) >= HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
r = nd_psh[i]; |
nd_create++; |
if ( HTD(g) >= r->td && ndl_reducible(HDL(g),r->dl) ) { |
nd_append_red(HDL(g),HTD(g),i); |
nd_create++; |
return i; |
nd_append_red(HDL(g),HTD(g),i); |
|
return i; |
|
} |
} |
} |
} |
else |
|
for ( i = 0; i < nd_psn; i++ ) { |
|
r = nd_psh[i]; |
|
if ( HTD(g) >= r->td && ndl_reducible(HDL(g),r->dl) ) { |
|
nd_create++; |
|
nd_append_red(HDL(g),HTD(g),i); |
|
return i; |
|
} |
|
} |
return -1; |
return -1; |
} |
} |
|
|
ND nd_find_monic_reducer(ND g) |
|
{ |
|
int *d; |
|
ND p,r; |
|
int i; |
|
|
|
for ( i = 0; i < nd_psn; i++ ) { |
|
p = nd_ps[i]; |
|
if ( HTD(g) >= HTD(p) && ndl_reducible(HDL(g),HDL(p)) ) { |
|
d = (int *)ALLOCA(nd_wpd*sizeof(int)); |
|
ndl_sub(HDL(g),HDL(p),d); |
|
r = nd_mul_term(p,HTD(g)-HTD(p),d); |
|
return r; |
|
} |
|
} |
|
return 0; |
|
} |
|
|
|
ND nd_add(ND p1,ND p2) |
ND nd_add(ND p1,ND p2) |
{ |
{ |
int n,c; |
int n,c; |
Line 915 ND nd_add(ND p1,ND p2) |
|
Line 901 ND nd_add(ND p1,ND p2) |
|
} |
} |
} |
} |
|
|
ND nd_mul_nm(ND p,NM m0) |
|
{ |
|
NM m,mr,mr0; |
|
unsigned int *d,*dt,*dm; |
|
int c,n,td,i,c1,c2; |
|
int *pt,*p1,*p2; |
|
ND r; |
|
|
|
if ( !p ) |
|
return 0; |
|
else { |
|
n = NV(p); m = BDY(p); |
|
d = m0->dl; td = m0->td; c = C(m0); |
|
mr0 = 0; |
|
for ( ; m; m = NEXT(m) ) { |
|
NEXTNM(mr0,mr); |
|
c1 = C(m); |
|
DMAR(c1,c,0,nd_mod,c2); |
|
C(mr) = c2; |
|
mr->td = m->td+td; |
|
ndl_add(m->dl,d,mr->dl); |
|
} |
|
NEXT(mr) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar + td; |
|
return r; |
|
} |
|
} |
|
|
|
ND nd_mul_ind_nm(int index,NM m0) |
|
{ |
|
register int c1,c2,c; |
|
register NM m,new,prev; |
|
NM mr0; |
|
unsigned int *d; |
|
int n,td,i,len,d0,d1; |
|
ND p,r; |
|
|
|
p = nd_ps[index]; |
|
len = nd_psl[index]; |
|
n = NV(p); m = BDY(p); |
|
d = m0->dl; td = m0->td; c = C(m0); |
|
|
|
NEWNM(mr0); |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); C(mr0) = c2; |
|
mr0->td = m->td+td; ndl_add(m->dl,d,mr0->dl); |
|
prev = mr0; m = NEXT(m); |
|
len--; |
|
|
|
switch ( nd_wpd ) { |
|
case 1: |
|
d0 = d[0]; |
|
while ( len-- ) { |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); |
|
NEWNM(new); C(new) = c2; |
|
new->td = m->td+td; new->dl[0] = m->dl[0]+d0; |
|
m = NEXT(m); NEXT(prev) = new; prev = new; |
|
} |
|
break; |
|
case 2: |
|
d0 = d[0]; d1 = d[1]; |
|
while ( len-- ) { |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); |
|
NEWNM(new); C(new) = c2; |
|
new->td = m->td+td; |
|
new->dl[0] = m->dl[0]+d0; |
|
new->dl[1] = m->dl[1]+d1; |
|
m = NEXT(m); NEXT(prev) = new; prev = new; |
|
} |
|
break; |
|
default: |
|
while ( len-- ) { |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); |
|
NEWNM(new); C(new) = c2; |
|
new->td = m->td+td; ndl_add(m->dl,d,new->dl); |
|
m = NEXT(m); NEXT(prev) = new; prev = new; |
|
} |
|
break; |
|
} |
|
|
|
NEXT(prev) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar + td; |
|
return r; |
|
} |
|
|
|
ND nd_mul_term(ND p,int td,unsigned int *d) |
|
{ |
|
NM m,mr,mr0; |
|
int c,n; |
|
ND r; |
|
|
|
if ( !p ) |
|
return 0; |
|
else { |
|
n = NV(p); m = BDY(p); |
|
for ( mr0 = 0; m; m = NEXT(m) ) { |
|
NEXTNM(mr0,mr); |
|
C(mr) = C(m); |
|
mr->td = m->td+td; |
|
ndl_add(m->dl,d,mr->dl); |
|
} |
|
NEXT(mr) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar + td; |
|
return r; |
|
} |
|
} |
|
|
|
#if 1 |
#if 1 |
/* ret=1 : success, ret=0 : overflow */ |
/* ret=1 : success, ret=0 : overflow */ |
int nd_nf(ND g,int full,ND *rp) |
int nd_nf(ND g,int full,ND *rp) |
{ |
{ |
ND p,d; |
ND d; |
NM m,mrd,tail; |
NM m,mrd,tail; |
struct oNM mul; |
NM mul; |
int n,sugar,psugar,stat,index; |
int n,sugar,psugar,sugar0,stat,index; |
int c,c1,c2; |
int c,c1,c2; |
#if USE_NDV |
#if USE_NDV |
NDV red; |
NDV p,red; |
#else |
#else |
ND red; |
ND p,red; |
#endif |
#endif |
|
|
if ( !g ) { |
if ( !g ) { |
*rp = 0; |
*rp = 0; |
return 1; |
return 1; |
} |
} |
sugar = g->sugar; |
sugar0 = sugar = g->sugar; |
n = NV(g); |
n = NV(g); |
|
mul = (NM)ALLOCA(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int)); |
for ( d = 0; g; ) { |
for ( d = 0; g; ) { |
index = nd_find_reducer(g); |
index = nd_find_reducer(g); |
if ( index >= 0 ) { |
if ( index >= 0 ) { |
p = nd_ps[index]; |
p = nd_ps[index]; |
ndl_sub(HDL(g),HDL(p),mul.dl); |
ndl_sub(HDL(g),HDL(p),mul->dl); |
mul.td = HTD(g)-HTD(p); |
mul->td = HTD(g)-HTD(p); |
if ( ndl_check_bound2(index,mul.dl) ) { |
#if 0 |
|
if ( d && (p->sugar+mul->td) > sugar ) { |
|
goto afo; |
|
} |
|
#endif |
|
if ( ndl_check_bound2(index,mul->dl) ) { |
nd_free(g); nd_free(d); |
nd_free(g); nd_free(d); |
return 0; |
return 0; |
} |
} |
c1 = invm(HC(p),nd_mod); c2 = nd_mod-HC(g); |
c1 = invm(HC(p),nd_mod); c2 = nd_mod-HC(g); |
DMAR(c1,c2,0,nd_mod,c); mul.c = c; |
DMAR(c1,c2,0,nd_mod,c); C(mul) = c; |
#if USE_NDV |
#if USE_NDV |
ndv_mul_nm(nd_psv[index],&mul,ndv_red); |
ndv_mul_nm(nd_ps[index],mul,ndv_red); |
g = ndv_add(g,ndv_red); |
g = ndv_add(g,ndv_red); |
sugar = MAX(sugar,ndv_red->sugar); |
sugar = MAX(sugar,ndv_red->sugar); |
#else |
#else |
red = nd_mul_ind_nm(index,&mul); |
red = nd_mul_ind_nm(index,mul); |
g = nd_add(g,red); |
g = nd_add(g,red); |
sugar = MAX(sugar,red->sugar); |
sugar = MAX(sugar,red->sugar); |
#endif |
#endif |
Line 1070 int nd_nf(ND g,int full,ND *rp) |
|
Line 953 int nd_nf(ND g,int full,ND *rp) |
|
*rp = g; |
*rp = g; |
return 1; |
return 1; |
} else { |
} else { |
|
afo: |
m = BDY(g); |
m = BDY(g); |
if ( NEXT(m) ) { |
if ( NEXT(m) ) { |
BDY(g) = NEXT(m); NEXT(m) = 0; |
BDY(g) = NEXT(m); NEXT(m) = 0; |
Line 1552 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
Line 1436 ND_pairs nd_minp( ND_pairs d, ND_pairs *prest ) |
|
c = ndl_compare(p->lcm,lcm); |
c = ndl_compare(p->lcm,lcm); |
if ( c < 0 ) |
if ( c < 0 ) |
goto find; |
goto find; |
|
#if 0 |
else if ( c == 0 ) { |
else if ( c == 0 ) { |
tlen = nd_psl[p->i1]+nd_psl[p->i2]; |
tlen = nd_psl[p->i1]+nd_psl[p->i2]; |
if ( tlen < len ) |
if ( tlen < len ) |
goto find; |
goto find; |
} |
} |
|
#endif |
} |
} |
} |
} |
continue; |
continue; |
|
|
int nd_newps(ND a) |
int nd_newps(ND a) |
{ |
{ |
int len; |
int len; |
|
RHist r; |
|
|
if ( nd_psn == nd_pslen ) { |
if ( nd_psn == nd_pslen ) { |
nd_pslen *= 2; |
nd_pslen *= 2; |
nd_ps = (ND *)REALLOC((char *)nd_ps,nd_pslen*sizeof(ND)); |
|
nd_psl = (int *)REALLOC((char *)nd_psl,nd_pslen*sizeof(int)); |
nd_psl = (int *)REALLOC((char *)nd_psl,nd_pslen*sizeof(int)); |
#if USE_NDV |
#if USE_NDV |
nd_psv = (NDV *)REALLOC((char *)nd_psv,nd_pslen*sizeof(NDV)); |
nd_ps = (NDV *)REALLOC((char *)nd_ps,nd_pslen*sizeof(NDV)); |
|
#else |
|
nd_ps = (ND *)REALLOC((char *)nd_ps,nd_pslen*sizeof(ND)); |
#endif |
#endif |
|
nd_psh = (RHist *)REALLOC((char *)nd_psh,nd_pslen*sizeof(RHist)); |
nd_bound = (unsigned int **) |
nd_bound = (unsigned int **) |
REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *)); |
REALLOC((char *)nd_bound,nd_pslen*sizeof(unsigned int *)); |
} |
} |
nd_monic(a); |
nd_monic(a); |
nd_ps[nd_psn] = a; |
|
nd_psl[nd_psn] = nd_length(a); |
|
nd_bound[nd_psn] = nd_compute_bound(a); |
nd_bound[nd_psn] = nd_compute_bound(a); |
|
NEWRHist(r); r->td = HTD(a); ndl_copy(HDL(a),r->dl); nd_psh[nd_psn] = r; |
#if USE_NDV |
#if USE_NDV |
nd_psv[nd_psn] = ndtondv(a); |
nd_ps[nd_psn]= ndtondv(a); |
len = nd_psv[nd_psn]->len; |
nd_free(a); |
|
nd_psl[nd_psn] = len = nd_ps[nd_psn]->len; |
if ( len > nmv_len ) { |
if ( len > nmv_len ) { |
nmv_len = 2*len; |
nmv_len = 2*len; |
BDY(ndv_red) = (NMV)REALLOC(BDY(ndv_red),nmv_len*nmv_adv); |
BDY(ndv_red) = (NMV)REALLOC(BDY(ndv_red),nmv_len*nmv_adv); |
} |
} |
|
#else |
|
nd_ps[nd_psn] = a; |
|
nd_psl[nd_psn] = nd_length(a); |
#endif |
#endif |
return nd_psn++; |
return nd_psn++; |
} |
} |
|
|
NODE NODE_sortb(NODE f,int); |
|
ND dptond(DP); |
|
DP ndtodp(ND); |
|
|
|
NODE nd_setup(NODE f) |
NODE nd_setup(NODE f) |
{ |
{ |
int i,j,td,len,max; |
int i,j,td,len,max; |
NODE s,s0,f0; |
NODE s,s0,f0; |
unsigned int *d; |
unsigned int *d; |
|
RHist r; |
|
|
nd_found = 0; |
nd_found = 0; nd_notfirst = 0; nd_create = 0; |
nd_notfirst = 0; |
|
nd_create = 0; |
|
#if 0 |
|
f0 = f = NODE_sortb(f,1); |
|
#endif |
|
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_psn = length(f); nd_pslen = 2*nd_psn; |
nd_ps = (ND *)MALLOC(nd_pslen*sizeof(ND)); |
|
nd_psl = (int *)MALLOC(nd_pslen*sizeof(int)); |
nd_psl = (int *)MALLOC(nd_pslen*sizeof(int)); |
#if USE_NDV |
#if USE_NDV |
nd_psv = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
nd_ps = (NDV *)MALLOC(nd_pslen*sizeof(NDV)); |
|
#else |
|
nd_ps = (ND *)MALLOC(nd_pslen*sizeof(ND)); |
#endif |
#endif |
|
nd_psh = (RHist *)MALLOC(nd_pslen*sizeof(RHist)); |
nd_bound = (unsigned int **)MALLOC(nd_pslen*sizeof(unsigned int *)); |
nd_bound = (unsigned int **)MALLOC(nd_pslen*sizeof(unsigned int *)); |
for ( max = 0, i = 0, s = f; i < nd_psn; i++, s = NEXT(s) ) { |
for ( max = 0, i = 0, s = f; i < nd_psn; i++, s = NEXT(s) ) { |
nd_bound[i] = d = dp_compute_bound((DP)BDY(s)); |
nd_bound[i] = d = dp_compute_bound((DP)BDY(s)); |
for ( j = 0; j < nd_nvar; j++ ) |
for ( j = 0; j < nd_nvar; j++ ) |
max = MAX(d[j],max); |
max = MAX(d[j],max); |
} |
} |
|
if ( !nd_red ) |
|
nd_red = (RHist *)MALLOC(REDTAB_LEN*sizeof(RHist)); |
|
bzero(nd_red,REDTAB_LEN*sizeof(RHist)); |
|
|
if ( max < 2 ) |
if ( max < 2 ) |
nd_bpe = 2; |
nd_bpe = 2; |
Line 1647 NODE nd_setup(NODE f) |
|
Line 1537 NODE nd_setup(NODE f) |
|
nd_bpe = 16; |
nd_bpe = 16; |
else |
else |
nd_bpe = 32; |
nd_bpe = 32; |
|
|
nd_setup_parameters(); |
nd_setup_parameters(); |
nd_free_private_storage(); |
nd_free_private_storage(); |
len = 0; |
len = 0; |
for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) { |
for ( i = 0; i < nd_psn; i++, f = NEXT(f) ) { |
|
#if USE_NDV |
|
nd_ps[i] = dptondv((DP)BDY(f)); |
|
ndv_mul_c(nd_ps[i],invm(HC(nd_ps[i]),nd_mod)); |
|
len = MAX(len,nd_ps[i]->len); |
|
#else |
nd_ps[i] = dptond((DP)BDY(f)); |
nd_ps[i] = dptond((DP)BDY(f)); |
nd_monic(nd_ps[i]); |
nd_mul_c(nd_ps[i],1); |
nd_psl[i] = nd_length(nd_ps[i]); |
nd_psl[i] = nd_length(nd_ps[i]); |
#if USE_NDV |
|
nd_psv[i] = ndtondv(nd_ps[i]); |
|
len = MAX(len,nd_psv[i]->len); |
|
#endif |
#endif |
|
NEWRHist(r); r->td = HTD(nd_ps[i]); ndl_copy(HDL(nd_ps[i]),r->dl); |
|
nd_psh[i] = r; |
} |
} |
nd_red = (NM *)MALLOC(REDTAB_LEN*sizeof(NM)); |
|
#if USE_NDV |
#if USE_NDV |
nmv_len = 16*len; |
nmv_len = 16*len; |
NEWNDV(ndv_red); |
NEWNDV(ndv_red); |
Line 1711 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
Line 1604 void nd_gr(LIST f,LIST v,int m,struct order_spec *ord, |
|
#endif |
#endif |
for ( r0 = 0; x; x = NEXT(x) ) { |
for ( r0 = 0; x; x = NEXT(x) ) { |
NEXTNODE(r0,r); |
NEXTNODE(r0,r); |
|
#if USE_NDV |
|
a = ndvtodp(nd_ps[(int)BDY(x)]); |
|
#else |
a = ndtodp(nd_ps[(int)BDY(x)]); |
a = ndtodp(nd_ps[(int)BDY(x)]); |
|
#endif |
_dtop_mod(CO,vv,a,(P *)&BDY(r)); |
_dtop_mod(CO,vv,a,(P *)&BDY(r)); |
} |
} |
if ( r0 ) NEXT(r) = 0; |
if ( r0 ) NEXT(r) = 0; |
Line 1885 void nd_free(ND p) |
|
Line 1782 void nd_free(ND p) |
|
|
|
void nd_append_red(unsigned int *d,int td,int i) |
void nd_append_red(unsigned int *d,int td,int i) |
{ |
{ |
NM m,m0; |
RHist m,m0; |
int h; |
int h; |
|
|
NEWNM(m); |
NEWRHist(m); |
h = ndl_hash_value(td,d); |
h = ndl_hash_value(td,d); |
m->c = i; |
m->index = i; |
m->td = td; |
m->td = td; |
bcopy(d,m->dl,nd_wpd*sizeof(unsigned int)); |
ndl_copy(d,m->dl); |
NEXT(m) = nd_red[h]; |
NEXT(m) = nd_red[h]; |
nd_red[h] = m; |
nd_red[h] = m; |
} |
} |
Line 1901 unsigned int *dp_compute_bound(DP p) |
|
Line 1798 unsigned int *dp_compute_bound(DP p) |
|
{ |
{ |
unsigned int *d,*d1,*d2,*t; |
unsigned int *d,*d1,*d2,*t; |
MP m; |
MP m; |
int i; |
int i,l; |
|
|
if ( !p ) |
if ( !p ) |
return 0; |
return 0; |
Line 1915 unsigned int *dp_compute_bound(DP p) |
|
Line 1812 unsigned int *dp_compute_bound(DP p) |
|
d2[i] = d[i] > d1[i] ? d[i] : d1[i]; |
d2[i] = d[i] > d1[i] ? d[i] : d1[i]; |
t = d1; d1 = d2; d2 = t; |
t = d1; d1 = d2; d2 = t; |
} |
} |
t = (unsigned int *)MALLOC_ATOMIC(nd_nvar*sizeof(unsigned int)); |
l = (nd_nvar+31); |
|
t = (unsigned int *)MALLOC_ATOMIC(l*sizeof(unsigned int)); |
|
bzero(t,l*sizeof(unsigned int)); |
bcopy(d1,t,nd_nvar*sizeof(unsigned int)); |
bcopy(d1,t,nd_nvar*sizeof(unsigned int)); |
return t; |
return t; |
} |
} |
Line 1923 unsigned int *dp_compute_bound(DP p) |
|
Line 1822 unsigned int *dp_compute_bound(DP p) |
|
unsigned int *nd_compute_bound(ND p) |
unsigned int *nd_compute_bound(ND p) |
{ |
{ |
unsigned int *d1,*d2,*t; |
unsigned int *d1,*d2,*t; |
int i; |
int i,l; |
NM m; |
NM m; |
|
|
if ( !p ) |
if ( !p ) |
Line 1935 unsigned int *nd_compute_bound(ND p) |
|
Line 1834 unsigned int *nd_compute_bound(ND p) |
|
ndl_lcm(m->dl,d1,d2); |
ndl_lcm(m->dl,d1,d2); |
t = d1; d1 = d2; d2 = t; |
t = d1; d1 = d2; d2 = t; |
} |
} |
t = (unsigned int *)MALLOC_ATOMIC(nd_nvar*sizeof(unsigned int)); |
l = nd_nvar+31; |
bzero(t,nd_nvar*sizeof(unsigned int)); |
t = (unsigned int *)MALLOC_ATOMIC(l*sizeof(unsigned int)); |
|
bzero(t,l*sizeof(unsigned int)); |
for ( i = 0; i < nd_nvar; i++ ) |
for ( i = 0; i < nd_nvar; i++ ) |
t[i] = (d1[i/nd_epw]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))&nd_mask0; |
t[i] = (d1[i/nd_epw]>>((nd_epw-(i%nd_epw)-1)*nd_bpe))&nd_mask0; |
return t; |
return t; |
Line 1958 void nd_setup_parameters() { |
|
Line 1858 void nd_setup_parameters() { |
|
nd_mask[nd_epw-i-1] = (nd_mask0<<(i*nd_bpe)); |
nd_mask[nd_epw-i-1] = (nd_mask0<<(i*nd_bpe)); |
nd_mask1 |= (1<<(nd_bpe-1))<<(i*nd_bpe); |
nd_mask1 |= (1<<(nd_bpe-1))<<(i*nd_bpe); |
} |
} |
|
nm_adv = sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int); |
#if USE_NDV |
#if USE_NDV |
nmv_adv = sizeof(struct oNMV)+(nd_wpd-1)*sizeof(unsigned int); |
nmv_adv = sizeof(struct oNMV)+(nd_wpd-1)*sizeof(unsigned int); |
#endif |
#endif |
Line 1965 void nd_setup_parameters() { |
|
Line 1866 void nd_setup_parameters() { |
|
|
|
ND_pairs nd_reconstruct(ND_pairs d) |
ND_pairs nd_reconstruct(ND_pairs d) |
{ |
{ |
int i,obpe; |
int i,obpe,oadv; |
NM prev_nm_free_list,mr0,mr,m; |
NM prev_nm_free_list; |
|
RHist mr0,mr; |
|
RHist r; |
ND_pairs s0,s,t,prev_ndp_free_list; |
ND_pairs s0,s,t,prev_ndp_free_list; |
|
|
obpe = nd_bpe; |
obpe = nd_bpe; |
|
#if USE_NDV |
|
oadv = nmv_adv; |
|
#endif |
if ( obpe < 4 ) |
if ( obpe < 4 ) |
nd_bpe = 4; |
nd_bpe = 4; |
else if ( obpe < 6 ) |
else if ( obpe < 6 ) |
Line 1988 ND_pairs nd_reconstruct(ND_pairs d) |
|
Line 1894 ND_pairs nd_reconstruct(ND_pairs d) |
|
prev_ndp_free_list = _ndp_free_list; |
prev_ndp_free_list = _ndp_free_list; |
_nm_free_list = 0; |
_nm_free_list = 0; |
_ndp_free_list = 0; |
_ndp_free_list = 0; |
for ( i = 0; i < nd_psn; i++ ) { |
for ( i = nd_psn-1; i >= 0; i-- ) { |
nd_ps[i] = nd_dup(nd_ps[i],obpe); |
|
#if USE_NDV |
#if USE_NDV |
nd_psv[i] = ndtondv(nd_ps[i]); |
ndv_realloc(nd_ps[i],obpe,oadv); |
|
#else |
|
nd_realloc(nd_ps[i],obpe); |
#endif |
#endif |
} |
} |
s0 = 0; |
s0 = 0; |
Line 2004 ND_pairs nd_reconstruct(ND_pairs d) |
|
Line 1911 ND_pairs nd_reconstruct(ND_pairs d) |
|
ndl_dup(obpe,t->lcm,s->lcm); |
ndl_dup(obpe,t->lcm,s->lcm); |
} |
} |
for ( i = 0; i < REDTAB_LEN; i++ ) { |
for ( i = 0; i < REDTAB_LEN; i++ ) { |
for ( mr0 = 0, m = nd_red[i]; m; m = NEXT(m) ) { |
for ( mr0 = 0, r = nd_red[i]; r; r = NEXT(r) ) { |
NEXTNM(mr0,mr); |
NEXTRHist(mr0,r); |
mr->c = m->c; |
mr->index = r->index; |
mr->td = m->td; |
mr->td = r->td; |
ndl_dup(obpe,m->dl,mr->dl); |
ndl_dup(obpe,r->dl,mr->dl); |
} |
} |
if ( mr0 ) NEXT(mr) = 0; |
if ( mr0 ) NEXT(mr) = 0; |
nd_red[i] = mr0; |
nd_red[i] = mr0; |
} |
} |
|
for ( i = 0; i < nd_psn; i++ ) { |
|
NEWRHist(r); r->td = nd_psh[i]->td; ndl_dup(obpe,nd_psh[i]->dl,r->dl); |
|
nd_psh[i] = r; |
|
} |
if ( s0 ) NEXT(s) = 0; |
if ( s0 ) NEXT(s) = 0; |
prev_nm_free_list = 0; |
prev_nm_free_list = 0; |
prev_ndp_free_list = 0; |
prev_ndp_free_list = 0; |
Line 2045 void ndl_dup(int obpe,unsigned int *d,unsigned int *r) |
|
Line 1956 void ndl_dup(int obpe,unsigned int *d,unsigned int *r) |
|
} |
} |
} |
} |
|
|
ND nd_dup(ND p,int obpe) |
void nd_realloc(ND p,int obpe) |
{ |
{ |
NM m,mr,mr0; |
NM m,mr,mr0; |
int c,n; |
|
ND r; |
|
|
|
if ( !p ) |
if ( p ) { |
return 0; |
m = BDY(p); |
else { |
|
n = NV(p); m = BDY(p); |
|
for ( mr0 = 0; m; m = NEXT(m) ) { |
for ( mr0 = 0; m; m = NEXT(m) ) { |
NEXTNM(mr0,mr); |
NEXTNM(mr0,mr); |
C(mr) = C(m); |
C(mr) = C(m); |
Line 2062 ND nd_dup(ND p,int obpe) |
|
Line 1969 ND nd_dup(ND p,int obpe) |
|
ndl_dup(obpe,m->dl,mr->dl); |
ndl_dup(obpe,m->dl,mr->dl); |
} |
} |
NEXT(mr) = 0; |
NEXT(mr) = 0; |
MKND(NV(p),mr0,r); |
BDY(p) = mr0; |
r->sugar = p->sugar; |
|
return r; |
|
} |
} |
} |
} |
|
|
Line 2092 ND nd_copy(ND p) |
|
Line 1997 ND nd_copy(ND p) |
|
} |
} |
|
|
#if USE_NDV |
#if USE_NDV |
|
int nd_sp(ND_pairs p,ND *rp) |
|
{ |
|
NM m; |
|
NDV p1,p2; |
|
ND t1,t2; |
|
unsigned int *lcm; |
|
int td; |
|
|
|
p1 = nd_ps[p->i1]; |
|
p2 = nd_ps[p->i2]; |
|
lcm = p->lcm; |
|
td = p->td; |
|
NEWNM(m); |
|
C(m) = HC(p2); m->td = td-HTD(p1); ndl_sub(lcm,HDL(p1),m->dl); |
|
if ( ndl_check_bound2(p->i1,m->dl) ) |
|
return 0; |
|
t1 = ndv_mul_nm_create(p1,m); |
|
C(m) = nd_mod-HC(p1); m->td = td-HTD(p2); ndl_sub(lcm,HDL(p2),m->dl); |
|
if ( ndl_check_bound2(p->i2,m->dl) ) { |
|
nd_free(t1); |
|
return 0; |
|
} |
|
ndv_mul_nm(p2,m,ndv_red); |
|
FREENM(m); |
|
*rp = ndv_add(t1,ndv_red); |
|
return 1; |
|
} |
|
|
|
void ndv_mul_c(NDV p,int mul) |
|
{ |
|
NMV m; |
|
int c,c1,len,i; |
|
|
|
if ( !p ) |
|
return; |
|
len = p->len; |
|
for ( m = BDY(p), i = 0; i < len; i++, NMV_ADV(m) ) { |
|
c1 = C(m); |
|
DMAR(c1,mul,0,nd_mod,c); |
|
C(m) = c; |
|
} |
|
} |
|
|
void ndv_mul_nm(NDV p,NM m0,NDV r) |
void ndv_mul_nm(NDV p,NM m0,NDV r) |
{ |
{ |
NMV m,mr,mr0; |
NMV m,mr,mr0; |
Line 2105 void ndv_mul_nm(NDV p,NM m0,NDV r) |
|
Line 2053 void ndv_mul_nm(NDV p,NM m0,NDV r) |
|
n = NV(p); m = BDY(p); len = p->len; |
n = NV(p); m = BDY(p); len = p->len; |
d = m0->dl; td = m0->td; c = C(m0); |
d = m0->dl; td = m0->td; c = C(m0); |
mr = BDY(r); |
mr = BDY(r); |
for ( i = 0; i < len; i++, NMV_ADV(m), NMV_ADV(mr) ) { |
for ( ; len > 0; len--, NMV_ADV(m), NMV_ADV(mr) ) { |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); C(mr) = c2; |
|
mr->td = m->td+td; ndl_add(m->dl,d,mr->dl); |
|
} |
|
NV(r) = NV(p); |
|
r->len = p->len; |
|
r->sugar = p->sugar + td; |
|
} |
|
} |
|
|
|
ND ndv_mul_nm_create(NDV p,NM m0) |
|
{ |
|
NM mr,mr0; |
|
NMV m; |
|
unsigned int *d,*dt,*dm; |
|
int c,n,td,i,c1,c2,len; |
|
ND r; |
|
|
|
if ( !p ) |
|
return 0; |
|
else { |
|
n = NV(p); m = BDY(p); |
|
d = m0->dl; td = m0->td; c = C(m0); |
|
len = p->len; |
|
mr0 = 0; |
|
for ( i = 0; i < len; i++, NMV_ADV(m) ) { |
|
NEXTNM(mr0,mr); |
c1 = C(m); |
c1 = C(m); |
DMAR(c1,c,0,nd_mod,c2); |
DMAR(c1,c,0,nd_mod,c2); |
C(mr) = c2; |
C(mr) = c2; |
mr->td = m->td+td; |
mr->td = m->td+td; |
ndl_add(m->dl,d,mr->dl); |
ndl_add(m->dl,d,mr->dl); |
} |
} |
NV(r) = NV(p); |
NEXT(mr) = 0; |
r->len = p->len; |
MKND(NV(p),mr0,r); |
r->sugar = p->sugar + td; |
r->sugar = p->sugar + td; |
|
return r; |
} |
} |
} |
} |
|
|
ND ndv_add(ND p1,NDV p2) |
ND ndv_add(ND p1,NDV p2) |
{ |
{ |
|
register NM prev,cur,new; |
int c,c1,c2,t,td,td2,mul,len,i; |
int c,c1,c2,t,td,td2,mul,len,i; |
NM prev,head,cur,new; |
NM head; |
unsigned int *d; |
unsigned int *d; |
NMV m2; |
NMV m2; |
|
|
Line 2129 ND ndv_add(ND p1,NDV p2) |
|
Line 2105 ND ndv_add(ND p1,NDV p2) |
|
return 0; |
return 0; |
else { |
else { |
prev = 0; head = cur = BDY(p1); |
prev = 0; head = cur = BDY(p1); |
NEWNM(new); |
NEWNM(new); len = p2->len; |
len = p2->len; |
for ( m2 = BDY(p2), i = 0; cur && i < len; ) { |
for ( m2 = BDY(p2), i = 0; i < len; ) { |
|
td2 = new->td = m2->td; |
td2 = new->td = m2->td; |
if ( !cur ) { |
if ( cur->td > td2 ) { |
C(new) = C(m2); |
prev = cur; cur = NEXT(cur); |
ndl_copy(m2->dl,new->dl); |
|
if ( !prev ) { |
|
prev = new; |
|
NEXT(prev) = 0; |
|
head = prev; |
|
} else { |
|
NEXT(prev) = new; |
|
NEXT(new) = 0; |
|
prev = new; |
|
} |
|
NMV_ADV(m2); i++; |
|
NEWNM(new); |
|
continue; |
continue; |
|
} else if ( cur->td < td2 ) c = -1; |
|
else if ( nd_wpd == 1 ) { |
|
if ( cur->dl[0] > m2->dl[0] ) c = is_rlex ? -1 : 1; |
|
else if ( cur->dl[0] < m2->dl[0] ) c = is_rlex ? 1 : -1; |
|
else c = 0; |
} |
} |
if ( cur->td > td2 ) |
else c = ndl_compare(cur->dl,m2->dl); |
c = 1; |
|
else if ( cur->td < td2 ) |
|
c = -1; |
|
else |
|
c = ndl_compare(cur->dl,m2->dl); |
|
switch ( c ) { |
switch ( c ) { |
case 0: |
case 0: |
t = C(m2)+C(cur)-nd_mod; |
t = C(m2)+C(cur)-nd_mod; |
if ( t < 0 ) |
if ( t < 0 ) t += nd_mod; |
t += nd_mod; |
if ( t ) C(cur) = t; |
if ( t ) |
|
C(cur) = t; |
|
else if ( !prev ) { |
else if ( !prev ) { |
head = NEXT(cur); |
head = NEXT(cur); FREENM(cur); cur = head; |
FREENM(cur); |
|
cur = head; |
|
} else { |
} else { |
NEXT(prev) = NEXT(cur); |
NEXT(prev) = NEXT(cur); FREENM(cur); cur = NEXT(prev); |
FREENM(cur); |
|
cur = NEXT(prev); |
|
} |
} |
NMV_ADV(m2); i++; |
NMV_ADV(m2); i++; |
break; |
break; |
case 1: |
case 1: |
prev = cur; |
prev = cur; cur = NEXT(cur); |
cur = NEXT(cur); |
|
break; |
break; |
case -1: |
case -1: |
ndl_copy(m2->dl,new->dl); |
ndl_copy(m2->dl,new->dl); |
|
C(new) = C(m2); |
if ( !prev ) { |
if ( !prev ) { |
/* cur = head */ |
/* cur = head */ |
prev = new; |
prev = new; NEXT(prev) = head; head = prev; |
C(prev) = C(m2); |
|
NEXT(prev) = head; |
|
head = prev; |
|
} else { |
} else { |
C(new) = C(m2); |
NEXT(prev) = new; NEXT(new) = cur; prev = new; |
NEXT(prev) = new; |
|
NEXT(new) = cur; |
|
prev = new; |
|
} |
} |
NEWNM(new); |
NEWNM(new); NMV_ADV(m2); i++; |
NMV_ADV(m2); i++; |
|
break; |
break; |
} |
} |
} |
} |
|
for ( ; i < len; i++, NMV_ADV(m2) ) { |
|
td2 = new->td = m2->td; C(new) = C(m2); ndl_copy(m2->dl,new->dl); |
|
if ( !prev ) { |
|
prev = new; NEXT(prev) = 0; head = prev; |
|
} else { |
|
NEXT(prev) = new; NEXT(new) = 0; prev = new; |
|
} |
|
NEWNM(new); |
|
} |
FREENM(new); |
FREENM(new); |
if ( head ) { |
if ( head ) { |
BDY(p1) = head; |
BDY(p1) = head; p1->sugar = MAX(p1->sugar,p2->sugar); |
p1->sugar = MAX(p1->sugar,p2->sugar+td); |
|
return p1; |
return p1; |
} else { |
} else { |
FREEND(p1); |
FREEND(p1); |
Line 2209 ND ndv_add(ND p1,NDV p2) |
|
Line 2167 ND ndv_add(ND p1,NDV p2) |
|
} |
} |
} |
} |
|
|
|
void ndv_realloc(NDV p,int obpe,int oadv) |
|
{ |
|
NMV m,mr,mr0,t; |
|
int len,i,k; |
|
|
|
#define NMV_OPREV(m) (m = (NMV)(((char *)m)-oadv)) |
|
#define NMV_PREV(m) (m = (NMV)(((char *)m)-nmv_adv)) |
|
|
|
if ( p ) { |
|
m = BDY(p); len = p->len; |
|
mr0 = (NMV)REALLOC(BDY(p),len*nmv_adv); |
|
m = (NMV)((char *)mr0+(len-1)*oadv); |
|
mr = (NMV)((char *)mr0+(len-1)*nmv_adv); |
|
t = (NMV)ALLOCA(nmv_adv); |
|
for ( i = 0; i < len; i++, NMV_OPREV(m), NMV_PREV(mr) ) { |
|
C(t) = C(m); |
|
t->td = m->td; |
|
for ( k = 0; k < nd_wpd; k++ ) t->dl[k] = 0; |
|
ndl_dup(obpe,m->dl,t->dl); |
|
C(mr) = C(t); |
|
mr->td = t->td; |
|
ndl_copy(t->dl,mr->dl); |
|
} |
|
BDY(p) = mr0; |
|
} |
|
} |
|
|
NDV ndtondv(ND p) |
NDV ndtondv(ND p) |
{ |
{ |
NDV d; |
NDV d; |
Line 2222 NDV ndtondv(ND p) |
|
Line 2207 NDV ndtondv(ND p) |
|
m0 = m = (NMV)MALLOC_ATOMIC(len*nmv_adv); |
m0 = m = (NMV)MALLOC_ATOMIC(len*nmv_adv); |
for ( t = BDY(p), i = 0; t; t = NEXT(t), i++, NMV_ADV(m) ) { |
for ( t = BDY(p), i = 0; t; t = NEXT(t), i++, NMV_ADV(m) ) { |
m->td = t->td; |
m->td = t->td; |
bcopy(t->dl,m->dl,nd_wpd*sizeof(unsigned int)); |
ndl_copy(t->dl,m->dl); |
m->c = t->c; |
m->c = t->c; |
} |
} |
MKNDV(NV(p),m0,len,d); |
MKNDV(NV(p),m0,len,d); |
Line 2230 NDV ndtondv(ND p) |
|
Line 2215 NDV ndtondv(ND p) |
|
return d; |
return d; |
} |
} |
|
|
|
NDV dptondv(DP p) |
|
{ |
|
NDV d; |
|
NMV m0,m; |
|
MP t; |
|
int l,i,n; |
|
|
|
if ( !p ) |
|
return 0; |
|
for ( t = BDY(p), l = 0; t; t = NEXT(t), l++ ); |
|
m0 = m = (NMV)MALLOC_ATOMIC(l*nmv_adv); |
|
n = NV(p); |
|
for ( t = BDY(p), i = 0; i < l; i++, t = NEXT(t), NMV_ADV(m) ) { |
|
m->c = ITOS(t->c); |
|
m->td = t->dl->td; |
|
dltondl(n,t->dl,m->dl); |
|
} |
|
MKNDV(n,m0,l,d); |
|
d->sugar = p->sugar; |
|
return d; |
|
} |
|
|
|
DP ndvtodp(NDV p) |
|
{ |
|
DP d; |
|
MP m0,m; |
|
NMV t; |
|
int len,i,n; |
|
|
|
if ( !p ) |
|
return 0; |
|
m0 = 0; |
|
len = p->len; |
|
n = NV(p); |
|
for ( t = BDY(p), i = 0; i < len; i++, NMV_ADV(t) ) { |
|
NEXTMP(m0,m); |
|
m->c = STOI(t->c); |
|
m->dl = ndltodl(n,t->td,t->dl); |
|
} |
|
NEXT(m) = 0; |
|
MKDP(NV(p),m0,d); |
|
d->sugar = p->sugar; |
|
return d; |
|
} |
|
|
void ndv_print(NDV p) |
void ndv_print(NDV p) |
{ |
{ |
NMV m; |
NMV m; |
Line 2245 void ndv_print(NDV p) |
|
Line 2275 void ndv_print(NDV p) |
|
} |
} |
printf("\n"); |
printf("\n"); |
} |
} |
|
} |
|
#else |
|
int nd_sp(ND_pairs p,ND *rp) |
|
{ |
|
NM m; |
|
ND p1,p2; |
|
ND t1,t2; |
|
unsigned int *lcm; |
|
int td; |
|
|
|
p1 = nd_ps[p->i1]; |
|
p2 = nd_ps[p->i2]; |
|
lcm = p->lcm; |
|
td = p->td; |
|
NEWNM(m); |
|
C(m) = HC(p2); m->td = td-HTD(p1); ndl_sub(lcm,HDL(p1),m->dl); |
|
if ( ndl_check_bound2(p->i1,m->dl) ) |
|
return 0; |
|
t1 = nd_mul_ind_nm(p->i1,m); |
|
C(m) = nd_mod-HC(p1); m->td = td-HTD(p2); ndl_sub(lcm,HDL(p2),m->dl); |
|
if ( ndl_check_bound2(p->i2,m->dl) ) { |
|
nd_free(t1); |
|
return 0; |
|
} |
|
t2 = nd_mul_ind_nm(p->i2,m); |
|
FREENM(m); |
|
*rp = nd_add(t1,t2); |
|
return 1; |
|
} |
|
|
|
ND nd_mul_nm(ND p,NM m0) |
|
{ |
|
NM m,mr,mr0; |
|
unsigned int *d,*dt,*dm; |
|
int c,n,td,i,c1,c2; |
|
int *pt,*p1,*p2; |
|
ND r; |
|
|
|
if ( !p ) |
|
return 0; |
|
else { |
|
n = NV(p); m = BDY(p); |
|
d = m0->dl; td = m0->td; c = C(m0); |
|
mr0 = 0; |
|
for ( ; m; m = NEXT(m) ) { |
|
NEXTNM(mr0,mr); |
|
c1 = C(m); |
|
DMAR(c1,c,0,nd_mod,c2); |
|
C(mr) = c2; |
|
mr->td = m->td+td; |
|
ndl_add(m->dl,d,mr->dl); |
|
} |
|
NEXT(mr) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar + td; |
|
return r; |
|
} |
|
} |
|
|
|
ND nd_mul_ind_nm(int index,NM m0) |
|
{ |
|
register int c1,c2,c; |
|
register NM m,new,prev; |
|
NM mr0; |
|
unsigned int *d; |
|
int n,td,i,len,d0,d1; |
|
ND p,r; |
|
|
|
p = nd_ps[index]; |
|
len = nd_psl[index]; |
|
n = NV(p); m = BDY(p); |
|
d = m0->dl; td = m0->td; c = C(m0); |
|
|
|
NEWNM(mr0); |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); C(mr0) = c2; |
|
mr0->td = m->td+td; ndl_add(m->dl,d,mr0->dl); |
|
prev = mr0; m = NEXT(m); |
|
len--; |
|
|
|
switch ( nd_wpd ) { |
|
case 1: |
|
d0 = d[0]; |
|
while ( len-- ) { |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); |
|
NEWNM(new); C(new) = c2; |
|
new->td = m->td+td; new->dl[0] = m->dl[0]+d0; |
|
m = NEXT(m); NEXT(prev) = new; prev = new; |
|
} |
|
break; |
|
case 2: |
|
d0 = d[0]; d1 = d[1]; |
|
while ( len-- ) { |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); |
|
NEWNM(new); C(new) = c2; |
|
new->td = m->td+td; |
|
new->dl[0] = m->dl[0]+d0; |
|
new->dl[1] = m->dl[1]+d1; |
|
m = NEXT(m); NEXT(prev) = new; prev = new; |
|
} |
|
break; |
|
default: |
|
while ( len-- ) { |
|
c1 = C(m); DMAR(c1,c,0,nd_mod,c2); |
|
NEWNM(new); C(new) = c2; |
|
new->td = m->td+td; ndl_add(m->dl,d,new->dl); |
|
m = NEXT(m); NEXT(prev) = new; prev = new; |
|
} |
|
break; |
|
} |
|
|
|
NEXT(prev) = 0; |
|
MKND(NV(p),mr0,r); |
|
r->sugar = p->sugar + td; |
|
return r; |
} |
} |
#endif |
#endif |