version 1.113, 2005/12/18 06:54:28 |
version 1.124, 2015/08/14 13:51:54 |
|
|
* 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.112 2005/12/18 01:57:21 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/strobj.c,v 1.123 2015/08/06 10:01:52 fujimoto Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 60 extern jmp_buf environnement; |
|
Line 60 extern jmp_buf environnement; |
|
|
|
#if defined(__GNUC__) |
#if defined(__GNUC__) |
#define INLINE inline |
#define INLINE inline |
#elif defined(VISUAL) |
#elif defined(VISUAL) || defined(__MINGW32__) |
#define INLINE __inline |
#define INLINE __inline |
#else |
#else |
#define INLINE |
#define INLINE |
Line 104 void Pnqt_match_rewrite(); |
|
Line 104 void Pnqt_match_rewrite(); |
|
void Pqt_to_nbp(); |
void Pqt_to_nbp(); |
void Pshuffle_mul(), Pharmonic_mul(); |
void Pshuffle_mul(), Pharmonic_mul(); |
void Pnbp_hm(), Pnbp_ht(), Pnbp_hc(), Pnbp_rest(); |
void Pnbp_hm(), Pnbp_ht(), Pnbp_hc(), Pnbp_rest(); |
void Pnbm_deg(); |
void Pnbp_tm(), Pnbp_tt(), Pnbp_tc(), Pnbp_trest(); |
|
void Pnbm_deg(), Pnbm_index(); |
void Pnbm_hp_rest(); |
void Pnbm_hp_rest(); |
void Pnbm_hxky(), Pnbm_xky_rest(); |
void Pnbm_hxky(), Pnbm_xky_rest(); |
void Pnbm_hv(), Pnbm_rest(); |
void Pnbm_hv(), Pnbm_tv(), Pnbm_rest(),Pnbm_trest(); |
|
|
void Pquote_to_funargs(),Pfunargs_to_quote(),Pget_function_name(); |
void Pquote_to_funargs(),Pfunargs_to_quote(),Pget_function_name(); |
void Pqt_match(),Pget_quote_id(); |
void Pqt_match(),Pget_quote_id(); |
Line 182 struct ftab str_tab[] = { |
|
Line 183 struct ftab str_tab[] = { |
|
{"nbp_ht", Pnbp_ht,1}, |
{"nbp_ht", Pnbp_ht,1}, |
{"nbp_hc", Pnbp_hc,1}, |
{"nbp_hc", Pnbp_hc,1}, |
{"nbp_rest", Pnbp_rest,1}, |
{"nbp_rest", Pnbp_rest,1}, |
|
{"nbp_tm", Pnbp_tm,1}, |
|
{"nbp_tt", Pnbp_tt,1}, |
|
{"nbp_tc", Pnbp_tc,1}, |
|
{"nbp_trest", Pnbp_trest,1}, |
{"nbm_deg", Pnbm_deg,1}, |
{"nbm_deg", Pnbm_deg,1}, |
|
{"nbm_index", Pnbm_index,1}, |
{"nbm_hxky", Pnbm_hxky,1}, |
{"nbm_hxky", Pnbm_hxky,1}, |
{"nbm_xky_rest", Pnbm_xky_rest,1}, |
{"nbm_xky_rest", Pnbm_xky_rest,1}, |
{"nbm_hp_rest", Pnbm_hp_rest,1}, |
{"nbm_hp_rest", Pnbm_hp_rest,1}, |
{"nbm_hv", Pnbm_hv,1}, |
{"nbm_hv", Pnbm_hv,1}, |
|
{"nbm_tv", Pnbm_tv,1}, |
{"nbm_rest", Pnbm_rest,1}, |
{"nbm_rest", Pnbm_rest,1}, |
|
{"nbm_trest", Pnbm_trest,1}, |
|
|
{"qt_to_nary",Pqt_to_nary,1}, |
{"qt_to_nary",Pqt_to_nary,1}, |
{"qt_to_bin",Pqt_to_bin,2}, |
{"qt_to_bin",Pqt_to_bin,2}, |
Line 462 int register_conv_func(Obj arg) |
|
Line 470 int register_conv_func(Obj arg) |
|
if ( !arg ) { |
if ( !arg ) { |
convfunc = 0; |
convfunc = 0; |
return 1; |
return 1; |
} else if ( OID(arg) == O_P && (int)(VR((P)arg))->attr == V_SR ) { |
} else if ( OID(arg) == O_P && (long)(VR((P)arg))->attr == V_SR ) { |
convfunc = (FUNC)(VR((P)arg)->priv); |
convfunc = (FUNC)(VR((P)arg)->priv); |
/* f must be a function which takes single argument */ |
/* f must be a function which takes single argument */ |
return 1; |
return 1; |
Line 841 void do_assign(NODE arg) |
|
Line 849 void do_assign(NODE arg) |
|
|
|
for ( t = arg; t; t = NEXT(t) ) { |
for ( t = arg; t; t = NEXT(t) ) { |
pair = BDY((LIST)BDY(t)); |
pair = BDY((LIST)BDY(t)); |
pv = (int)FA0((FNODE)BDY((QUOTE)BDY(pair))); |
pv = (long)FA0((FNODE)BDY((QUOTE)BDY(pair))); |
value = (QUOTE)(BDY(NEXT(pair))); |
value = (QUOTE)(BDY(NEXT(pair))); |
ASSPV(pv,value); |
ASSPV(pv,value); |
} |
} |
|
|
Obj *rp; |
Obj *rp; |
{ |
{ |
FNODE fnode; |
FNODE fnode; |
|
SNODE snode; |
char *cmd; |
char *cmd; |
#if defined(PARI) |
#if defined(PARI) |
void recover(int); |
void recover(int); |
|
|
# endif |
# endif |
#endif |
#endif |
cmd = BDY((STRING)ARG0(arg)); |
cmd = BDY((STRING)ARG0(arg)); |
|
#if 0 |
exprparse_create_var(0,cmd,&fnode); |
exprparse_create_var(0,cmd,&fnode); |
*rp = eval(fnode); |
*rp = eval(fnode); |
|
#else |
|
exprparse_create_var(0,cmd,&snode); |
|
*rp = evalstat(snode); |
|
#endif |
} |
} |
|
|
void Prtostr(arg,rp) |
void Prtostr(arg,rp) |
|
|
P *rp; |
P *rp; |
{ |
{ |
char *p; |
char *p; |
|
FUNC f; |
|
|
p = BDY((STRING)ARG0(arg)); |
p = BDY((STRING)ARG0(arg)); |
#if 0 |
#if 0 |
|
|
makevar(p,rp); |
makevar(p,rp); |
} |
} |
#else |
#else |
makevar(p,rp); |
gen_searchf_searchonly(p,&f); |
|
if ( f ) |
|
makesrvar(f,rp); |
|
else |
|
makevar(p,rp); |
#endif |
#endif |
} |
} |
|
|
Line 1417 char *symbol_name(char *name) |
|
Line 1436 char *symbol_name(char *name) |
|
|
|
void Pget_function_name(NODE arg,STRING *rp) |
void Pget_function_name(NODE arg,STRING *rp) |
{ |
{ |
QUOTEARG qa; |
QUOTEARG qa; |
ARF f; |
|
char *opname; |
|
|
|
qa = (QUOTEARG)BDY(arg); |
qa = (QUOTEARG)BDY(arg); |
if ( !qa || OID(qa) != O_QUOTEARG || qa->type != A_arf ) |
if ( !qa || OID(qa) != O_QUOTEARG ) { |
|
*rp = 0; return; |
|
} |
|
switch ( qa->type ) { |
|
case A_arf: |
|
MKSTR(*rp,((ARF)BDY(qa))->name); |
|
break; |
|
case A_func: |
|
MKSTR(*rp,((FUNC)BDY(qa))->name); |
|
break; |
|
default: |
*rp = 0; |
*rp = 0; |
else { |
break; |
f = (ARF)BDY(qa); |
} |
opname = f->name; |
|
MKSTR(*rp,opname); |
|
} |
|
} |
} |
|
|
FNODE strip_paren(FNODE); |
FNODE strip_paren(FNODE); |
Line 1538 void fnodetotex_tb(FNODE f,TB tb) |
|
Line 1562 void fnodetotex_tb(FNODE f,TB tb) |
|
for ( args = NEXT(args); args; args = NEXT(args) ) { |
for ( args = NEXT(args); args; args = NEXT(args) ) { |
write_tb("+",tb); |
write_tb("+",tb); |
f1 = (FNODE)BDY(args); |
f1 = (FNODE)BDY(args); |
if ( fnode_is_var(f1) || IS_MUL(f1) ) |
/* if ( fnode_is_var(f1) || IS_MUL(f1) ) |
fnodetotex_tb(f1,tb); |
fnodetotex_tb(f1,tb); |
else { |
else */ { |
write_tb("(",tb); |
write_tb("(",tb); |
fnodetotex_tb(f1,tb); |
fnodetotex_tb(f1,tb); |
write_tb(")",tb); |
write_tb(")",tb); |
Line 2410 void Pnbp_ht(NODE arg, NBP *rp) |
|
Line 2434 void Pnbp_ht(NODE arg, NBP *rp) |
|
else { |
else { |
m = (NBM)BDY(BDY(p)); |
m = (NBM)BDY(BDY(p)); |
NEWNBM(m1); |
NEWNBM(m1); |
m1->d = m->d; m1->c = ONE; m1->b = m->b; |
m1->d = m->d; m1->c = (P)ONE; m1->b = m->b; |
MKNODE(n,m1,0); |
MKNODE(n,m1,0); |
MKNBP(*rp,n); |
MKNBP(*rp,n); |
} |
} |
} |
} |
|
|
void Pnbp_hc(NODE arg, Q *rp) |
void Pnbp_hc(NODE arg, P *rp) |
{ |
{ |
NBP p; |
NBP p; |
NBM m; |
NBM m; |
Line 2444 void Pnbp_rest(NODE arg, NBP *rp) |
|
Line 2468 void Pnbp_rest(NODE arg, NBP *rp) |
|
} |
} |
} |
} |
|
|
|
void Pnbp_tm(NODE arg, NBP *rp) |
|
{ |
|
NBP p; |
|
NODE n; |
|
NBM m; |
|
|
|
p = (NBP)ARG0(arg); |
|
if ( !p ) *rp = 0; |
|
else { |
|
for ( n = BDY(p); NEXT(n); n = NEXT(n) ); |
|
m = (NBM)BDY(n); |
|
MKNODE(n,m,0); |
|
MKNBP(*rp,n); |
|
} |
|
} |
|
|
|
void Pnbp_tt(NODE arg, NBP *rp) |
|
{ |
|
NBP p; |
|
NODE n; |
|
NBM m,m1; |
|
|
|
p = (NBP)ARG0(arg); |
|
if ( !p ) *rp = 0; |
|
else { |
|
for ( n = BDY(p); NEXT(n); n = NEXT(n) ); |
|
m = (NBM)BDY(n); |
|
NEWNBM(m1); |
|
m1->d = m->d; m1->c = (P)ONE; m1->b = m->b; |
|
MKNODE(n,m1,0); |
|
MKNBP(*rp,n); |
|
} |
|
} |
|
|
|
void Pnbp_tc(NODE arg, P *rp) |
|
{ |
|
NBP p; |
|
NBM m; |
|
NODE n; |
|
|
|
p = (NBP)ARG0(arg); |
|
if ( !p ) *rp = 0; |
|
else { |
|
for ( n = BDY(p); NEXT(n); n = NEXT(n) ); |
|
m = (NBM)BDY(n); |
|
*rp = m->c; |
|
} |
|
} |
|
|
|
void Pnbp_trest(NODE arg, NBP *rp) |
|
{ |
|
NBP p; |
|
NODE n,r,r0; |
|
|
|
p = (NBP)ARG0(arg); |
|
if ( !p ) *rp = 0; |
|
else { |
|
n = BDY(p); |
|
for ( r0 = 0; NEXT(n); n = NEXT(n) ) { |
|
NEXTNODE(r0,r); |
|
BDY(r) = (pointer)BDY(n); |
|
} |
|
if ( r0 ) { |
|
NEXT(r) = 0; |
|
MKNBP(*rp,r0); |
|
} else |
|
*rp = 0; |
|
} |
|
} |
|
|
void Pnbm_deg(NODE arg, Q *rp) |
void Pnbm_deg(NODE arg, Q *rp) |
{ |
{ |
NBP p; |
NBP p; |
Line 2458 void Pnbm_deg(NODE arg, Q *rp) |
|
Line 2552 void Pnbm_deg(NODE arg, Q *rp) |
|
} |
} |
} |
} |
|
|
|
void Pnbm_index(NODE arg, Q *rp) |
|
{ |
|
NBP p; |
|
NBM m; |
|
unsigned int *b; |
|
int d,i,r; |
|
|
|
p = (NBP)ARG0(arg); |
|
if ( !p ) |
|
STOQ(0,*rp); |
|
else { |
|
m = (NBM)BDY(BDY(p)); |
|
d = m->d; |
|
if ( d > 32 ) |
|
error("nbm_index : weight too large"); |
|
b = m->b; |
|
for ( r = 0, i = d-2; i > 0; i-- ) |
|
if ( !NBM_GET(b,i) ) r |= (1<<(d-2-i)); |
|
STOQ(r,*rp); |
|
} |
|
} |
|
|
void Pnbm_hp_rest(NODE arg, LIST *rp) |
void Pnbm_hp_rest(NODE arg, LIST *rp) |
{ |
{ |
NBP p,h,r; |
NBP p,h,r; |
Line 2479 void Pnbm_hp_rest(NODE arg, LIST *rp) |
|
Line 2595 void Pnbm_hp_rest(NODE arg, LIST *rp) |
|
for ( i = 1; i < d; i++ ) |
for ( i = 1; i < d; i++ ) |
if ( NBM_GET(b,i) != v ) break; |
if ( NBM_GET(b,i) != v ) break; |
NEWNBM(m1); NEWNBMBDY(m1,i); |
NEWNBM(m1); NEWNBMBDY(m1,i); |
b1 = m1->b; m1->d = i; m1->c = ONE; |
b1 = m1->b; m1->d = i; m1->c = (P)ONE; |
if ( v ) for ( j = 0; j < i; j++ ) NBM_SET(b1,j); |
if ( v ) for ( j = 0; j < i; j++ ) NBM_SET(b1,j); |
else for ( j = 0; j < i; j++ ) NBM_CLR(b1,j); |
else for ( j = 0; j < i; j++ ) NBM_CLR(b1,j); |
MKNODE(n,m1,0); MKNBP(h,n); |
MKNODE(n,m1,0); MKNBP(h,n); |
|
|
d1 = d-i; |
d1 = d-i; |
NEWNBM(m1); NEWNBMBDY(m1,d1); |
NEWNBM(m1); NEWNBMBDY(m1,d1); |
b1 = m1->b; m1->d = d1; m1->c = ONE; |
b1 = m1->b; m1->d = d1; m1->c = (P)ONE; |
for ( j = 0, k = i; j < d1; j++, k++ ) |
for ( j = 0, k = i; j < d1; j++, k++ ) |
if ( NBM_GET(b,k) ) NBM_SET(b1,j); |
if ( NBM_GET(b,k) ) NBM_SET(b1,j); |
else NBM_CLR(b1,j); |
else NBM_CLR(b1,j); |
Line 2541 void Pnbm_rest(NODE arg, NBP *rp) |
|
Line 2657 void Pnbm_rest(NODE arg, NBP *rp) |
|
separate_nbm((NBM)BDY(BDY(p)),0,0,rp); |
separate_nbm((NBM)BDY(BDY(p)),0,0,rp); |
} |
} |
|
|
|
void Pnbm_tv(NODE arg, NBP *rp) |
|
{ |
|
NBP p; |
|
|
|
p = (NBP)ARG0(arg); |
|
if ( !p ) |
|
*rp = 0; |
|
else |
|
separate_tail_nbm((NBM)BDY(BDY(p)),0,0,rp); |
|
} |
|
|
|
void Pnbm_trest(NODE arg, NBP *rp) |
|
{ |
|
NBP p; |
|
|
|
p = (NBP)ARG0(arg); |
|
if ( !p ) |
|
*rp = 0; |
|
else |
|
separate_tail_nbm((NBM)BDY(BDY(p)),0,rp,0); |
|
} |
|
|
NBP fnode_to_nbp(FNODE f) |
NBP fnode_to_nbp(FNODE f) |
{ |
{ |
Q r; |
Q r; |
Line 2554 NBP fnode_to_nbp(FNODE f) |
|
Line 2692 NBP fnode_to_nbp(FNODE f) |
|
r = eval(f); |
r = eval(f); |
NEWNBM(m); |
NEWNBM(m); |
if ( OID(r) == O_N ) { |
if ( OID(r) == O_N ) { |
m->d = 0; m->c = (Q)r; m->b = 0; |
m->d = 0; m->c = (P)r; m->b = 0; |
} else { |
} else { |
v = VR((P)r); |
v = VR((P)r); |
m->d = 1; m->c = ONE; NEWNBMBDY(m,1); |
m->d = 1; m->c = (P)ONE; NEWNBMBDY(m,1); |
if ( !strcmp(NAME(v),"x") ) NBM_SET(m->b,0); |
if ( !strcmp(NAME(v),"x") ) NBM_SET(m->b,0); |
else NBM_CLR(m->b,0); |
else NBM_CLR(m->b,0); |
} |
} |
Line 2968 FNODE fnode_node_to_nary(ARF op,NODE n) |
|
Line 3106 FNODE fnode_node_to_nary(ARF op,NODE n) |
|
{ |
{ |
if ( !n ) { |
if ( !n ) { |
if ( op->name[0] == '+' ) |
if ( op->name[0] == '+' ) |
return mkfnode(1,I_FORMULA,0); |
return mkfnode(1,I_FORMULA,NULLP); |
else |
else |
return mkfnode(1,I_FORMULA,ONE); |
return mkfnode(1,I_FORMULA,ONE); |
} else if ( !NEXT(n) ) return BDY(n); |
} else if ( !NEXT(n) ) return BDY(n); |
Line 2984 FNODE nfnode_mul(FNODE f1,FNODE f2,int expand) |
|
Line 3122 FNODE nfnode_mul(FNODE f1,FNODE f2,int expand) |
|
Obj c1,c2,c,e; |
Obj c1,c2,c,e; |
int l1,l,i,j; |
int l1,l,i,j; |
|
|
if ( IS_ZERO(f1) || IS_ZERO(f2) ) return mkfnode(1,I_FORMULA,0); |
if ( IS_ZERO(f1) || IS_ZERO(f2) ) return mkfnode(1,I_FORMULA,NULLP); |
else if ( fnode_is_coef(f1) ) |
else if ( fnode_is_coef(f1) ) |
return nfnode_mul_coef((Obj)eval(f1),f2,expand); |
return nfnode_mul_coef((Obj)eval(f1),f2,expand); |
else if ( fnode_is_coef(f2) ) |
else if ( fnode_is_coef(f2) ) |
return nfnode_mul_coef((Obj)eval(f2),f1,expand); |
return nfnode_mul_coef((Obj)eval(f2),f1,expand); |
|
|
if ( expand && IS_NARYADD(f1) ) { |
if ( expand && IS_NARYADD(f1) ) { |
t = mkfnode(1,I_FORMULA,0); |
t = mkfnode(1,I_FORMULA,NULLP); |
for ( n1 = (NODE)FA1(f1); n1; n1 = NEXT(n1) ) { |
for ( n1 = (NODE)FA1(f1); n1; n1 = NEXT(n1) ) { |
t1 = nfnode_mul(BDY(n1),f2,expand); |
t1 = nfnode_mul(BDY(n1),f2,expand); |
t = nfnode_add(t,t1,expand); |
t = nfnode_add(t,t1,expand); |
Line 2999 FNODE nfnode_mul(FNODE f1,FNODE f2,int expand) |
|
Line 3137 FNODE nfnode_mul(FNODE f1,FNODE f2,int expand) |
|
return t; |
return t; |
} |
} |
if ( expand && IS_NARYADD(f2) ) { |
if ( expand && IS_NARYADD(f2) ) { |
t = mkfnode(1,I_FORMULA,0); |
t = mkfnode(1,I_FORMULA,NULLP); |
for ( n2 = (NODE)FA1(f2); n2; n2 = NEXT(n2) ) { |
for ( n2 = (NODE)FA1(f2); n2; n2 = NEXT(n2) ) { |
t1 = nfnode_mul(f1,BDY(n2),expand); |
t1 = nfnode_mul(f1,BDY(n2),expand); |
t = nfnode_add(t,t1,expand); |
t = nfnode_add(t,t1,expand); |
Line 3009 FNODE nfnode_mul(FNODE f1,FNODE f2,int expand) |
|
Line 3147 FNODE nfnode_mul(FNODE f1,FNODE f2,int expand) |
|
|
|
fnode_coef_body(f1,&c1,&b1); fnode_coef_body(f2,&c2,&b2); |
fnode_coef_body(f1,&c1,&b1); fnode_coef_body(f2,&c2,&b2); |
arf_mul(CO,c1,c2,&c); |
arf_mul(CO,c1,c2,&c); |
if ( !c ) return mkfnode(1,I_FORMULA,0); |
if ( !c ) return mkfnode(1,I_FORMULA,NULLP); |
|
|
|
|
n1 = (NODE)FA1(to_narymul(b1)); n2 = (NODE)FA1(to_narymul(b2)); |
n1 = (NODE)FA1(to_narymul(b1)); n2 = (NODE)FA1(to_narymul(b2)); |
Line 3059 FNODE nfnode_pwr(FNODE f1,FNODE f2,int expand) |
|
Line 3197 FNODE nfnode_pwr(FNODE f1,FNODE f2,int expand) |
|
Q q; |
Q q; |
|
|
if ( IS_ZERO(f2) ) return mkfnode(1,I_FORMULA,ONE); |
if ( IS_ZERO(f2) ) return mkfnode(1,I_FORMULA,ONE); |
else if ( IS_ZERO(f1) ) return mkfnode(1,I_FORMULA,0); |
else if ( IS_ZERO(f1) ) return mkfnode(1,I_FORMULA,NULLP); |
else if ( fnode_is_coef(f1) ) { |
else if ( fnode_is_coef(f1) ) { |
if ( fnode_is_integer(f2) ) { |
if ( fnode_is_integer(f2) ) { |
if ( fnode_is_one(f2) ) return f1; |
if ( fnode_is_one(f2) ) return f1; |
Line 3118 FNODE fnode_expand_pwr(FNODE f,int n,int expand) |
|
Line 3256 FNODE fnode_expand_pwr(FNODE f,int n,int expand) |
|
Q q; |
Q q; |
|
|
if ( !n ) return mkfnode(1,I_FORMULA,ONE); |
if ( !n ) return mkfnode(1,I_FORMULA,ONE); |
else if ( IS_ZERO(f) ) return mkfnode(1,I_FORMULA,0); |
else if ( IS_ZERO(f) ) return mkfnode(1,I_FORMULA,NULLP); |
else if ( n == 1 ) return f; |
else if ( n == 1 ) return f; |
else { |
else { |
switch ( expand ) { |
switch ( expand ) { |
Line 3181 FNODE nfnode_mul_coef(Obj c,FNODE f,int expand) |
|
Line 3319 FNODE nfnode_mul_coef(Obj c,FNODE f,int expand) |
|
NODE n,r,r0; |
NODE n,r,r0; |
|
|
if ( !c ) |
if ( !c ) |
return mkfnode(I_FORMULA,0); |
return mkfnode(1,I_FORMULA,NULLP); |
else { |
else { |
fnode_coef_body(f,&c1,&b1); |
fnode_coef_body(f,&c1,&b1); |
arf_mul(CO,c,c1,&c2); |
arf_mul(CO,c,c1,&c2); |
Line 3301 int nfnode_comp_lex(FNODE f1,FNODE f2) |
|
Line 3439 int nfnode_comp_lex(FNODE f1,FNODE f2) |
|
NODE n1,n2; |
NODE n1,n2; |
int r,i1,i2,ret; |
int r,i1,i2,ret; |
char *nm1,*nm2; |
char *nm1,*nm2; |
FNODE b1,b2,e1,e2,g,a1,a2,fn1,fn2; |
FNODE b1,b2,e1,e2,g,a1,a2,fn1,fn2,h1,h2; |
Num ee,ee1; |
Num ee,ee1; |
Obj c1,c2; |
Obj c1,c2; |
int w1,w2; |
int w1,w2; |
Line 3309 int nfnode_comp_lex(FNODE f1,FNODE f2) |
|
Line 3447 int nfnode_comp_lex(FNODE f1,FNODE f2) |
|
if ( IS_NARYADD(f1) || IS_NARYADD(f2) ) { |
if ( IS_NARYADD(f1) || IS_NARYADD(f2) ) { |
f1 = to_naryadd(f1); f2 = to_naryadd(f2); |
f1 = to_naryadd(f1); f2 = to_naryadd(f2); |
n1 = (NODE)FA1(f1); n2 = (NODE)FA1(f2); |
n1 = (NODE)FA1(f1); n2 = (NODE)FA1(f2); |
while ( n1 && n2 ) |
for ( ; n1 && n2; n1 = NEXT(n1), n2 = NEXT(n2) ) { |
if ( r = nfnode_comp_lex(BDY(n1),BDY(n2)) ) return r; |
r = nfnode_comp_lex(BDY(n1),BDY(n2)); |
else { |
if ( r ) return r; |
n1 = NEXT(n1); n2 = NEXT(n2); |
} |
} |
if ( !n1 && !n2 ) return 0; |
return n1?1:(n2?-1:0); |
h1 = n1 ? (FNODE)BDY(n1) : mkfnode(1,I_FORMULA,NULLP); |
|
h2 = n2 ? (FNODE)BDY(n2) : mkfnode(1,I_FORMULA,NULLP); |
|
return nfnode_comp_lex(h1,h2); |
} |
} |
if ( IS_NARYMUL(f1) || IS_NARYMUL(f2) ) { |
if ( IS_NARYMUL(f1) || IS_NARYMUL(f2) ) { |
fnode_coef_body(f1,&c1,&b1); |
fnode_coef_body(f1,&c1,&b1); |
Line 3322 int nfnode_comp_lex(FNODE f1,FNODE f2) |
|
Line 3462 int nfnode_comp_lex(FNODE f1,FNODE f2) |
|
if ( !compfnode(b1,b2) ) return arf_comp(CO,c1,c2); |
if ( !compfnode(b1,b2) ) return arf_comp(CO,c1,c2); |
b1 = to_narymul(b1); b2 = to_narymul(b2); |
b1 = to_narymul(b1); b2 = to_narymul(b2); |
n1 = (NODE)FA1(b1); n2 = (NODE)FA1(b2); |
n1 = (NODE)FA1(b1); n2 = (NODE)FA1(b2); |
while ( 1 ) { |
for ( ; n1 && n2; n1 = NEXT(n1), n2 = NEXT(n2) ) { |
while ( n1 && n2 && !compfnode(BDY(n1),BDY(n2)) ) { |
r = nfnode_comp_lex(BDY(n1),BDY(n2)); |
n1 = NEXT(n1); n2 = NEXT(n2); |
if ( r ) return r; |
} |
|
if ( !n1 || !n2 ) { |
|
return n1?1:(n2?-1:0); |
|
} |
|
fnode_base_exp(BDY(n1),&b1,&e1); |
|
fnode_base_exp(BDY(n2),&b2,&e2); |
|
|
|
if ( r = nfnode_comp_lex(b1,b2) ) { |
|
if ( r > 0 ) |
|
return nfnode_comp_lex(e1,mkfnode(1,I_FORMULA,0)); |
|
else if ( r < 0 ) |
|
return nfnode_comp_lex(mkfnode(1,I_FORMULA,0),e2); |
|
} else { |
|
n1 = NEXT(n1); n2 = NEXT(n2); |
|
if ( fnode_is_number(e1) && fnode_is_number(e2) ) { |
|
/* f1 = t b^e1 ... , f2 = t b^e2 ... */ |
|
subnum(0,eval(e1),eval(e2),&ee); |
|
r = compnum(0,ee,0); |
|
if ( r > 0 ) { |
|
g = mkfnode(3,I_BOP,pwrfs,b1,mkfnode(1,I_FORMULA,ee)); |
|
MKNODE(n1,g,n1); |
|
} else if ( r < 0 ) { |
|
chsgnnum(ee,&ee1); |
|
g = mkfnode(3,I_BOP,pwrfs,b1,mkfnode(1,I_FORMULA,ee1)); |
|
MKNODE(n2,g,n2); |
|
} |
|
} else { |
|
r = nfnode_comp_lex(e1,e2); |
|
if ( r > 0 ) return 1; |
|
else if ( r < 0 ) return -1; |
|
} |
|
} |
|
} |
} |
|
if ( !n1 && !n2 ) return 0; |
|
h1 = n1 ? (FNODE)BDY(n1) : mkfnode(1,I_FORMULA,ONE); |
|
h2 = n2 ? (FNODE)BDY(n2) : mkfnode(1,I_FORMULA,ONE); |
|
return nfnode_comp_lex(h1,h2); |
} |
} |
if ( IS_BINARYPWR(f1) || IS_BINARYPWR(f2) ) { |
if ( IS_BINARYPWR(f1) || IS_BINARYPWR(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 = nfnode_comp_lex(b1,b2) ) { |
if ( r = nfnode_comp_lex(b1,b2) ) { |
if ( r > 0 ) |
if ( r > 0 ) |
return nfnode_comp_lex(e1,mkfnode(1,I_FORMULA,0)); |
return nfnode_comp_lex(e1,mkfnode(1,I_FORMULA,NULLP)); |
else if ( r < 0 ) |
else if ( r < 0 ) |
return nfnode_comp_lex(mkfnode(1,I_FORMULA,0),e2); |
return nfnode_comp_lex(mkfnode(1,I_FORMULA,NULLP),e2); |
} else return nfnode_comp_lex(e1,e2); |
} else return nfnode_comp_lex(e1,e2); |
} |
} |
|
|
Line 3525 int nfnode_match(FNODE f,FNODE pat,NODE *rp) |
|
Line 3637 int nfnode_match(FNODE f,FNODE pat,NODE *rp) |
|
} else { |
} else { |
/* XXX : I_FUNC_HEAD is a dummy id to pass FUNC */ |
/* XXX : I_FUNC_HEAD is a dummy id to pass FUNC */ |
fh = mkfnode(1,I_FUNC_HEAD,FA0(f)); |
fh = mkfnode(1,I_FUNC_HEAD,FA0(f)); |
m = mknode(1,mknode(2,FA0((FNODE)FA0(pat)),fh),0); |
m = mknode(1,mknode(2,FA0((FNODE)FA0(pat)),fh),NULLP); |
} |
} |
/* FA1(f) and FA1(pat) are I_LIST */ |
/* FA1(f) and FA1(pat) are I_LIST */ |
fa = (NODE)FA0((FNODE)FA1(f)); |
fa = (NODE)FA0((FNODE)FA1(f)); |