version 1.49, 2009/01/04 05:44:51 |
version 1.65, 2017/03/27 09:05:46 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/dp-supp.c,v 1.48 2007/10/21 07:47:59 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/dp-supp.c,v 1.64 2016/03/31 08:43:25 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
Line 206 void dp_mbase(NODE hlist,NODE *mbase) |
|
Line 206 void dp_mbase(NODE hlist,NODE *mbase) |
|
{ |
{ |
DL *dl; |
DL *dl; |
DL d; |
DL d; |
int i,j,n,nvar,td; |
int *t; |
|
int i,j,k,n,nvar,td; |
|
|
n = length(hlist); nvar = ((DP)BDY(hlist))->nv; |
n = length(hlist); nvar = ((DP)BDY(hlist))->nv; |
dl = (DL *)MALLOC(n*sizeof(DL)); |
dl = (DL *)MALLOC(n*sizeof(DL)); |
for ( i = 0; i < n; i++, hlist = NEXT(hlist) ) |
|
dl[i] = BDY((DP)BDY(hlist))->dl; |
|
NEWDL(d,nvar); *mbase = 0; |
NEWDL(d,nvar); *mbase = 0; |
|
for ( i = 0; i < n; i++, hlist = NEXT(hlist) ) { |
|
dl[i] = BDY((DP)BDY(hlist))->dl; |
|
/* trivial ideal check */ |
|
if ( (*cmpdl)(nvar,d,dl[i]) == 0 ) { |
|
return; |
|
} |
|
} |
|
/* zero-dim. ideal check */ |
|
for ( i = 0; i < nvar; i++ ) { |
|
for ( j = 0; j < n; j++ ) { |
|
for ( k = 0, t = dl[j]->d; k < nvar; k++ ) |
|
if ( k != i && t[k] != 0 ) break; |
|
if ( k == nvar ) break; |
|
} |
|
if ( j == n ) |
|
error("dp_mbase : input ideal is not zero-dimensional"); |
|
} |
while ( 1 ) { |
while ( 1 ) { |
insert_to_node(d,mbase,nvar); |
insert_to_node(d,mbase,nvar); |
for ( i = nvar-1; i >= 0; ) { |
for ( i = nvar-1; i >= 0; ) { |
Line 651 void dp_sp(DP p1,DP p2,DP *rp) |
|
Line 667 void dp_sp(DP p1,DP p2,DP *rp) |
|
LIST hist; |
LIST hist; |
NODE node; |
NODE node; |
|
|
node = mknode(4,ONE,0,s1,ONE); |
node = mknode(4,ONE,NULLP,s1,ONE); |
MKLIST(hist,node); |
MKLIST(hist,node); |
MKNODE(TraceList,hist,0); |
MKNODE(TraceList,hist,0); |
|
|
node = mknode(4,ONE,0,0,ONE); |
node = mknode(4,ONE,NULLP,NULLP,ONE); |
chsgnd(s2,(DP *)&ARG2(node)); |
chsgnd(s2,(DP *)&ARG2(node)); |
MKLIST(hist,node); |
MKLIST(hist,node); |
MKNODE(node,hist,TraceList); TraceList = node; |
MKNODE(node,hist,TraceList); TraceList = node; |
Line 704 void _dp_sp_dup(DP p1,DP p2,DP *rp) |
|
Line 720 void _dp_sp_dup(DP p1,DP p2,DP *rp) |
|
LIST hist; |
LIST hist; |
NODE node; |
NODE node; |
|
|
node = mknode(4,ONE,0,s1,ONE); |
node = mknode(4,ONE,NULLP,s1,ONE); |
MKLIST(hist,node); |
MKLIST(hist,node); |
MKNODE(TraceList,hist,0); |
MKNODE(TraceList,hist,0); |
|
|
node = mknode(4,ONE,0,0,ONE); |
node = mknode(4,ONE,NULLP,NULLP,ONE); |
chsgnd(s2,(DP *)&ARG2(node)); |
chsgnd(s2,(DP *)&ARG2(node)); |
MKLIST(hist,node); |
MKLIST(hist,node); |
MKNODE(node,hist,TraceList); TraceList = node; |
MKNODE(node,hist,TraceList); TraceList = node; |
Line 887 void dp_red_marked(DP p0,DP p1,DP p2,DP hp2,DP *head,D |
|
Line 903 void dp_red_marked(DP p0,DP p1,DP p2,DP hp2,DP *head,D |
|
*head = h; *rest = r; *dnp = (P)c2; |
*head = h; *rest = r; *dnp = (P)c2; |
} |
} |
|
|
void dp_red_marked_mod(DP p0,DP p1,DP p2,DP hp2,int mod,DP *head,DP *rest,P *dnp) |
void dp_red_marked_mod(DP p0,DP p1,DP p2,DP hp2,int mod,DP *head,DP *rest,P *dnp,DP *multp) |
{ |
{ |
int i,n; |
int i,n; |
DL d1,d2,d; |
DL d1,d2,d; |
Line 905 void dp_red_marked_mod(DP p0,DP p1,DP p2,DP hp2,int mo |
|
Line 921 void dp_red_marked_mod(DP p0,DP p1,DP p2,DP hp2,int mo |
|
if ( NUM(c2) ) { |
if ( NUM(c2) ) { |
divsmp(CO,mod,c1,c2,&u); c1 = u; c2 = (P)ONEM; |
divsmp(CO,mod,c1,c2,&u); c1 = u; c2 = (P)ONEM; |
} |
} |
NEWMP(m); m->dl = d; chsgnmp(mod,(P)c1,&m->c); NEXT(m) = 0; |
NEWMP(m); m->dl = d; m->c = (P)c1; NEXT(m) = 0; |
MKDP(n,m,s); s->sugar = d->td; mulmd(CO,mod,s,p2,&t); |
MKDP(n,m,s); s->sugar = d->td; |
|
*multp = s; |
|
mulmd(CO,mod,s,p2,&t); |
if ( NUM(c2) ) { |
if ( NUM(c2) ) { |
addmd(CO,mod,p1,t,&r); h = p0; |
submd(CO,mod,p1,t,&r); h = p0; |
} else { |
} else { |
mulmdc(CO,mod,p1,c2,&s); addmd(CO,mod,s,t,&r); mulmdc(CO,mod,p0,c2,&h); |
mulmdc(CO,mod,p1,c2,&s); submd(CO,mod,s,t,&r); mulmdc(CO,mod,p0,c2,&h); |
} |
} |
*head = h; *rest = r; *dnp = c2; |
*head = h; *rest = r; *dnp = c2; |
} |
} |
|
|
|
|
void dp_true_nf_marked_mod(NODE b,DP g,DP *ps,DP *hps,int mod,DP *rp,P *dnp) |
void dp_true_nf_marked_mod(NODE b,DP g,DP *ps,DP *hps,int mod,DP *rp,P *dnp) |
{ |
{ |
DP hp,u,p,d,s,t; |
DP hp,u,p,d,s,t,dmy; |
NODE l; |
NODE l; |
MP m,mr; |
MP m,mr; |
int i,n; |
int i,n; |
Line 1203 void dp_true_nf_marked_mod(NODE b,DP g,DP *ps,DP *hps, |
|
Line 1221 void dp_true_nf_marked_mod(NODE b,DP g,DP *ps,DP *hps, |
|
for ( u = 0, i = 0; i < n; i++ ) { |
for ( u = 0, i = 0; i < n; i++ ) { |
if ( dp_redble(g,hp = hps[wb[i]]) ) { |
if ( dp_redble(g,hp = hps[wb[i]]) ) { |
p = ps[wb[i]]; |
p = ps[wb[i]]; |
dp_red_marked_mod(d,g,p,hp,mod,&t,&u,&tdn); |
dp_red_marked_mod(d,g,p,hp,mod,&t,&u,&tdn,&dmy); |
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
sugar = MAX(sugar,psugar); |
sugar = MAX(sugar,psugar); |
if ( !u ) { |
if ( !u ) { |
Line 1247 DP *dp_true_nf_and_quotient_marked (NODE b,DP g,DP *ps |
|
Line 1265 DP *dp_true_nf_and_quotient_marked (NODE b,DP g,DP *ps |
|
|
|
dn = (P)ONE; |
dn = (P)ONE; |
if ( !g ) { |
if ( !g ) { |
*rp = 0; *dnp = dn; return; |
*rp = 0; *dnp = dn; return 0; |
} |
} |
for ( n = 0, l = b; l; l = NEXT(l), n++ ); |
for ( n = 0, l = b; l; l = NEXT(l), n++ ); |
wb = (int *)ALLOCA(n*sizeof(int)); |
wb = (int *)ALLOCA(n*sizeof(int)); |
|
|
return q; |
return q; |
} |
} |
|
|
|
DP *dp_true_nf_and_quotient_marked_mod(NODE b,DP g,DP *ps,DP *hps,int mod,DP *rp,P *dnp) |
|
{ |
|
DP u,p,d,s,t,dmy,hp,mult; |
|
DP *q; |
|
NODE l; |
|
MP m,mr; |
|
int i,n,j; |
|
int *wb; |
|
int sugar,psugar; |
|
P dn,tdn,tdn1; |
|
|
|
for ( n = 0, l = b; l; l = NEXT(l), n++ ); |
|
q = (DP *)MALLOC(n*sizeof(DP)); |
|
for ( i = 0; i < n; i++ ) q[i] = 0; |
|
dn = (P)ONEM; |
|
if ( !g ) { |
|
*rp = 0; *dnp = dn; return 0; |
|
} |
|
wb = (int *)ALLOCA(n*sizeof(int)); |
|
for ( i = 0, l = b; i < n; l = NEXT(l), i++ ) |
|
wb[i] = QTOS((Q)BDY(l)); |
|
sugar = g->sugar; |
|
for ( d = 0; g; ) { |
|
for ( u = 0, i = 0; i < n; i++ ) { |
|
if ( dp_redble(g,hp = hps[wb[i]]) ) { |
|
p = ps[wb[i]]; |
|
dp_red_marked_mod(d,g,p,hp,mod,&t,&u,&tdn,&mult); |
|
psugar = (BDY(g)->dl->td - BDY(p)->dl->td) + p->sugar; |
|
sugar = MAX(sugar,psugar); |
|
for ( j = 0; j < n; j++ ) { |
|
mulmdc(CO,mod,q[j],(P)tdn,&dmy); q[j] = dmy; |
|
} |
|
addmd(CO,mod,q[wb[i]],mult,&dmy); q[wb[i]] = dmy; |
|
mulmp(CO,mod,dn,tdn,&tdn1); dn = tdn1; |
|
d = t; |
|
if ( !u ) goto last; |
|
break; |
|
} |
|
} |
|
if ( u ) |
|
g = u; |
|
else { |
|
m = BDY(g); NEWMP(mr); mr->dl = m->dl; mr->c = m->c; |
|
NEXT(mr) = 0; MKDP(g->nv,mr,t); t->sugar = mr->dl->td; |
|
addmd(CO,mod,d,t,&s); d = s; |
|
dp_rest(g,&t); g = t; |
|
} |
|
} |
|
last: |
|
if ( d ) |
|
d->sugar = sugar; |
|
*rp = d; *dnp = dn; |
|
return q; |
|
} |
|
|
/* nf computation over Z */ |
/* nf computation over Z */ |
|
|
void dp_nf_z(NODE b,DP g,DP *ps,int full,int multiple,DP *rp) |
void dp_nf_z(NODE b,DP g,DP *ps,int full,int multiple,DP *rp) |
Line 1678 void dp_nf_tab_f(DP p,LIST *tab,DP *rp) |
|
Line 1751 void dp_nf_tab_f(DP p,LIST *tab,DP *rp) |
|
|
|
int create_order_spec(VL vl,Obj obj,struct order_spec **specp) |
int create_order_spec(VL vl,Obj obj,struct order_spec **specp) |
{ |
{ |
int i,j,n,s,row,col,ret; |
int i,j,n,s,row,col,ret,wlen; |
struct order_spec *spec; |
struct order_spec *spec; |
struct order_pair *l; |
struct order_pair *l; |
NODE node,t,tn; |
Obj wp,wm; |
|
NODE node,t,tn,wpair; |
MAT m; |
MAT m; |
VECT v; |
VECT v; |
pointer **b,*bv; |
pointer **b,*bv; |
Line 1700 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
Line 1774 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
spec->ord.simple = QTOS((Q)obj); |
spec->ord.simple = QTOS((Q)obj); |
return 1; |
return 1; |
} else if ( OID(obj) == O_LIST ) { |
} else if ( OID(obj) == O_LIST ) { |
|
/* module order; obj = [0|1,w,ord] or [0|1,ord] */ |
node = BDY((LIST)obj); |
node = BDY((LIST)obj); |
for ( n = 0, t = node; t; t = NEXT(t), n++ ); |
if ( !BDY(node) || NUM(BDY(node)) ) { |
l = (struct order_pair *)MALLOC_ATOMIC(n*sizeof(struct order_pair)); |
switch ( length(node) ) { |
for ( i = 0, t = node, s = 0; i < n; t = NEXT(t), i++ ) { |
case 2: |
tn = BDY((LIST)BDY(t)); l[i].order = QTOS((Q)BDY(tn)); |
create_order_spec(0,(Obj)BDY(NEXT(node)),&spec); |
tn = NEXT(tn); l[i].length = QTOS((Q)BDY(tn)); |
spec->id += 256; spec->obj = obj; |
s += l[i].length; |
spec->top_weight = 0; |
} |
spec->module_rank = 0; |
spec->id = 1; spec->obj = obj; |
spec->module_top_weight = 0; |
spec->ord.block.order_pair = l; |
spec->ispot = (BDY(node)!=0); |
spec->ord.block.length = n; spec->nv = s; |
if ( spec->ispot ) { |
return 1; |
n = QTOS((Q)BDY(node)); |
|
if ( n < 0 ) |
|
spec->pot_nelim = -n; |
|
else |
|
spec->pot_nelim = 0; |
|
} |
|
break; |
|
|
|
case 3: |
|
create_order_spec(0,(Obj)BDY(NEXT(NEXT(node))),&spec); |
|
spec->id += 256; spec->obj = obj; |
|
spec->ispot = (BDY(node)!=0); |
|
node = NEXT(node); |
|
if ( !BDY(node) || OID(BDY(node)) != O_LIST ) |
|
error("create_order_spec : [weight_for_poly,weight_for_modlue] must be specified as a module topweight"); |
|
wpair = BDY((LIST)BDY(node)); |
|
if ( length(wpair) != 2 ) |
|
error("create_order_spec : [weight_for_poly,weight_for_modlue] must be specified as a module topweight"); |
|
|
|
wp = BDY(wpair); |
|
wm = BDY(NEXT(wpair)); |
|
if ( !wp || OID(wp) != O_LIST || !wm || OID(wm) != O_LIST ) |
|
error("create_order_spec : [weight_for_poly,weight_for_modlue] must be specified as a module topweight"); |
|
spec->nv = length(BDY((LIST)wp)); |
|
spec->top_weight = (int *)MALLOC_ATOMIC(spec->nv*sizeof(int)); |
|
for ( i = 0, t = BDY((LIST)wp); i < spec->nv; t = NEXT(t), i++ ) |
|
spec->top_weight[i] = QTOS((Q)BDY(t)); |
|
|
|
spec->module_rank = length(BDY((LIST)wm)); |
|
spec->module_top_weight = (int *)MALLOC_ATOMIC(spec->module_rank*sizeof(int)); |
|
for ( i = 0, t = BDY((LIST)wm); i < spec->module_rank; t = NEXT(t), i++ ) |
|
spec->module_top_weight[i] = QTOS((Q)BDY(t)); |
|
break; |
|
default: |
|
error("create_order_spec : invalid arguments for module order"); |
|
} |
|
|
|
*specp = spec; |
|
return 1; |
|
} else { |
|
/* block order in polynomial ring */ |
|
for ( n = 0, t = node; t; t = NEXT(t), n++ ); |
|
l = (struct order_pair *)MALLOC_ATOMIC(n*sizeof(struct order_pair)); |
|
for ( i = 0, t = node, s = 0; i < n; t = NEXT(t), i++ ) { |
|
tn = BDY((LIST)BDY(t)); l[i].order = QTOS((Q)BDY(tn)); |
|
tn = NEXT(tn); l[i].length = QTOS((Q)BDY(tn)); |
|
s += l[i].length; |
|
} |
|
spec->id = 1; spec->obj = obj; |
|
spec->ord.block.order_pair = l; |
|
spec->ord.block.length = n; spec->nv = s; |
|
return 1; |
|
} |
} else if ( OID(obj) == O_MAT ) { |
} else if ( OID(obj) == O_MAT ) { |
m = (MAT)obj; row = m->row; col = m->col; b = BDY(m); |
m = (MAT)obj; row = m->row; col = m->col; b = BDY(m); |
w = almat(row,col); |
w = almat(row,col); |
Line 1722 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
Line 1849 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
spec->nv = col; spec->ord.matrix.row = row; |
spec->nv = col; spec->ord.matrix.row = row; |
spec->ord.matrix.matrix = w; |
spec->ord.matrix.matrix = w; |
return 1; |
return 1; |
} else if ( OID(obj) == O_VECT ) { |
|
v = (VECT)obj; bv = BDY(v); |
|
if ( v->len < 2 ) error("create_order_spec : invalid argument"); |
|
create_order_spec(0,(Obj)bv[1],&spec); |
|
spec->id += 256; spec->obj = obj; |
|
spec->istop = bv[0]==0; |
|
*specp = spec; |
|
return 1; |
|
} else |
} else |
return 0; |
return 0; |
} |
} |
Line 2193 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2312 void homogenize_order(struct order_spec *old,int n,str |
|
error("homogenize_order : invalid input"); |
error("homogenize_order : invalid input"); |
} |
} |
break; |
break; |
case 1: |
case 1: case 257: |
length = old->ord.block.length; |
length = old->ord.block.length; |
l = (struct order_pair *) |
l = (struct order_pair *) |
MALLOC_ATOMIC((length+1)*sizeof(struct order_pair)); |
MALLOC_ATOMIC((length+1)*sizeof(struct order_pair)); |
bcopy((char *)old->ord.block.order_pair,(char *)l,length*sizeof(struct order_pair)); |
bcopy((char *)old->ord.block.order_pair,(char *)l,length*sizeof(struct order_pair)); |
l[length].order = 2; l[length].length = 1; |
l[length].order = 2; l[length].length = 1; |
new->id = 1; new->nv = n+1; |
new->id = old->id; new->nv = n+1; |
new->ord.block.order_pair = l; |
new->ord.block.order_pair = l; |
new->ord.block.length = length+1; |
new->ord.block.length = length+1; |
|
new->ispot = old->ispot; |
break; |
break; |
case 2: |
case 2: case 258: |
nv = old->nv; row = old->ord.matrix.row; |
nv = old->nv; row = old->ord.matrix.row; |
oldm = old->ord.matrix.matrix; newm = almat(row+1,nv+1); |
oldm = old->ord.matrix.matrix; newm = almat(row+1,nv+1); |
for ( i = 0; i <= nv; i++ ) |
for ( i = 0; i <= nv; i++ ) |
Line 2213 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2333 void homogenize_order(struct order_spec *old,int n,str |
|
newm[i+1][j] = oldm[i][j]; |
newm[i+1][j] = oldm[i][j]; |
newm[i+1][j] = 0; |
newm[i+1][j] = 0; |
} |
} |
new->id = 2; new->nv = nv+1; |
new->id = old->id; new->nv = nv+1; |
new->ord.matrix.row = row+1; new->ord.matrix.matrix = newm; |
new->ord.matrix.row = row+1; new->ord.matrix.matrix = newm; |
|
new->ispot = old->ispot; |
break; |
break; |
case 3: |
case 3: case 259: |
onv = old->nv; |
onv = old->nv; |
nnv = onv+1; |
nnv = onv+1; |
olen = old->ord.composite.length; |
olen = old->ord.composite.length; |
Line 2250 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2371 void homogenize_order(struct order_spec *old,int n,str |
|
(struct sparse_weight *)MALLOC(sizeof(struct sparse_weight)); |
(struct sparse_weight *)MALLOC(sizeof(struct sparse_weight)); |
nwb[i].body.sparse_weight[0].pos = onv; |
nwb[i].body.sparse_weight[0].pos = onv; |
nwb[i].body.sparse_weight[0].value = 1; |
nwb[i].body.sparse_weight[0].value = 1; |
new->id = 3; |
new->id = old->id; |
new->nv = nnv; |
new->nv = nnv; |
new->ord.composite.length = nlen; |
new->ord.composite.length = nlen; |
new->ord.composite.w_or_b = nwb; |
new->ord.composite.w_or_b = nwb; |
|
new->ispot = old->ispot; |
print_composite_order_spec(new); |
print_composite_order_spec(new); |
break; |
break; |
|
case 256: /* simple module order */ |
|
switch ( old->ord.simple ) { |
|
case 0: |
|
new->id = 256; new->ord.simple = 0; break; |
|
case 1: |
|
l = (struct order_pair *) |
|
MALLOC_ATOMIC(2*sizeof(struct order_pair)); |
|
l[0].length = n; l[0].order = old->ord.simple; |
|
l[1].length = 1; l[1].order = 2; |
|
new->id = 257; |
|
new->ord.block.order_pair = l; |
|
new->ord.block.length = 2; new->nv = n+1; |
|
break; |
|
case 2: |
|
new->id = 256; new->ord.simple = 1; break; |
|
default: |
|
error("homogenize_order : invalid input"); |
|
} |
|
new->ispot = old->ispot; |
|
break; |
default: |
default: |
error("homogenize_order : invalid input"); |
error("homogenize_order : invalid input"); |
} |
} |
Line 2276 void qltozl(Q *w,int n,Q *dvr) |
|
Line 2418 void qltozl(Q *w,int n,Q *dvr) |
|
v.id = O_VECT; v.len = n; v.body = (pointer *)w; |
v.id = O_VECT; v.len = n; v.body = (pointer *)w; |
igcdv(&v,dvr); return; |
igcdv(&v,dvr); return; |
} |
} |
c = w[0]; nm = NM(c); dn = INT(c) ? ONEN : DN(c); |
for ( i = 0; !w[i]; i++ ); |
for ( i = 1; i < n; i++ ) { |
c = w[i]; nm = NM(c); dn = INT(c) ? ONEN : DN(c); |
c = w[i]; l1 = INT(c) ? ONEN : DN(c); |
for ( i++; i < n; i++ ) { |
|
c = w[i]; |
|
if ( !c ) continue; |
|
l1 = INT(c) ? ONEN : DN(c); |
gcdn(nm,NM(c),&g); nm = g; |
gcdn(nm,NM(c),&g); nm = g; |
gcdn(dn,l1,&l2); muln(dn,l1,&l3); divsn(l3,l2,&dn); |
gcdn(dn,l1,&l2); muln(dn,l1,&l3); divsn(l3,l2,&dn); |
} |
} |
Line 2951 NODE compute_essential_df(DP *g,DP *gh,int ng) |
|
Line 3096 NODE compute_essential_df(DP *g,DP *gh,int ng) |
|
} |
} |
MKNODE(r1,0,ri); MKLIST(l,r1); |
MKNODE(r1,0,ri); MKLIST(l,r1); |
BDY(rt) = (pointer)l; |
BDY(rt) = (pointer)l; |
|
} |
|
return r; |
|
} |
|
|
|
int comp_bits_divisible(int *a,int *b,int n) |
|
{ |
|
int bpi,i,wi,bi; |
|
|
|
bpi = (sizeof(int)/sizeof(char))*8; |
|
for ( i = 0; i < n; i++ ) { |
|
wi = i/bpi; bi = i%bpi; |
|
if ( !(a[wi]&(1<<bi)) && (b[wi]&(1<<bi)) ) return 0; |
|
} |
|
return 1; |
|
} |
|
|
|
int comp_bits_lex(int *a,int *b,int n) |
|
{ |
|
int bpi,i,wi,ba,bb,bi; |
|
|
|
bpi = (sizeof(int)/sizeof(char))*8; |
|
for ( i = 0; i < n; i++ ) { |
|
wi = i/bpi; bi = i%bpi; |
|
ba = (a[wi]&(1<<bi))?1:0; |
|
bb = (b[wi]&(1<<bi))?1:0; |
|
if ( ba > bb ) return 1; |
|
else if ( ba < bb ) return -1; |
|
} |
|
return 0; |
|
} |
|
|
|
NODE mono_raddec(NODE ideal) |
|
{ |
|
DP p; |
|
int nv,w,i,bpi,di,c,len; |
|
int *d,*s,*u,*new; |
|
NODE t,t1,v,r,rem,prev; |
|
|
|
if( !ideal ) return 0; |
|
p = (DP)BDY(ideal); |
|
nv = NV(p); |
|
bpi = (sizeof(int)/sizeof(char))*8; |
|
w = (nv+(bpi-1))/bpi; |
|
d = p->body->dl->d; |
|
if ( !NEXT(ideal) ) { |
|
for ( t = 0, i = nv-1; i >= 0; i-- ) { |
|
if ( d[i] ) { |
|
s = (int *)CALLOC(w,sizeof(int)); |
|
s[i/bpi] |= 1<<(i%bpi); |
|
MKNODE(t1,s,t); |
|
t = t1; |
|
} |
|
} |
|
return t; |
|
} |
|
rem = mono_raddec(NEXT(ideal)); |
|
r = 0; |
|
len = w*sizeof(int); |
|
u = (int *)CALLOC(w,sizeof(int)); |
|
for ( i = nv-1; i >= 0; i-- ) { |
|
if ( d[i] ) { |
|
for ( t = rem; t; t = NEXT(t) ) { |
|
bcopy((char *)BDY(t),(char *)u,len); |
|
u[i/bpi] |= 1<<(i%bpi); |
|
for ( v = r; v; v = NEXT(v) ) { |
|
if ( comp_bits_divisible(u,(int *)BDY(v),nv) ) break; |
|
} |
|
if ( v ) continue; |
|
for ( v = r, prev = 0; v; v = NEXT(v) ) { |
|
if ( comp_bits_divisible((int *)BDY(v),u,nv) ) { |
|
if ( prev ) NEXT(prev) = NEXT(v); |
|
else r = NEXT(r); |
|
} else prev =v; |
|
} |
|
for ( v = r, prev = 0; v; prev = v, v = NEXT(v) ) { |
|
if ( comp_bits_lex(u,(int *)BDY(v),nv) < 0 ) break; |
|
} |
|
new = (int *)CALLOC(w,sizeof(int)); |
|
bcopy((char *)u,(char *)new,len); |
|
MKNODE(t1,new,v); |
|
if ( prev ) NEXT(prev) = t1; |
|
else r = t1; |
|
} |
|
} |
} |
} |
return r; |
return r; |
} |
} |