version 1.2, 2000/08/21 08:31:18 |
version 1.5, 2018/03/29 01:32:50 |
|
|
* shall be made on your publication or presentation in any form of the |
* shall be made on your publication or presentation in any form of the |
* results obtained by use of the SOFTWARE. |
* results obtained by use of the SOFTWARE. |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification |
* e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification |
* for such modification or the source code of the modified part of the |
* for such modification or the source code of the modified part of the |
* SOFTWARE. |
* SOFTWARE. |
* |
* |
|
|
* 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/algnum_ff.c,v 1.1.1.1 1999/12/03 07:39:07 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/algnum_ff.c,v 1.4 2000/12/05 01:24:49 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
|
|
void Pdefpoly(), Pnewalg(), Pmainalg(), Palgtorat(), Prattoalg(), Pgetalg(); |
void Pdefpoly(), Pnewalg(), Pmainalg(), Palgtorat(), Prattoalg(), Pgetalg(); |
void Palg(), Palgv(), Pgetalgtree(); |
void Palg(), Palgv(), Pgetalgtree(); |
|
|
#if defined(THINK_C) |
|
void mkalg(P,Alg *); |
void mkalg(P,Alg *); |
int cmpalgp(P,P); |
int cmpalgp(P,P); |
void algptop(P,P *); |
void algptop(P,P *); |
void algtorat(Num,Obj *); |
void algtorat(Num,Obj *); |
void rattoalg(Obj,Alg *); |
void rattoalg(Obj,Alg *); |
void ptoalgp(P,P *); |
void ptoalgp(P,P *); |
#else |
void clctalg(P,VL *); |
void mkalg(); |
|
int cmpalgp(); |
|
void algptop(); |
|
void algtorat(); |
|
void rattoalg(); |
|
void ptoalgp(); |
|
void clctalg(); |
|
#endif |
|
|
|
struct ftab alg_tab[] = { |
struct ftab alg_tab[] = { |
{"defpoly",Pdefpoly,1}, |
{"defpoly",Pdefpoly,1}, |
{"newalg",Pnewalg,1}, |
{"newalg",Pnewalg,1}, |
{"mainalg",Pmainalg,1}, |
{"mainalg",Pmainalg,1}, |
{"algtorat",Palgtorat,1}, |
{"algtorat",Palgtorat,1}, |
{"rattoalg",Prattoalg,1}, |
{"rattoalg",Prattoalg,1}, |
{"getalg",Pgetalg,1}, |
{"getalg",Pgetalg,1}, |
{"getalgtree",Pgetalgtree,1}, |
{"getalgtree",Pgetalgtree,1}, |
{"alg",Palg,1}, |
{"alg",Palg,1}, |
{"algv",Palgv,1}, |
{"algv",Palgv,1}, |
{0,0,0}, |
{0,0,0}, |
}; |
}; |
|
|
static int UCN,ACNT; |
static int UCN,ACNT; |
Line 89 void Pnewalg(arg,rp) |
|
Line 80 void Pnewalg(arg,rp) |
|
NODE arg; |
NODE arg; |
Alg *rp; |
Alg *rp; |
{ |
{ |
P p; |
P p; |
VL vl; |
VL vl; |
P c; |
P c; |
|
|
p = (P)ARG0(arg); |
p = (P)ARG0(arg); |
if ( !p || OID(p) != O_P ) |
if ( !p || OID(p) != O_P ) |
error("newalg : invalid argument"); |
error("newalg : invalid argument"); |
clctv(CO,p,&vl); |
clctv(CO,p,&vl); |
if ( NEXT(vl) ) |
if ( NEXT(vl) ) |
error("newalg : invalid argument"); |
error("newalg : invalid argument"); |
c = COEF(DC(p)); |
c = COEF(DC(p)); |
if ( !NUM(c) || !RATN(c) ) |
if ( !NUM(c) || !RATN(c) ) |
error("newalg : invalid argument"); |
error("newalg : invalid argument"); |
mkalg(p,rp); |
mkalg(p,rp); |
} |
} |
|
|
void mkalg(p,r) |
void mkalg(p,r) |
P p; |
P p; |
Alg *r; |
Alg *r; |
{ |
{ |
VL vl,mvl,nvl; |
VL vl,mvl,nvl; |
V a,tv; |
V a,tv; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
char *name; |
char *name; |
P x,t,s; |
P x,t,s; |
Num c; |
Num c; |
DCP dc,dcr,dcr0; |
DCP dc,dcr,dcr0; |
|
|
for ( vl = ALG; vl; vl = NEXT(vl) ) |
for ( vl = ALG; vl; vl = NEXT(vl) ) |
if ( !cmpalgp(p,(P)vl->v->attr) ) { |
if ( !cmpalgp(p,(P)vl->v->attr) ) { |
a = vl->v; break; |
a = vl->v; break; |
} |
} |
if ( !vl ) { |
if ( !vl ) { |
NEWVL(vl); NEXT(vl) = ALG; ALG = vl; |
NEWVL(vl); NEXT(vl) = ALG; ALG = vl; |
NEWV(a); vl->v = a; |
NEWV(a); vl->v = a; |
sprintf(buf,"#%d",ACNT++); |
sprintf(buf,"#%d",ACNT++); |
name = (char *)MALLOC(strlen(buf)+1); |
name = (char *)MALLOC(strlen(buf)+1); |
strcpy(name,buf); NAME(a) = name; |
strcpy(name,buf); NAME(a) = name; |
|
|
for ( dc = DC(p), dcr0 = 0; dc; dc = NEXT(dc) ) { |
for ( dc = DC(p), dcr0 = 0; dc; dc = NEXT(dc) ) { |
NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); c = (Num)COEF(dc); |
NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); c = (Num)COEF(dc); |
if ( NID(c) != N_A ) |
if ( NID(c) != N_A ) |
COEF(dcr) = (P)c; |
COEF(dcr) = (P)c; |
else |
else |
COEF(dcr) = (P)BDY(((Alg)c)); |
COEF(dcr) = (P)BDY(((Alg)c)); |
} |
} |
NEXT(dcr) = 0; MKP(a,dcr0,t); a->attr = (pointer)t; |
NEXT(dcr) = 0; MKP(a,dcr0,t); a->attr = (pointer)t; |
|
|
sprintf(buf,"t%s",name); makevar(buf,&s); |
sprintf(buf,"t%s",name); makevar(buf,&s); |
|
|
if ( NEXT(ALG) ) { |
if ( NEXT(ALG) ) { |
tv = (V)NEXT(ALG)->v->priv; |
tv = (V)NEXT(ALG)->v->priv; |
for ( vl = CO; NEXT(NEXT(vl)); vl = NEXT(vl) ); |
for ( vl = CO; NEXT(NEXT(vl)); vl = NEXT(vl) ); |
nvl = NEXT(vl); NEXT(vl) = 0; |
nvl = NEXT(vl); NEXT(vl) = 0; |
for ( vl = CO; NEXT(vl) && (NEXT(vl)->v != tv); vl = NEXT(vl) ); |
for ( vl = CO; NEXT(vl) && (NEXT(vl)->v != tv); vl = NEXT(vl) ); |
mvl = NEXT(vl); NEXT(vl) = nvl; NEXT(nvl) = mvl; |
mvl = NEXT(vl); NEXT(vl) = nvl; NEXT(nvl) = mvl; |
} |
} |
|
|
a->priv = (pointer)VR(s); VR(s)->priv = (pointer)a; |
a->priv = (pointer)VR(s); VR(s)->priv = (pointer)a; |
} |
} |
MKV(a,x); MKAlg(x,*r); |
MKV(a,x); MKAlg(x,*r); |
} |
} |
|
|
int cmpalgp(p,defp) |
int cmpalgp(p,defp) |
P p,defp; |
P p,defp; |
{ |
{ |
DCP dc,dcd; |
DCP dc,dcd; |
P t; |
P t; |
|
|
for ( dc = DC(p), dcd = DC(defp); dc && dcd; |
for ( dc = DC(p), dcd = DC(defp); dc && dcd; |
dc = NEXT(dc), dcd = NEXT(dcd) ) { |
dc = NEXT(dc), dcd = NEXT(dcd) ) { |
if ( cmpq(DEG(dc),DEG(dcd)) ) |
if ( cmpq(DEG(dc),DEG(dcd)) ) |
break; |
break; |
t = NID((Num)COEF(dc)) == N_A ? (P)BDY((Alg)COEF(dc)) : COEF(dc); |
t = NID((Num)COEF(dc)) == N_A ? (P)BDY((Alg)COEF(dc)) : COEF(dc); |
if ( compp(ALG,t,COEF(dcd)) ) |
if ( compp(ALG,t,COEF(dcd)) ) |
break; |
break; |
} |
} |
if ( dc || dcd ) |
if ( dc || dcd ) |
return 1; |
return 1; |
else |
else |
return 0; |
return 0; |
} |
} |
|
|
void Pdefpoly(arg,rp) |
void Pdefpoly(arg,rp) |
NODE arg; |
NODE arg; |
P *rp; |
P *rp; |
{ |
{ |
asir_assert(ARG0(arg),O_N,"defpoly"); |
asir_assert(ARG0(arg),O_N,"defpoly"); |
algptop((P)VR((P)BDY((Alg)ARG0(arg)))->attr,rp); |
algptop((P)VR((P)BDY((Alg)ARG0(arg)))->attr,rp); |
} |
} |
|
|
void Pmainalg(arg,r) |
void Pmainalg(arg,r) |
NODE arg; |
NODE arg; |
Alg *r; |
Alg *r; |
{ |
{ |
Num c; |
Num c; |
V v; |
V v; |
P b; |
P b; |
|
|
c = (Num)(ARG0(arg)); |
c = (Num)(ARG0(arg)); |
if ( NID(c) <= N_R ) |
if ( NID(c) <= N_R ) |
*r = 0; |
*r = 0; |
else { |
else { |
v = VR((P)BDY((Alg)c)); MKV(v,b); MKAlg(b,*r); |
v = VR((P)BDY((Alg)c)); MKV(v,b); MKAlg(b,*r); |
} |
} |
} |
} |
|
|
void Palgtorat(arg,rp) |
void Palgtorat(arg,rp) |
NODE arg; |
NODE arg; |
Obj *rp; |
Obj *rp; |
{ |
{ |
asir_assert(ARG0(arg),O_N,"algtorat"); |
asir_assert(ARG0(arg),O_N,"algtorat"); |
algtorat((Num)ARG0(arg),rp); |
algtorat((Num)ARG0(arg),rp); |
} |
} |
|
|
void Prattoalg(arg,rp) |
void Prattoalg(arg,rp) |
NODE arg; |
NODE arg; |
Alg *rp; |
Alg *rp; |
{ |
{ |
asir_assert(ARG0(arg),O_R,"rattoalg"); |
asir_assert(ARG0(arg),O_R,"rattoalg"); |
rattoalg((Obj)ARG0(arg),rp); |
rattoalg((Obj)ARG0(arg),rp); |
} |
} |
|
|
void Pgetalg(arg,rp) |
void Pgetalg(arg,rp) |
NODE arg; |
NODE arg; |
LIST *rp; |
LIST *rp; |
{ |
{ |
Obj t; |
Obj t; |
P p; |
P p; |
VL vl; |
VL vl; |
Num a; |
Num a; |
Alg b; |
Alg b; |
NODE n0,n; |
NODE n0,n; |
|
|
if ( !(a = (Num)ARG0(arg)) || NID(a) <= N_R ) |
if ( !(a = (Num)ARG0(arg)) || NID(a) <= N_R ) |
vl = 0; |
vl = 0; |
else { |
else { |
t = BDY((Alg)a); |
t = BDY((Alg)a); |
switch ( OID(t) ) { |
switch ( OID(t) ) { |
case O_P: case O_R: |
case O_P: case O_R: |
clctvr(ALG,t,&vl); break; |
clctvr(ALG,t,&vl); break; |
default: |
default: |
vl = 0; break; |
vl = 0; break; |
} |
} |
} |
} |
for ( n0 = 0; vl; vl = NEXT(vl) ) { |
for ( n0 = 0; vl; vl = NEXT(vl) ) { |
NEXTNODE(n0,n); MKV(vl->v,p); MKAlg(p,b); BDY(n) = (pointer)b; |
NEXTNODE(n0,n); MKV(vl->v,p); MKAlg(p,b); BDY(n) = (pointer)b; |
} |
} |
if ( n0 ) |
if ( n0 ) |
NEXT(n) = 0; |
NEXT(n) = 0; |
MKLIST(*rp,n0); |
MKLIST(*rp,n0); |
} |
} |
|
|
void Pgetalgtree(arg,rp) |
void Pgetalgtree(arg,rp) |
NODE arg; |
NODE arg; |
LIST *rp; |
LIST *rp; |
{ |
{ |
Obj t; |
Obj t; |
P p; |
P p; |
VL vl,vl1,vl2; |
VL vl,vl1,vl2; |
Num a; |
Num a; |
Alg b; |
Alg b; |
NODE n0,n; |
NODE n0,n; |
|
|
if ( !(a = (Num)ARG0(arg)) || NID(a) <= N_R ) |
if ( !(a = (Num)ARG0(arg)) || NID(a) <= N_R ) |
vl = 0; |
vl = 0; |
else { |
else { |
t = BDY((Alg)a); |
t = BDY((Alg)a); |
switch ( OID(t) ) { |
switch ( OID(t) ) { |
case O_P: |
case O_P: |
clctalg(t,&vl); break; |
clctalg(t,&vl); break; |
case O_R: |
case O_R: |
clctalg(NM((R)t),&vl1); |
clctalg(NM((R)t),&vl1); |
clctalg(DN((R)t),&vl2); |
clctalg(DN((R)t),&vl2); |
mergev(ALG,vl1,vl2,&vl); break; |
mergev(ALG,vl1,vl2,&vl); break; |
default: |
default: |
vl = 0; break; |
vl = 0; break; |
} |
} |
} |
} |
for ( n0 = 0; vl; vl = NEXT(vl) ) { |
for ( n0 = 0; vl; vl = NEXT(vl) ) { |
NEXTNODE(n0,n); MKV(vl->v,p); MKAlg(p,b); BDY(n) = (pointer)b; |
NEXTNODE(n0,n); MKV(vl->v,p); MKAlg(p,b); BDY(n) = (pointer)b; |
} |
} |
if ( n0 ) |
if ( n0 ) |
NEXT(n) = 0; |
NEXT(n) = 0; |
MKLIST(*rp,n0); |
MKLIST(*rp,n0); |
} |
} |
|
|
void clctalg(p,vl) |
void clctalg(p,vl) |
P p; |
P p; |
VL *vl; |
VL *vl; |
{ |
{ |
int n,i; |
int n,i; |
VL tvl; |
VL tvl; |
VN vn,vn1; |
VN vn,vn1; |
P d; |
P d; |
DCP dc; |
DCP dc; |
|
|
for ( n = 0, tvl = ALG; tvl; tvl = NEXT(tvl), n++ ); |
for ( n = 0, tvl = ALG; tvl; tvl = NEXT(tvl), n++ ); |
vn = (VN) ALLOCA((n+1)*sizeof(struct oVN)); |
vn = (VN) ALLOCA((n+1)*sizeof(struct oVN)); |
for ( i = n-1, tvl = ALG; tvl; tvl = NEXT(tvl), i-- ) { |
for ( i = n-1, tvl = ALG; tvl; tvl = NEXT(tvl), i-- ) { |
vn[i].v = tvl->v; |
vn[i].v = tvl->v; |
vn[i].n = 0; |
vn[i].n = 0; |
} |
} |
markv(vn,n,p); |
markv(vn,n,p); |
for ( i = n-1; i >= 0; i-- ) { |
for ( i = n-1; i >= 0; i-- ) { |
if ( !vn[i].n ) |
if ( !vn[i].n ) |
continue; |
continue; |
d = (P)vn[i].v->attr; |
d = (P)vn[i].v->attr; |
for ( dc = DC(d); dc; dc = NEXT(dc) ) |
for ( dc = DC(d); dc; dc = NEXT(dc) ) |
markv(vn,i,COEF(dc)); |
markv(vn,i,COEF(dc)); |
} |
} |
vn1 = (VN) ALLOCA((n+1)*sizeof(struct oVN)); |
vn1 = (VN) ALLOCA((n+1)*sizeof(struct oVN)); |
for ( i = 0; i < n; i++ ) { |
for ( i = 0; i < n; i++ ) { |
vn1[i].v = vn[n-1-i].v; vn1[i].n = vn[n-1-i].n; |
vn1[i].v = vn[n-1-i].v; vn1[i].n = vn[n-1-i].n; |
} |
} |
vntovl(vn1,n,vl); |
vntovl(vn1,n,vl); |
} |
} |
|
|
void Palg(arg,rp) |
void Palg(arg,rp) |
NODE arg; |
NODE arg; |
Alg *rp; |
Alg *rp; |
{ |
{ |
Q a; |
Q a; |
VL vl; |
VL vl; |
P x; |
P x; |
int n; |
int n; |
|
|
a = (Q)ARG0(arg); |
a = (Q)ARG0(arg); |
if ( a && (OID(a) != O_N || NID(a) != N_Q || !INT(a)) ) |
if ( a && (OID(a) != O_N || NID(a) != N_Q || !INT(a)) ) |
*rp = 0; |
*rp = 0; |
else { |
else { |
n = ACNT-QTOS(a)-1; |
n = ACNT-QTOS(a)-1; |
for ( vl = ALG; vl && n; vl = NEXT(vl), n-- ); |
for ( vl = ALG; vl && n; vl = NEXT(vl), n-- ); |
if ( vl ) { |
if ( vl ) { |
MKV(vl->v,x); MKAlg(x,*rp); |
MKV(vl->v,x); MKAlg(x,*rp); |
} else |
} else |
*rp = 0; |
*rp = 0; |
} |
} |
} |
} |
|
|
void Palgv(arg,rp) |
void Palgv(arg,rp) |
NODE arg; |
NODE arg; |
Obj *rp; |
Obj *rp; |
{ |
{ |
Q a; |
Q a; |
VL vl; |
VL vl; |
P x; |
P x; |
int n; |
int n; |
Alg b; |
Alg b; |
|
|
a = (Q)ARG0(arg); |
a = (Q)ARG0(arg); |
if ( a && (OID(a) != O_N || NID(a) != N_Q || !INT(a)) ) |
if ( a && (OID(a) != O_N || NID(a) != N_Q || !INT(a)) ) |
*rp = 0; |
*rp = 0; |
else { |
else { |
n = ACNT-QTOS(a)-1; |
n = ACNT-QTOS(a)-1; |
for ( vl = ALG; vl && n; vl = NEXT(vl), n-- ); |
for ( vl = ALG; vl && n; vl = NEXT(vl), n-- ); |
if ( vl ) { |
if ( vl ) { |
MKV(vl->v,x); MKAlg(x,b); algtorat((Num)b,rp); |
MKV(vl->v,x); MKAlg(x,b); algtorat((Num)b,rp); |
} else |
} else |
*rp = 0; |
*rp = 0; |
} |
} |
} |
} |
|
|
void algptop(p,r) |
void algptop(p,r) |
P p,*r; |
P p,*r; |
{ |
{ |
DCP dc,dcr,dcr0; |
DCP dc,dcr,dcr0; |
|
|
if ( NUM(p) ) |
if ( NUM(p) ) |
*r = (P)p; |
*r = (P)p; |
else { |
else { |
for ( dc = DC(p), dcr0 = 0; dc; dc = NEXT(dc) ) { |
for ( dc = DC(p), dcr0 = 0; dc; dc = NEXT(dc) ) { |
NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); |
NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); |
algptop(COEF(dc),&COEF(dcr)); |
algptop(COEF(dc),&COEF(dcr)); |
} |
} |
NEXT(dcr) = 0; MKP((V)(VR(p)->priv),dcr0,*r); |
NEXT(dcr) = 0; MKP((V)(VR(p)->priv),dcr0,*r); |
} |
} |
} |
} |
|
|
void algtorat(n,r) |
void algtorat(n,r) |
Num n; |
Num n; |
Obj *r; |
Obj *r; |
{ |
{ |
Obj obj; |
Obj obj; |
P nm,dn; |
P nm,dn; |
|
|
if ( !n || NID(n) <= N_R ) |
if ( !n || NID(n) <= N_R ) |
*r = (Obj)n; |
*r = (Obj)n; |
else { |
else { |
obj = BDY((Alg)n); |
obj = BDY((Alg)n); |
if ( ID(obj) <= O_P ) |
if ( ID(obj) <= O_P ) |
algptop((P)obj,(P *)r); |
algptop((P)obj,(P *)r); |
else { |
else { |
algptop(NM((R)obj),&nm); algptop(DN((R)obj),&dn); |
algptop(NM((R)obj),&nm); algptop(DN((R)obj),&dn); |
divr(CO,(Obj)nm,(Obj)dn,r); |
divr(CO,(Obj)nm,(Obj)dn,r); |
} |
} |
} |
} |
} |
} |
|
|
void rattoalg(obj,n) |
void rattoalg(obj,n) |
Obj obj; |
Obj obj; |
Alg *n; |
Alg *n; |
{ |
{ |
P nm,dn; |
P nm,dn; |
Obj t; |
Obj t; |
|
|
if ( !obj || ID(obj) == O_N ) |
if ( !obj || ID(obj) == O_N ) |
*n = (Alg)obj; |
*n = (Alg)obj; |
else if ( ID(obj) == O_P ) { |
else if ( ID(obj) == O_P ) { |
ptoalgp((P)obj,(P *)&t); MKAlg(t,*n); |
ptoalgp((P)obj,(P *)&t); MKAlg(t,*n); |
} else { |
} else { |
ptoalgp(NM((R)obj),&nm); ptoalgp(DN((R)obj),&dn); |
ptoalgp(NM((R)obj),&nm); ptoalgp(DN((R)obj),&dn); |
divr(ALG,(Obj)nm,(Obj)dn,&t); MKAlg(t,*n); |
divr(ALG,(Obj)nm,(Obj)dn,&t); MKAlg(t,*n); |
} |
} |
} |
} |
|
|
void ptoalgp(p,r) |
void ptoalgp(p,r) |
P p,*r; |
P p,*r; |
{ |
{ |
DCP dc,dcr,dcr0; |
DCP dc,dcr,dcr0; |
|
|
if ( NUM(p) ) |
if ( NUM(p) ) |
*r = (P)p; |
*r = (P)p; |
else { |
else { |
for ( dc = DC(p), dcr0 = 0; dc; dc = NEXT(dc) ) { |
for ( dc = DC(p), dcr0 = 0; dc; dc = NEXT(dc) ) { |
NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); |
NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); |
ptoalgp(COEF(dc),&COEF(dcr)); |
ptoalgp(COEF(dc),&COEF(dcr)); |
} |
} |
NEXT(dcr) = 0; MKP((V)(VR(p)->priv),dcr0,*r); |
NEXT(dcr) = 0; MKP((V)(VR(p)->priv),dcr0,*r); |
} |
} |
} |
} |