version 1.4, 2001/10/09 01:36:24 |
version 1.12, 2015/08/14 13:51:56 |
|
|
* 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/parse/puref.c,v 1.3 2000/08/22 05:04:27 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/parse/puref.c,v 1.11 2015/08/08 14:19:42 fujimoto Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 63 void searchpf(char *name,FUNC *fp) |
|
Line 63 void searchpf(char *name,FUNC *fp) |
|
pf = (PF)node->body; |
pf = (PF)node->body; |
*fp = t = (FUNC)MALLOC(sizeof(struct oFUNC)); |
*fp = t = (FUNC)MALLOC(sizeof(struct oFUNC)); |
t->name = name; t->id = A_PURE; t->argc = pf->argc; |
t->name = name; t->id = A_PURE; t->argc = pf->argc; |
t->f.puref = pf; |
t->f.puref = pf; t->fullname = name; |
return; |
return; |
} |
} |
*fp = 0; |
*fp = 0; |
Line 81 void searchc(char *name,FUNC *fp) |
|
Line 81 void searchc(char *name,FUNC *fp) |
|
pf = (PF)node->body; |
pf = (PF)node->body; |
*fp = t = (FUNC)MALLOC(sizeof(struct oFUNC)); |
*fp = t = (FUNC)MALLOC(sizeof(struct oFUNC)); |
t->name = name; t->id = A_PURE; t->argc = pf->argc; |
t->name = name; t->id = A_PURE; t->argc = pf->argc; |
t->f.puref = pf; |
t->f.puref = pf; t->fullname = name; |
return; |
return; |
} |
} |
*fp = 0; |
*fp = 0; |
Line 183 void appendpfins(V v,V *vp) |
|
Line 183 void appendpfins(V v,V *vp) |
|
for ( node = fdef->ins; node; node = NEXT(node) ) { |
for ( node = fdef->ins; node; node = NEXT(node) ) { |
for ( i = 0, tad = ((PFINS)((V)node->body)->priv)->ad; |
for ( i = 0, tad = ((PFINS)((V)node->body)->priv)->ad; |
i < fdef->argc; i++ ) |
i < fdef->argc; i++ ) |
if ( (ad[i].d != tad[i].d) || compr(CO,ad[i].arg,tad[i].arg) ) |
if ( (ad[i].d != tad[i].d) || !equalr(CO,ad[i].arg,tad[i].arg) ) |
break; |
break; |
if ( i == fdef->argc ) { |
if ( i == fdef->argc ) { |
*vp = (V)node->body; |
*vp = (V)node->body; |
Line 284 void derivr(VL vl,Obj a,V v,Obj *b) |
|
Line 284 void derivr(VL vl,Obj a,V v,Obj *b) |
|
} |
} |
} |
} |
|
|
|
void simple_derivr(VL vl,Obj a,V v,Obj *b) |
|
{ |
|
Obj r,s,t,u,nm,dn; |
|
|
|
if ( !a || NUM(a) ) |
|
*b = 0; |
|
else |
|
switch ( OID(a) ) { |
|
case O_P: |
|
pderivr(vl,a,v,b); break; |
|
case O_R: |
|
nm = (Obj)NM((R)a); dn = (Obj)DN((R)a); |
|
/* (nm/dn)' = nm'/dn - dn'/dn*nm/dn */ |
|
pderivr(vl,nm,v,&s); divr(vl,s,dn,&u); reductr(vl,u,&t); |
|
pderivr(vl,dn,v,&s); divr(vl,s,dn,&u); reductr(vl,u,&s); mulr(vl,s,a,&u); |
|
subr(vl,t,u,&s); reductr(vl,s,b); |
|
break; |
|
default: |
|
error("simple_derivr : invalid argument"); |
|
} |
|
} |
|
|
|
int obj_is_dependent(Obj a,V v) |
|
{ |
|
if ( !a || OID(a) <= O_N ) return 0; |
|
else if ( OID(a) == O_P ) return poly_is_dependent((P)a,v); |
|
else if ( OID(a) == O_R ) return poly_is_dependent(NM((R)a),v) |
|
|| poly_is_dependent(DN((R)a),v); |
|
else |
|
error("obj_is_dependent : not implemented"); |
|
} |
|
|
|
int poly_is_dependent(P p,V v) |
|
{ |
|
DCP dc; |
|
|
|
if ( !p || OID(p) <= O_N ) return 0; |
|
else if ( v == VR(p) ) return 1; |
|
else { |
|
for ( dc = DC(p); dc; dc = NEXT(dc) ) |
|
if ( poly_is_dependent(COEF(dc),v) ) return 1; |
|
return 0; |
|
} |
|
} |
|
|
|
void gen_pwrr(VL vl,Obj a,Obj d,Obj *r) |
|
{ |
|
if ( INT(d) ) |
|
pwrr(vl,a,d,r); |
|
else |
|
mkpow(vl,a,d,r); |
|
} |
|
|
void substr(VL vl,int partial,Obj a,V v,Obj b,Obj *c) |
void substr(VL vl,int partial,Obj a,V v,Obj b,Obj *c) |
{ |
{ |
Obj nm,dn,t; |
Obj nm,dn,t; |
Line 338 void substpr(VL vl,int partial,Obj p,V v0,Obj p0,Obj * |
|
Line 391 void substpr(VL vl,int partial,Obj p,V v0,Obj p0,Obj * |
|
for ( c = 0, dc = DC((P)p); dc; dc = NEXT(dc) ) { |
for ( c = 0, dc = DC((P)p); dc; dc = NEXT(dc) ) { |
substpr(vl,partial,(Obj)COEF(dc),v0,p0,&t); |
substpr(vl,partial,(Obj)COEF(dc),v0,p0,&t); |
if ( DEG(dc) ) { |
if ( DEG(dc) ) { |
pwrp(vl,x,DEG(dc),(P *)&s); mulr(vl,s,t,&m); |
gen_pwrr(vl,(Obj)x,(Obj)DEG(dc),&s); |
|
mulr(vl,s,t,&m); |
addr(vl,m,c,&a); c = a; |
addr(vl,m,c,&a); c = a; |
} else { |
} else { |
addr(vl,t,c,&a); c = a; |
addr(vl,t,c,&a); c = a; |
Line 352 void substpr(VL vl,int partial,Obj p,V v0,Obj p0,Obj * |
|
Line 406 void substpr(VL vl,int partial,Obj p,V v0,Obj p0,Obj * |
|
else |
else |
c = (Obj)COEF(dc); |
c = (Obj)COEF(dc); |
for ( d = DEG(dc), dc = NEXT(dc); dc; d = DEG(dc), dc = NEXT(dc) ) { |
for ( d = DEG(dc), dc = NEXT(dc); dc; d = DEG(dc), dc = NEXT(dc) ) { |
subq(d,DEG(dc),(Q *)&t); pwrr(vl,p0,t,&s); mulr(vl,s,c,&m); |
subq(d,DEG(dc),(Q *)&t); |
|
gen_pwrr(vl,p0,t,&s); mulr(vl,s,c,&m); |
if ( !partial ) |
if ( !partial ) |
substpr(vl,partial,(Obj)COEF(dc),v0,p0,&t); |
substpr(vl,partial,(Obj)COEF(dc),v0,p0,&t); |
else |
else |
Line 360 void substpr(VL vl,int partial,Obj p,V v0,Obj p0,Obj * |
|
Line 415 void substpr(VL vl,int partial,Obj p,V v0,Obj p0,Obj * |
|
addr(vl,m,t,&c); |
addr(vl,m,t,&c); |
} |
} |
if ( d ) { |
if ( d ) { |
pwrr(vl,p0,(Obj)d,&t); mulr(vl,t,c,&m); |
gen_pwrr(vl,p0,(Obj)d,&t); |
|
mulr(vl,t,c,&m); |
c = m; |
c = m; |
} |
} |
*pr = c; |
*pr = c; |
Line 596 void devalins(PFINS ins,Obj *rp) |
|
Line 652 void devalins(PFINS ins,Obj *rp) |
|
} |
} |
} |
} |
|
|
|
extern int evalef; |
|
|
|
void simplify_elemfunc_ins(PFINS ins,Obj *rp) |
|
{ |
|
V v; |
|
P t; |
|
|
|
if ( evalef ) |
|
evalins(ins,0,rp); |
|
else { |
|
instov(ins,&v); MKV(v,t); *rp = (Obj)t; |
|
} |
|
} |
|
|
void simplify_ins(PFINS ins,Obj *rp) |
void simplify_ins(PFINS ins,Obj *rp) |
{ |
{ |
V v; |
V v; |
Line 658 void substfp(VL vl,Obj p,PF u,PF f,Obj *pr) |
|
Line 728 void substfp(VL vl,Obj p,PF u,PF f,Obj *pr) |
|
for ( c = 0; dc; dc = NEXT(dc) ) { |
for ( c = 0; dc; dc = NEXT(dc) ) { |
substfp(vl,(Obj)COEF(dc),u,f,&t); |
substfp(vl,(Obj)COEF(dc),u,f,&t); |
if ( DEG(dc) ) { |
if ( DEG(dc) ) { |
pwrp(vl,x,DEG(dc),(P *)&s); mulr(vl,s,t,&m); |
gen_pwrr(vl,(Obj)x,(Obj)DEG(dc),&s); |
|
mulr(vl,s,t,&m); |
addr(vl,m,c,&a); c = a; |
addr(vl,m,c,&a); c = a; |
} else { |
} else { |
addr(vl,t,c,&a); c = a; |
addr(vl,t,c,&a); c = a; |
Line 668 void substfp(VL vl,Obj p,PF u,PF f,Obj *pr) |
|
Line 739 void substfp(VL vl,Obj p,PF u,PF f,Obj *pr) |
|
substfv(vl,v,u,f,&p0); |
substfv(vl,v,u,f,&p0); |
substfp(vl,(Obj)COEF(dc),u,f,&c); |
substfp(vl,(Obj)COEF(dc),u,f,&c); |
for ( d = DEG(dc), dc = NEXT(dc); dc; d = DEG(dc), dc = NEXT(dc) ) { |
for ( d = DEG(dc), dc = NEXT(dc); dc; d = DEG(dc), dc = NEXT(dc) ) { |
subq(d,DEG(dc),(Q *)&t); pwrr(vl,p0,t,&s); mulr(vl,s,c,&m); |
subq(d,DEG(dc),(Q *)&t); |
|
gen_pwrr(vl,p0,t,&s); mulr(vl,s,c,&m); |
substfp(vl,(Obj)COEF(dc),u,f,&t); addr(vl,m,t,&c); |
substfp(vl,(Obj)COEF(dc),u,f,&t); addr(vl,m,t,&c); |
} |
} |
if ( d ) { |
if ( d ) { |
pwrr(vl,p0,(Obj)d,&t); mulr(vl,t,c,&m); |
gen_pwrr(vl,p0,(Obj)d,&t); mulr(vl,t,c,&m); |
c = m; |
c = m; |
} |
} |
} |
} |