1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|

2 | |
---|

3 | /** |
---|

4 | * |
---|

5 | * @file cf_hnf.cc |
---|

6 | * |
---|

7 | * HNF/LLL of NTL |
---|

8 | * |
---|

9 | * Header file: cf_hnf.h |
---|

10 | * |
---|

11 | **/ |
---|

12 | |
---|

13 | |
---|

14 | #include "config.h" |
---|

15 | |
---|

16 | #include "canonicalform.h" |
---|

17 | #include "cf_defs.h" |
---|

18 | #include "cf_hnf.h" |
---|

19 | |
---|

20 | #ifdef HAVE_NTL |
---|

21 | #include "NTLconvert.h" |
---|

22 | #include <NTL/mat_ZZ.h> |
---|

23 | #include <NTL/HNF.h> |
---|

24 | #include <NTL/LLL.h> |
---|

25 | #endif |
---|

26 | |
---|

27 | #ifdef HAVE_FLINT |
---|

28 | #include "FLINTconvert.h" |
---|

29 | #endif |
---|

30 | |
---|

31 | /** |
---|

32 | * The input matrix A is an n x m matrix of rank m (so n >= m), and D |
---|

33 | * is a multiple of the determinant of the lattice L spanned by the |
---|

34 | * rows of A. W is computed as the Hermite Normal Form of A; that is, |
---|

35 | * W is the unique m x m matrix whose rows span L, such that |
---|

36 | * |
---|

37 | * - W is lower triangular, |
---|

38 | * - the diagonal entries are positive, |
---|

39 | * - any entry below the diagonal is a non-negative number |
---|

40 | * strictly less than the diagonal entry in its column. |
---|

41 | * |
---|

42 | **/ |
---|

43 | CFMatrix* cf_HNF(CFMatrix& A) |
---|

44 | { |
---|

45 | #ifdef HAVE_FLINT |
---|

46 | fmpz_mat_t FLINTM; |
---|

47 | convertFacCFMatrix2Fmpz_mat_t(FLINTM,A); |
---|

48 | fmpz_mat_hnf(FLINTM,FLINTM); |
---|

49 | CFMatrix *r=convertFmpz_mat_t2FacCFMatrix(FLINTM); |
---|

50 | fmpz_mat_clear(FLINTM); |
---|

51 | return r; |
---|

52 | #elif defined(HAVE_NTL) |
---|

53 | mat_ZZ *AA=convertFacCFMatrix2NTLmat_ZZ(A); |
---|

54 | ZZ DD=convertFacCF2NTLZZ(determinant(A,A.rows())); |
---|

55 | mat_ZZ WW; |
---|

56 | HNF(WW,*AA,DD); |
---|

57 | delete AA; |
---|

58 | return convertNTLmat_ZZ2FacCFMatrix(WW); |
---|

59 | #endif |
---|

60 | } |
---|

61 | |
---|

62 | CFMatrix* cf_LLL(CFMatrix& A) |
---|

63 | { |
---|

64 | #ifdef HAVE_FLINT |
---|

65 | fmpz_mat_t FLINTM; |
---|

66 | convertFacCFMatrix2Fmpz_mat_t(FLINTM,A); |
---|

67 | fmpq_t delta,eta; |
---|

68 | fmpq_init(delta); fmpq_set_si(delta,1,1); |
---|

69 | fmpq_init(eta); fmpq_set_si(eta,3,4); |
---|

70 | fmpz_mat_lll_storjohann(FLINTM,delta,eta); |
---|

71 | CFMatrix *r=convertFmpz_mat_t2FacCFMatrix(FLINTM); |
---|

72 | fmpz_mat_clear(FLINTM); |
---|

73 | return r; |
---|

74 | #elif defined(HAVE_NTL) |
---|

75 | mat_ZZ *AA=convertFacCFMatrix2NTLmat_ZZ(A); |
---|

76 | ZZ det2; |
---|

77 | LLL(det2,*AA,0L); |
---|

78 | CFMatrix *r= convertNTLmat_ZZ2FacCFMatrix(*AA); |
---|

79 | delete AA; |
---|

80 | return r; |
---|

81 | #endif |
---|

82 | } |
---|