version 1.72, 2005/10/14 06:00:03 |
version 1.73, 2005/10/14 07:39:38 |
|
|
* 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/strobj.c,v 1.71 2005/10/12 14:43:36 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.72 2005/10/14 06:00:03 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 1923 void Pfunargs_to_quote(NODE arg,QUOTE *rp) |
|
Line 1923 void Pfunargs_to_quote(NODE arg,QUOTE *rp) |
|
|
|
FNODE fnode_apply(FNODE f,FNODE (*func)()); |
FNODE fnode_apply(FNODE f,FNODE (*func)()); |
FNODE fnode_normalize(FNODE f); |
FNODE fnode_normalize(FNODE f); |
FNODE fnode_normalize_nary(FNODE f); |
|
|
|
void Pquote_normalize(NODE arg,QUOTE *rp) |
void Pquote_normalize(NODE arg,QUOTE *rp) |
{ |
{ |
Line 2096 int fnode_is_dependent(FNODE f,V v) |
|
Line 2095 int fnode_is_dependent(FNODE f,V v) |
|
|
|
FNODE fnode_normalize_add(FNODE a1,FNODE a2); |
FNODE fnode_normalize_add(FNODE a1,FNODE a2); |
FNODE fnode_normalize_mul(FNODE a1,FNODE a2); |
FNODE fnode_normalize_mul(FNODE a1,FNODE a2); |
|
FNODE fnode_normalize_pwr(FNODE a1,FNODE a2); |
FNODE to_narymul(FNODE f); |
FNODE to_narymul(FNODE f); |
FNODE to_naryadd(FNODE f); |
FNODE to_naryadd(FNODE f); |
FNODE fnode_normalize_mul_coef(Num c,FNODE f); |
FNODE fnode_normalize_mul_coef(Num c,FNODE f); |
Line 2105 void fnode_coef_body(FNODE f,Num *cp,FNODE *bp); |
|
Line 2105 void fnode_coef_body(FNODE f,Num *cp,FNODE *bp); |
|
|
|
FNODE fnode_normalize(FNODE f) |
FNODE fnode_normalize(FNODE f) |
{ |
{ |
FNODE a1,a2,mone,r; |
FNODE a1,a2,mone,r,b2; |
NODE n; |
NODE n; |
|
Num invc2,c2; |
Q q; |
Q q; |
|
|
STOQ(-1,q); |
STOQ(-1,q); |
Line 2131 FNODE fnode_normalize(FNODE f) |
|
Line 2132 FNODE fnode_normalize(FNODE f) |
|
case '*': |
case '*': |
return fnode_normalize_mul(a1,a2); |
return fnode_normalize_mul(a1,a2); |
case '/': |
case '/': |
a2 = mkfnode(3,I_BOP,pwrfs,a2,mone); |
a2 = fnode_normalize_pwr(a2,mone); |
return fnode_normalize_mul(FA1(f),a2); |
return fnode_normalize_mul(a1,a2); |
|
case '^': |
|
return fnode_normalize_pwr(a1,a2); |
default: |
default: |
return mkfnode(3,I_BOP,FA0(f),a1,a2); |
return mkfnode(3,I_BOP,FA0(f),a1,a2); |
} |
} |
Line 2141 FNODE fnode_normalize(FNODE f) |
|
Line 2144 FNODE fnode_normalize(FNODE f) |
|
case I_NARYOP: |
case I_NARYOP: |
switch ( OPNAME(f) ) { |
switch ( OPNAME(f) ) { |
case '+': |
case '+': |
n = BDY((NODE)FA1(f)); |
n = (NODE)FA1(f); |
r = fnode_normalize(BDY(n)); n = NEXT(n); |
r = fnode_normalize(BDY(n)); n = NEXT(n); |
for ( ; n; n = NEXT(n) ) { |
for ( ; n; n = NEXT(n) ) { |
a1 = fnode_normalize(BDY(n)); |
a1 = fnode_normalize(BDY(n)); |
Line 2149 FNODE fnode_normalize(FNODE f) |
|
Line 2152 FNODE fnode_normalize(FNODE f) |
|
} |
} |
return r; |
return r; |
case '*': |
case '*': |
n = BDY((NODE)FA1(f)); |
n = (NODE)FA1(f); |
r = fnode_normalize(BDY(n)); n = NEXT(n); |
r = fnode_normalize(BDY(n)); n = NEXT(n); |
for ( ; n; n = NEXT(n) ) { |
for ( ; n; n = NEXT(n) ) { |
a1 = fnode_normalize(BDY(n)); |
a1 = fnode_normalize(BDY(n)); |
Line 2216 FNODE fnode_normalize_add(FNODE f1,FNODE f2) |
|
Line 2219 FNODE fnode_normalize_add(FNODE f1,FNODE f2) |
|
fnode_coef_body(BDY(n2),&c2,&b2); |
fnode_coef_body(BDY(n2),&c2,&b2); |
s = compfnode(b1,b2); |
s = compfnode(b1,b2); |
if ( s > 0 ) { |
if ( s > 0 ) { |
NEXTNODE(r0,r); BDY(r) = b1; n1 = NEXT(n1); |
NEXTNODE(r0,r); BDY(r) = BDY(n1); n1 = NEXT(n1); |
} else if ( s < 0 ) { |
} else if ( s < 0 ) { |
NEXTNODE(r0,r); BDY(r) = b2; n2 = NEXT(n2); |
NEXTNODE(r0,r); BDY(r) = BDY(n2); n2 = NEXT(n2); |
} else { |
} else { |
addnum(0,c1,c2,&c); |
addnum(0,c1,c2,&c); |
if ( c ) { |
if ( c ) { |
Line 2311 FNODE fnode_normalize_mul(FNODE f1,FNODE f2) |
|
Line 2314 FNODE fnode_normalize_mul(FNODE f1,FNODE f2) |
|
r = r1; |
r = r1; |
return mkfnode(2,I_NARYOP,mulfs,r); |
return mkfnode(2,I_NARYOP,mulfs,r); |
} |
} |
|
} |
|
|
|
FNODE fnode_normalize_pwr(FNODE f1,FNODE f2) |
|
{ |
|
FNODE b,b1,e1,e,cc,r; |
|
Num c,c1; |
|
NODE arg,n; |
|
|
|
if ( fnode_is_zero(f2) ) return mkfnode(1,I_FORMULA,ONE); |
|
else if ( fnode_is_zero(f1) ) return mkfnode(1,I_FORMULA,0); |
|
else if ( fnode_is_one(f2) ) return f1; |
|
else if ( fnode_is_number(f1) ) |
|
if ( fnode_is_integer(f2) ) { |
|
pwrnum(0,(Num)eval(f1),(Num)eval(f2),&c); |
|
return mkfnode(1,I_FORMULA,c); |
|
} else |
|
return mkfnode(3,I_BOP,pwrfs,f1,f2); |
|
else if ( f1->id == I_BOP && OPNAME(f1) == '^' ) { |
|
b1 = FA1(f1); e1 = FA2(f1); |
|
e = fnode_normalize_mul(e1,f2); |
|
if ( fnode_is_one(e) ) |
|
return b1; |
|
else |
|
return mkfnode(3,I_BOP,FA0(f1),b1,e); |
|
} else if ( f1->id == I_NARYOP && OPNAME(f1) == '*' ) { |
|
fnode_coef_body(f1,&c1,&b1); |
|
if ( fnode_is_integer(f2) ) { |
|
pwrnum(0,(Num)c1,(Num)eval(f2),&c); |
|
cc = mkfnode(1,I_FORMULA,c); |
|
b = fnode_normalize_pwr(b1,f2); |
|
if ( fnode_is_one(cc) ) |
|
return b; |
|
else { |
|
NEWFNODE(r,2); |
|
r->id = I_NARYOP; FA0(r) = mulfs; FA1(r) = mknode(2,cc,b); |
|
return r; |
|
} |
|
} else |
|
return mkfnode(3,I_BOP,pwrfs,f1,f2); |
|
} else |
|
return mkfnode(3,I_BOP,pwrfs,f1,f2); |
} |
} |
|
|
/* f = b^e */ |
/* f = b^e */ |