1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | /**************************************** |
---|
3 | * Computer Algebra System SINGULAR * |
---|
4 | ****************************************/ |
---|
5 | /* |
---|
6 | * ABSTRACT: convert data between Singular and Flint |
---|
7 | */ |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | #include <misc/auxiliary.h> |
---|
12 | #include "flintconv.h" |
---|
13 | |
---|
14 | #ifdef FLINT_VER_2_4_5 |
---|
15 | #include <coeffs/coeffs.h> |
---|
16 | #include <polys/monomials/p_polys.h> |
---|
17 | |
---|
18 | #include <omalloc/omalloc.h> |
---|
19 | // #include <coeffs/longrat.h> |
---|
20 | // #include <coeffs/modulop.h> |
---|
21 | #include <polys/sbuckets.h> |
---|
22 | #include <polys/clapconv.h> |
---|
23 | |
---|
24 | #include "simpleideals.h" |
---|
25 | |
---|
26 | |
---|
27 | #ifdef HAVE_FLINT |
---|
28 | int convFlintISingI (fmpz_t f) |
---|
29 | { |
---|
30 | int res; |
---|
31 | res = fmpz_get_si(f); |
---|
32 | return res; |
---|
33 | } |
---|
34 | |
---|
35 | void convSingIFlintI(fmpz_t f, int p) |
---|
36 | { |
---|
37 | fmpz_set_si(f,p); |
---|
38 | return; |
---|
39 | } |
---|
40 | |
---|
41 | void convFlintNSingN (mpz_t z, fmpz_t f) |
---|
42 | { |
---|
43 | fmpz_get_mpz(z,f); |
---|
44 | } |
---|
45 | |
---|
46 | void convSingNFlintN(fmpz_t f, mpz_t z) |
---|
47 | { |
---|
48 | fmpz_set_mpz(f,z); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | bigintmat* singflint_LLL(bigintmat* m) |
---|
53 | { |
---|
54 | int r=m->rows(); |
---|
55 | int c=m->cols(); |
---|
56 | bigintmat* res=new bigintmat(r,c,m->basecoeffs()); |
---|
57 | fmpz_mat_t M; |
---|
58 | fmpz_mat_init(M, r, c); |
---|
59 | fmpz_t dummy; |
---|
60 | mpz_t n; |
---|
61 | int i,j; |
---|
62 | for(i=r;i>0;i--) |
---|
63 | { |
---|
64 | for(j=c;j>0;j--) |
---|
65 | { |
---|
66 | n_MPZ(n, BIMATELEM(*m, i, j),m->basecoeffs()); |
---|
67 | convSingNFlintN(dummy,n); |
---|
68 | fmpz_set(fmpz_mat_entry(M, i-1, j-1), dummy); |
---|
69 | } |
---|
70 | } |
---|
71 | fmpz_lll_t fl; |
---|
72 | fmpz_lll_context_init_default(fl); |
---|
73 | //printf("\nBefore LLL (in Flint)\n");fmpz_mat_print(M); |
---|
74 | fmpz_lll(M, NULL, fl); |
---|
75 | //printf("\nAfter LLL (in Flint)\n");fmpz_mat_print(M);printf("\n\n"); |
---|
76 | for(i=r;i>0;i--) |
---|
77 | { |
---|
78 | for(j=c;j>0;j--) |
---|
79 | { |
---|
80 | //printf("\nThis is here:\n");fmpz_print(fmpz_mat_entry(M, i-1, j-1)); |
---|
81 | convFlintNSingN(n, fmpz_mat_entry(M, i-1, j-1)); |
---|
82 | BIMATELEM(*res,i,j)=n_InitMPZ(n,m->basecoeffs()); |
---|
83 | //printf("\nThis is res[%i] = %i\n", i+j, *res[i+j]); |
---|
84 | } |
---|
85 | } |
---|
86 | return res; |
---|
87 | } |
---|
88 | |
---|
89 | intvec* singflint_LLL(intvec* m) |
---|
90 | { |
---|
91 | int r=m->rows(); |
---|
92 | int c=m->cols(); |
---|
93 | intvec* res = new intvec(r,c,(int)0); |
---|
94 | fmpz_mat_t M; |
---|
95 | fmpz_mat_init(M, r, c); |
---|
96 | fmpz_t dummy; |
---|
97 | int i,j; |
---|
98 | for(i=r;i>0;i--) |
---|
99 | { |
---|
100 | for(j=c;j>0;j--) |
---|
101 | { |
---|
102 | convSingIFlintI(dummy,IMATELEM(*m,i,j)); |
---|
103 | fmpz_set(fmpz_mat_entry(M, i-1, j-1), dummy); |
---|
104 | } |
---|
105 | } |
---|
106 | fmpz_lll_t fl; |
---|
107 | fmpz_lll_context_init_default(fl); |
---|
108 | //printf("\nBefore LLL (in Flint)\n");fmpz_mat_print(M); |
---|
109 | fmpz_lll(M, NULL, fl); |
---|
110 | //printf("\nAfter LLL (in Flint)\n");fmpz_mat_print(M);printf("\n\n"); |
---|
111 | for(i=r;i>0;i--) |
---|
112 | { |
---|
113 | for(j=c;j>0;j--) |
---|
114 | { |
---|
115 | //printf("\nThis is here:\n");fmpz_print(fmpz_mat_entry(M, i-1, j-1)); |
---|
116 | IMATELEM(*res,i,j)=convFlintISingI(fmpz_mat_entry(M, i-1, j-1)); |
---|
117 | //printf("\nThis is res[%i] = %i\n", i+j, *res[i+j]); |
---|
118 | } |
---|
119 | } |
---|
120 | return res; |
---|
121 | } |
---|
122 | #endif |
---|
123 | #endif |
---|