version 1.80, 2005/10/26 02:58:25 |
version 1.83, 2005/10/26 10:44:50 |
|
|
* 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.79 2005/10/19 10:31:18 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.82 2005/10/26 08:39:58 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 127 struct ftab str_tab[] = { |
|
Line 127 struct ftab str_tab[] = { |
|
{"quote_is_dependent",Pquote_is_dependent,2}, |
{"quote_is_dependent",Pquote_is_dependent,2}, |
|
|
{"quote_normalize",Pquote_normalize,-2}, |
{"quote_normalize",Pquote_normalize,-2}, |
{"quote_normalize_comp",Pquote_normalize_comp,2}, |
{"quote_normalize_comp",Pquote_normalize_comp,2,0x3}, |
|
|
{"quote_to_nary",Pquote_to_nary,1}, |
{"quote_to_nary",Pquote_to_nary,1}, |
{"quote_to_bin",Pquote_to_bin,2}, |
{"quote_to_bin",Pquote_to_bin,2}, |
Line 2364 FNODE fnode_normalize_pwr(FNODE f1,FNODE f2,int expand |
|
Line 2364 FNODE fnode_normalize_pwr(FNODE f1,FNODE f2,int expand |
|
return b; |
return b; |
else |
else |
return fnode_node_to_narymul(mknode(2,cc,b)); |
return fnode_node_to_narymul(mknode(2,cc,b)); |
} else if ( expand && fnode_is_nonnegative_integer(f2) ) { |
} else if ( expand && fnode_is_integer(f2) |
|
&& fnode_is_nonnegative_integer(f2) ) { |
q = (Q)eval(f2); |
q = (Q)eval(f2); |
if ( PL(NM(q)) > 1 ) error("fnode_normalize_pwr : exponent too large"); |
if ( PL(NM(q)) > 1 ) error("fnode_normalize_pwr : exponent too large"); |
return fnode_expand_pwr(f1,QTOS(q)); |
return fnode_expand_pwr(f1,QTOS(q)); |
Line 2483 int fnode_normalize_comp(FNODE f1,FNODE f2) |
|
Line 2484 int fnode_normalize_comp(FNODE f1,FNODE f2) |
|
{ |
{ |
NODE n1,n2; |
NODE n1,n2; |
int r,i1,i2; |
int r,i1,i2; |
FUNC fp1,fp2; |
char *nm1,*nm2; |
FNODE b1,b2,e1,e2,g; |
FNODE b1,b2,e1,e2,g; |
Num ee,ee1; |
Num ee,ee1,c1,c2; |
|
|
if ( IS_ZERO(f1) ) |
if ( IS_ZERO(f1) ) |
if ( IS_ZERO(f2) ) return 0; |
if ( IS_ZERO(f2) ) return 0; |
Line 2505 int fnode_normalize_comp(FNODE f1,FNODE f2) |
|
Line 2506 int fnode_normalize_comp(FNODE f1,FNODE f2) |
|
else return 0; |
else return 0; |
} |
} |
if ( IS_NARYMUL(f1) || IS_NARYMUL(f2) ) { |
if ( IS_NARYMUL(f1) || IS_NARYMUL(f2) ) { |
f1 = to_narymul(f1); f2 = to_narymul(f2); |
fnode_coef_body(f1,&c1,&b1); |
n1 = (NODE)FA1(f1); n2 = (NODE)FA1(f2); |
fnode_coef_body(f2,&c2,&b2); |
|
if ( !compfnode(b1,b2) ) return compnum(0,c1,c2); |
|
b1 = to_narymul(b1); b2 = to_narymul(b2); |
|
n1 = (NODE)FA1(b1); n2 = (NODE)FA1(b2); |
while ( 1 ) { |
while ( 1 ) { |
while ( n1 && n2 && !compfnode(BDY(n1),BDY(n2)) ) { |
while ( n1 && n2 && !compfnode(BDY(n1),BDY(n2)) ) { |
n1 = NEXT(n1); n2 = NEXT(n2); |
n1 = NEXT(n1); n2 = NEXT(n2); |
Line 2518 int fnode_normalize_comp(FNODE f1,FNODE f2) |
|
Line 2522 int fnode_normalize_comp(FNODE f1,FNODE f2) |
|
} |
} |
fnode_base_exp(BDY(n1),&b1,&e1); |
fnode_base_exp(BDY(n1),&b1,&e1); |
fnode_base_exp(BDY(n2),&b2,&e2); |
fnode_base_exp(BDY(n2),&b2,&e2); |
n1 = NEXT(n1); n2 = NEXT(n2); |
|
|
|
if ( r = fnode_normalize_comp(b1,b2) ) return r; |
if ( r = fnode_normalize_comp(b1,b2) ) { |
else if ( fnode_is_number(e1) && fnode_is_number(e2) ) { |
if ( r > 0 ) |
/* f1 = t b^e1 ... , f2 = t b^e2 ... */ |
return fnode_normalize_comp(e1,mkfnode(1,I_FORMULA,0)); |
subnum(0,eval(e1),eval(e2),&ee); |
else if ( r < 0 ) |
r = compnum(0,ee,0); |
return fnode_normalize_comp(mkfnode(1,I_FORMULA,0),e2); |
if ( r > 0 ) { |
} else { |
/* e1>e2 */ |
n1 = NEXT(n1); n2 = NEXT(n2); |
g = mkfnode(3,I_BOP,pwrfs,b1,mkfnode(1,I_FORMULA,ee)); |
if ( fnode_is_number(e1) && fnode_is_number(e2) ) { |
MKNODE(n1,g,n1); |
/* f1 = t b^e1 ... , f2 = t b^e2 ... */ |
} else if ( r < 0 ) { |
subnum(0,eval(e1),eval(e2),&ee); |
/* e1<e2 */ |
r = compnum(0,ee,0); |
chsgnnum(ee,&ee1); ee1 = ee; |
if ( r > 0 ) { |
g = mkfnode(3,I_BOP,pwrfs,b1,mkfnode(1,I_FORMULA,ee)); |
/* e1>e2 */ |
|
g = mkfnode(3,I_BOP,pwrfs,b1,mkfnode(1,I_FORMULA,ee)); |
|
MKNODE(n1,g,n1); |
|
} else if ( r < 0 ) { |
|
/* e1<e2 */ |
|
chsgnnum(ee,&ee1); ee = ee1; |
|
g = mkfnode(3,I_BOP,pwrfs,b1,mkfnode(1,I_FORMULA,ee)); |
MKNODE(n2,g,n2); |
MKNODE(n2,g,n2); |
|
} |
|
} else { |
|
r = fnode_normalize_comp(e1,e2); |
|
if ( r > 0 ) return 1; |
|
else if ( r < 0 ) return -1; |
} |
} |
} else { |
|
r = fnode_normalize_comp(e1,e2); |
|
if ( r > 0 ) return 1; |
|
else if ( r < 0 ) return -1; |
|
} |
} |
} |
} |
} |
} |
Line 2562 int fnode_normalize_comp(FNODE f1,FNODE f2) |
|
Line 2572 int fnode_normalize_comp(FNODE f1,FNODE f2) |
|
case I_FORMULA: |
case I_FORMULA: |
return 1; |
return 1; |
case I_FUNC: |
case I_FUNC: |
fp1 = (FUNC)FA0(f1); fp2 = (FUNC)FA0(f2); |
nm1 = ((FUNC)FA0(f1))->name; nm2 = ((FUNC)FA0(f2))->name; |
if ( fp1 > fp2 ) return 1; |
r = strcmp(nm1,nm2); |
else if ( fp1 < fp2 ) return -1; |
if ( r > 0 ) return 1; |
|
else if ( r < 0 ) return -1; |
else { |
else { |
/* compare args */ |
/* compare args */ |
n1 = FA0((FNODE)FA1(f1)); n2 = FA0((FNODE)FA1(f2)); |
n1 = FA0((FNODE)FA1(f1)); n2 = FA0((FNODE)FA1(f2)); |
while ( n1 && n2 ) |
while ( n1 && n2 ) |
if ( r = fnode_normalize_comp(BDY(n1),BDY(n2)) ) |
if ( r = fnode_normalize_comp(BDY(n1),BDY(n2)) ) return r; |
return r; |
else { |
|
n1 = NEXT(n1); n2 = NEXT(n2); |
|
} |
if ( n1 ) return 1; |
if ( n1 ) return 1; |
else if ( n2 ) return -1; |
else if ( n2 ) return -1; |
else return 0; |
else return 0; |
Line 2606 int fnode_normalize_comp_pwr(FNODE f1,FNODE f2) |
|
Line 2619 int fnode_normalize_comp_pwr(FNODE f1,FNODE f2) |
|
|
|
fnode_base_exp(f1,&b1,&e1); |
fnode_base_exp(f1,&b1,&e1); |
fnode_base_exp(f2,&b2,&e2); |
fnode_base_exp(f2,&b2,&e2); |
if ( r = fnode_normalize_comp(b1,b2) ) return r; |
if ( r = fnode_normalize_comp(b1,b2) ) { |
else return fnode_normalize_comp(e1,e2); |
if ( r > 0 ) |
|
return fnode_normalize_comp(e1,mkfnode(1,I_FORMULA,0)); |
|
else if ( r < 0 ) |
|
return fnode_normalize_comp(mkfnode(1,I_FORMULA,0),e2); |
|
} else return fnode_normalize_comp(e1,e2); |
} |
} |