version 1.5, 2019/09/13 02:04:42 |
version 1.7, 2019/10/11 03:45:56 |
|
|
* 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/asir2018/builtin/dp-supp.c,v 1.4 2019/09/04 01:12:02 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2018/builtin/dp-supp.c,v 1.6 2019/09/19 06:29:47 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
Line 2175 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
Line 2175 int create_order_spec(VL vl,Obj obj,struct order_spec |
|
spec->ord.simple = ZTOS((Q)obj); |
spec->ord.simple = ZTOS((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] */ |
/* module order */ |
node = BDY((LIST)obj); |
node = BDY((LIST)obj); |
if ( !BDY(node) || NUM(BDY(node)) ) { |
if ( !BDY(node) || NUM(BDY(node)) ) { |
switch ( length(node) ) { |
switch ( length(node) ) { |
case 2: |
case 2: /* [n,ord] */ |
create_order_spec(0,(Obj)BDY(NEXT(node)),&spec); |
create_order_spec(0,(Obj)BDY(NEXT(node)),&spec); |
spec->id += 256; spec->obj = obj; |
spec->id += 256; spec->obj = obj; |
spec->top_weight = 0; |
spec->top_weight = 0; |
spec->module_rank = 0; |
spec->module_rank = 0; |
spec->module_top_weight = 0; |
spec->module_top_weight = 0; |
spec->ispot = (BDY(node)!=0); |
spec->module_ordtype = ZTOS((Z)BDY(node)); |
if ( spec->ispot ) { |
if ( spec->module_ordtype < 0 ) { |
n = ZTOS((Q)BDY(node)); |
spec->pot_nelim = -spec->module_ordtype; |
if ( n < 0 ) |
spec->module_ordtype = 1; |
spec->pot_nelim = -n; |
} else |
else |
|
spec->pot_nelim = 0; |
spec->pot_nelim = 0; |
} |
|
break; |
break; |
|
|
case 3: |
case 3: /* [n,[wv,wm],ord] */ |
create_order_spec(0,(Obj)BDY(NEXT(NEXT(node))),&spec); |
spec->module_ordtype = ZTOS((Z)BDY(node)); |
spec->id += 256; spec->obj = obj; |
if ( spec->module_ordtype < 0 ) { |
spec->ispot = (BDY(node)!=0); |
spec->pot_nelim = -spec->module_ordtype; |
node = NEXT(node); |
spec->module_ordtype = 1; |
if ( !BDY(node) || OID(BDY(node)) != O_LIST ) |
} else |
error("create_order_spec : [weight_for_poly,weight_for_modlue] must be specified as a module topweight"); |
spec->pot_nelim = 0; |
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); |
if ( spec->module_ordtype == 3 ) { /* schreyer order */ |
wm = BDY(NEXT(wpair)); |
Obj baseobj; |
if ( !wp || OID(wp) != O_LIST || !wm || OID(wm) != O_LIST ) |
struct order_spec *basespec; |
error("create_order_spec : [weight_for_poly,weight_for_modlue] must be specified as a module topweight"); |
int len; |
spec->nv = length(BDY((LIST)wp)); |
NODE in; |
spec->top_weight = (int *)MALLOC_ATOMIC(spec->nv*sizeof(int)); |
LIST *la; |
for ( i = 0, t = BDY((LIST)wp); i < spec->nv; t = NEXT(t), i++ ) |
DMMstack stack; |
spec->top_weight[i] = ZTOS((Q)BDY(t)); |
DMMstack push_schreyer_order(LIST l,DMMstack s); |
|
|
spec->module_rank = length(BDY((LIST)wm)); |
spec->id = 300; spec->obj = obj; |
spec->module_top_weight = (int *)MALLOC_ATOMIC(spec->module_rank*sizeof(int)); |
node = NEXT(node); |
for ( i = 0, t = BDY((LIST)wm); i < spec->module_rank; t = NEXT(t), i++ ) |
if ( !BDY(node) || OID(BDY(node)) != O_LIST ) |
spec->module_top_weight[i] = ZTOS((Q)BDY(t)); |
error("create_order_spec : [mlist1,mlist,...] must be specified for defining a schreyer order"); |
|
stack = 0; |
|
in = BDY((LIST)BDY(node)); |
|
len = length(in); |
|
la = (LIST *)MALLOC(len*sizeof(LIST)); |
|
for ( i = 0; i < len; i++, in = NEXT(in) ) la[i] = (LIST)(BDY(in)); |
|
for ( i = len-1; i >= 0; i-- ) stack = push_schreyer_order(la[i],stack); |
|
spec->dmmstack = stack; |
|
|
|
node = NEXT(node); |
|
baseobj = (Obj)BDY(node); |
|
create_order_spec(0,baseobj,&basespec); |
|
basespec->obj = baseobj; |
|
spec->base = basespec; |
|
} else { /* weighted order */ |
|
int ordtype; |
|
|
|
ordtype = spec->module_ordtype; |
|
create_order_spec(0,(Obj)BDY(NEXT(NEXT(node))),&spec); |
|
spec->module_ordtype = ordtype; |
|
spec->id += 256; spec->obj = obj; |
|
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] = ZTOS((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] = ZTOS((Q)BDY(t)); |
|
} |
break; |
break; |
|
|
default: |
default: |
error("create_order_spec : invalid arguments for module order"); |
error("create_order_spec : invalid arguments for module order"); |
} |
} |
Line 2587 void create_modorder_spec(int id,LIST shift,struct mod |
|
Line 2624 void create_modorder_spec(int id,LIST shift,struct mod |
|
* |
* |
*/ |
*/ |
|
|
|
void dpm_homo(DPM p,DPM *rp) |
|
{ |
|
DMM m,mr,mr0,t; |
|
int i,n,nv,td; |
|
DL dl,dlh; |
|
|
|
if ( !p ) |
|
*rp = 0; |
|
else { |
|
n = p->nv; nv = n + 1; |
|
m = BDY(p); |
|
td = 0; |
|
for ( t = m; t; t = NEXT(t) ) |
|
if ( m->dl->td > td ) td = m->dl->td; |
|
for ( mr0 = 0; m; m = NEXT(m) ) { |
|
NEXTDMM(mr0,mr); mr->c = m->c; mr->pos = m->pos; |
|
dl = m->dl; |
|
mr->dl = dlh = (DL)MALLOC_ATOMIC((nv+1)*sizeof(int)); |
|
dlh->td = td; |
|
for ( i = 0; i < n; i++ ) |
|
dlh->d[i] = dl->d[i]; |
|
dlh->d[n] = td - dl->td; |
|
} |
|
NEXT(mr) = 0; MKDPM(nv,mr0,*rp); (*rp)->sugar = p->sugar; |
|
} |
|
} |
|
|
|
void dpm_dehomo(DPM p,DPM *rp) |
|
{ |
|
DMM m,mr,mr0; |
|
int i,n,nv; |
|
DL dl,dlh; |
|
|
|
if ( !p ) |
|
*rp = 0; |
|
else { |
|
n = p->nv; nv = n - 1; |
|
m = BDY(p); |
|
for ( mr0 = 0; m; m = NEXT(m) ) { |
|
NEXTDMM(mr0,mr); mr->c = m->c; mr->pos = m->pos; |
|
dlh = m->dl; |
|
mr->dl = dl = (DL)MALLOC_ATOMIC((nv+1)*sizeof(int)); |
|
dl->td = dlh->td - dlh->d[nv]; |
|
for ( i = 0; i < nv; i++ ) |
|
dl->d[i] = dlh->d[i]; |
|
} |
|
NEXT(mr) = 0; MKDPM(nv,mr0,*rp); (*rp)->sugar = p->sugar; |
|
} |
|
} |
|
|
void dp_homo(DP p,DP *rp) |
void dp_homo(DP p,DP *rp) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr,mr0; |
Line 2634 void dp_dehomo(DP p,DP *rp) |
|
Line 2721 void dp_dehomo(DP p,DP *rp) |
|
} |
} |
} |
} |
|
|
|
|
void dp_mod(DP p,int mod,NODE subst,DP *rp) |
void dp_mod(DP p,int mod,NODE subst,DP *rp) |
{ |
{ |
MP m,mr,mr0; |
MP m,mr,mr0; |
Line 2689 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2777 void homogenize_order(struct order_spec *old,int n,str |
|
struct weight_or_block *owb,*nwb; |
struct weight_or_block *owb,*nwb; |
|
|
*newp = new = (struct order_spec *)MALLOC(sizeof(struct order_spec)); |
*newp = new = (struct order_spec *)MALLOC(sizeof(struct order_spec)); |
|
bcopy((char *)old,(char *)new,sizeof(struct order_spec)); |
switch ( old->id ) { |
switch ( old->id ) { |
case 0: |
case 0: |
switch ( old->ord.simple ) { |
switch ( old->ord.simple ) { |
case 0: |
case 0: |
new->id = 0; new->ord.simple = 0; break; |
break; |
case 1: |
case 1: |
l = (struct order_pair *) |
l = (struct order_pair *) |
MALLOC_ATOMIC(2*sizeof(struct order_pair)); |
MALLOC_ATOMIC(2*sizeof(struct order_pair)); |
Line 2704 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2793 void homogenize_order(struct order_spec *old,int n,str |
|
new->ord.block.length = 2; new->nv = n+1; |
new->ord.block.length = 2; new->nv = n+1; |
break; |
break; |
case 2: |
case 2: |
new->id = 0; new->ord.simple = 1; break; |
new->ord.simple = 1; break; |
case 3: case 4: case 5: |
case 3: case 4: case 5: |
new->id = 0; new->ord.simple = old->ord.simple+3; |
new->ord.simple = old->ord.simple+3; |
dp_nelim = n-1; break; |
dp_nelim = n-1; break; |
case 6: case 7: case 8: case 9: |
case 6: case 7: case 8: case 9: |
new->id = 0; new->ord.simple = old->ord.simple; break; |
break; |
default: |
default: |
error("homogenize_order : invalid input"); |
error("homogenize_order : invalid input"); |
} |
} |
Line 2720 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2809 void homogenize_order(struct order_spec *old,int n,str |
|
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 = old->id; new->nv = n+1; |
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 258: |
case 2: case 258: |
nv = old->nv; row = old->ord.matrix.row; |
nv = old->nv; row = old->ord.matrix.row; |
Line 2735 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2823 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 = old->id; new->nv = nv+1; |
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 259: |
case 3: case 259: |
onv = old->nv; |
onv = old->nv; |
Line 2773 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2860 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 = 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 */ |
case 256: /* simple module order */ |
switch ( old->ord.simple ) { |
switch ( old->ord.simple ) { |
case 0: |
case 0: |
new->id = 256; new->ord.simple = 0; break; |
break; |
case 1: |
case 1: |
l = (struct order_pair *) |
l = (struct order_pair *) |
MALLOC_ATOMIC(2*sizeof(struct order_pair)); |
MALLOC_ATOMIC(2*sizeof(struct order_pair)); |
Line 2794 void homogenize_order(struct order_spec *old,int n,str |
|
Line 2879 void homogenize_order(struct order_spec *old,int n,str |
|
new->ord.block.length = 2; new->nv = n+1; |
new->ord.block.length = 2; new->nv = n+1; |
break; |
break; |
case 2: |
case 2: |
new->id = 256; new->ord.simple = 1; break; |
new->ord.simple = 1; break; |
default: |
default: |
error("homogenize_order : invalid input"); |
error("homogenize_order : invalid input"); |
} |
} |
new->ispot = old->ispot; |
|
break; |
break; |
default: |
default: |
error("homogenize_order : invalid input"); |
error("homogenize_order : invalid input"); |