=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/dist.c,v retrieving revision 1.2 retrieving revision 1.4 diff -u -p -r1.2 -r1.4 --- OpenXM_contrib2/asir2000/engine/dist.c 2000/04/05 08:32:17 1.2 +++ OpenXM_contrib2/asir2000/engine/dist.c 2000/04/25 04:07:59 1.4 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM_contrib2/asir2000/engine/dist.c,v 1.1.1.1 1999/12/03 07:39:08 noro Exp $ */ +/* $OpenXM: OpenXM_contrib2/asir2000/engine/dist.c,v 1.3 2000/04/13 06:01:02 noro Exp $ */ #include "ca.h" #define NV(p) ((p)->nv) @@ -315,6 +315,59 @@ DP p1,p2,*pr; } } +/* + * destructive merge of two list + * + * p1, p2 : list of DL + * return : a merged list + */ + +NODE symb_merge(m1,m2,n) +NODE m1,m2; +int n; +{ + NODE top,prev,cur,m,t; + + if ( !m1 ) + return m2; + else if ( !m2 ) + return m1; + else { + switch ( (*cmpdl)(n,(DL)BDY(m1),(DL)BDY(m2)) ) { + case 0: + top = m1; m = NEXT(m2); + break; + case 1: + top = m1; m = m2; + break; + case -1: + top = m2; m = m1; + break; + } + prev = top; cur = NEXT(top); + /* BDY(prev) > BDY(m) always holds */ + while ( cur && m ) { + switch ( (*cmpdl)(n,(DL)BDY(cur),(DL)BDY(m)) ) { + case 0: + m = NEXT(m); + prev = cur; cur = NEXT(cur); + break; + case 1: + t = NEXT(cur); NEXT(cur) = m; m = t; + prev = cur; cur = NEXT(cur); + break; + case -1: + NEXT(prev) = m; m = cur; + prev = NEXT(prev); cur = NEXT(prev); + break; + } + } + if ( !cur ) + NEXT(prev) = m; + return top; + } +} + void subd(vl,p1,p2,pr) VL vl; DP p1,p2,*pr; @@ -361,6 +414,8 @@ DP p1,p2,*pr; { MP m; DP s,t,u; + int i,l; + MP *w; if ( !p1 || !p2 ) *pr = 0; @@ -369,8 +424,12 @@ DP p1,p2,*pr; else if ( OID(p2) <= O_P ) muldc(vl,p1,(P)p2,pr); else { - for ( m = BDY(p2), s = 0; m; m = NEXT(m) ) { - muldm(vl,p1,m,&t); addd(vl,s,t,&u); s = u; + for ( m = BDY(p2), l = 0; m; m = NEXT(m), l++ ); + w = ALLOCA(l*sizeof(MP)); + for ( m = BDY(p2), i = 0; i < l; m = NEXT(m), i++ ) + w[i] = m; + for ( s = 0, i = l-1; i >= 0; i-- ) { + muldm(vl,p1,w[i],&t); addd(vl,s,t,&u); s = u; } *pr = s; } @@ -411,6 +470,8 @@ DP p1,p2,*pr; { MP m; DP s,t,u; + int i,l; + MP *w; if ( !p1 || !p2 ) *pr = 0; @@ -419,8 +480,12 @@ DP p1,p2,*pr; else if ( OID(p2) <= O_P ) muldc(vl,p1,(P)p2,pr); else { - for ( m = BDY(p2), s = 0; m; m = NEXT(m) ) { - weyl_muldm(vl,p1,m,&t); addd(vl,s,t,&u); s = u; + for ( m = BDY(p2), l = 0; m; m = NEXT(m), l++ ); + w = ALLOCA(l*sizeof(MP)); + for ( m = BDY(p2), i = 0; i < l; m = NEXT(m), i++ ) + w[i] = m; + for ( s = 0, i = l-1; i >= 0; i-- ) { + weyl_muldm(vl,p1,w[i],&t); addd(vl,s,t,&u); s = u; } *pr = s; } @@ -434,13 +499,18 @@ DP *pr; { DP r,t,t1; MP m; - int n; + int n,l,i; + MP *w; if ( !p ) *pr = 0; else { - for ( r = 0, m = BDY(p), n = NV(p); m; m = NEXT(m) ) { - weyl_mulmm(vl,m,m0,n,&t); + for ( m = BDY(p), l = 0; m; m = NEXT(m), l++ ); + w = ALLOCA(l*sizeof(MP)); + for ( m = BDY(p), i = 0; i < l; m = NEXT(m), i++ ) + w[i] = m; + for ( r = 0, i = l-1, n = NV(p); i >= 0; i-- ) { + weyl_mulmm(vl,w[i],m0,n,&t); addd(vl,r,t,&t1); r = t1; } if ( r )