version 1.9, 2000/11/08 08:02:49 |
version 1.21, 2001/09/17 07:16:58 |
|
|
* 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/array.c,v 1.8 2000/09/21 09:19:25 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/array.c,v 1.20 2001/09/17 03:33:57 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
|
|
#define DMAR(a1,a2,a3,d,r) (r)=dmar(a1,a2,a3,d); |
#define DMAR(a1,a2,a3,d,r) (r)=dmar(a1,a2,a3,d); |
#endif |
#endif |
|
|
extern int Print; /* XXX */ |
extern int DP_Print; /* XXX */ |
|
|
void inner_product_mat_int_mod(Q **,int **,int,int,int,Q *); |
void inner_product_mat_int_mod(Q **,int **,int,int,int,Q *); |
void solve_by_lu_mod(int **,int,int,int **,int); |
void solve_by_lu_mod(int **,int,int,int **,int); |
Line 67 void mat_to_gfmmat(MAT,unsigned int,GFMMAT *); |
|
Line 67 void mat_to_gfmmat(MAT,unsigned int,GFMMAT *); |
|
|
|
int generic_gauss_elim_mod(int **,int,int,int,int *); |
int generic_gauss_elim_mod(int **,int,int,int,int *); |
int generic_gauss_elim(MAT ,MAT *,Q *,int **,int **); |
int generic_gauss_elim(MAT ,MAT *,Q *,int **,int **); |
|
void reduce_sp_by_red_mod_compress (int *,CDP *,int *,int,int,int); |
|
|
int gauss_elim_mod(int **,int,int,int); |
int gauss_elim_mod(int **,int,int,int); |
int gauss_elim_mod1(int **,int,int,int); |
int gauss_elim_mod1(int **,int,int,int); |
Line 90 void Px962_irredpoly_up2(); |
|
Line 91 void Px962_irredpoly_up2(); |
|
void Pirredpoly_up2(); |
void Pirredpoly_up2(); |
void Pnbpoly_up2(); |
void Pnbpoly_up2(); |
void Pqsort(); |
void Pqsort(); |
|
void Pexponent_vector(); |
|
|
struct ftab array_tab[] = { |
struct ftab array_tab[] = { |
{"solve_by_lu_gfmmat",Psolve_by_lu_gfmmat,4}, |
{"solve_by_lu_gfmmat",Psolve_by_lu_gfmmat,4}, |
Line 97 struct ftab array_tab[] = { |
|
Line 99 struct ftab array_tab[] = { |
|
{"mat_to_gfmmat",Pmat_to_gfmmat,2}, |
{"mat_to_gfmmat",Pmat_to_gfmmat,2}, |
{"generic_gauss_elim_mod",Pgeneric_gauss_elim_mod,2}, |
{"generic_gauss_elim_mod",Pgeneric_gauss_elim_mod,2}, |
{"newvect",Pnewvect,-2}, |
{"newvect",Pnewvect,-2}, |
|
{"vector",Pnewvect,-2}, |
|
{"exponent_vector",Pexponent_vector,-99999999}, |
{"newmat",Pnewmat,-3}, |
{"newmat",Pnewmat,-3}, |
|
{"matrix",Pnewmat,-3}, |
{"newbytearray",Pnewbytearray,-2}, |
{"newbytearray",Pnewbytearray,-2}, |
{"sepmat_destructive",Psepmat_destructive,2}, |
{"sepmat_destructive",Psepmat_destructive,2}, |
{"sepvect",Psepvect,2}, |
{"sepvect",Psepvect,2}, |
|
|
*rp = vect; |
*rp = vect; |
} |
} |
|
|
|
void Pexponent_vector(arg,rp) |
|
NODE arg; |
|
DP *rp; |
|
{ |
|
nodetod(arg,rp); |
|
} |
|
|
void Pnewbytearray(arg,rp) |
void Pnewbytearray(arg,rp) |
NODE arg; |
NODE arg; |
BYTEARRAY *rp; |
BYTEARRAY *rp; |
|
|
int len,i,r; |
int len,i,r; |
BYTEARRAY array; |
BYTEARRAY array; |
unsigned char *vb; |
unsigned char *vb; |
|
char *str; |
LIST list; |
LIST list; |
NODE tn; |
NODE tn; |
|
|
|
|
error("newbytearray : invalid size"); |
error("newbytearray : invalid size"); |
MKBYTEARRAY(array,len); |
MKBYTEARRAY(array,len); |
if ( argc(arg) == 2 ) { |
if ( argc(arg) == 2 ) { |
list = (LIST)ARG1(arg); |
if ( !ARG1(arg) ) |
asir_assert(list,O_LIST,"newbytearray"); |
error("newbytearray : invalid initialization"); |
for ( r = 0, tn = BDY(list); tn; r++, tn = NEXT(tn) ); |
switch ( OID((Obj)ARG1(arg)) ) { |
if ( r > len ) { |
case O_LIST: |
*rp = array; |
list = (LIST)ARG1(arg); |
return; |
asir_assert(list,O_LIST,"newbytearray"); |
|
for ( r = 0, tn = BDY(list); tn; r++, tn = NEXT(tn) ); |
|
if ( r <= len ) { |
|
for ( i = 0, tn = BDY(list), vb = BDY(array); tn; |
|
i++, tn = NEXT(tn) ) |
|
vb[i] = (unsigned char)QTOS((Q)BDY(tn)); |
|
} |
|
break; |
|
case O_STR: |
|
str = BDY((STRING)ARG1(arg)); |
|
r = strlen(str); |
|
if ( r <= len ) |
|
bcopy(str,BDY(array),r); |
|
break; |
|
default: |
|
if ( !ARG1(arg) ) |
|
error("newbytearray : invalid initialization"); |
} |
} |
for ( i = 0, tn = BDY(list), vb = BDY(array); tn; i++, tn = NEXT(tn) ) |
|
vb[i] = (unsigned char)QTOS((Q)BDY(tn)); |
|
} |
} |
*rp = array; |
*rp = array; |
} |
} |
Line 790 int **rindp,**cindp; |
|
Line 817 int **rindp,**cindp; |
|
colstat = (int *)MALLOC_ATOMIC(col*sizeof(int)); |
colstat = (int *)MALLOC_ATOMIC(col*sizeof(int)); |
wcolstat = (int *)MALLOC_ATOMIC(col*sizeof(int)); |
wcolstat = (int *)MALLOC_ATOMIC(col*sizeof(int)); |
for ( ind = 0; ; ind++ ) { |
for ( ind = 0; ; ind++ ) { |
if ( Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"."); fflush(asir_out); |
fprintf(asir_out,"."); fflush(asir_out); |
} |
} |
md = lprime[ind]; |
md = get_lprime(ind); |
get_eg(&tmp0); |
get_eg(&tmp0); |
for ( i = 0; i < row; i++ ) |
for ( i = 0; i < row; i++ ) |
for ( j = 0, bmi = bmat[i], wmi = wmat[i]; j < col; j++ ) |
for ( j = 0, bmi = bmat[i], wmi = wmat[i]; j < col; j++ ) |
|
|
} |
} |
} else { |
} else { |
if ( rank < rank0 ) { |
if ( rank < rank0 ) { |
if ( Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"lower rank matrix; continuing...\n"); |
fprintf(asir_out,"lower rank matrix; continuing...\n"); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
continue; |
continue; |
} else if ( rank > rank0 ) { |
} else if ( rank > rank0 ) { |
if ( Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"higher rank matrix; resetting...\n"); |
fprintf(asir_out,"higher rank matrix; resetting...\n"); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
|
|
} else { |
} else { |
for ( j = 0; (j<col) && (colstat[j]==wcolstat[j]); j++ ); |
for ( j = 0; (j<col) && (colstat[j]==wcolstat[j]); j++ ); |
if ( j < col ) { |
if ( j < col ) { |
if ( Print ) { |
if ( DP_Print ) { |
fprintf(asir_out,"inconsitent colstat; resetting...\n"); |
fprintf(asir_out,"inconsitent colstat; resetting...\n"); |
fflush(asir_out); |
fflush(asir_out); |
} |
} |
|
|
add_eg(&eg_chrem_split,&tmp0,&tmp1); |
add_eg(&eg_chrem_split,&tmp0,&tmp1); |
|
|
get_eg(&tmp0); |
get_eg(&tmp0); |
ret = intmtoratm(crmat,m1,*nm,dn); |
if ( ind % 16 ) |
|
ret = 0; |
|
else |
|
ret = intmtoratm(crmat,m1,*nm,dn); |
get_eg(&tmp1); |
get_eg(&tmp1); |
add_eg(&eg_intrat,&tmp0,&tmp1); |
add_eg(&eg_intrat,&tmp0,&tmp1); |
add_eg(&eg_intrat_split,&tmp0,&tmp1); |
add_eg(&eg_intrat_split,&tmp0,&tmp1); |
|
|
get_eg(&tmp1); |
get_eg(&tmp1); |
add_eg(&eg_gschk,&tmp0,&tmp1); |
add_eg(&eg_gschk,&tmp0,&tmp1); |
add_eg(&eg_gschk_split,&tmp0,&tmp1); |
add_eg(&eg_gschk_split,&tmp0,&tmp1); |
if ( Print ) { |
if ( DP_Print ) { |
print_eg("Mod",&eg_mod_split); |
print_eg("Mod",&eg_mod_split); |
print_eg("Elim",&eg_elim_split); |
print_eg("Elim",&eg_elim_split); |
print_eg("ChRem",&eg_chrem_split); |
print_eg("ChRem",&eg_chrem_split); |
Line 938 int **rindp,**cindp; |
|
Line 968 int **rindp,**cindp; |
|
row = mat->row; col = mat->col; |
row = mat->row; col = mat->col; |
w = (int **)almat(row,col); |
w = (int **)almat(row,col); |
for ( ind = 0; ; ind++ ) { |
for ( ind = 0; ; ind++ ) { |
md = lprime[ind]; |
md = get_lprime(ind); |
STOQ(md,mdq); |
STOQ(md,mdq); |
for ( i = 0; i < row; i++ ) |
for ( i = 0; i < row; i++ ) |
for ( j = 0, ai = a0[i], wi = w[i]; j < col; j++ ) |
for ( j = 0, ai = a0[i], wi = w[i]; j < col; j++ ) |
Line 1020 int **rindp,**cindp; |
|
Line 1050 int **rindp,**cindp; |
|
add_eg(&eg_mul,&tmp0,&tmp1); |
add_eg(&eg_mul,&tmp0,&tmp1); |
/* q = q*md */ |
/* q = q*md */ |
mulq(q,mdq,&u); q = u; |
mulq(q,mdq,&u); q = u; |
if ( !(count % 2) && intmtoratm_q(xmat,NM(q),*nmmat,dn) ) { |
if ( !(count % 16) && intmtoratm_q(xmat,NM(q),*nmmat,dn) ) { |
for ( j = k = l = 0; j < col; j++ ) |
for ( j = k = l = 0; j < col; j++ ) |
if ( cinfo[j] ) |
if ( cinfo[j] ) |
rind[k++] = j; |
rind[k++] = j; |
|
|
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
ONE_STEP1 ONE_STEP1 ONE_STEP1 ONE_STEP1 |
} |
} |
for ( ; k >= 0; k-- ) { |
for ( ; k > 0; k-- ) { |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
} |
} |
} |
} |
|
|
hc = md-hc; |
hc = md-hc; |
s = redmat[i]+j; |
s = redmat[i]+j; |
tj = sp+j; |
tj = sp+j; |
for ( k = col-j; k >= 0; k-- ) { |
for ( k = col-j; k > 0; k-- ) { |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
if ( zzz = *s ) { DMAR(zzz,hc,*tj,md,*tj) } tj++; s++; |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
|
/* |
|
mat[i] : compressed reducers (i=0,...,nred-1) |
|
mat[0] < mat[1] < ... < mat[nred-1] w.r.t the term order |
|
*/ |
|
|
|
int red_by_compress(m,p,r,ri,hc,len) |
|
int m; |
|
unsigned int *p; |
|
register unsigned int *r; |
|
register unsigned short *ri; |
|
unsigned int hc; |
|
register int len; |
|
{ |
|
unsigned int up,lo; |
|
unsigned int dmy; |
|
unsigned int *pj; |
|
|
|
p[*ri] = 0; r++; ri++; |
|
for ( len--; len; len--, r++, ri++ ) { |
|
pj = p+ *ri; |
|
DMA(*r,hc,*pj,up,lo); |
|
if ( up ) { |
|
DSAB(m,up,lo,dmy,*pj); |
|
} else |
|
*pj = lo; |
|
} |
|
} |
|
|
|
/* p -= hc*r */ |
|
|
|
int red_by_vect(m,p,r,hc,len) |
|
int m; |
|
unsigned int *p,*r; |
|
unsigned int hc; |
|
int len; |
|
{ |
|
register unsigned int up,lo; |
|
unsigned int dmy; |
|
|
|
*p++ = 0; r++; len--; |
|
for ( ; len; len--, r++, p++ ) |
|
if ( *r ) { |
|
DMA(*r,hc,*p,up,lo); |
|
if ( up ) { |
|
DSAB(m,up,lo,dmy,*p); |
|
} else |
|
*p = lo; |
|
} |
|
} |
|
|
|
extern unsigned int **psca; |
|
|
|
void reduce_sp_by_red_mod_compress (sp,redmat,ind,nred,col,md) |
|
int *sp; |
|
CDP *redmat; |
|
int *ind; |
|
int nred,col; |
|
int md; |
|
{ |
|
int i,j,k,len; |
|
unsigned int *tj; |
|
CDP ri; |
|
unsigned int hc,up,lo,up1,lo1,c; |
|
unsigned int *usp; |
|
|
|
usp = (unsigned int *)sp; |
|
/* reduce the spolys by redmat */ |
|
for ( i = nred-1; i >= 0; i-- ) { |
|
/* reduce sp by redmat[i] */ |
|
usp[ind[i]] %= md; |
|
if ( hc = usp[ind[i]] ) { |
|
/* sp = sp-hc*redmat[i] */ |
|
hc = md-hc; |
|
ri = redmat[i]; |
|
len = ri->len; |
|
red_by_compress(md,usp,psca[ri->psindex],ri->body,hc,len); |
|
} |
|
} |
|
for ( i = 0; i < col; i++ ) |
|
if ( usp[i] >= md ) |
|
usp[i] %= md; |
|
} |
|
|
#define ONE_STEP2 if ( zzz = *pk ) { DMAR(zzz,a,*tk,md,*tk) } pk++; tk++; |
#define ONE_STEP2 if ( zzz = *pk ) { DMAR(zzz,a,*tk,md,*tk) } pk++; tk++; |
|
|
int generic_gauss_elim_mod(mat,row,col,md,colstat) |
int generic_gauss_elim_mod(mat0,row,col,md,colstat) |
int **mat; |
int **mat0; |
int row,col,md; |
int row,col,md; |
int *colstat; |
int *colstat; |
{ |
{ |
int i,j,k,l,inv,a,rank,zzz; |
int i,j,k,l,inv,a,rank,zzz; |
int *t,*pivot,*pk,*tk; |
unsigned int *t,*pivot,*pk,*tk; |
|
unsigned int **mat; |
|
|
|
mat = (unsigned int **)mat0; |
for ( rank = 0, j = 0; j < col; j++ ) { |
for ( rank = 0, j = 0; j < col; j++ ) { |
for ( i = rank; i < row && !mat[i][j]; i++ ); |
for ( i = rank; i < row; i++ ) |
|
mat[i][j] %= md; |
|
for ( i = rank; i < row; i++ ) |
|
if ( mat[i][j] ) |
|
break; |
if ( i == row ) { |
if ( i == row ) { |
colstat[j] = 0; |
colstat[j] = 0; |
continue; |
continue; |
|
|
inv = invm(pivot[j],md); |
inv = invm(pivot[j],md); |
for ( k = j, pk = pivot+k; k < col; k++, pk++ ) |
for ( k = j, pk = pivot+k; k < col; k++, pk++ ) |
if ( *pk ) { |
if ( *pk ) { |
|
if ( *pk >= md ) |
|
*pk %= md; |
DMAR(*pk,inv,0,md,*pk) |
DMAR(*pk,inv,0,md,*pk) |
} |
} |
for ( i = rank+1; i < row; i++ ) { |
for ( i = rank+1; i < row; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) { |
if ( a = t[j] ) |
a = md - a; pk = pivot+j; tk = t+j; |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
k = col-j; |
|
for ( ; k >= 64; k -= 64 ) { |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
} |
|
for ( ; k >= 0; k -- ) { |
|
if ( zzz = *pk ) { DMAR(zzz,a,*tk,md,*tk) } pk++; tk++; |
|
} |
|
} |
|
} |
} |
rank++; |
rank++; |
} |
} |
|
|
pivot = mat[l]; |
pivot = mat[l]; |
for ( i = 0; i < l; i++ ) { |
for ( i = 0; i < l; i++ ) { |
t = mat[i]; |
t = mat[i]; |
if ( a = t[j] ) { |
t[j] %= md; |
a = md-a; pk = pivot+j; tk = t+j; |
if ( a = t[j] ) |
k = col-j; |
red_by_vect(md,t+j,pivot+j,md-a,col-j); |
for ( ; k >= 64; k -= 64 ) { |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
ONE_STEP2 ONE_STEP2 ONE_STEP2 ONE_STEP2 |
|
} |
|
for ( ; k >= 0; k -- ) { |
|
if ( zzz = *pk ) { DMAR(zzz,a,*tk,md,*tk) } pk++; tk++; |
|
} |
|
} |
|
} |
} |
l--; |
l--; |
|
} |
|
for ( j = 0, l = 0; l < rank; j++ ) |
|
if ( colstat[j] ) { |
|
t = mat[l]; |
|
for ( k = j; k < col; k++ ) |
|
if ( t[k] >= md ) |
|
t[k] %= md; |
|
l++; |
} |
} |
return rank; |
return rank; |
} |
} |