version 1.6, 2001/10/09 01:36:13 |
version 1.7, 2018/03/29 01:32:52 |
|
|
* 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/engine/num.c,v 1.5 2001/09/05 09:01:27 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/num.c,v 1.6 2001/10/09 01:36:13 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
|
|
void addnum(VL vl,Num a,Num b,Num *c) |
void addnum(VL vl,Num a,Num b,Num *c) |
{ |
{ |
(*addnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
(*addnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
} |
} |
|
|
void subnum(VL vl,Num a,Num b,Num *c) |
void subnum(VL vl,Num a,Num b,Num *c) |
{ |
{ |
(*subnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
(*subnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
} |
} |
|
|
void mulnum(VL vl,Num a,Num b,Num *c) |
void mulnum(VL vl,Num a,Num b,Num *c) |
{ |
{ |
(*mulnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
(*mulnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
} |
} |
|
|
void divnum(VL vl,Num a,Num b,Num *c) |
void divnum(VL vl,Num a,Num b,Num *c) |
{ |
{ |
(*divnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
(*divnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
} |
} |
|
|
void pwrnum(VL vl,Num a,Num b,Num *c) |
void pwrnum(VL vl,Num a,Num b,Num *c) |
{ |
{ |
(*pwrnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
(*pwrnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b,c); |
} |
} |
|
|
void chsgnnum(Num a,Num *c) |
void chsgnnum(Num a,Num *c) |
{ |
{ |
(*chsgnnumt[a?NID(a):0])(a,c); |
(*chsgnnumt[a?NID(a):0])(a,c); |
} |
} |
|
|
int compnum(VL vl,Num a,Num b) |
int compnum(VL vl,Num a,Num b) |
{ |
{ |
return (*cmpnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b); |
return (*cmpnumt[MAX(a?NID(a):0,b?NID(b):0)])(a,b); |
} |
} |
|
|
extern int current_ff; |
extern int current_ff; |
|
|
void one_ff(Num *c) |
void one_ff(Num *c) |
{ |
{ |
LM lm; |
LM lm; |
GFS fs; |
GFS fs; |
GFSN fspn; |
GFSN fspn; |
|
|
switch ( current_ff ) { |
switch ( current_ff ) { |
case FF_GFP: |
case FF_GFP: |
case FF_GFPN: |
case FF_GFPN: |
MKLM(ONEN,lm); |
MKLM(ONEN,lm); |
*c = (Num)lm; |
*c = (Num)lm; |
break; |
break; |
case FF_GFS: |
case FF_GFS: |
mqtogfs(ONEM,&fs); |
mqtogfs(ONEM,&fs); |
*c = (Num)fs; |
*c = (Num)fs; |
break; |
break; |
case FF_GFSN: |
case FF_GFSN: |
ntogfsn((Obj)ONE,&fspn); |
ntogfsn((Obj)ONE,&fspn); |
*c = (Num)fspn; |
*c = (Num)fspn; |
break; |
break; |
default: |
default: |
error("one_ff : not implemented yet"); |
error("one_ff : not implemented yet"); |
} |
} |
} |
} |
|
|
int negative_number(Num c) |
int negative_number(Num c) |
{ |
{ |
if ( !c ) |
if ( !c ) |
return 0; |
return 0; |
else { |
else { |
switch ( NID(c) ) { |
switch ( NID(c) ) { |
case N_Q: |
case N_Q: |
return SGN((Q)c)<0; |
return SGN((Q)c)<0; |
case N_R: |
case N_R: |
return BDY((Real)c)<0; |
return BDY((Real)c)<0; |
case N_B: |
case N_B: |
return 0; /* XXX */ |
return 0; /* XXX */ |
default: |
default: |
return 0; |
return 0; |
} |
} |
} |
} |
} |
} |
|
|
/* general simplifier for finite field elements */ |
/* general simplifier for finite field elements */ |
Line 134 int negative_number(Num c) |
|
Line 134 int negative_number(Num c) |
|
|
|
void simp_ff(Obj p,Obj *rp) |
void simp_ff(Obj p,Obj *rp) |
{ |
{ |
LM s; |
LM s; |
DCP dc,dcr0,dcr; |
DCP dc,dcr0,dcr; |
GF2N rg,sg; |
GF2N rg,sg; |
GFPN rpn,spn; |
GFPN rpn,spn; |
GFS rs; |
GFS rs; |
GFSN rspn,sspn; |
GFSN rspn,sspn; |
P t; |
P t; |
Obj obj; |
Obj obj; |
|
|
lm_lazy = 0; |
lm_lazy = 0; |
if ( !p ) |
if ( !p ) |
*rp = 0; |
*rp = 0; |
else if ( OID(p) == O_N ) { |
else if ( OID(p) == O_N ) { |
switch ( current_ff ) { |
switch ( current_ff ) { |
case FF_GFP: |
case FF_GFP: |
ptolmp((P)p,&t); simplm((LM)t,&s); *rp = (Obj)s; |
ptolmp((P)p,&t); simplm((LM)t,&s); *rp = (Obj)s; |
break; |
break; |
case FF_GF2N: |
case FF_GF2N: |
ptogf2n((Obj)p,&rg); simpgf2n((GF2N)rg,&sg); *rp = (Obj)sg; |
ptogf2n((Obj)p,&rg); simpgf2n((GF2N)rg,&sg); *rp = (Obj)sg; |
break; |
break; |
case FF_GFPN: |
case FF_GFPN: |
ntogfpn((Obj)p,&rpn); simpgfpn((GFPN)rpn,&spn); *rp = (Obj)spn; |
ntogfpn((Obj)p,&rpn); simpgfpn((GFPN)rpn,&spn); *rp = (Obj)spn; |
break; |
break; |
case FF_GFS: |
case FF_GFS: |
if ( NID((Num)p) == N_GFS ) |
if ( NID((Num)p) == N_GFS ) |
*rp = p; |
*rp = p; |
else { |
else { |
ptomp(current_gfs_p,(P)p,&t); mqtogfs((MQ)t,&rs); |
ptomp(current_gfs_p,(P)p,&t); mqtogfs((MQ)t,&rs); |
*rp = (Obj)rs; |
*rp = (Obj)rs; |
} |
} |
break; |
break; |
case FF_GFSN: |
case FF_GFSN: |
ntogfsn((Obj)p,&rspn); simpgfsn((GFSN)rspn,&sspn); |
ntogfsn((Obj)p,&rspn); simpgfsn((GFSN)rspn,&sspn); |
*rp = (Obj)sspn; |
*rp = (Obj)sspn; |
break; |
break; |
default: |
default: |
*rp = (Obj)p; |
*rp = (Obj)p; |
break; |
break; |
} |
} |
} else if ( OID(p) == O_P ) { |
} else if ( OID(p) == O_P ) { |
for ( dc = DC((P)p), dcr0 = 0; dc; dc = NEXT(dc) ) { |
for ( dc = DC((P)p), dcr0 = 0; dc; dc = NEXT(dc) ) { |
simp_ff((Obj)COEF(dc),&obj); |
simp_ff((Obj)COEF(dc),&obj); |
if ( obj ) { |
if ( obj ) { |
NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = (P)obj; |
NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = (P)obj; |
} |
} |
} |
} |
if ( !dcr0 ) |
if ( !dcr0 ) |
*rp = 0; |
*rp = 0; |
else { |
else { |
NEXT(dcr) = 0; MKP(VR((P)p),dcr0,t); *rp = (Obj)t; |
NEXT(dcr) = 0; MKP(VR((P)p),dcr0,t); *rp = (Obj)t; |
} |
} |
} else |
} else |
error("simp_ff : not implemented yet"); |
error("simp_ff : not implemented yet"); |
} |
} |
|
|
|
|
void field_order_ff(N *order) |
void field_order_ff(N *order) |
{ |
{ |
UP2 up2; |
UP2 up2; |
UP up; |
UP up; |
UM dp; |
UM dp; |
N m; |
N m; |
int d,w; |
int d,w; |
|
|
switch ( current_ff ) { |
switch ( current_ff ) { |
case FF_GFP: |
case FF_GFP: |
getmod_lm(order); break; |
getmod_lm(order); break; |
case FF_GF2N: |
case FF_GF2N: |
getmod_gf2n(&up2); d = degup2(up2); |
getmod_gf2n(&up2); d = degup2(up2); |
w = (d>>5)+1; |
w = (d>>5)+1; |
*order = m = NALLOC(w); |
*order = m = NALLOC(w); |
PL(m)=w; |
PL(m)=w; |
bzero((char *)BD(m),w*sizeof(unsigned int)); |
bzero((char *)BD(m),w*sizeof(unsigned int)); |
BD(m)[d>>5] |= 1<<(d&31); |
BD(m)[d>>5] |= 1<<(d&31); |
break; |
break; |
case FF_GFPN: |
case FF_GFPN: |
getmod_lm(&m); |
getmod_lm(&m); |
getmod_gfpn(&up); pwrn(m,up->d,order); |
getmod_gfpn(&up); pwrn(m,up->d,order); |
break; |
break; |
case FF_GFS: |
case FF_GFS: |
STON(current_gfs_q,*order); break; |
STON(current_gfs_q,*order); break; |
case FF_GFSN: |
case FF_GFSN: |
STON(current_gfs_q,m); |
STON(current_gfs_q,m); |
getmod_gfsn(&dp); pwrn(m,DEG(dp),order); |
getmod_gfsn(&dp); pwrn(m,DEG(dp),order); |
break; |
break; |
default: |
default: |
error("field_order_ff : current_ff is not set"); |
error("field_order_ff : current_ff is not set"); |
} |
} |
} |
} |