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