version 1.2, 2000/08/21 08:31:25 |
version 1.10, 2015/08/08 14:19:41 |
|
|
* 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/engine/H.c,v 1.1.1.1 1999/12/03 07:39:08 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/H.c,v 1.9 2015/08/06 10:01:52 fujimoto Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
#include "base.h" |
#include "base.h" |
#include <math.h> |
#include <math.h> |
|
|
void modfctrp(P,int,int,DCP *); |
|
void gensqfrum(int,UM,struct oDUM *); |
|
void srchum(int,UM,UM,UM); |
|
UM *resberle(int,UM,UM *); |
|
int substum(int,UM,int); |
|
void ddd(int,UM,UM *); |
|
void canzas(int,UM,int,UM *,UM *); |
|
int divum(int,UM,UM,UM); |
|
void randum(int,int,UM); |
|
void pwrmodum(int,UM,int,UM,UM); |
|
void spwrum(int,UM,UM *,UM,N,UM); |
|
void spwrum0(int,UM,UM,N,UM); |
|
void mulum(int,UM,UM,UM); |
|
void mulsum(int,UM,int,UM); |
|
void gcdum(int,UM,UM,UM); |
|
void mult_mod_tab(UM,int,UM *,UM,int); |
|
void make_qmat(UM,int,UM *,int ***); |
|
void null_mod(int **,int,int,int *); |
|
void null_to_sol(int **,int *,int,int,UM *); |
|
void newddd(int,UM,UM *); |
|
int irred_check(UM,int); |
|
int berlekamp(UM,int,int,UM *,UM *); |
|
int nfctr_mod(UM,int); |
|
void minipoly_mod(int,UM,UM,UM); |
|
int find_root(int,UM,int *); |
|
void showum(UM); |
|
void showumat(int **,int); |
|
#if 1 |
#if 1 |
#define Mulum mulum |
#define Mulum mulum |
#define Divum divum |
#define Divum divum |
Line 93 void showumat(int **,int); |
|
Line 66 void showumat(int **,int); |
|
|
|
LUM LUMALLOC(); |
LUM LUMALLOC(); |
|
|
struct p_pair { |
void berle(int index,int count,P f,ML *listp) |
UM p0; |
|
UM p1; |
|
struct p_pair *next; |
|
}; |
|
|
|
void lnf_mod(int,int,UM,UM,struct p_pair *,UM,UM); |
|
|
|
void berle(index,count,f,listp) |
|
int index,count; |
|
P f; |
|
ML *listp; |
|
{ |
{ |
UM wf,wf1,wf2,wfs,gcd; |
UM wf,wf1,wf2,wfs,gcd; |
ML flist; |
ML flist; |
|
|
ptr[i] = ( ptr[i] * hd ) % m; |
ptr[i] = ( ptr[i] * hd ) % m; |
} |
} |
|
|
int berlecnt(mod,f) |
int berlecnt(int mod,UM f) |
register int mod; |
|
UM f; |
|
{ |
{ |
register int i,j,**c; |
register int i,j,**c; |
int d,dr,n; |
int d,dr,n; |
|
|
|
|
/* XXX berlecntmain should not be used for large mod */ |
/* XXX berlecntmain should not be used for large mod */ |
|
|
int berlecntmain(mod,n,m,c) |
int berlecntmain(int mod,int n,int m,int **c) |
register int mod; |
|
int n,m; |
|
register int **c; |
|
{ |
{ |
register int *p1,*p2,i,j,k,l,a; |
register int *p1,*p2,i,j,k,l,a; |
int *tmp,inv; |
int *tmp,inv; |
Line 205 register int **c; |
|
Line 162 register int **c; |
|
return ( cfs ); |
return ( cfs ); |
} |
} |
|
|
UM *berlemain(mod,f,fp) |
UM *berlemain(int mod,UM f,UM *fp) |
register int mod; |
|
UM f; |
|
UM *fp; |
|
{ |
{ |
UM wg,ws,wf,f0,gcd,q; |
UM wg,ws,wf,f0,gcd,q; |
int n; |
int n; |
|
|
return ( fp ); |
return ( fp ); |
} |
} |
|
|
void hensel(index,count,f,listp) |
void hensel(int index,int count,P f,ML *listp) |
int index,count; |
|
P f; |
|
ML *listp; |
|
{ |
{ |
register int i,j; |
register int i,j; |
int q,n,bound; |
int q,n,bound; |
|
|
} |
} |
} |
} |
|
|
void hsq(index,count,f,nindex,dcp) |
void hensel2(int index,int count,P f,ML *listp) |
int index,count,*nindex; |
|
P f; |
|
DCP *dcp; |
|
{ |
{ |
|
register int i,j; |
|
int mod,q,n,bound,dx; |
|
ML blist,clist,bqlist,cqlist,rlist; |
|
UM fm,qfm,gm,qgm,hm,qhm,qam,qbm,w; |
|
UM *b; |
|
LUM fl,tl; |
|
int k; |
|
|
|
dx = UDEG(f); |
|
if ( dx == 1 ) { |
|
*listp = blist = MLALLOC(1); blist->n = 1; blist->c[0] = 0; |
|
return; |
|
} |
|
berle(index,count,f,&blist); |
|
n = blist->n; |
|
mod = blist->mod; |
|
|
|
if ( n == 1 ) { |
|
*listp = blist = MLALLOC(1); blist->n = 1; blist->c[0] = 0; |
|
return; |
|
} |
|
|
|
/* find k s.t. mod^k <= 2^27 < mod^(k+1); set q = mod^k */ |
|
for ( k = 1, q = mod; q <= ((1<<27)/mod); q *= mod, k++ ); |
|
|
|
/* mignotte bound */ |
|
bound = mignotte(q,f); |
|
|
|
*listp = rlist = MLALLOC(n); |
|
rlist->n = n; |
|
rlist->mod = q; |
|
rlist->bound = bound; |
|
|
|
if ( bound == 1 ) { |
|
gcdgen(f,blist,&clist); |
|
henprep(f,blist,clist,&bqlist,&cqlist); |
|
|
|
for ( i = 0, b = (UM *)bqlist->c; i < n; i++ ) { |
|
COEF(rlist)[i] = tl = LUMALLOC(DEG(b[i]),1); |
|
for ( j = 0; j <= DEG(tl); j++ ) |
|
COEF(tl)[j][0] = COEF(b[i])[j]; |
|
COEF(rlist)[i] = tl; |
|
} |
|
} else { |
|
/* fl = f mod q */ |
|
fl = LUMALLOC(dx,bound); |
|
ptolum(q,bound,f,fl); |
|
/* fm = f mod mod */ |
|
fm = W_UMALLOC(dx); |
|
ptoum(mod,f,fm); |
|
/* fm = f mod q */ |
|
qfm = W_UMALLOC(dx); |
|
ptoum(q,f,qfm); |
|
|
|
gm = W_UMALLOC(dx); qgm = W_UMALLOC(dx); |
|
hm = W_UMALLOC(dx); qhm = W_UMALLOC(dx); |
|
qam = W_UMALLOC(dx); qbm = W_UMALLOC(dx); |
|
w = W_UMALLOC(dx); |
|
for ( i = 0; i < n-1; i++ ) { |
|
cpyum(COEF(blist)[i],gm); |
|
cpyum(fm,w); |
|
divum(mod,w,gm,hm); |
|
|
|
/* find am,bm s.t. qam*qgm+qbm*qhm=1 mod q, qgm=gm mod mod, qhm=hm mod mod */ |
|
henprep2(mod,q,k,qfm,gm,hm,qgm,qhm,qam,qbm); |
|
|
|
henmain2(fl,qgm,qhm,qam,qbm,q,bound,&tl); |
|
rlist->c[i] = (pointer)tl; |
|
cpyum(hm,fm); |
|
cpyum(qhm,qfm); |
|
} |
|
rlist->c[i] = fl; |
|
} |
|
} |
|
|
|
/* |
|
f = g0*h0 mod m -> f = gk*hk mod m^(bound), f is replaced by hk |
|
*/ |
|
|
|
void henmain2(LUM f,UM g0,UM h0,UM a0,UM b0,int m,int bound,LUM *gp) |
|
{ |
|
int n,dg,dh,i,k,j,dg1,dh1; |
|
UM wu,wr,ws,wt,q,wh1,wg1,wc,wd,we,wz; |
|
LUM wb0,wb1,wb2,fk,gk,hk; |
|
|
|
n = DEG(f); dg = DEG(g0); dh = DEG(h0); |
|
|
|
W_LUMALLOC(n,bound,wb0); |
|
W_LUMALLOC(n,bound,wb1); |
|
W_LUMALLOC(n,bound,wb2); |
|
|
|
wt = W_UMALLOC(2*n); ws = W_UMALLOC(2*n); |
|
wr = W_UMALLOC(2*n); wu = W_UMALLOC(2*n); |
|
q = W_UMALLOC(2*n); |
|
wh1 = W_UMALLOC(2*n); wg1 = W_UMALLOC(2*n); |
|
|
|
/* gk = g0 */ |
|
gk = LUMALLOC(n,bound); |
|
DEG(gk) = dg; |
|
for ( i = 0; i <= dg; i++ ) |
|
COEF(gk)[i][0] = COEF(g0)[i]; |
|
|
|
/* hk = h0 */ |
|
W_LUMALLOC(n,bound,hk); |
|
DEG(hk) = dh; |
|
for ( i = 0; i <= dh; i++ ) |
|
COEF(hk)[i][0] = COEF(h0)[i]; |
|
|
|
/* fk = gk*hk */ |
|
W_LUMALLOC(n,bound,fk); |
|
mullum(m,bound,gk,hk,fk); |
|
|
|
wc = W_UMALLOC(2*n); wd = W_UMALLOC(2*n); |
|
we = W_UMALLOC(2*n); wz = W_UMALLOC(2*n); |
|
|
|
#if 0 |
|
mulum(m,a0,g0,wc); |
|
mulum(m,b0,h0,wd); |
|
addum(m,wc,wd,wz); |
|
if ( DEG(wz) != 0 || COEF(wz)[0] != 1 ) |
|
error("henmain2 : cannot happen(extgcd)"); |
|
#endif |
|
|
|
#if 1 |
|
fprintf(stderr,"bound=%d\n",bound); |
|
#endif |
|
for ( k = 1; k < bound; k++ ) { |
|
#if 1 |
|
fprintf(stderr,"."); |
|
#endif |
|
|
|
#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) |
|
check_intr(); |
|
#endif |
|
/* at this point, f = gk*hk mod y^k */ |
|
|
|
#if 0 |
|
for ( j = 0; j < k; j++ ) |
|
for ( i = 0; i <= n; i++ ) |
|
if ( COEF(f)[i][j] != COEF(f)[i][j] ) |
|
error("henmain2 : cannot happen(f=fk)"); |
|
#endif |
|
|
|
/* wt = (f-gk*hk)/y^k */ |
|
for ( i = 0; i <= n; i++ ) |
|
COEF(ws)[i] = COEF(f)[i][k]; |
|
degum(ws,n); |
|
for ( i = 0; i <= n; i++ ) |
|
COEF(wu)[i] = COEF(fk)[i][k]; |
|
degum(wu,n); |
|
subum(m,ws,wu,wt); |
|
|
|
/* compute wf1,wg1 s.t. wh1*g0+wg1*h0 = wt */ |
|
mulum(m,a0,wt,wh1); DEG(wh1) = divum(m,wh1,h0,q); |
|
mulum(m,wh1,g0,wc); subum(m,wt,wc,wd); DEG(wd) = divum(m,wd,h0,wg1); |
|
|
|
/* check */ |
|
#if 0 |
|
if ( DEG(wd) >= 0 || DEG(wg1) > dg ) |
|
error("henmain2 : cannot happen(adj)"); |
|
|
|
mulum(m,wg1,h0,wc); mulum(m,wh1,g0,wd); addum(m,wc,wd,we); |
|
subum(m,we,wt,wz); |
|
if ( DEG(wz) >= 0 ) |
|
error("henmain2 : cannot happen(coef)"); |
|
#endif |
|
|
|
/* fk += ((wg1*hk+wh1*gk)*y^k+wg1*wh1*y^(2*k) mod m^bound */ |
|
|
|
/* wb0 = wh1*y^k */ |
|
clearlum(n,bound,wb0); |
|
DEG(wb0) = dh1 = DEG(wh1); |
|
for ( i = 0; i <= dh1; i++ ) |
|
COEF(wb0)[i][k] = COEF(wh1)[i]; |
|
|
|
/* wb2 = gk*wb0 mod y^bound */ |
|
clearlum(n,bound,wb2); |
|
mullum(m,bound,gk,wb0,wb2); |
|
|
|
/* fk += wb2 */ |
|
addtolum(m,bound,wb2,fk); |
|
|
|
/* wb1 = wg1*y^k */ |
|
clearlum(n,bound,wb1); |
|
DEG(wb1) = dg1 = DEG(wg1); |
|
for ( i = 0; i <= n; i++ ) |
|
COEF(wb1)[i][k] = COEF(wg1)[i]; |
|
|
|
/* wb2 = hk*wb1 mod y^bound */ |
|
clearlum(n,bound,wb2); |
|
mullum(m,bound,hk,wb1,wb2); |
|
|
|
/* fk += wb2 */ |
|
addtolum(m,bound,wb2,fk); |
|
|
|
/* fk += wg1*wh1*y^(2*k) mod y^bound) */ |
|
if ( 2*k < bound ) { |
|
clearlum(n,bound,wb2); |
|
mullum(m,bound,wb0,wb1,wb2); |
|
addtolum(m,bound,wb2,fk); |
|
} |
|
|
|
/* gk += wg1*y^k, hk += wh1*y^k */ |
|
for ( i = 0; i <= DEG(wg1); i++ ) |
|
COEF(gk)[i][k] = COEF(wg1)[i]; |
|
for ( i = 0; i <= DEG(wh1); i++ ) |
|
COEF(hk)[i][k] = COEF(wh1)[i]; |
|
} |
|
#if 1 |
|
fprintf(stderr,"\n"); |
|
#if defined(__MINGW32__) || defined(__MINGW64__) |
|
fflush(stderr); |
|
#endif |
|
#endif |
|
*gp = gk; |
|
clearlum(n,bound,f); |
|
DEG(f) = dh; |
|
for ( i = 0; i <= dh; i++ ) |
|
for ( j = 0; j < bound; j++ ) |
|
COEF(f)[i][j] = COEF(hk)[i][j]; |
|
} |
|
|
|
void clearlum(int n,int bound,LUM f) |
|
{ |
|
int i; |
|
|
|
for ( i = 0; i <= n; i++ ) |
|
bzero(COEF(f)[i],bound*sizeof(int)); |
|
} |
|
|
|
/* g += f */ |
|
|
|
void addtolum(int m,int bound,LUM f,LUM g) |
|
{ |
|
int n,i; |
|
|
|
n = DEG(f); |
|
for ( i = 0; i <= n; i++ ) |
|
addpadic(m,bound,COEF(f)[i],COEF(g)[i]); |
|
} |
|
|
|
void hsq(int index,int count,P f,int *nindex,DCP *dcp) |
|
{ |
register int i,j,k; |
register int i,j,k; |
register int **pp,**fpp; |
register int **pp,**fpp; |
register int *px,*py; |
register int *px,*py; |
|
|
*dcp = 0; |
*dcp = 0; |
} |
} |
|
|
void gcdgen(f,blist,clistp) |
void gcdgen(P f,ML blist,ML *clistp) |
P f; |
|
ML blist,*clistp; |
|
{ |
{ |
register int i; |
register int i; |
int n,d,mod,np; |
int n,d,mod,np; |
Line 435 ML blist,*clistp; |
|
Line 624 ML blist,*clistp; |
|
} |
} |
} |
} |
|
|
|
/* find a,b s.t. qa*qg+qb*qh=1 mod q, qg=g mod mod, qh=h mod mod */ |
|
/* q = mod^k */ |
|
|
|
void henprep2(int mod,int q,int k,UM f,UM g,UM h,UM qg,UM qh,UM qa,UM qb) |
|
{ |
|
int n; |
|
UM wg,wh,wa,wb; |
|
ML bl,cl,bql,cql; |
|
P ff; |
|
|
|
n = DEG(f); |
|
wg = W_UMALLOC(2*n); wh = W_UMALLOC(2*n); |
|
wa = W_UMALLOC(2*n); wb = W_UMALLOC(2*n); |
|
cpyum(g,wg); cpyum(h,wh); |
|
|
|
/* wa*g+wb*h = 1 mod mod */ |
|
eucum(mod,wg,wh,wa,wb); |
|
|
|
#if 0 |
|
/* check */ |
|
wt = W_UMALLOC(2*n); ws = W_UMALLOC(2*n); wu = W_UMALLOC(2*n); |
|
mulum(mod,wa,g,wt); |
|
mulum(mod,wb,h,ws); |
|
addum(mod,wt,ws,wu); |
|
if ( DEG(wu) != 0 || COEF(wu)[0] != 1 ) |
|
error("henprep 1"); |
|
#endif |
|
|
|
bl = MLALLOC(2); bl->n = 2; bl->mod = mod; bl->c[0] = g; bl->c[1] = h; |
|
cl = MLALLOC(2); cl->n = 2; cl->mod = mod; cl->c[0] = wb; cl->c[1] = wa; |
|
umtop(CO->v,f,&ff); /* XXX */ |
|
henprep(ff,bl,cl,&bql,&cql); /* XXX */ |
|
|
|
cpyum(bql->c[0],qg); cpyum(bql->c[1],qh); |
|
cpyum(cql->c[0],qb); cpyum(cql->c[1],qa); |
|
|
|
#if 0 |
|
/* check */ |
|
mulum(q,qa,qg,wt); |
|
mulum(q,qb,qh,ws); |
|
addum(q,wt,ws,wu); |
|
if ( DEG(wu) != 0 || COEF(wu)[0] != 1 ) |
|
error("henprep 2"); |
|
#endif |
|
} |
|
|
/* |
/* |
henprep(f,&blist,&clist,&bqlist,&cqlist); |
henprep(f,blist,clist,&bqlist,&cqlist); |
*/ |
*/ |
|
|
void henprep(f,blist,clist,bqlistp,cqlistp) |
void henprep(P f,ML blist,ML clist,ML *bqlistp,ML *cqlistp) |
P f; |
|
ML blist,clist,*bqlistp,*cqlistp; |
|
{ |
{ |
register int i,j,k,*px,*py,*pz; |
register int i,j,k,*px,*py,*pz; |
int n,pmax,dr,tmp,p,p1,mod,np,b,q; |
int n,pmax,dr,tmp,p,p1,mod,np,b,q; |
Line 522 ML blist,clist,*bqlistp,*cqlistp; |
|
Line 755 ML blist,clist,*bqlistp,*cqlistp; |
|
henmain(fl,bqlist,cqlist,listp) |
henmain(fl,bqlist,cqlist,listp) |
*/ |
*/ |
|
|
void henmain(f,bqlist,cqlist,listp) |
void henmain(LUM f,ML bqlist,ML cqlist,ML *listp) |
LUM f; |
|
ML bqlist,cqlist,*listp; |
|
{ |
{ |
register int i,j,k; |
register int i,j,k; |
int *px,*py; |
int *px,*py; |
Line 549 ML bqlist,cqlist,*listp; |
|
Line 780 ML bqlist,cqlist,*listp; |
|
for ( j = DEG(b[i]), pp = COEF(l[i]), px = COEF(b[i]); j >= 0; j-- ) |
for ( j = DEG(b[i]), pp = COEF(l[i]), px = COEF(b[i]); j >= 0; j-- ) |
pp[j][0] = px[j]; |
pp[j][0] = px[j]; |
} |
} |
|
#if 0 |
|
fprintf(stderr,"bound=%d\n",bound); |
|
#endif |
for ( i = 1; i < bound; i++ ) { |
for ( i = 1; i < bound; i++ ) { |
|
#if 0 |
|
fprintf(stderr,"."); |
|
#endif |
|
#if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) |
|
check_intr(); |
|
#endif |
mullum(mod,i+1,l[0],l[1],wb0); |
mullum(mod,i+1,l[0],l[1],wb0); |
for ( j = 2; j < np; j++ ) { |
for ( j = 2; j < np; j++ ) { |
mullum(mod,i+1,l[j],wb0,wb1); |
mullum(mod,i+1,l[j],wb0,wb1); |
Line 578 ML bqlist,cqlist,*listp; |
|
Line 818 ML bqlist,cqlist,*listp; |
|
for ( j = n, px = COEF(wq0); j >= 0; j-- ) |
for ( j = n, px = COEF(wq0); j >= 0; j-- ) |
px[j] = 0; |
px[j] = 0; |
} |
} |
|
#if 0 |
|
fprintf(stderr,"\n"); |
|
#endif |
} |
} |
|
|
|
/* |
|
henmain_incremental(fl,bqlist,cqlist,start) |
|
fl = bqlist[0]*... mod q^start |
|
*/ |
|
|
|
void henmain_incremental(LUM f,LUM *bqlist,ML cqlist, |
|
int np, int mod, int start, int bound) |
|
{ |
|
register int i,j,k; |
|
int *px,*py; |
|
int **pp,**pp1; |
|
int n,dr,tmp; |
|
UM wt,wq0,wq,wr,wm,wm0,wa,q; |
|
LUM wb0,wb1,tlum; |
|
UM *b,*c; |
|
LUM *l; |
|
ML list; |
|
|
|
n = DEG(f); |
|
W_LUMALLOC(n,bound,wb0); W_LUMALLOC(n,bound,wb1); |
|
wt = W_UMALLOC(n); wq0 = W_UMALLOC(n); wq = W_UMALLOC(n); |
|
wr = W_UMALLOC(n); wm = W_UMALLOC(2*n); wm0 = W_UMALLOC(2*n); |
|
wa = W_UMALLOC(2*n); q = W_UMALLOC(2*n); |
|
c = (UM *)cqlist->c; l = bqlist; |
|
b = (UM *)ALLOCA(n*sizeof(UM)); |
|
for ( i = 0; i < np; i++ ) { |
|
j = DEG(l[i]); |
|
b[i] = W_UMALLOC(j); |
|
DEG(b[i]) = j; |
|
for ( pp = COEF(l[i]), px = COEF(b[i]); j >= 0; j-- ) |
|
px[j] = pp[j][0]; |
|
} |
|
#if 0 |
|
fprintf(stderr,"bound=%d\n",bound); |
|
#endif |
|
for ( i = start; i < bound; i++ ) { |
|
#if 0 |
|
fprintf(stderr,"."); |
|
#endif |
|
mullum(mod,i+1,l[0],l[1],wb0); |
|
for ( j = 2; j < np; j++ ) { |
|
mullum(mod,i+1,l[j],wb0,wb1); |
|
tlum = wb0; wb0 = wb1; wb1 = tlum; |
|
} |
|
for ( j = n, px = COEF(wt); j >= 0; j-- ) |
|
px[j] = 0; |
|
for ( j = n, pp = COEF(f), pp1 = COEF(wb0); j >= 0; j-- ) { |
|
tmp = ( pp[j][i] - pp1[j][i] ) % mod; |
|
COEF(wt)[j] = ( tmp < 0 ? tmp + mod : tmp ); |
|
} |
|
degum(wt,n); |
|
for ( j = n, px = COEF(wq0); j >= 0; j-- ) |
|
px[j] = 0; |
|
for ( j = 1; j < np; j++ ) { |
|
mulum(mod,wt,c[j],wm); dr = divum(mod,wm,b[j],q); |
|
for ( k = DEG(q), px = COEF(wq0), py = COEF(q); k >= 0; k-- ) |
|
px[k] = ( px[k] + py[k] ) % mod; |
|
for ( k = dr, pp = COEF(l[j]), px = COEF(wm); k >= 0; k-- ) |
|
pp[k][i] = px[k]; |
|
} |
|
degum(wq0,n); mulum(mod,wq0,b[0],wm); |
|
mulum(mod,wt,c[0],wm0); addum(mod,wm,wm0,wa); |
|
for ( j = DEG(wa), pp = COEF(l[0]), px = COEF(wa); j >= 0; j-- ) |
|
pp[j][i] = px[j]; |
|
for ( j = n, px = COEF(wq0); j >= 0; j-- ) |
|
px[j] = 0; |
|
} |
|
#if 0 |
|
fprintf(stderr,"\n"); |
|
#endif |
|
} |
|
|
static double M; |
static double M; |
static int E; |
static int E; |
|
|
int mignotte(q,f) |
int mignotte(int q,P f) |
int q; |
|
P f; |
|
{ |
{ |
int p; |
int p; |
unsigned int *b; |
unsigned int *b; |
|
|
return (int)ceil( (0.31*(E+UDEG(f)+1)+log10((double)M)) / log10((double)q) ); |
return (int)ceil( (0.31*(E+UDEG(f)+1)+log10((double)M)) / log10((double)q) ); |
} |
} |
|
|
int mig(q,d,f) |
int mig(int q,int d,P f) |
int q,d; |
|
P f; |
|
{ |
{ |
int p; |
int p; |
unsigned int *b; |
unsigned int *b; |
|
|
return (int)ceil( (0.31*(E+d+1)+log10((double)M)) / log10((double)q) ); |
return (int)ceil( (0.31*(E+d+1)+log10((double)M)) / log10((double)q) ); |
} |
} |
|
|
void sqad(man,exp) |
void sqad(unsigned int man,int exp) |
unsigned int man; |
|
int exp; |
|
{ |
{ |
int e,sqe; |
int e,sqe; |
unsigned int t; |
unsigned int t; |
|
|
} |
} |
} |
} |
|
|
void ptolum(q,bound,f,fl) |
void ptolum(int q,int bound,P f,LUM fl) |
int q,bound; |
|
P f; |
|
LUM fl; |
|
{ |
{ |
DCP dc; |
DCP dc; |
int i,j; |
int i,j; |
|
|
c = pp[QTOS(DEG(dc))]; w = (unsigned int *)W_ALLOC(d); |
c = pp[QTOS(DEG(dc))]; w = (unsigned int *)W_ALLOC(d); |
for ( i = 0; i < d; i++ ) |
for ( i = 0; i < d; i++ ) |
w[i] = m[i]; |
w[i] = m[i]; |
for ( i = 0; d >= 1; ) { |
for ( i = 0; i < bound && d >= 1; ) { |
for ( j = d - 1, r = 0; j >= 0; j-- ) { |
for ( j = d - 1, r = 0; j >= 0; j-- ) { |
DSAB(q,r,w[j],w[j],r) |
DSAB(q,r,w[j],w[j],r) |
} |
} |
|
|
} |
} |
} |
} |
|
|
void modfctrp(p,mod,flag,dcp) |
void modfctrp(P p,int mod,int flag,DCP *dcp) |
P p; |
|
int mod,flag; |
|
DCP *dcp; |
|
{ |
{ |
int cm,n,i,j,k; |
int cm,n,i,j,k; |
DCP dc,dc0; |
DCP dc,dc0; |
|
|
NEXT(dc) = 0; *dcp = dc0; |
NEXT(dc) = 0; *dcp = dc0; |
} |
} |
|
|
void gensqfrum(mod,p,dc) |
void gensqfrum(int mod,UM p,struct oDUM *dc) |
int mod; |
|
UM p; |
|
struct oDUM *dc; |
|
{ |
{ |
int n,i,j,d; |
int n,i,j,d; |
UM t,s,g,f,f1,b; |
UM t,s,g,f,f1,b; |
Line 845 struct oDUM *dc; |
|
Line 1145 struct oDUM *dc; |
|
} |
} |
|
|
#if 0 |
#if 0 |
void srchum(mod,p1,p2,gr) |
void srchum(int mod,UM p1,UM p2,UM gr) |
int mod; |
|
UM p1,p2,gr; |
|
{ |
{ |
UM m,m1,m2,q,r,t,g1,g2; |
UM m,m1,m2,q,r,t,g1,g2; |
int lc,d,d1,d2,i,j,k,l,l1,l2,l3,tmp,adj; |
int lc,d,d1,d2,i,j,k,l,l1,l2,l3,tmp,adj; |
|
|
} |
} |
} |
} |
|
|
UM *resberle(mod,f,fp) |
UM *resberle(int mod,UM f,UM *fp) |
register int mod; |
|
UM f; |
|
UM *fp; |
|
{ |
{ |
UM w,wg,ws,wf,f0,gcd,q,res; |
UM w,wg,ws,wf,f0,gcd,q,res; |
int n; |
int n; |
|
|
return ( fp ); |
return ( fp ); |
} |
} |
|
|
int substum(mod,p,a) |
int substum(int mod,UM p,int a) |
int mod; |
|
UM p; |
|
int a; |
|
{ |
{ |
int i,j,s; |
int i,j,s; |
int *c; |
int *c; |
|
|
} |
} |
#endif |
#endif |
|
|
void ddd(mod,f,r) |
void ddd(int mod,UM f,UM *r) |
int mod; |
|
UM f,*r; |
|
{ |
{ |
register int i,j; |
register int i,j; |
int d,n; |
int d,n; |
|
|
} |
} |
|
|
#if 0 |
#if 0 |
void canzas(mod,f,d,base,r) |
void canzas(int mod,UM f,int d,UM *base,UM *r) |
int mod; |
|
UM f,*base,*r; |
|
{ |
{ |
UM t,s,u,w,g,o,q; |
UM t,s,u,w,g,o,q; |
N n1,n2,n3,n4,n5; |
N n1,n2,n3,n4,n5; |
|
|
} |
} |
} |
} |
#else |
#else |
void canzas(mod,f,d,base,r) |
void canzas(int mod,UM f,int d,UM *base,UM *r) |
int mod; |
|
UM f,*base,*r; |
|
{ |
{ |
UM t,s,u,w,g,o,q; |
UM t,s,u,w,g,o,q; |
N n1,n2,n3,n4,n5; |
N n1,n2,n3,n4,n5; |
|
|
} |
} |
#endif |
#endif |
|
|
void randum(mod,d,p) |
void randum(int mod,int d,UM p) |
int mod,d; |
|
UM p; |
|
{ |
{ |
unsigned int n; |
unsigned int n; |
int i; |
int i; |
|
|
COEF(p)[i] = ((unsigned int)random()) % mod; |
COEF(p)[i] = ((unsigned int)random()) % mod; |
} |
} |
|
|
void pwrmodum(mod,p,e,f,pr) |
void pwrmodum(int mod,UM p,int e,UM f,UM pr) |
int mod,e; |
|
UM p,f,pr; |
|
{ |
{ |
UM wt,ws,q; |
UM wt,ws,q; |
|
|
|
|
} |
} |
} |
} |
|
|
void spwrum(mod,m,base,f,e,r) |
void spwrum(int mod,UM m,UM *base,UM f,N e,UM r) |
int mod; |
|
UM f,m,r; |
|
UM *base; |
|
N e; |
|
{ |
{ |
int a,n,i; |
int a,n,i; |
N e1,an; |
N e1,an; |
|
|
} |
} |
} |
} |
|
|
void spwrum0(mod,m,f,e,r) |
void spwrum0(int mod,UM m,UM f,N e,UM r) |
int mod; |
|
UM f,m,r; |
|
N e; |
|
{ |
{ |
UM t,s,q; |
UM t,s,q; |
N e1; |
N e1; |
|
|
} |
} |
|
|
#if 0 |
#if 0 |
void Mulum(mod,p1,p2,pr) |
void Mulum(int mod,UM p1,UM p2,UM pr) |
register int mod; |
|
UM p1,p2,pr; |
|
{ |
{ |
register int *pc1,*pcr; |
register int *pc1,*pcr; |
register int mul,i,j,d1,d2; |
register int mul,i,j,d1,d2; |
|
|
DEG(pr) = d1 + d2; |
DEG(pr) = d1 + d2; |
} |
} |
|
|
void Mulsum(mod,p,n,pr) |
void Mulsum(int mod,UM p,int n,UM pr) |
register int mod,n; |
|
UM p,pr; |
|
{ |
{ |
register int *sp,*dp; |
register int *sp,*dp; |
register int i; |
register int i; |
|
|
*dp = (*sp * n) % mod; |
*dp = (*sp * n) % mod; |
} |
} |
|
|
int Divum(mod,p1,p2,pq) |
int Divum(int mod,UM p1,UM p2,UM pq) |
register int mod; |
|
UM p1,p2,pq; |
|
{ |
{ |
register int *pc1,*pct; |
register int *pc1,*pct; |
register int tmp,i,j,inv; |
register int tmp,i,j,inv; |
|
|
return( i ); |
return( i ); |
} |
} |
|
|
void Gcdum(mod,p1,p2,pr) |
void Gcdum(int mod,UM p1,UM p2,UM pr) |
register int mod; |
|
UM p1,p2,pr; |
|
{ |
{ |
register int *sp,*dp; |
register int *sp,*dp; |
register int i,inv; |
register int i,inv; |
|
|
} |
} |
#endif |
#endif |
|
|
void mult_mod_tab(p,mod,tab,r,d) |
void mult_mod_tab(UM p,int mod,UM *tab,UM r,int d) |
UM p,r; |
|
UM *tab; |
|
int mod,d; |
|
{ |
{ |
UM w,w1,c; |
UM w,w1,c; |
int n,i; |
int n,i; |
|
|
} |
} |
} |
} |
|
|
void make_qmat(p,mod,tab,mp) |
void make_qmat(UM p,int mod,UM *tab,int ***mp) |
UM p; |
|
int mod; |
|
UM *tab; |
|
int ***mp; |
|
{ |
{ |
int n,i,j; |
int n,i,j; |
int *c; |
int *c; |
|
|
mat[i][i] = (mat[i][i]+mod-1) % mod; |
mat[i][i] = (mat[i][i]+mod-1) % mod; |
} |
} |
|
|
void null_mod(mat,mod,n,ind) |
void null_mod(int **mat,int mod,int n,int *ind) |
int **mat; |
|
int *ind; |
|
int mod,n; |
|
{ |
{ |
int i,j,l,s,h,inv; |
int i,j,l,s,h,inv; |
int *t,*u; |
int *t,*u; |
|
|
} |
} |
} |
} |
|
|
void null_to_sol(mat,ind,mod,n,r) |
void null_to_sol(int **mat,int *ind,int mod,int n,UM *r) |
int **mat; |
|
int *ind; |
|
int mod,n; |
|
UM *r; |
|
{ |
{ |
int i,j,k,l; |
int i,j,k,l; |
int *c; |
int *c; |
Line 1414 null_mod(mat,mod,n,ind) |
|
Line 1667 null_mod(mat,mod,n,ind) |
|
null_to_sol(mat,ind,mod,n,r) |
null_to_sol(mat,ind,mod,n,r) |
*/ |
*/ |
|
|
void newddd(mod,f,r) |
void newddd(int mod,UM f,UM *r) |
int mod; |
|
UM f,*r; |
|
{ |
{ |
register int i,j; |
register int i,j; |
int d,n; |
int d,n; |
|
|
r[j] = 0; |
r[j] = 0; |
} |
} |
|
|
int nfctr_mod(f,mod) |
int nfctr_mod(UM f,int mod) |
int mod; |
|
UM f; |
|
{ |
{ |
register int i,j; |
register int i,j; |
int d,n; |
int d,n; |
|
|
return j; |
return j; |
} |
} |
|
|
int irred_check(f,mod) |
int irred_check(UM f,int mod) |
UM f; |
|
int mod; |
|
{ |
{ |
register int i,j; |
register int i,j; |
int d,n; |
int d,n; |
|
|
return 1; |
return 1; |
} |
} |
|
|
int berlekamp(p,mod,df,tab,r) |
int berlekamp(UM p,int mod,int df,UM *tab,UM *r) |
UM p; |
|
int mod,df; |
|
UM *tab,*r; |
|
{ |
{ |
int n,i,j,k,nf,d,nr; |
int n,i,j,k,nf,d,nr; |
int **mat; |
int **mat; |
|
|
} |
} |
} |
} |
} |
} |
|
/* NOTREACHED */ |
|
error("berlekamp : cannot happen"); |
|
return -1; |
} |
} |
|
|
void minipoly_mod(mod,f,p,mp) |
void minipoly_mod(int mod,UM f,UM p,UM mp) |
int mod; |
|
UM f,p,mp; |
|
{ |
{ |
struct p_pair *list,*l,*l1,*lprev; |
struct p_pair *list,*l,*l1,*lprev; |
int n,d; |
int n,d; |
|
|
} |
} |
} |
} |
|
|
void lnf_mod(mod,n,p0,p1,list,np0,np1) |
void lnf_mod(int mod,int n,UM p0,UM p1,struct p_pair *list,UM np0,UM np1) |
int mod,n; |
|
UM p0,p1; |
|
struct p_pair *list; |
|
UM np0,np1; |
|
{ |
{ |
int inv,h,d1; |
int inv,h,d1; |
UM t0,t1,s0,s1; |
UM t0,t1,s0,s1; |
|
|
} |
} |
} |
} |
|
|
int find_root(mod,p,root) |
int find_root(int mod,UM p,int *root) |
int mod; |
|
UM p; |
|
int *root; |
|
{ |
{ |
UM *r; |
UM *r; |
int i,j; |
int i,j; |
|
|
return j; |
return j; |
} |
} |
|
|
void showum(p) |
void showum(UM p) |
UM p; |
|
{ |
{ |
int i; |
int i; |
int *c; |
int *c; |
|
|
printf("\n"); |
printf("\n"); |
} |
} |
|
|
void showumat(mat,n) |
void showumat(int **mat,int n) |
int **mat; |
|
int n; |
|
{ |
{ |
int i,j; |
int i,j; |
|
|