version 1.8, 2004/12/06 01:15:18 |
version 1.15, 2017/08/31 02:36:20 |
|
|
* 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.c,v 1.7 2004/12/02 13:48:43 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/algnum.c,v 1.14 2013/11/17 17:34:59 ohara Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
Line 54 void Pdefpoly(), Pnewalg(), Pmainalg(), Palgtorat(), P |
|
Line 54 void Pdefpoly(), Pnewalg(), Pmainalg(), Palgtorat(), P |
|
void Palg(), Palgv(), Pgetalgtree(); |
void Palg(), Palgv(), Pgetalgtree(); |
void Pinvalg_le(); |
void Pinvalg_le(); |
void Pset_field(),Palgtodalg(),Pdalgtoalg(); |
void Pset_field(),Palgtodalg(),Pdalgtoalg(); |
|
void Pinv_or_split_dalg(); |
|
void Pdalgtoup(); |
|
void Pget_field_defpoly(); |
|
void Pget_field_generator(); |
|
|
void mkalg(P,Alg *); |
void mkalg(P,Alg *); |
int cmpalgp(P,P); |
int cmpalgp(P,P); |
Line 63 void rattoalg(Obj,Alg *); |
|
Line 67 void rattoalg(Obj,Alg *); |
|
void ptoalgp(P,P *); |
void ptoalgp(P,P *); |
void clctalg(P,VL *); |
void clctalg(P,VL *); |
void get_algtree(Obj f,VL *r); |
void get_algtree(Obj f,VL *r); |
|
void Pinvalg_chrem(); |
|
void Pdalgtodp(); |
|
void Pdptodalg(); |
|
|
struct ftab alg_tab[] = { |
struct ftab alg_tab[] = { |
{"set_field",Pset_field,1}, |
{"set_field",Pset_field,-3}, |
|
{"get_field_defpoly",Pget_field_defpoly,1}, |
|
{"get_field_generator",Pget_field_generator,1}, |
{"algtodalg",Palgtodalg,1}, |
{"algtodalg",Palgtodalg,1}, |
{"dalgtoalg",Pdalgtoalg,1}, |
{"dalgtoalg",Pdalgtoalg,1}, |
|
{"dalgtodp",Pdalgtodp,1}, |
|
{"dalgtoup",Pdalgtoup,1}, |
|
{"dptodalg",Pdptodalg,1}, |
|
{"inv_or_split_dalg",Pinv_or_split_dalg,1}, |
|
{"invalg_chrem",Pinvalg_chrem,2}, |
{"invalg_le",Pinvalg_le,1}, |
{"invalg_le",Pinvalg_le,1}, |
{"defpoly",Pdefpoly,1}, |
{"defpoly",Pdefpoly,1}, |
{"newalg",Pnewalg,1}, |
{"newalg",Pnewalg,1}, |
Line 85 static int UCN,ACNT; |
|
Line 99 static int UCN,ACNT; |
|
|
|
void Pset_field(NODE arg,Q *rp) |
void Pset_field(NODE arg,Q *rp) |
{ |
{ |
setfield_dalg(BDY((LIST)ARG0(arg))); |
int ac; |
|
NODE a0,a1; |
|
VL vl0,vl; |
|
struct order_spec *spec; |
|
|
|
if ( (ac = argc(arg)) == 1 ) |
|
setfield_dalg(BDY((LIST)ARG0(arg))); |
|
else if ( ac == 3 ) { |
|
a0 = BDY((LIST)ARG0(arg)); |
|
a1 = BDY((LIST)ARG1(arg)); |
|
for ( vl0 = 0; a1; a1 = NEXT(a1) ) { |
|
NEXTVL(vl0,vl); |
|
vl->v = VR((P)BDY(a1)); |
|
} |
|
if ( vl0 ) NEXT(vl) = 0; |
|
create_order_spec(0,ARG2(arg),&spec); |
|
setfield_gb(a0,vl0,spec); |
|
} |
*rp = 0; |
*rp = 0; |
} |
} |
|
|
Line 99 void Pdalgtoalg(NODE arg,Alg *rp) |
|
Line 130 void Pdalgtoalg(NODE arg,Alg *rp) |
|
dalgtoalg((DAlg)ARG0(arg),rp); |
dalgtoalg((DAlg)ARG0(arg),rp); |
} |
} |
|
|
|
void Pdalgtodp(NODE arg,LIST *r) |
|
{ |
|
NODE b; |
|
DP nm; |
|
Q dn; |
|
DAlg da; |
|
|
|
da = (DAlg)ARG0(arg); |
|
nm = da->nm; |
|
dn = da->dn; |
|
b = mknode(2,nm,dn); |
|
MKLIST(*r,b); |
|
} |
|
|
|
void Pdptodalg(NODE arg,DAlg *r) |
|
{ |
|
DP d,nm,nm1; |
|
MP m; |
|
Q c,a; |
|
DAlg t; |
|
|
|
d = (DP)ARG0(arg); |
|
if ( !d ) *r = 0; |
|
else { |
|
for ( m = BDY(d); m; m = NEXT(m) ) |
|
if ( !INT((Q)m->c) ) break; |
|
if ( !m ) { |
|
MKDAlg(d,(Q)ONE,t); |
|
} else { |
|
dp_ptozp(d,&nm); |
|
divq((Q)BDY(d)->c,(Q)BDY(nm)->c,&c); |
|
NTOQ(NM(c),SGN(c),a); |
|
muldc(CO,nm,(Obj)a,&nm1); |
|
NTOQ(DN(c),1,a); |
|
MKDAlg(nm1,a,t); |
|
} |
|
simpdalg(t,r); |
|
} |
|
} |
|
|
|
void Pdalgtoup(NODE arg,LIST *r) |
|
{ |
|
NODE b; |
|
int pos; |
|
P up; |
|
DP nm; |
|
Q dn,q; |
|
|
|
pos = dalgtoup((DAlg)ARG0(arg),&up,&dn); |
|
STOQ(pos,q); |
|
b = mknode(3,up,dn,q); |
|
MKLIST(*r,b); |
|
} |
|
|
|
NODE inv_or_split_dalg(DAlg,DAlg *); |
|
NumberField get_numberfield(); |
|
|
|
void Pget_field_defpoly(NODE arg,DAlg *r) |
|
{ |
|
NumberField nf; |
|
DP d; |
|
|
|
nf = get_numberfield(); |
|
d = nf->ps[QTOS((Q)ARG0(arg))]; |
|
MKDAlg(d,ONE,*r); |
|
} |
|
|
|
void Pget_field_generator(NODE arg,DAlg *r) |
|
{ |
|
int index,n,i; |
|
DL dl; |
|
MP m; |
|
DP d; |
|
|
|
index = QTOS((Q)ARG0(arg)); |
|
n = get_numberfield()->n; |
|
NEWDL(dl,n); |
|
for ( i = 0; i < n; i++ ) dl->d[i] = 0; |
|
dl->d[index] = 1; dl->td = 1; |
|
NEWMP(m); m->dl = dl; m->c = (Obj)ONE; NEXT(m) = 0; |
|
MKDP(n,m,d); |
|
MKDAlg(d,ONE,*r); |
|
} |
|
|
|
|
|
void Pinv_or_split_dalg(NODE arg,Obj *rp) |
|
{ |
|
NODE gen,t,nd0,nd; |
|
LIST list; |
|
int l,i,j,n; |
|
DP *ps,*ps1,*psw; |
|
NumberField nf; |
|
DAlg inv; |
|
extern struct order_spec *dp_current_spec; |
|
struct order_spec *current_spec; |
|
|
|
gen = inv_or_split_dalg((DAlg)ARG0(arg),&inv); |
|
if ( !gen ) |
|
*rp = (Obj)inv; |
|
else { |
|
nf = get_numberfield(); |
|
current_spec = dp_current_spec; initd(nf->spec); |
|
l = length(gen); |
|
n = nf->n; |
|
ps = nf->ps; |
|
psw = (DP *)ALLOCA((n+l)*sizeof(DP)); |
|
for ( i = j = 0; i < n; i++ ) { |
|
for ( t = gen; t; t = NEXT(t) ) |
|
if ( dp_redble(ps[i],(DP)BDY(t)) ) break; |
|
if ( !t ) |
|
psw[j++] = ps[i]; |
|
} |
|
nd0 = 0; |
|
/* gen[0] < gen[1] < ... */ |
|
/* psw[0] > psw[1] > ... */ |
|
for ( i = j-1, t = gen; i >= 0 && t; ) { |
|
NEXTNODE(nd0,nd); |
|
if ( compd(CO,psw[i],(DP)BDY(t)) > 0 ) { |
|
BDY(nd) = BDY(t); t = NEXT(t); |
|
} else |
|
BDY(nd) = (pointer)psw[i--]; |
|
} |
|
for ( ; i >= 0; i-- ) { |
|
NEXTNODE(nd0,nd); BDY(nd) = (pointer)psw[i]; |
|
} |
|
for ( ; t; t = NEXT(t) ) { |
|
NEXTNODE(nd0,nd); BDY(nd) = BDY(t); |
|
} |
|
NEXT(nd) = 0; |
|
MKLIST(list,nd0); |
|
initd(current_spec); |
|
*rp = (Obj)list; |
|
} |
|
} |
|
|
void Pnewalg(arg,rp) |
void Pnewalg(arg,rp) |
NODE arg; |
NODE arg; |
Alg *rp; |
Alg *rp; |
|
|
} |
} |
} |
} |
|
|
|
void Pinvalg_chrem(NODE arg,LIST *r) |
|
{ |
|
NODE n; |
|
|
|
inva_chrem((P)ARG0(arg),(P)ARG1(arg),&n); |
|
MKLIST(*r,n); |
|
} |
|
|
void invalg_le(Alg a,LIST *r); |
void invalg_le(Alg a,LIST *r); |
|
|
void Pinvalg_le(NODE arg,LIST *r) |
void Pinvalg_le(NODE arg,LIST *r) |
Line 568 void invalg_le(Alg a,LIST *r) |
|
Line 742 void invalg_le(Alg a,LIST *r) |
|
for ( i = 0, t = rev0, mp0 = 0; i < len; i++, t = NEXT(t) ) |
for ( i = 0, t = rev0, mp0 = 0; i < len; i++, t = NEXT(t) ) |
if ( solmat[i][0] ) { |
if ( solmat[i][0] ) { |
NEXTMP(mp0,mp); |
NEXTMP(mp0,mp); |
mp->c = (P)solmat[i][0]; |
mp->c = (Obj)solmat[i][0]; |
mp->dl = BDY((DP)BDY(t))->dl; |
mp->dl = BDY((DP)BDY(t))->dl; |
} |
} |
NEXT(mp) = 0; MKDP(n,mp0,u); |
NEXT(mp) = 0; MKDP(n,mp0,u); |
dp_ptozp(u,&u1); |
dp_ptozp(u,&u1); |
divq((Q)BDY(u)->c,(Q)BDY(u1)->c,&cont); |
divq((Q)BDY(u)->c,(Q)BDY(u1)->c,&cont); |
dtop(ALG,vl,u1,&ap); |
dtop(ALG,vl,u1,(Obj *)&ap); |
MKAlg(ap,inv); |
MKAlg(ap,inv); |
mulq(dnsol,(Q)dn,&c1); |
mulq(dnsol,(Q)dn,&c1); |
mulq(c1,c,&c2); |
mulq(c1,c,&c2); |
Line 660 void get_algtree(Obj f,VL *r) |
|
Line 834 void get_algtree(Obj f,VL *r) |
|
break; |
break; |
default: |
default: |
*r = 0; |
*r = 0; |
|
break; |
|
} |
|
} |
|
|
|
void algobjtorat(Obj f,Obj *r) |
|
{ |
|
Obj t; |
|
DCP dc,dcr,dcr0; |
|
P p,nm,dn; |
|
R rat; |
|
NODE b,s,s0; |
|
VECT v; |
|
MAT mat; |
|
LIST list; |
|
pointer *a; |
|
pointer **m; |
|
int len,row,col,i,j,l; |
|
|
|
if ( !f ) *r = 0; |
|
else |
|
switch ( OID(f) ) { |
|
case O_N: |
|
algtorat((Num)f,r); |
|
break; |
|
case O_P: |
|
dcr0 = 0; |
|
for ( dc = DC((P)f); dc; dc = NEXT(dc) ) { |
|
NEXTDC(dcr0,dcr); |
|
algobjtorat((Obj)COEF(dc),&t); |
|
COEF(dcr) = (P)t; |
|
DEG(dcr) = DEG(dc); |
|
} |
|
NEXT(dcr) = 0; MKP(VR((P)f),dcr0,p); *r = (Obj)p; |
|
break; |
|
case O_R: |
|
algobjtorat((Obj)NM((R)f),&t); nm = (P)t; |
|
algobjtorat((Obj)DN((R)f),&t); dn = (P)t; |
|
MKRAT(nm,dn,0,rat); *r = (Obj)rat; |
|
break; |
|
case O_LIST: |
|
s0 = 0; |
|
for ( b = BDY((LIST)f); b; b = NEXT(b) ) { |
|
NEXTNODE(s0,s); |
|
algobjtorat((Obj)BDY(b),&t); |
|
BDY(s) = (pointer)t; |
|
} |
|
NEXT(s) = 0; |
|
MKLIST(list,s0); |
|
*r = (Obj)list; |
|
break; |
|
case O_VECT: |
|
l = ((VECT)f)->len; |
|
a = BDY((VECT)f); |
|
MKVECT(v,l); |
|
for ( i = 0; i < l; i++ ) { |
|
algobjtorat((Obj)a[i],&t); |
|
BDY(v)[i] = (pointer)t; |
|
} |
|
*r = (Obj)v; |
|
break; |
|
case O_MAT: |
|
row = ((MAT)f)->row; col = ((MAT)f)->col; |
|
m = BDY((MAT)f); |
|
MKMAT(mat,row,col); |
|
for ( i = 0; i < row; i++ ) |
|
for ( j = 0; j < col; j++ ) { |
|
algobjtorat((Obj)m[i][j],&t); |
|
BDY(mat)[i][j] = (pointer)t; |
|
} |
|
*r = (Obj)mat; |
|
break; |
|
default: |
|
*r = f; |
break; |
break; |
} |
} |
} |
} |