version 1.113, 2005/12/18 06:54:28 |
version 1.121, 2011/03/30 02:43:18 |
|
|
* 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.120 2010/04/23 06:53:30 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
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 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,0); |
|
h2 = n2 ? (FNODE)BDY(n2) : mkfnode(1,I_FORMULA,0); |
|
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); |