[a99a04] | 1 | /////////////////////////////////////////////////////////////////////////////// |
---|
[341696] | 2 | version="$Id$"; |
---|
[a99a04] | 3 | category="Commutative Algebra"; |
---|
| 4 | info=" |
---|
[50cbdc] | 5 | LIBRARY: LLL.lib Integral LLL-Algorithm |
---|
[a99a04] | 6 | AUTHOR: Alberto Vigneron-Tenorio and Alfredo Sanchez-Navarro |
---|
| 7 | email: alberto.vigneron@uca.es, alfredo.sanchez@uca.es |
---|
| 8 | |
---|
| 9 | PROCEDURES: |
---|
| 10 | LLL(..); Integral LLL-Algorithm |
---|
| 11 | "; |
---|
| 12 | |
---|
| 13 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 14 | proc LLL(list #) |
---|
| 15 | "The output is a LLL-reduced basis of the lattice of Z^n" |
---|
| 16 | { |
---|
| 17 | // input: list(list(int,...),...) |
---|
| 18 | // check arguments as far as necessary |
---|
| 19 | // other inconsistencies are detected by the external program |
---|
| 20 | int num_of_vect=size(#); |
---|
| 21 | if(num_of_vect <=0) |
---|
| 22 | { ERROR("no input parameters ?"); } |
---|
| 23 | int num_of_coords=size(#[1]); |
---|
| 24 | |
---|
| 25 | // create first temporary file with which the external program is |
---|
| 26 | // called |
---|
| 27 | |
---|
| 28 | int process=system("pid"); |
---|
| 29 | string file="temp_"+string(process); |
---|
| 30 | string resfile="res_"+string(process); |
---|
| 31 | link l=":w "+file; |
---|
| 32 | open(l); |
---|
| 33 | |
---|
| 34 | write(l,string(num_of_vect)+","+string(num_of_coords)); |
---|
| 35 | int j; |
---|
| 36 | list tmp; |
---|
| 37 | for(j=1;j<=num_of_vect;j++) |
---|
| 38 | { |
---|
| 39 | if(size(#[j])!=num_of_coords) |
---|
| 40 | { ERROR("mismatch of number of coordinates"); } |
---|
| 41 | tmp=#[j]; |
---|
| 42 | write(l,(tmp)[1..num_of_coords]); |
---|
| 43 | } |
---|
| 44 | write(l," "); |
---|
| 45 | |
---|
| 46 | close(l); |
---|
| 47 | |
---|
| 48 | // call external program |
---|
| 49 | int dummy=system("sh","LLL <"+file+">"+resfile); |
---|
| 50 | |
---|
| 51 | // read solution from created file |
---|
| 52 | link SOLUTION=":r "+resfile; |
---|
| 53 | string solution=read(SOLUTION); |
---|
| 54 | |
---|
| 55 | // delete all created files |
---|
| 56 | if (dummy==0) //return code okay |
---|
| 57 | { |
---|
| 58 | dummy=system("sh","rm -f "+file+" "+resfile); |
---|
[50cbdc] | 59 | } |
---|
[a99a04] | 60 | else |
---|
| 61 | { |
---|
| 62 | ERROR("external program returns "+string(dummy)+newline+ |
---|
| 63 | "see "+file+" and "+resfile+" for details"); |
---|
[50cbdc] | 64 | } |
---|
[a99a04] | 65 | |
---|
| 66 | execute(solution); // result is now in list "res" |
---|
| 67 | return(res); |
---|
| 68 | } |
---|
| 69 | example |
---|
| 70 | { |
---|
| 71 | "EXAMPLE:";echo=2; |
---|
| 72 | list l=list(1,-2,4),list(2,1,-7); |
---|
| 73 | LLL(l); |
---|
[50cbdc] | 74 | } |
---|
[a99a04] | 75 | /////////////////////////////////////////////////////////////////////////////// |
---|