version 1.11, 2002/09/27 04:24:04 |
version 1.14, 2002/12/18 06:15:40 |
|
|
* 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/gfs.c,v 1.10 2001/11/06 09:40:36 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/gfs.c,v 1.13 2002/09/30 06:13:07 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
Line 688 void gfs_embed(GFS z,int k,int pm,GFS *c) |
|
Line 688 void gfs_embed(GFS z,int k,int pm,GFS *c) |
|
} |
} |
} |
} |
|
|
void qtogfs(Q a,GFS *c) |
/* 0 <= index <= q-1 */ |
{ |
|
int s; |
|
|
|
s = QTOS(a)%current_gfs_q; |
void indextogfs(int index, GFS *c) |
if ( s < 0 ) |
{ |
s += current_gfs_q; |
if ( index == 0 ) |
if ( !s ) |
|
*c = 0; |
*c = 0; |
|
else if ( index >= current_gfs_q ) |
|
error("indextogfs : exhausted"); |
else if ( !current_gfs_ntoi ) { |
else if ( !current_gfs_ntoi ) { |
MKGFS(s,*c); |
MKGFS(index,*c); |
} else { |
} else { |
MKGFS(current_gfs_ntoi[s],*c); |
MKGFS(index-1,*c); |
} |
} |
} |
} |
|
|
|
void itogfs(int n, GFS *c) |
|
{ |
|
n = _itosf(n); |
|
if ( !n ) |
|
*c = 0; |
|
else { |
|
n = IFTOF(n); |
|
MKGFS(n,*c); |
|
} |
|
} |
|
|
|
void iftogfs(int n, GFS *c) |
|
{ |
|
if ( !n ) |
|
*c = 0; |
|
else { |
|
MKGFS(IFTOF(n),*c); |
|
} |
|
} |
|
|
|
void qtogfs(Q a,GFS *c) |
|
{ |
|
int s; |
|
|
|
s = QTOS(a)%current_gfs_q; |
|
itogfs(s,c); |
|
} |
|
|
void mqtogfs(MQ a,GFS *c) |
void mqtogfs(MQ a,GFS *c) |
{ |
{ |
if ( !a ) |
if ( !a ) |
*c = 0; |
*c = 0; |
else if ( !current_gfs_ntoi ) { |
else |
MKGFS(CONT(a),*c); |
itogfs(CONT(a),c); |
} else { |
|
MKGFS(current_gfs_ntoi[CONT(a)],*c); |
|
} |
|
} |
} |
|
|
void gfstomq(GFS a,MQ *c) |
void gfstomq(GFS a,MQ *c) |
Line 879 void pwrgfs(GFS a,Q b,GFS *c) |
|
Line 903 void pwrgfs(GFS a,Q b,GFS *c) |
|
|
|
ntogfs((Obj)a,&z); a = z; |
ntogfs((Obj)a,&z); a = z; |
if ( !b ) |
if ( !b ) |
MKGFS(0,*c); |
itogfs(1,c); |
else if ( !a ) |
else if ( !a ) |
*c = 0; |
*c = 0; |
else if ( !current_gfs_ntoi ) { |
else if ( !current_gfs_ntoi) { |
ai = pwrm(current_gfs_q,CONT(a),QTOS(b)); |
ai = pwrm(current_gfs_q,CONT(a),QTOS(b)); |
MKGFS(ai,*c); |
MKGFS(ai,*c); |
} else { |
} else { |
STON(CONT(a),an); muln(an,NM(b),&tn); |
STON(CONT(a),an); muln(an,NM(b),&tn); |
STON(current_gfs_q1,an); remn(tn,an,&rn); |
STON(current_gfs_q1,an); remn(tn,an,&rn); |
if ( !rn ) |
if ( !rn ) |
MKGFS(0,*c); |
itogfs(1,c); |
else if ( SGN(b) > 0 ) |
else if ( SGN(b) > 0 ) |
MKGFS(BD(rn)[0],*c); |
MKGFS(BD(rn)[0],*c); |
else { |
else { |
MKGFS(0,t); |
itogfs(1,&t); |
MKGFS(BD(rn)[0],s); |
MKGFS(BD(rn)[0],s); |
divgfs(t,s,c); |
divgfs(t,s,c); |
} |
} |
Line 920 int cmpgfs(GFS a,GFS b) |
|
Line 944 int cmpgfs(GFS a,GFS b) |
|
} |
} |
} |
} |
|
|
|
void pthrootgfs(GFS a,GFS *b) |
|
{ |
|
Q p; |
|
int e,i; |
|
GFS t,s; |
|
|
|
STOQ(characteristic_sf(),p); |
|
e = extdeg_sf()-1; |
|
t = a; |
|
for ( i = 0; i < e; i++ ) { |
|
pwrgfs(t,p,&s); t = s; |
|
} |
|
*b = t; |
|
} |
|
|
void randomgfs(GFS *r) |
void randomgfs(GFS *r) |
{ |
{ |
unsigned int t; |
unsigned int t; |
Line 927 void randomgfs(GFS *r) |
|
Line 966 void randomgfs(GFS *r) |
|
if ( !current_gfs_q1 ) |
if ( !current_gfs_q1 ) |
error("addgfs : current_gfs_q is not set"); |
error("addgfs : current_gfs_q is not set"); |
t = mt_genrand()%current_gfs_q; |
t = mt_genrand()%current_gfs_q; |
if ( !t ) |
indextogfs(t,r); |
*r = 0; |
|
else { |
|
if ( current_gfs_ntoi && t == (unsigned int)current_gfs_q1 ) |
|
t = 0; |
|
MKGFS(t,*r); |
|
} |
|
} |
} |
|
|
/* arithmetic operations for 'immediate values of GFS */ |
/* arithmetic operations for 'immediate values of GFS */ |
Line 1082 int _pwrsf(int a,int b) |
|
Line 1115 int _pwrsf(int a,int b) |
|
a = pwrm(current_gfs_q,IFTOF(a),b); |
a = pwrm(current_gfs_q,IFTOF(a),b); |
return FTOIF(a); |
return FTOIF(a); |
} else { |
} else { |
a = IFTOF(a); |
iftogfs(a,&at); |
MKGFS(a,at); |
|
STOQ(b,bt); |
STOQ(b,bt); |
pwrgfs(at,bt,&ct); |
pwrgfs(at,bt,&ct); |
c = CONT(ct); |
c = CONT(ct); |
Line 1100 int _itosf(int n) |
|
Line 1132 int _itosf(int n) |
|
{ |
{ |
int i; |
int i; |
|
|
|
/* XXX */ |
|
#if 0 |
n %= current_gfs_p; |
n %= current_gfs_p; |
|
#else |
|
n %= current_gfs_q; |
|
#endif |
if ( !n ) |
if ( !n ) |
return 0; |
return 0; |
i = !current_gfs_ntoi ? n : current_gfs_ntoi[n]; |
i = !current_gfs_ntoi ? n : current_gfs_ntoi[n]; |
Line 1112 int _itosf(int n) |
|
Line 1149 int _itosf(int n) |
|
|
|
int _isonesf(int a) |
int _isonesf(int a) |
{ |
{ |
return a == (!current_gfs_ntoi ? FTOIF(1) : FTOIF(0)); |
return a == _onesf(); |
} |
} |
|
|
int _randomsf() |
int _randomsf() |