My Project  UNKNOWN_GIT_VERSION
flintconv.cc
Go to the documentation of this file.
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 HAVE_FLINT
15 #if __FLINT_RELEASE >= 20500
16 #include "coeffs/coeffs.h"
18 
19 #include "omalloc/omalloc.h"
20 #include "polys/sbuckets.h"
21 #include "polys/clapconv.h"
22 
23 #include "simpleideals.h"
24 
25 
26 int convFlintISingI (fmpz_t f)
27 {
28  int res;
29  res = fmpz_get_si(f);
30  return res;
31 }
32 
33 void convSingIFlintI(fmpz_t f, int p)
34 {
35  fmpz_init(f);
36  fmpz_set_si(f,p);
37  return;
38 }
39 
40 void convFlintNSingN (mpz_t z, fmpz_t f)
41 {
42  mpz_init(z);
43  fmpz_get_mpz(z,f);
44 }
45 
46 void convSingNFlintN(fmpz_t f, mpz_t z)
47 {
48  fmpz_init(f);
49  fmpz_set_mpz(f,z);
50 }
51 
52 
53 bigintmat* singflint_LLL(bigintmat* m, bigintmat* T)
54 {
55  int r=m->rows();
56  int c=m->cols();
57  bigintmat* res=new bigintmat(r,c,m->basecoeffs());
58  fmpz_mat_t M, Transf;
59  fmpz_mat_init(M, r, c);
60  if(T != NULL)
61  {
62  fmpz_mat_init(Transf, T->rows(), T->rows());
63  }
64  fmpz_t dummy;
65  mpz_t n;
66  int i,j;
67  for(i=r;i>0;i--)
68  {
69  for(j=c;j>0;j--)
70  {
71  n_MPZ(n, BIMATELEM(*m, i, j),m->basecoeffs());
72  convSingNFlintN(dummy,n);
73  mpz_clear(n);
74  fmpz_set(fmpz_mat_entry(M, i-1, j-1), dummy);
75  fmpz_clear(dummy);
76  }
77  }
78  if(T != NULL)
79  {
80  for(i=T->rows();i>0;i--)
81  {
82  for(j=T->rows();j>0;j--)
83  {
84  n_MPZ(n, BIMATELEM(*T, i, j),T->basecoeffs());
85  convSingNFlintN(dummy,n);
86  mpz_clear(n);
87  fmpz_set(fmpz_mat_entry(Transf, i-1, j-1), dummy);
88  fmpz_clear(dummy);
89  }
90  }
91  }
92  fmpz_lll_t fl;
93  fmpz_lll_context_init_default(fl);
94  if(T != NULL)
95  fmpz_lll(M, Transf, fl);
96  else
97  fmpz_lll(M, NULL, fl);
98  for(i=r;i>0;i--)
99  {
100  for(j=c;j>0;j--)
101  {
102  convFlintNSingN(n, fmpz_mat_entry(M, i-1, j-1));
103  n_Delete(&(BIMATELEM(*res,i,j)),res->basecoeffs());
104  BIMATELEM(*res,i,j)=n_InitMPZ(n,res->basecoeffs());
105  mpz_clear(n);
106  }
107  }
108  if(T != NULL)
109  {
110  for(i=T->rows();i>0;i--)
111  {
112  for(j=T->cols();j>0;j--)
113  {
114  convFlintNSingN(n, fmpz_mat_entry(Transf, i-1, j-1));
115  n_Delete(&(BIMATELEM(*T,i,j)),T->basecoeffs());
116  BIMATELEM(*T,i,j)=n_InitMPZ(n,T->basecoeffs());
117  mpz_clear(n);
118  }
119  }
120  }
121  return res;
122 }
123 
124 intvec* singflint_LLL(intvec* m, intvec* T)
125 {
126  int r=m->rows();
127  int c=m->cols();
128  intvec* res = new intvec(r,c,(int)0);
129  fmpz_mat_t M,Transf;
130  fmpz_mat_init(M, r, c);
131  if(T != NULL)
132  fmpz_mat_init(Transf, r, r);
133  fmpz_t dummy;
134  int i,j;
135  for(i=r;i>0;i--)
136  {
137  for(j=c;j>0;j--)
138  {
139  convSingIFlintI(dummy,IMATELEM(*m,i,j));
140  fmpz_set(fmpz_mat_entry(M, i-1, j-1), dummy);
141  fmpz_clear(dummy);
142  }
143  }
144  if(T != NULL)
145  {
146  for(i=T->rows();i>0;i--)
147  {
148  for(j=T->rows();j>0;j--)
149  {
150  convSingIFlintI(dummy,IMATELEM(*T,i,j));
151  fmpz_set(fmpz_mat_entry(Transf, i-1, j-1), dummy);
152  fmpz_clear(dummy);
153  }
154  }
155  }
156  fmpz_lll_t fl;
157  fmpz_lll_context_init_default(fl);
158  if(T != NULL)
159  fmpz_lll(M, Transf, fl);
160  else
161  fmpz_lll(M, NULL, fl);
162  for(i=r;i>0;i--)
163  {
164  for(j=c;j>0;j--)
165  {
166  IMATELEM(*res,i,j)=convFlintISingI(fmpz_mat_entry(M, i-1, j-1));
167  }
168  }
169  if(T != NULL)
170  {
171  for(i=Transf->r;i>0;i--)
172  {
173  for(j=Transf->r;j>0;j--)
174  {
175  IMATELEM(*T,i,j)=convFlintISingI(fmpz_mat_entry(Transf, i-1, j-1));
176  }
177  }
178  }
179  return res;
180 }
181 #endif
182 #endif
omalloc.h
j
int j
Definition: facHensel.cc:105
f
FILE * f
Definition: checklibs.c:9
bigintmat
Matrices of numbers.
Definition: bigintmat.h:52
simpleideals.h
n_Delete
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
clapconv.h
auxiliary.h
All the auxiliary stuff.
n_InitMPZ
static FORCE_INLINE number n_InitMPZ(mpz_t n, const coeffs r)
conversion of a GMP integer to number
Definition: coeffs.h:542
i
int i
Definition: cfEzgcd.cc:125
res
CanonicalForm res
Definition: facAbsFact.cc:64
M
#define M
Definition: sirandom.c:24
T
static jList * T
Definition: janet.cc:31
intvec
Definition: intvec.h:21
p_polys.h
IMATELEM
#define IMATELEM(M, I, J)
Definition: intvec.h:83
m
int m
Definition: cfEzgcd.cc:121
NULL
#define NULL
Definition: omList.c:10
BIMATELEM
#define BIMATELEM(M, I, J)
Definition: bigintmat.h:134
p
int p
Definition: cfModGcd.cc:4019
flintconv.h
This file is work in progress and currently not part of the official Singular.
n_MPZ
static FORCE_INLINE void n_MPZ(mpz_t result, number &n, const coeffs r)
conversion of n to a GMP integer; 0 if not possible
Definition: coeffs.h:551
sbuckets.h
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.