version 1.27, 2003/08/10 01:31:24 |
version 1.28, 2003/08/11 06:58:01 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.26 2003/08/07 09:47:08 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/engine/nd.c,v 1.27 2003/08/10 01:31:24 noro Exp $ */ |
|
|
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
|
|
#define INLINE |
#define INLINE |
#endif |
#endif |
|
|
|
#define USE_GEOBUCKET 1 |
|
|
#define REDTAB_LEN 32003 |
#define REDTAB_LEN 32003 |
|
|
typedef struct oPGeoBucket { |
typedef struct oPGeoBucket { |
Line 921 ND nd_add_q(ND p1,ND p2) |
|
Line 923 ND nd_add_q(ND p1,ND p2) |
|
} |
} |
} |
} |
|
|
#if 1 |
#if !USE_GEOBUCKET |
/* ret=1 : success, ret=0 : overflow */ |
/* ret=1 : success, ret=0 : overflow */ |
int nd_nf(int mod,ND g,int full,ND *rp) |
int nd_nf(int mod,ND g,int full,ND *rp) |
{ |
{ |
|
|
*rp = d; |
*rp = d; |
return 1; |
return 1; |
} |
} |
|
|
|
int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full,ND *rp) |
|
{ |
|
ND d; |
|
NM m,mrd,tail; |
|
NM mul; |
|
int n,sugar,psugar,sugar0,stat,index; |
|
int c,c1,c2; |
|
RHist h; |
|
NDV p,red; |
|
Q cg,cred,gcd; |
|
double hmag; |
|
|
|
if ( !g ) { |
|
*rp = 0; |
|
return 1; |
|
} |
|
#if 0 |
|
if ( !mod ) |
|
hmag = ((double)p_mag((P)HCQ(g)))*nd_scale; |
#else |
#else |
|
/* XXX */ |
|
hmag = 0; |
|
#endif |
|
|
|
sugar0 = sugar = SG(g); |
|
n = NV(g); |
|
mul = (NM)ALLOCA(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int)); |
|
for ( d = 0; g; ) { |
|
index = nd_find_reducer_direct(g,ps,len); |
|
if ( index >= 0 ) { |
|
p = ps[index]; |
|
ndl_sub(HDL(g),HDL(p),DL(mul)); |
|
TD(mul) = HTD(g)-HTD(p); |
|
if ( ndl_check_bound2_direct(HDL(p),DL(mul)) ) { |
|
nd_free(g); nd_free(d); |
|
return 0; |
|
} |
|
if ( mod ) { |
|
c1 = invm(HCM(p),mod); c2 = mod-HCM(g); |
|
DMAR(c1,c2,0,mod,c); CM(mul) = c; |
|
} else { |
|
igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred); |
|
chsgnq(cg,&CQ(mul)); |
|
nd_mul_c_q(d,cred); nd_mul_c_q(g,cred); |
|
} |
|
g = nd_add(mod,g,ndv_mul_nm(mod,p,mul)); |
|
sugar = MAX(sugar,SG(p)+TD(mul)); |
|
if ( !mod && hmag && g && ((double)(p_mag((P)HCQ(g))) > hmag) ) { |
|
nd_removecont2(d,g); |
|
hmag = ((double)p_mag((P)HCQ(g)))*nd_scale; |
|
} |
|
} else if ( !full ) { |
|
*rp = g; |
|
return 1; |
|
} else { |
|
m = BDY(g); |
|
if ( NEXT(m) ) { |
|
BDY(g) = NEXT(m); NEXT(m) = 0; |
|
} else { |
|
FREEND(g); g = 0; |
|
} |
|
if ( d ) { |
|
NEXT(tail)=m; |
|
tail=m; |
|
} else { |
|
MKND(n,m,d); |
|
tail = BDY(d); |
|
} |
|
} |
|
} |
|
if ( d ) |
|
SG(d) = sugar; |
|
*rp = d; |
|
return 1; |
|
} |
|
#else |
int nd_nf(int mod,ND g,int full,ND *rp) |
int nd_nf(int mod,ND g,int full,ND *rp) |
{ |
{ |
int hindex,index; |
int hindex,index; |
Line 1014 int nd_nf(int mod,ND g,int full,ND *rp) |
|
Line 1092 int nd_nf(int mod,ND g,int full,ND *rp) |
|
int c,c1,c2; |
int c,c1,c2; |
Q cg,cred,gcd,zzz; |
Q cg,cred,gcd,zzz; |
RHist h; |
RHist h; |
|
double hmag,gmag; |
|
|
if ( !g ) { |
if ( !g ) { |
*rp = 0; |
*rp = 0; |
Line 1021 int nd_nf(int mod,ND g,int full,ND *rp) |
|
Line 1100 int nd_nf(int mod,ND g,int full,ND *rp) |
|
} |
} |
sugar = SG(g); |
sugar = SG(g); |
n = NV(g); |
n = NV(g); |
|
if ( !mod ) |
|
hmag = ((double)p_mag((P)HCQ(g)))*nd_scale; |
bucket = create_pbucket(); |
bucket = create_pbucket(); |
add_pbucket(mod,bucket,g,nd_length(g)); |
add_pbucket(mod,bucket,g,nd_length(g)); |
d = 0; |
d = 0; |
Line 1056 int nd_nf(int mod,ND g,int full,ND *rp) |
|
Line 1137 int nd_nf(int mod,ND g,int full,ND *rp) |
|
nd_mul_c_q(d,cred); |
nd_mul_c_q(d,cred); |
mulq_pbucket(bucket,cred); |
mulq_pbucket(bucket,cred); |
g = bucket->body[hindex]; |
g = bucket->body[hindex]; |
|
gmag = (double)p_mag((P)HCQ(g)); |
} |
} |
red = ndv_mul_nm(mod,p,mul); |
red = ndv_mul_nm(mod,p,mul); |
bucket->body[hindex] = nd_remove_head(g); |
bucket->body[hindex] = nd_remove_head(g); |
red = nd_remove_head(red); |
red = nd_remove_head(red); |
add_pbucket(mod,bucket,red,LEN(p)-1); |
add_pbucket(mod,bucket,red,LEN(p)-1); |
sugar = MAX(sugar,SG(p)+TD(mul)); |
sugar = MAX(sugar,SG(p)+TD(mul)); |
|
if ( !mod && hmag && (gmag > hmag) ) { |
|
g = normalize_pbucket(mod,bucket); |
|
if ( !g ) { |
|
if ( d ) |
|
SG(d) = sugar; |
|
*rp = d; |
|
return 1; |
|
} |
|
nd_removecont2(d,g); |
|
hmag = ((double)p_mag((P)HCQ(g)))*nd_scale; |
|
add_pbucket(mod,bucket,g,nd_length(g)-1); |
|
} |
} else if ( !full ) { |
} else if ( !full ) { |
g = normalize_pbucket(mod,bucket); |
g = normalize_pbucket(mod,bucket); |
if ( g ) |
if ( g ) |
Line 1086 int nd_nf(int mod,ND g,int full,ND *rp) |
|
Line 1180 int nd_nf(int mod,ND g,int full,ND *rp) |
|
} |
} |
} |
} |
} |
} |
#endif |
|
|
|
/* input : list of DP, cand : list of DP */ |
|
|
|
int nd_check_candidate(NODE input,NODE cand) |
|
{ |
|
int n,i,stat; |
|
ND nf,d; |
|
NODE t; |
|
|
|
nd_setup(0,cand); |
|
|
|
/* membercheck : list is a subset of Id(cand) ? */ |
|
for ( t = input; t; t = NEXT(t) ) { |
|
d = dptond(0,(DP)BDY(t)); |
|
stat = nd_nf_direct(0,d,nd_psq,n,0,&nf); |
|
if ( !stat ) |
|
nd_reconstruct_direct(0,nd_psq,n); |
|
else if ( nf ) |
|
return 0; |
|
} |
|
/* gbcheck : cand is a GB of Id(cand) ? */ |
|
if ( !nd_gb(0,1) ) |
|
return 0; |
|
/* XXX */ |
|
return 1; |
|
} |
|
|
|
int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full,ND *rp) |
int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full,ND *rp) |
{ |
{ |
ND d; |
int hindex,index; |
NM m,mrd,tail; |
NDV p; |
NM mul; |
ND u,d,red; |
int n,sugar,psugar,sugar0,stat,index; |
NODE l; |
|
NM mul,m,mrd; |
|
int sugar,psugar,n,h_reducible; |
|
PGeoBucket bucket; |
int c,c1,c2; |
int c,c1,c2; |
|
Q cg,cred,gcd,zzz; |
RHist h; |
RHist h; |
NDV p,red; |
double hmag,gmag; |
Q cg,cred,gcd; |
|
double hmag; |
|
|
|
if ( !g ) { |
if ( !g ) { |
*rp = 0; |
*rp = 0; |
return 1; |
return 1; |
} |
} |
|
sugar = SG(g); |
|
n = NV(g); |
#if 0 |
#if 0 |
if ( !mod ) |
if ( !mod ) |
hmag = ((double)p_mag((P)HCQ(g)))*nd_scale; |
hmag = ((double)p_mag((P)HCQ(g)))*nd_scale; |
Line 1137 int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full |
|
Line 1208 int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full |
|
/* XXX */ |
/* XXX */ |
hmag = 0; |
hmag = 0; |
#endif |
#endif |
|
bucket = create_pbucket(); |
sugar0 = sugar = SG(g); |
add_pbucket(mod,bucket,g,nd_length(g)); |
n = NV(g); |
d = 0; |
mul = (NM)ALLOCA(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int)); |
mul = (NM)ALLOCA(sizeof(struct oNM)+(nd_wpd-1)*sizeof(unsigned int)); |
for ( d = 0; g; ) { |
while ( 1 ) { |
|
hindex = mod?head_pbucket(mod,bucket):head_pbucket_q(bucket); |
|
if ( hindex < 0 ) { |
|
if ( d ) |
|
SG(d) = sugar; |
|
*rp = d; |
|
return 1; |
|
} |
|
g = bucket->body[hindex]; |
index = nd_find_reducer_direct(g,ps,len); |
index = nd_find_reducer_direct(g,ps,len); |
if ( index >= 0 ) { |
if ( index >= 0 ) { |
p = ps[index]; |
p = ps[index]; |
ndl_sub(HDL(g),HDL(p),DL(mul)); |
ndl_sub(HDL(g),HDL(p),DL(mul)); |
TD(mul) = HTD(g)-HTD(p); |
TD(mul) = HTD(g)-HTD(p); |
if ( ndl_check_bound2_direct(HDL(p),DL(mul)) ) { |
if ( ndl_check_bound2_direct(HDL(p),DL(mul)) ) { |
nd_free(g); nd_free(d); |
nd_free(d); |
|
free_pbucket(bucket); |
|
*rp = 0; |
return 0; |
return 0; |
} |
} |
if ( mod ) { |
if ( mod ) { |
c1 = invm(HCM(p),mod); c2 = mod-HCM(g); |
c1 = invm(HCM(p),mod); c2 = mod-HCM(g); |
DMAR(c1,c2,0,mod,c); CM(mul) = c; |
DMAR(c1,c2,0,mod,c); CM(mul) = c; |
} else { |
} else { |
igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred); |
igcd_cofactor(HCQ(g),HCQ(p),&gcd,&cg,&cred); |
chsgnq(cg,&CQ(mul)); |
chsgnq(cg,&CQ(mul)); |
nd_mul_c_q(d,cred); nd_mul_c_q(g,cred); |
nd_mul_c_q(d,cred); |
|
mulq_pbucket(bucket,cred); |
|
g = bucket->body[hindex]; |
|
gmag = (double)p_mag((P)HCQ(g)); |
} |
} |
g = nd_add(mod,g,ndv_mul_nm(mod,p,mul)); |
red = ndv_mul_nm(mod,p,mul); |
|
bucket->body[hindex] = nd_remove_head(g); |
|
red = nd_remove_head(red); |
|
add_pbucket(mod,bucket,red,LEN(p)-1); |
sugar = MAX(sugar,SG(p)+TD(mul)); |
sugar = MAX(sugar,SG(p)+TD(mul)); |
if ( !mod && hmag && g && ((double)(p_mag((P)HCQ(g))) > hmag) ) { |
if ( !mod && hmag && (gmag > hmag) ) { |
|
g = normalize_pbucket(mod,bucket); |
|
if ( !g ) { |
|
if ( d ) |
|
SG(d) = sugar; |
|
*rp = d; |
|
return 1; |
|
} |
nd_removecont2(d,g); |
nd_removecont2(d,g); |
hmag = ((double)p_mag((P)HCQ(g)))*nd_scale; |
hmag = ((double)p_mag((P)HCQ(g)))*nd_scale; |
|
add_pbucket(mod,bucket,g,nd_length(g)-1); |
} |
} |
} else if ( !full ) { |
} else if ( !full ) { |
|
g = normalize_pbucket(mod,bucket); |
|
if ( g ) |
|
SG(g) = sugar; |
*rp = g; |
*rp = g; |
return 1; |
return 1; |
} else { |
} else { |
Line 1175 int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full |
|
Line 1273 int nd_nf_direct(int mod,ND g,NDV *ps,int len,int full |
|
} else { |
} else { |
FREEND(g); g = 0; |
FREEND(g); g = 0; |
} |
} |
|
bucket->body[hindex] = g; |
|
NEXT(m) = 0; |
if ( d ) { |
if ( d ) { |
NEXT(tail)=m; |
for ( mrd = BDY(d); NEXT(mrd); mrd = NEXT(mrd) ); |
tail=m; |
NEXT(mrd) = m; |
} else { |
} else { |
MKND(n,m,d); |
MKND(n,m,d); |
tail = BDY(d); |
|
} |
} |
} |
} |
} |
} |
if ( d ) |
} |
SG(d) = sugar; |
#endif |
*rp = d; |
|
|
/* input : list of DP, cand : list of DP */ |
|
|
|
int nd_check_candidate(NODE input,NODE cand) |
|
{ |
|
int n,i,stat; |
|
ND nf,d; |
|
NODE t; |
|
|
|
nd_setup(0,cand); |
|
|
|
/* membercheck : list is a subset of Id(cand) ? */ |
|
for ( t = input; t; t = NEXT(t) ) { |
|
d = dptond(0,(DP)BDY(t)); |
|
stat = nd_nf_direct(0,d,nd_psq,n,0,&nf); |
|
if ( !stat ) |
|
nd_reconstruct_direct(0,nd_psq,n); |
|
else if ( nf ) |
|
return 0; |
|
} |
|
/* gbcheck : cand is a GB of Id(cand) ? */ |
|
if ( !nd_gb(0,1) ) |
|
return 0; |
|
/* XXX */ |
return 1; |
return 1; |
} |
} |
|
|
Line 1360 ND normalize_pbucket(int mod,PGeoBucket g) |
|
Line 1482 ND normalize_pbucket(int mod,PGeoBucket g) |
|
ND r,t; |
ND r,t; |
|
|
r = 0; |
r = 0; |
for ( i = 0; i <= g->m; i++ ) |
for ( i = 0; i <= g->m; i++ ) { |
r = nd_add(mod,r,g->body[i]); |
r = nd_add(mod,r,g->body[i]); |
|
g->body[i] = 0; |
|
} |
|
g->m = -1; |
return r; |
return r; |
} |
} |
|
|