My Project
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"
17#include "coeffs/longrat.h"
19
20#include "polys/sbuckets.h"
21#include "polys/clapconv.h"
22
23#include "simpleideals.h"
24
25
26int convFlintISingI (fmpz_t f)
27{
28 //return fmpz_get_si(f);
29 return (int)*f;
30}
31
32void convSingIFlintI(fmpz_t f, int p)
33{
34 fmpz_init(f);
35 *f=p;
36 //fmpz_set_si(f,p);
37 return;
38}
39
40void convFlintNSingN (mpz_t z, fmpz_t f)
41{
42 mpz_init(z);
43 fmpz_get_mpz(z,f);
44}
45
46number convFlintNSingN (fmpz_t f)
47{
48 number n;
49 if(COEFF_IS_MPZ(*f))
50 nlMPZ(COEFF_TO_PTR(*f),n,NULL);
51 else
52 {
53 mpz_t z;
54 mpz_init(z);
55 fmpz_get_mpz(z,f);
56 nlMPZ(z,n,NULL);
57 mpz_clear(z);
58 }
59 return n;
60}
61
62number convFlintNSingN (fmpq_t f, const coeffs cf)
63{
64#if __FLINT_RELEASE > 20502
65 number z;
66 if (nCoeff_is_Q(cf))
67 {
68 z=ALLOC_RNUMBER();
69 #if defined(LDEBUG)
70 z->debug=123456;
71 #endif
72 z->s=0;
73 mpz_init(z->z);
74 mpz_init(z->n);
75 fmpq_get_mpz_frac(z->z,z->n,f);
76 }
77 else
78 {
79 mpz_t a,b;
80 mpz_init(a);
81 mpz_init(b);
82 fmpq_get_mpz_frac(a,b,f);
83 number na=n_InitMPZ(a,cf);
84 number nb=n_InitMPZ(b,cf);
85 z=n_Div(na,nb,cf);
86 n_Delete(&na,cf);
87 n_Delete(&nb,cf);
88 mpz_clear(a);
89 mpz_clear(b);
90 }
91 n_Normalize(z,cf);
92 n_Test(z,cf);
93 return z;
94#else
95 WerrorS("not implemented");
96 return NULL;
97#endif
98}
99
100number convFlintNSingN (fmpz_t f, const coeffs cf)
101{
102#if __FLINT_RELEASE > 20502
103 number z;
104 mpz_t a;
105 mpz_init(a);
106 fmpz_get_mpz(a,f);
107 z=n_InitMPZ(a,cf);
108 mpz_clear(a);
109 n_Normalize(z,cf);
110 n_Test(z,cf);
111 return z;
112#else
113 WerrorS("not implemented");
114 return NULL;
115#endif
116}
117
118number convFlintNSingN_QQ (fmpq_t f, const coeffs cf)
119{
120#if __FLINT_RELEASE > 20502
121 if (fmpz_is_one(fmpq_denref(f)))
122 {
123 if (fmpz_fits_si(fmpq_numref(f)))
124 {
125 long i=fmpz_get_si(fmpq_numref(f));
126 return n_Init(i,cf);
127 }
128 }
129 number z=ALLOC_RNUMBER();
130 #if defined(LDEBUG)
131 z->debug=123456;
132 #endif
133 mpz_init(z->z);
134 if (fmpz_is_one(fmpq_denref(f)))
135 {
136 z->s=3;
137 fmpz_get_mpz(z->z,fmpq_numref(f));
138 }
139 else
140 {
141 z->s=0;
142 mpz_init(z->n);
143 fmpq_get_mpz_frac(z->z,z->n,f);
144 }
145 n_Test(z,cf);
146 return z;
147#else
148 WerrorS("not implemented");
149 return NULL;
150#endif
151}
152
153void convSingNFlintN(fmpz_t f, mpz_t n)
154{
155 fmpz_init(f);
156 fmpz_set_mpz(f,n);
157}
158
159void convSingNFlintN(fmpz_t f, number n)
160{
161 fmpz_init(f);
162 fmpz_set_mpz(f,(mpz_ptr)n);
163}
164
165void convSingNFlintN(fmpq_t f, number n, const coeffs cf)
166{
167 if (nCoeff_is_Q(cf))
168 {
169 fmpq_init(f);
170 if (SR_HDL(n)&SR_INT)
171 fmpq_set_si(f,SR_TO_INT(n),1);
172 else if (n->s<3)
173 {
174 fmpz_set_mpz(fmpq_numref(f), n->z);
175 fmpz_set_mpz(fmpq_denref(f), n->n);
176 }
177 else
178 {
179 mpz_t one;
180 mpz_init_set_si(one,1);
181 fmpz_set_mpz(fmpq_numref(f), n->z);
182 fmpz_set_mpz(fmpq_denref(f), one);
183 mpz_clear(one);
184 }
185 }
186 else
187 {
189 nMapFunc nMap=n_SetMap(cf,QQ);
190 if (nMap!=NULL)
191 {
192 number nn=nMap(n,cf,QQ);
193 convSingNFlintN(f,nn,QQ);
194 }
195 nKillChar(QQ);
196 }
197}
198
199void convSingNFlintN_QQ(fmpq_t f, number n)
200{
201 fmpq_init(f);
202 if (SR_HDL(n)&SR_INT)
203 fmpq_set_si(f,SR_TO_INT(n),1);
204 else if (n->s<3)
205 {
206 fmpz_set_mpz(fmpq_numref(f), n->z);
207 fmpz_set_mpz(fmpq_denref(f), n->n);
208 }
209 else
210 {
211 mpz_t one;
212 mpz_init_set_si(one,1);
213 fmpz_set_mpz(fmpq_numref(f), n->z);
214 fmpz_set_mpz(fmpq_denref(f), one);
215 mpz_clear(one);
216 }
217}
218
219void convSingNFlintNN(fmpq_t re, fmpq_t im, number n, const coeffs cf)
220{
221 number n_2=n_RePart(n,cf);
222 convSingNFlintN(re,n_2,cf);
223 n_Delete(&n_2,cf);
224 n_2=n_ImPart(n,cf);
225 convSingNFlintN(im,n_2,cf);
226 n_Delete(&n_2,cf);
227}
228
229void convSingPFlintP(fmpq_poly_t res, poly p, const ring r)
230{
231 int d=p_GetExp(p,1,r);
232 fmpq_poly_init2(res,d+1);
233 _fmpq_poly_set_length (res, d + 1);
234 while(p!=NULL)
235 {
236 number n=pGetCoeff(p);
237 fmpq_t c;
238 convSingNFlintN(c,n,r->cf);
239 fmpq_poly_set_coeff_fmpq(res,p_GetExp(p,1,r),c);
240 fmpq_clear(c);
241 pIter(p);
242 }
243}
244
245void convSingImPFlintP(fmpq_poly_t res, poly p, const ring r)
246{
247 int d=p_GetExp(p,1,r);
248 fmpq_poly_init2(res,d+1);
249 _fmpq_poly_set_length (res, d + 1);
250 while(p!=NULL)
251 {
252 number n=n_ImPart(pGetCoeff(p),r->cf);
253 fmpq_t c;
254 convSingNFlintN(c,n,r->cf);
255 fmpq_poly_set_coeff_fmpq(res,p_GetExp(p,1,r),c);
256 fmpq_clear(c);
257 n_Delete(&n,r->cf);
258 pIter(p);
259 }
260}
261
262poly convFlintPSingP(fmpq_poly_t f, const ring r)
263{
264 int d=fmpq_poly_length(f);
265 poly p=NULL;
266 fmpq_t c;
267 fmpq_init(c);
268 for(int i=0; i<=d; i++)
269 {
270 fmpq_poly_get_coeff_fmpq(c,f,i);
271 number n=convFlintNSingN(c,r->cf);
272 poly pp=p_Init(r);
273 pSetCoeff0(pp,n);
274 p_SetExp(pp,1,i,r);
275 p_Setm(pp,r);
276 p=p_Add_q(p,pp,r);
277 }
278 fmpq_clear(c);
279 p_Test(p,r);
280 return p;
281}
282
284{
285 int r=m->rows();
286 int c=m->cols();
287 bigintmat* res=new bigintmat(r,c,m->basecoeffs());
288 fmpz_mat_t M, Transf;
289 fmpz_mat_init(M, r, c);
290 if(T != NULL)
291 {
292 fmpz_mat_init(Transf, T->rows(), T->rows());
293 }
294 fmpz_t dummy;
295 mpz_t n;
296 int i,j;
297 for(i=r;i>0;i--)
298 {
299 for(j=c;j>0;j--)
300 {
301 n_MPZ(n, BIMATELEM(*m, i, j),m->basecoeffs());
302 convSingNFlintN(dummy,n);
303 mpz_clear(n);
304 fmpz_set(fmpz_mat_entry(M, i-1, j-1), dummy);
305 fmpz_clear(dummy);
306 }
307 }
308 if(T != NULL)
309 {
310 for(i=T->rows();i>0;i--)
311 {
312 for(j=T->rows();j>0;j--)
313 {
314 n_MPZ(n, BIMATELEM(*T, i, j),T->basecoeffs());
315 convSingNFlintN(dummy,n);
316 mpz_clear(n);
317 fmpz_set(fmpz_mat_entry(Transf, i-1, j-1), dummy);
318 fmpz_clear(dummy);
319 }
320 }
321 }
322 fmpz_lll_t fl;
323 fmpz_lll_context_init_default(fl);
324 if(T != NULL)
325 fmpz_lll(M, Transf, fl);
326 else
327 fmpz_lll(M, NULL, fl);
328 for(i=r;i>0;i--)
329 {
330 for(j=c;j>0;j--)
331 {
332 convFlintNSingN(n, fmpz_mat_entry(M, i-1, j-1));
333 n_Delete(&(BIMATELEM(*res,i,j)),res->basecoeffs());
334 BIMATELEM(*res,i,j)=n_InitMPZ(n,res->basecoeffs());
335 mpz_clear(n);
336 }
337 }
338 if(T != NULL)
339 {
340 for(i=T->rows();i>0;i--)
341 {
342 for(j=T->cols();j>0;j--)
343 {
344 convFlintNSingN(n, fmpz_mat_entry(Transf, i-1, j-1));
345 n_Delete(&(BIMATELEM(*T,i,j)),T->basecoeffs());
346 BIMATELEM(*T,i,j)=n_InitMPZ(n,T->basecoeffs());
347 mpz_clear(n);
348 }
349 }
350 }
351 return res;
352}
353
355{
356 int r=m->rows();
357 int c=m->cols();
358 intvec* res = new intvec(r,c,(int)0);
359 fmpz_mat_t M,Transf;
360 fmpz_mat_init(M, r, c);
361 if(T != NULL)
362 fmpz_mat_init(Transf, r, r);
363 fmpz_t dummy;
364 int i,j;
365 for(i=r;i>0;i--)
366 {
367 for(j=c;j>0;j--)
368 {
369 convSingIFlintI(dummy,IMATELEM(*m,i,j));
370 fmpz_set(fmpz_mat_entry(M, i-1, j-1), dummy);
371 fmpz_clear(dummy);
372 }
373 }
374 if(T != NULL)
375 {
376 for(i=T->rows();i>0;i--)
377 {
378 for(j=T->rows();j>0;j--)
379 {
380 convSingIFlintI(dummy,IMATELEM(*T,i,j));
381 fmpz_set(fmpz_mat_entry(Transf, i-1, j-1), dummy);
382 fmpz_clear(dummy);
383 }
384 }
385 }
386 fmpz_lll_t fl;
387 fmpz_lll_context_init_default(fl);
388 if(T != NULL)
389 fmpz_lll(M, Transf, fl);
390 else
391 fmpz_lll(M, NULL, fl);
392 for(i=r;i>0;i--)
393 {
394 for(j=c;j>0;j--)
395 {
396 IMATELEM(*res,i,j)=convFlintISingI(fmpz_mat_entry(M, i-1, j-1));
397 }
398 }
399 if(T != NULL)
400 {
401 for(i=Transf->r;i>0;i--)
402 {
403 for(j=Transf->r;j>0;j--)
404 {
405 IMATELEM(*T,i,j)=convFlintISingI(fmpz_mat_entry(Transf, i-1, j-1));
406 }
407 }
408 }
409 return res;
410}
411#endif
412#endif
All the auxiliary stuff.
#define NULL
Definition: auxiliary.h:104
#define BIMATELEM(M, I, J)
Definition: bigintmat.h:133
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:676
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4080
f
Definition: cfModGcd.cc:4083
CanonicalForm cf
Definition: cfModGcd.cc:4085
CanonicalForm b
Definition: cfModGcd.cc:4105
Matrices of numbers.
Definition: bigintmat.h:51
Definition: intvec.h:23
Coefficient rings, fields and other domains suitable for Singular polynomials.
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:736
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:31
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:552
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:723
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:616
static FORCE_INLINE number n_RePart(number i, const coeffs cf)
Definition: coeffs.h:814
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:830
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:358
#define ALLOC_RNUMBER()
Definition: coeffs.h:88
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:456
static FORCE_INLINE number n_InitMPZ(mpz_t n, const coeffs r)
conversion of a GMP integer to number
Definition: coeffs.h:543
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:539
static FORCE_INLINE number n_ImPart(number i, const coeffs cf)
Definition: coeffs.h:817
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:74
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:579
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:526
CanonicalForm res
Definition: facAbsFact.cc:60
int j
Definition: facHensel.cc:110
void WerrorS(const char *s)
Definition: feFopen.cc:24
This file is work in progress and currently not part of the official Singular.
void convSingPFlintP(fmpq_poly_t res, poly p, const ring r)
void convSingNFlintN(fmpz_t f, mpz_t z)
void convSingNFlintNN(fmpq_t re, fmpq_t im, number n, const coeffs cf)
void convSingIFlintI(fmpz_t f, int p)
void convSingNFlintN_QQ(fmpq_t f, number n)
void convFlintNSingN(mpz_t z, fmpz_t f)
poly convFlintPSingP(fmpq_poly_t f, const ring r)
void convSingImPFlintP(fmpq_poly_t res, poly p, const ring r)
int convFlintISingI(fmpz_t f)
number convFlintNSingN_QQ(fmpq_t f, const coeffs cf)
bigintmat * singflint_LLL(bigintmat *A, bigintmat *T)
#define IMATELEM(M, I, J)
Definition: intvec.h:85
STATIC_VAR jList * T
Definition: janet.cc:30
void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2779
#define SR_INT
Definition: longrat.h:67
#define SR_TO_INT(SR)
Definition: longrat.h:69
#define pIter(p)
Definition: monomials.h:37
#define pSetCoeff0(p, n)
Definition: monomials.h:59
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
The main handler for Singular numbers which are suitable for Singular polynomials.
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:896
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:488
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:233
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:469
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1280
#define p_Test(p, r)
Definition: p_polys.h:162
#define M
Definition: sirandom.c:25
#define SR_HDL(A)
Definition: tgb.cc:35