Return to ntl.rr CVS log | Up to [local] / OpenXM / src / ox_ntl |
version 1.1, 2003/11/03 03:11:21 | version 1.3, 2003/11/25 13:48:50 | ||
---|---|---|---|
|
|
||
/* $OpenXM$ */ | /* $OpenXM: OpenXM/src/ox_ntl/ntl.rr,v 1.2 2003/11/15 09:06:20 iwane Exp $ */ | ||
module ntl; | module ntl; | ||
localf factor$ | localf factor$ | ||
localf lll$ | |||
localf ex_data$ | localf ex_data$ | ||
localf ex_data_tmp$ | localf ex_data_tmp$ | ||
localf mat2list$ | |||
localf list2mat$ | |||
/* static variables */ | /* static variables */ | ||
|
|
||
/* extern variables */ | /* extern variables */ | ||
#if 1 | #if 1 | ||
localf test$ | localf test_factor$ | ||
localf test_lll$ | |||
/*&usage begin: ntl.test(PID, POLY) | /*&usage begin: ntl.test_factor(PID, POLY) | ||
compare on ox_NTL and on asir. | compare on ox_NTL and on asir. | ||
example: | example: | ||
|
|
||
[1031] ntl.test(PID, F); | [1031] ntl.test(PID, F); | ||
[CPU,0.121539,0.001354,GC,0.0222,0] | [CPU,0.121539,0.001354,GC,0.0222,0] | ||
end: */ | end: */ | ||
def test(PID, F) | def test_factor(PID, F) | ||
{ | { | ||
T0 = time(); | T0 = time(); | ||
fctr(F); | fctr(F); | ||
|
|
||
return (["CPU", T1[0]-T0[0],T2[0]-T1[0],"GC",T1[1]-T0[1],T2[1]-T1[1]]); | return (["CPU", T1[0]-T0[0],T2[0]-T1[0],"GC",T1[1]-T0[1],T2[1]-T1[1]]); | ||
} | } | ||
def test_lll(PID, F) | |||
{ | |||
T0 = time(); | |||
pari(lllint, F); | |||
T1 = time(); | |||
ntl.lll(PID, F); | |||
T2 = time(); | |||
return (["CPU", T1[0]-T0[0],T2[0]-T1[0],"GC",T1[1]-T0[1],T2[1]-T1[1]]); | |||
} | |||
#endif | #endif | ||
/*&usage begin: ntl.factor(PID, POLY) | /*&usage begin: ntl.factor(PID, POLY) | ||
|
|
||
/* ERROR Check */ | /* ERROR Check */ | ||
if (type(RET_NTL) != 4 || length(RET_NTL) < 2) { | if (type(RET_NTL) != 4 || length(RET_NTL) < 2) { | ||
error(RET_NTL); | return (RET_NTL); | ||
} | } | ||
RET = cons([RET_NTL[0] * C, 1], RET_NTL[1]); | RET = cons([RET_NTL[0] * C, 1], RET_NTL[1]); | ||
|
|
||
} | } | ||
return (ex_data_tmp(t^2-p, N)); | return (ex_data_tmp(t^2-p, N)); | ||
} | |||
def mat2list(M) | |||
{ | |||
A = size(M); | |||
ROW=A[0]; | |||
COL=A[1]; | |||
for (I = 0; I < ROW; I++) { | |||
for (J = 0; J < COL; J++) { | |||
A = append(A, [M[I][J]]); | |||
} | |||
} | |||
return (A); | |||
} | |||
def list2mat(L) | |||
{ | |||
if (type(L) != 4) { | |||
return ("Invalid Argument"); | |||
} | |||
ROW = L[0]; | |||
if (type(ROW) == 10) | |||
ROW = int32ton(ROW); | |||
COL = L[1]; | |||
if (type(COL) == 10) | |||
COL = int32ton(COL); | |||
A = newmat(ROW, COL); | |||
C = 2; | |||
for (I = 0; I < ROW; I++) { | |||
for (J = 0; J < COL; J++) { | |||
A[I][J] = L[C]; | |||
C++; | |||
} | |||
} | |||
return (A); | |||
} | |||
/*&usage begin: ntl.lll(PID, MAT) | |||
the basics of LLL reducation. | |||
{M} | |||
Matrix which element is Integer. | |||
example: | |||
[1046] def trans(M) { | |||
RET = newmat(size(M)[1], size(M)[0]); | |||
for (I = 0; I < size(M)[0]; I++) | |||
for (J = 0; J < size(M)[1]; J++) | |||
RET[J][I] = M[I][J]; | |||
return (RET); | |||
} | |||
[1047] def lllpari(A) { | |||
return (trans(trans(A) * pari(lllint, trans(A)))); | |||
} | |||
[1048] M=newmat(3, 3, [[10,0, 10], [-7,3, 30], [7, 3, 20]]); | |||
[ 10 0 10 ] | |||
[ -7 3 30 ] | |||
[ 7 3 20 ] | |||
[1049] ntl.lll(PID, M); | |||
[ 2 -6 0 ] | |||
[ -1 -3 10 ] | |||
[ 11 3 0 ] | |||
[1050] lllpari(M); | |||
[ 2 -6 0 ] | |||
[ -1 -3 10 ] | |||
[ 11 3 0 ] | |||
ref: | |||
pari(lll) | |||
end: */ | |||
def lll(PID, M) | |||
{ | |||
/* parameter check */ | |||
TYPE = type(M); | |||
if (TYPE != 6) { /* matrix */ | |||
MES = "ntl.lll: invalid argument: " + TYPE; | |||
error(MES); | |||
} | |||
A = mat2list(M); | |||
ox_cmo_rpc(PID, "lll", A); | |||
RET_NTL = ox_pop_cmo(PID); | |||
/* return value check */ | |||
if (type(RET_NTL) != 4) { /* list */ | |||
error("ntl.lll: error"); | |||
} | |||
R = list2mat(RET_NTL); | |||
return (R); | |||
} | } | ||