My Project
Loading...
Searching...
No Matches
Macros | Functions
FLINTconvert.cc File Reference

This file implements functions for conversion to FLINT (www.flintlib.org) and back. More...

#include <config.h>
#include "canonicalform.h"
#include "fac_util.h"
#include "cf_iter.h"
#include "cf_factory.h"
#include "gmpext.h"
#include "singext.h"
#include "cf_algorithm.h"
#include <cstdio>
#include <flint/fmpz.h>
#include <flint/fmpq.h>
#include <flint/fmpz_poly.h>
#include <flint/fmpz_mod_poly.h>
#include <flint/nmod_poly.h>
#include <flint/fmpq_poly.h>
#include <flint/nmod_mat.h>
#include <flint/fmpz_mat.h>
#include <flint/fq.h>
#include <flint/fq_poly.h>
#include <flint/fq_nmod.h>
#include <flint/fq_nmod_poly.h>
#include <flint/fq_nmod_mat.h>
#include "FLINTconvert.h"

Go to the source code of this file.

Macros

#define Alloc(L)   omAlloc(L)
 
#define Free(A, L)   omFreeSize(A,L)
 

Functions

void convertCF2Fmpz (fmpz_t result, const CanonicalForm &f)
 conversion of a factory integer to fmpz_t More...
 
void convertCF2initFmpz (fmpz_t result, const CanonicalForm &f)
 conversion of a factory integer to fmpz_t(init.) More...
 
void convertFacCF2Fmpz_poly_t (fmpz_poly_t result, const CanonicalForm &f)
 conversion of a factory univariate polynomial over Z to a fmpz_poly_t More...
 
CanonicalForm convertFmpz2CF (const fmpz_t coefficient)
 conversion of a FLINT integer to CanonicalForm More...
 
CanonicalForm convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, const Variable &x)
 conversion of a FLINT poly over Z to CanonicalForm More...
 
void convertFacCF2nmod_poly_t (nmod_poly_t result, const CanonicalForm &f)
 conversion of a factory univariate polynomials over Z/p (for word size p) to nmod_poly_t More...
 
CanonicalForm convertnmod_poly_t2FacCF (const nmod_poly_t poly, const Variable &x)
 conversion of a FLINT poly over Z/p to CanonicalForm More...
 
void convertCF2Fmpq (fmpq_t result, const CanonicalForm &f)
 conversion of a factory rationals to fmpq_t More...
 
CanonicalForm convertFmpq2CF (const fmpq_t q)
 conversion of a FLINT rational to CanonicalForm More...
 
CanonicalForm convertFmpq_poly_t2FacCF (const fmpq_poly_t p, const Variable &x)
 conversion of a FLINT poly over Q to CanonicalForm More...
 
void convertFacCF2Fmpz_array (fmpz *result, const CanonicalForm &f)
 
void convertFacCF2Fmpq_poly_t (fmpq_poly_t result, const CanonicalForm &f)
 conversion of a factory univariate polynomials over Q to fmpq_poly_t More...
 
CFFList convertFLINTnmod_poly_factor2FacCFFList (const nmod_poly_factor_t fac, const mp_limb_t leadingCoeff, const Variable &x)
 conversion of a FLINT factorization over Z/p (for word size p) to a CFFList More...
 
CFFList convertFLINTFq_nmod_poly_factor2FacCFFList (const fq_nmod_poly_factor_t fac, const Variable &x, const Variable &alpha, const fq_nmod_ctx_t fq_con)
 conversion of a FLINT factorization over Fq (for word size p) to a CFFList More...
 
void convertFacCF2Fmpz_mod_poly_t (fmpz_mod_poly_t result, const CanonicalForm &f, const fmpz_t p)
 conversion of a factory univariate poly over Z to a FLINT poly over Z/p (for non word size p) More...
 
CanonicalForm convertFmpz_mod_poly_t2FacCF (const fmpz_mod_poly_t poly, const Variable &x, const modpk &b)
 conversion of a FLINT poly over Z/p (for non word size p) to a CanonicalForm over Z More...
 
void convertFacCF2Fq_nmod_t (fq_nmod_t result, const CanonicalForm &f, const fq_nmod_ctx_t ctx)
 conversion of a factory element of F_q to a FLINT fq_nmod_t, does not do any memory allocation for poly More...
 
CanonicalForm convertFq_nmod_t2FacCF (const fq_nmod_t poly, const Variable &alpha, const fq_nmod_ctx_t)
 conversion of a FLINT element of F_q to a CanonicalForm with alg. variable alpha More...
 
void convertFacCF2Fq_t (fq_t result, const CanonicalForm &f, const fq_ctx_t ctx)
 conversion of a factory element of F_q (for non-word size p) to a FLINT fq_t More...
 
CanonicalForm convertFq_t2FacCF (const fq_t poly, const Variable &alpha)
 conversion of a FLINT element of F_q with non-word size p to a CanonicalForm with alg. variable alpha More...
 
void convertFacCF2Fq_poly_t (fq_poly_t result, const CanonicalForm &f, const fq_ctx_t ctx)
 conversion of a factory univariate poly over F_q (for non-word size p) to a FLINT fq_poly_t More...
 
void convertFacCF2Fq_nmod_poly_t (fq_nmod_poly_t result, const CanonicalForm &f, const fq_nmod_ctx_t ctx)
 conversion of a factory univariate poly over F_q to a FLINT fq_nmod_poly_t More...
 
CanonicalForm convertFq_poly_t2FacCF (const fq_poly_t p, const Variable &x, const Variable &alpha, const fq_ctx_t ctx)
 conversion of a FLINT poly over Fq (for non-word size p) to a CanonicalForm with alg. variable alpha and polynomial variable x More...
 
CanonicalForm convertFq_nmod_poly_t2FacCF (const fq_nmod_poly_t p, const Variable &x, const Variable &alpha, const fq_nmod_ctx_t ctx)
 conversion of a FLINT poly over Fq to a CanonicalForm with alg. variable alpha and polynomial variable x More...
 
void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, const CFMatrix &m)
 conversion of a factory matrix over Z to a fmpz_mat_t More...
 
CFMatrixconvertFmpz_mat_t2FacCFMatrix (const fmpz_mat_t m)
 conversion of a FLINT matrix over Z to a factory matrix More...
 
void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, const CFMatrix &m)
 conversion of a factory matrix over Z/p to a nmod_mat_t More...
 
CFMatrixconvertNmod_mat_t2FacCFMatrix (const nmod_mat_t m)
 conversion of a FLINT matrix over Z/p to a factory matrix More...
 
void convertFacCFMatrix2Fq_nmod_mat_t (fq_nmod_mat_t M, const fq_nmod_ctx_t fq_con, const CFMatrix &m)
 conversion of a factory matrix over F_q to a fq_nmod_mat_t More...
 
CFMatrixconvertFq_nmod_mat_t2FacCFMatrix (const fq_nmod_mat_t m, const fq_nmod_ctx_t &fq_con, const Variable &alpha)
 conversion of a FLINT matrix over F_q to a factory matrix More...
 

Detailed Description

This file implements functions for conversion to FLINT (www.flintlib.org) and back.

Author
Martin Lee

Definition in file FLINTconvert.cc.

Macro Definition Documentation

◆ Alloc

#define Alloc (   L)    omAlloc(L)

Definition at line 28 of file FLINTconvert.cc.

◆ Free

#define Free (   A,
 
)    omFreeSize(A,L)

Definition at line 29 of file FLINTconvert.cc.

Function Documentation

◆ convertCF2Fmpq()

void convertCF2Fmpq ( fmpq_t  result,
const CanonicalForm f 
)

conversion of a factory rationals to fmpq_t

Parameters
[in,out]resultan fmpq_t
[in]fa CanonicalForm wrapping a rational

Definition at line 223 of file FLINTconvert.cc.

224{
225 //ASSERT (isOn (SW_RATIONAL), "expected rational");
226 if (f.isImm ())
227 {
228 fmpq_set_si (result, f.intval(), 1);
229 }
230 else if(f.inQ())
231 {
232 mpz_t gmp_val;
233 gmp_numerator (f, gmp_val);
234 fmpz_set_mpz (fmpq_numref (result), gmp_val);
235 mpz_clear (gmp_val);
236 gmp_denominator (f, gmp_val);
237 fmpz_set_mpz (fmpq_denref (result), gmp_val);
238 mpz_clear (gmp_val);
239 }
240 else if(f.inZ())
241 {
242 mpz_t gmp_val;
243 f.mpzval(gmp_val);
244 fmpz_set_mpz (fmpq_numref (result), gmp_val);
245 mpz_clear (gmp_val);
246 fmpz_one(fmpq_denref(result));
247 }
248 else
249 {
250 printf("wrong type\n");
251 }
252}
FILE * f
Definition: checklibs.c:9
return result
Definition: facAbsBiFact.cc:75
void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20

◆ convertCF2Fmpz()

void convertCF2Fmpz ( fmpz_t  result,
const CanonicalForm f 
)

conversion of a factory integer to fmpz_t

Parameters
[out]resultan fmpz_t
[in]fa CanonicalForm wrapping an integer

Definition at line 116 of file FLINTconvert.cc.

117{
118 if (f.isImm())
119 *result=f.intval();
120 else
121 {
122 mpz_t gmp_val;
123 f.mpzval(gmp_val);
124 fmpz_init(result);
125 fmpz_set_mpz (result, gmp_val);
126 mpz_clear (gmp_val);
127 }
128}

◆ convertCF2initFmpz()

void convertCF2initFmpz ( fmpz_t  result,
const CanonicalForm f 
)

conversion of a factory integer to fmpz_t(init.)

Parameters
[in,out]resultan fmpz_t
[in]fa CanonicalForm wrapping an integer

Definition at line 131 of file FLINTconvert.cc.

132{
133 if (f.isImm())
134 fmpz_set_si (result, f.intval());
135 else
136 {
137 mpz_t gmp_val;
138 f.mpzval(gmp_val);
139
140 mpz_swap(gmp_val, _fmpz_promote(result));
141 _fmpz_demote_val(result);
142
143 mpz_clear (gmp_val);
144 }
145}

◆ convertFacCF2Fmpq_poly_t()

void convertFacCF2Fmpq_poly_t ( fmpq_poly_t  result,
const CanonicalForm f 
)

conversion of a factory univariate polynomials over Q to fmpq_poly_t

Parameters
[in,out]resultan fmpq_poly_t
[in]funivariate poly over Q

Definition at line 322 of file FLINTconvert.cc.

323{
324 bool isRat= isOn (SW_RATIONAL);
325 if (!isRat)
326 On (SW_RATIONAL);
327
328 fmpq_poly_init2 (result, degree (f)+1);
329 _fmpq_poly_set_length (result, degree (f) + 1);
331 convertFacCF2Fmpz_array (fmpq_poly_numref (result), f*den);
332 convertCF2initFmpz (fmpq_poly_denref (result), den); // assumes initialized
333
334 if (!isRat)
336}
void convertFacCF2Fmpz_array(fmpz *result, const CanonicalForm &f)
void convertCF2initFmpz(fmpz_t result, const CanonicalForm &f)
conversion of a factory integer to fmpz_t(init.)
bool isOn(int sw)
switches
void On(int sw)
switches
void Off(int sw)
switches
int degree(const CanonicalForm &f)
CanonicalForm den(const CanonicalForm &f)
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:31
factory's main class
Definition: canonicalform.h:86

◆ convertFacCF2Fmpz_array()

void convertFacCF2Fmpz_array ( fmpz *  result,
const CanonicalForm f 
)

Definition at line 316 of file FLINTconvert.cc.

317{
318 for (CFIterator i= f; i.hasTerms(); i++)
319 convertCF2initFmpz (&result[i.exp()], i.coeff()); // assumes initialized
320}
int i
Definition: cfEzgcd.cc:132
class to iterate through CanonicalForm's
Definition: cf_iter.h:44

◆ convertFacCF2Fmpz_mod_poly_t()

void convertFacCF2Fmpz_mod_poly_t ( fmpz_mod_poly_t  result,
const CanonicalForm f,
const fmpz_t  p 
)

conversion of a factory univariate poly over Z to a FLINT poly over Z/p (for non word size p)

Parameters
[in,out]resultfmpz_mod_poly_t
[in]funivariate poly over Z
[in]psome integer p

Definition at line 399 of file FLINTconvert.cc.

401{
402 #if (__FLINT_RELEASE >= 20700)
403 fmpz_mod_ctx_t ctx;
404 fmpz_mod_ctx_init(ctx,p);
405 fmpz_mod_poly_init2 (result, degree (f) + 1, ctx);
406 #else
407 fmpz_mod_poly_init2 (result, p, degree (f) + 1);
408 #endif
409 fmpz_poly_t buf;
411 #if (__FLINT_RELEASE >= 20700)
412 fmpz_mod_poly_set_fmpz_poly (result, buf, ctx);
413 fmpz_mod_ctx_clear(ctx);
414 #else
415 fmpz_mod_poly_set_fmpz_poly (result, buf);
416 #endif
417 fmpz_poly_clear (buf);
418}
void convertFacCF2Fmpz_poly_t(fmpz_poly_t result, const CanonicalForm &f)
conversion of a factory univariate polynomial over Z to a fmpz_poly_t
int p
Definition: cfModGcd.cc:4078
int status int void * buf
Definition: si_signals.h:59

◆ convertFacCF2Fmpz_poly_t()

void convertFacCF2Fmpz_poly_t ( fmpz_poly_t  result,
const CanonicalForm f 
)

conversion of a factory univariate polynomial over Z to a fmpz_poly_t

Parameters
[in,out]resultan fmpz_poly_t
[in]funivariate poly over Z

Definition at line 147 of file FLINTconvert.cc.

148{
149 fmpz_poly_init2 (result, degree (f)+1);
150 _fmpz_poly_set_length(result, degree(f)+1);
151 for (CFIterator i= f; i.hasTerms(); i++)
152 convertCF2initFmpz (fmpz_poly_get_coeff_ptr(result, i.exp()), i.coeff()); // assumes initialized
153}

◆ convertFacCF2Fq_nmod_poly_t()

void convertFacCF2Fq_nmod_poly_t ( fq_nmod_poly_t  result,
const CanonicalForm f,
const fq_nmod_ctx_t  ctx 
)

conversion of a factory univariate poly over F_q to a FLINT fq_nmod_poly_t

Parameters
[in,out]resultfq_nmod_poly_t
[in]funivariate poly over Fq
[in]ctxFq context

Definition at line 528 of file FLINTconvert.cc.

530{
531 fq_nmod_poly_init2 (result, degree (f)+1, ctx);
532 _fq_nmod_poly_set_length (result, degree (f) + 1, ctx);
533 fq_nmod_t buf;
534 fq_nmod_init2 (buf, ctx);
535 for (CFIterator i= f; i.hasTerms(); i++)
536 {
537 convertFacCF2Fq_nmod_t (buf, i.coeff(), ctx);
538 fq_nmod_poly_set_coeff (result, i.exp(), buf, ctx);
539 fq_nmod_zero (buf, ctx);
540 }
541 fq_nmod_clear (buf, ctx);
542}
void convertFacCF2Fq_nmod_t(fq_nmod_t result, const CanonicalForm &f, const fq_nmod_ctx_t ctx)
conversion of a factory element of F_q to a FLINT fq_nmod_t, does not do any memory allocation for po...

◆ convertFacCF2Fq_nmod_t()

void convertFacCF2Fq_nmod_t ( fq_nmod_t  result,
const CanonicalForm f,
const fq_nmod_ctx_t  ctx 
)

conversion of a factory element of F_q to a FLINT fq_nmod_t, does not do any memory allocation for poly

Parameters
[in,out]resultfq_nmod_t
[in]felement of Fq
[in]ctxFq context

Definition at line 444 of file FLINTconvert.cc.

446{
447 bool save_sym_ff= isOn (SW_SYMMETRIC_FF);
448 if (save_sym_ff) Off (SW_SYMMETRIC_FF);
449 #if __FLINT_RELEASE >= 20503
450 nmod_poly_t res;
452 #endif
453 for (CFIterator i= f; i.hasTerms(); i++)
454 {
455 CanonicalForm c= i.coeff();
456 if (!c.isImm()) c=c.mapinto(); //c%= getCharacteristic();
457 if (!c.isImm())
458 { //This case will never happen if the characteristic is in fact a prime
459 // number, since all coefficients are represented as immediates
460 printf("convertFacCF2Fq_nmod_t: coefficient not immediate!, char=%d\n",
462 }
463 else
464 {
465 STICKYASSERT (i.exp() <= fq_nmod_ctx_degree(ctx), "convertFacCF2Fq_nmod_t: element is not reduced");
466 #if __FLINT_RELEASE >= 20503
467 nmod_poly_set_coeff_ui (res, i.exp(), c.intval());
468 #else
469 nmod_poly_set_coeff_ui (result, i.exp(), c.intval());
470 #endif
471 }
472 }
473 #if __FLINT_RELEASE >= 20503
474 fq_nmod_init(result,ctx);
475 fq_nmod_set_nmod_poly(result,res,ctx);
476 #endif
477 if (save_sym_ff) On (SW_SYMMETRIC_FF);
478}
int FACTORY_PUBLIC getCharacteristic()
Definition: cf_char.cc:70
#define STICKYASSERT(expression, message)
Definition: cf_assert.h:64
static const int SW_SYMMETRIC_FF
set to 1 for symmetric representation over F_q
Definition: cf_defs.h:33
long intval() const
conversion functions
bool isImm() const
CanonicalForm mapinto() const
CanonicalForm res
Definition: facAbsFact.cc:60
nmod_poly_init(FLINTmipo, getCharacteristic())

◆ convertFacCF2Fq_poly_t()

void convertFacCF2Fq_poly_t ( fq_poly_t  result,
const CanonicalForm f,
const fq_ctx_t  ctx 
)

conversion of a factory univariate poly over F_q (for non-word size p) to a FLINT fq_poly_t

Parameters
[in,out]resultfq_poly_t
[in]funivariate poly over Fq
[in]ctxFq context

Definition at line 511 of file FLINTconvert.cc.

513{
514 fq_poly_init2 (result, degree (f)+1, ctx);
515
516 _fq_poly_set_length (result, degree (f) + 1, ctx);
517
518 for (CFIterator i= f; i.hasTerms(); i++)
519 {
520 fq_t buf;
521 convertFacCF2Fq_t (buf, i.coeff(), ctx);
522 fq_poly_set_coeff (result, i.exp(), buf, ctx);
523 fq_clear (buf, ctx);
524 }
525}
void convertFacCF2Fq_t(fq_t result, const CanonicalForm &f, const fq_ctx_t ctx)
conversion of a factory element of F_q (for non-word size p) to a FLINT fq_t

◆ convertFacCF2Fq_t()

void convertFacCF2Fq_t ( fq_t  result,
const CanonicalForm f,
const fq_ctx_t  ctx 
)

conversion of a factory element of F_q (for non-word size p) to a FLINT fq_t

Parameters
[in,out]resultfq_t
[in]felement of Fq
[in]ctxFq context

Definition at line 487 of file FLINTconvert.cc.

488{
489 fmpz_poly_init2 (result, fq_ctx_degree(ctx));
490 _fmpz_poly_set_length(result, fq_ctx_degree(ctx));
491
492 for (CFIterator i= f; i.hasTerms(); i++)
493 {
494 ASSERT(i.exp() < result->length, "input is not reduced");
495 convertCF2initFmpz (fmpz_poly_get_coeff_ptr(result, i.exp()), i.coeff()); // assumes initialized
496 }
497
498 _fmpz_vec_scalar_mod_fmpz (result->coeffs, result->coeffs, result->length,
499 fq_ctx_prime(ctx));
500
501 _fmpz_poly_normalise (result);
502}
#define ASSERT(expression, message)
Definition: cf_assert.h:99

◆ convertFacCF2nmod_poly_t()

void convertFacCF2nmod_poly_t ( nmod_poly_t  result,
const CanonicalForm f 
)

conversion of a factory univariate polynomials over Z/p (for word size p) to nmod_poly_t

Parameters
[in,out]resulta nmod_poly_t
[in]funivariate poly over Z/p

Definition at line 189 of file FLINTconvert.cc.

190{
191 bool save_sym_ff= isOn (SW_SYMMETRIC_FF);
192 if (save_sym_ff) Off (SW_SYMMETRIC_FF);
193 nmod_poly_init2 (result, getCharacteristic(), degree (f)+1);
194 for (CFIterator i= f; i.hasTerms(); i++)
195 {
196 CanonicalForm c= i.coeff();
197 if (!c.isImm()) c=c.mapinto(); //c%= getCharacteristic();
198 if (!c.isImm())
199 { //This case will never happen if the characteristic is in fact a prime
200 // number, since all coefficients are represented as immediates
201 printf("convertCF2nmod_poly_t: coefficient not immediate!, char=%d\n",
203 }
204 else
205 nmod_poly_set_coeff_ui (result, i.exp(), c.intval());
206 }
207 if (save_sym_ff) On (SW_SYMMETRIC_FF);
208}

◆ convertFacCFMatrix2Fmpz_mat_t()

void convertFacCFMatrix2Fmpz_mat_t ( fmpz_mat_t  M,
const CFMatrix m 
)

conversion of a factory matrix over Z to a fmpz_mat_t

Parameters
[in,out]Mfmpz_mat_t
[in]mmatrix over Z

Definition at line 587 of file FLINTconvert.cc.

588{
589 fmpz_mat_init (M, (long) m.rows(), (long) m.columns());
590
591 int i,j;
592 for(i=m.rows();i>0;i--)
593 {
594 for(j=m.columns();j>0;j--)
595 {
596 convertCF2initFmpz (fmpz_mat_entry (M,i-1,j-1), m(i,j)); // assumes initialized
597 }
598 }
599}
int m
Definition: cfEzgcd.cc:128
int j
Definition: facHensel.cc:110
#define M
Definition: sirandom.c:25

◆ convertFacCFMatrix2Fq_nmod_mat_t()

void convertFacCFMatrix2Fq_nmod_mat_t ( fq_nmod_mat_t  M,
const fq_nmod_ctx_t  fq_con,
const CFMatrix m 
)

conversion of a factory matrix over F_q to a fq_nmod_mat_t

Parameters
[in,out]Mfq_nmod_mat_t
[in]fq_conFq context
[in]mmatrix over Fq

Definition at line 648 of file FLINTconvert.cc.

650{
651 fq_nmod_mat_init (M, (long) m.rows(), (long) m.columns(), fq_con);
652 int i,j;
653 for(i=m.rows();i>0;i--)
654 {
655 for(j=m.columns();j>0;j--)
656 {
657 convertFacCF2nmod_poly_t (M->rows[i-1]+j-1, m (i,j));
658 }
659 }
660}
void convertFacCF2nmod_poly_t(nmod_poly_t result, const CanonicalForm &f)
conversion of a factory univariate polynomials over Z/p (for word size p) to nmod_poly_t
fq_nmod_ctx_t fq_con
Definition: facHensel.cc:99

◆ convertFacCFMatrix2nmod_mat_t()

void convertFacCFMatrix2nmod_mat_t ( nmod_mat_t  M,
const CFMatrix m 
)

conversion of a factory matrix over Z/p to a nmod_mat_t

Parameters
[in,out]Mnmod_mat_t
[in]mmatrix over Z/p

Definition at line 614 of file FLINTconvert.cc.

615{
616 nmod_mat_init (M, (long) m.rows(), (long) m.columns(), getCharacteristic());
617
618 bool save_sym_ff= isOn (SW_SYMMETRIC_FF);
619 if (save_sym_ff) Off (SW_SYMMETRIC_FF);
620 int i,j;
621 for(i=m.rows();i>0;i--)
622 {
623 for(j=m.columns();j>0;j--)
624 {
625 if(!(m(i,j)).isImm()) printf("convertFacCFMatrix2FLINTmat_zz_p: not imm.\n");
626 nmod_mat_entry (M,i-1,j-1)= (m(i,j)).intval();
627 }
628 }
629 if (save_sym_ff) On (SW_SYMMETRIC_FF);
630}

◆ convertFLINTFq_nmod_poly_factor2FacCFFList()

CFFList convertFLINTFq_nmod_poly_factor2FacCFFList ( const fq_nmod_poly_factor_t  fac,
const Variable x,
const Variable alpha,
const fq_nmod_ctx_t  fq_con 
)

conversion of a FLINT factorization over Fq (for word size p) to a CFFList

Parameters
[in]facfq_nmod_poly_factor_t
[in]xpolynomial variable
[in]alphaalgebraic variable
[in]fq_conFq context

Definition at line 381 of file FLINTconvert.cc.

385{
387
388 long i;
389
390 for (i = 0; i < fac->num; i++)
392 (fq_nmod_poly_t &)fac->poly[i], x, alpha, fq_con),
393 fac->exp[i]));
394 return result;
395}
CanonicalForm convertFq_nmod_poly_t2FacCF(const fq_nmod_poly_t p, const Variable &x, const Variable &alpha, const fq_nmod_ctx_t ctx)
conversion of a FLINT poly over Fq to a CanonicalForm with alg. variable alpha and polynomial variabl...
Variable x
Definition: cfModGcd.cc:4082
Variable alpha
Definition: facAbsBiFact.cc:51

◆ convertFLINTnmod_poly_factor2FacCFFList()

CFFList convertFLINTnmod_poly_factor2FacCFFList ( const nmod_poly_factor_t  fac,
const mp_limb_t  leadingCoeff,
const Variable x 
)

conversion of a FLINT factorization over Z/p (for word size p) to a CFFList

Parameters
[in]faca nmod_poly_factor_t
[in]leadingCoeffleading coefficient
[in]xvariable the result should have

Definition at line 339 of file FLINTconvert.cc.

343{
345 if (leadingCoeff != 1)
346 result.insert (CFFactor (CanonicalForm ((long) leadingCoeff), 1));
347
348 long i;
349
350 for (i = 0; i < fac->num; i++)
352 (nmod_poly_t &)fac->p[i],x),
353 fac->exp[i]));
354 return result;
355}
CanonicalForm convertnmod_poly_t2FacCF(const nmod_poly_t poly, const Variable &x)
conversion of a FLINT poly over Z/p to CanonicalForm

◆ convertFmpq2CF()

CanonicalForm convertFmpq2CF ( const fmpq_t  q)

conversion of a FLINT rational to CanonicalForm

Definition at line 254 of file FLINTconvert.cc.

255{
256 bool isRat= isOn (SW_RATIONAL);
257 if (!isRat)
258 On (SW_RATIONAL);
259
261 mpz_t nnum, nden;
262 mpz_init (nnum);
263 mpz_init (nden);
264 fmpz_get_mpz (nnum, fmpq_numref (q));
265 fmpz_get_mpz (nden, fmpq_denref (q));
266
268 if (mpz_is_imm (nden))
269 {
270 if (mpz_is_imm(nnum))
271 {
272 num= CanonicalForm (mpz_get_si(nnum));
273 den= CanonicalForm (mpz_get_si(nden));
274 mpz_clear (nnum);
275 mpz_clear (nden);
276 result= num/den;
277 }
278 else if (mpz_cmp_si(nden,1)==0)
279 {
281 mpz_clear (nden);
282 }
283 else
284 result= CanonicalForm( CFFactory::rational( nnum, nden, false));
285 }
286 else
287 {
288 result= CanonicalForm( CFFactory::rational( nnum, nden, false));
289 }
290 if (!isRat)
292 return result;
293}
CanonicalForm num(const CanonicalForm &f)
static InternalCF * basic(int value)
Definition: cf_factory.cc:61
static InternalCF * rational(long num, long den)
Definition: cf_factory.cc:268
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:19

◆ convertFmpq_poly_t2FacCF()

CanonicalForm convertFmpq_poly_t2FacCF ( const fmpq_poly_t  p,
const Variable x 
)

conversion of a FLINT poly over Q to CanonicalForm

Parameters
[in]pan fmpq_poly_t
[in]xvariable the result should have

Definition at line 296 of file FLINTconvert.cc.

297{
299 fmpq_t coeff;
300 long n= p->length;
301 for (long i= 0; i < n; i++)
302 {
303 fmpq_init (coeff);
304 fmpq_poly_get_coeff_fmpq (coeff, p, i);
305 if (fmpq_is_zero (coeff))
306 {
307 fmpq_clear (coeff);
308 continue;
309 }
310 result += convertFmpq2CF (coeff)*power (x, i);
311 fmpq_clear (coeff);
312 }
313 return result;
314}
CanonicalForm convertFmpq2CF(const fmpq_t q)
conversion of a FLINT rational to CanonicalForm
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation

◆ convertFmpz2CF()

CanonicalForm convertFmpz2CF ( const fmpz_t  coefficient)

conversion of a FLINT integer to CanonicalForm

Parameters
[in]coefficienta FLINT integer

Definition at line 155 of file FLINTconvert.cc.

156{
157 if(!COEFF_IS_MPZ(*coefficient)
158 && (fmpz_cmp_si (coefficient, MINIMMEDIATE) >= 0)
159 && (fmpz_cmp_si (coefficient, MAXIMMEDIATE) <= 0))
160 {
161 long coeff= fmpz_get_si (coefficient);
162 return CanonicalForm (coeff);
163 }
164 else
165 {
166 mpz_t gmp_val;
167 mpz_init (gmp_val);
168 fmpz_get_mpz (gmp_val, coefficient);
170 return result;
171 }
172}
const long MAXIMMEDIATE
Definition: imm.h:55
const long MINIMMEDIATE
Definition: imm.h:54

◆ convertFmpz_mat_t2FacCFMatrix()

CFMatrix * convertFmpz_mat_t2FacCFMatrix ( const fmpz_mat_t  m)

conversion of a FLINT matrix over Z to a factory matrix

Parameters
[in]mfmpz_mat_t

Definition at line 600 of file FLINTconvert.cc.

601{
602 CFMatrix *res=new CFMatrix(fmpz_mat_nrows (m),fmpz_mat_ncols (m));
603 int i,j;
604 for(i=res->rows();i>0;i--)
605 {
606 for(j=res->columns();j>0;j--)
607 {
608 (*res)(i,j)=convertFmpz2CF(fmpz_mat_entry (m,i-1,j-1));
609 }
610 }
611 return res;
612}
CanonicalForm convertFmpz2CF(const fmpz_t coefficient)
conversion of a FLINT integer to CanonicalForm
Matrix< CanonicalForm > CFMatrix

◆ convertFmpz_mod_poly_t2FacCF()

CanonicalForm convertFmpz_mod_poly_t2FacCF ( const fmpz_mod_poly_t  poly,
const Variable x,
const modpk b 
)

conversion of a FLINT poly over Z/p (for non word size p) to a CanonicalForm over Z

Parameters
[in]polyfmpz_mod_poly_t
[in]xvariable the result should have
[in]bcoeff bound to map coeffs in (-p/2,p/2)

Definition at line 421 of file FLINTconvert.cc.

423{
424 fmpz_poly_t buf;
425 fmpz_poly_init (buf);
426 #if (__FLINT_RELEASE >= 20700)
427 fmpz_t FLINTp;
428 fmpz_init (FLINTp);
429 convertCF2initFmpz (FLINTp, b.getpk()); // assumes initialized
430 fmpz_mod_ctx_t ctx;
431 fmpz_mod_ctx_init(ctx,FLINTp);
432 fmpz_clear(FLINTp);
433 fmpz_mod_poly_get_fmpz_poly (buf, poly, ctx);
434 #else
435 fmpz_mod_poly_get_fmpz_poly (buf, poly);
436 #endif
438 fmpz_poly_clear (buf);
439 return b (result);
440}
CanonicalForm convertFmpz_poly_t2FacCF(const fmpz_poly_t poly, const Variable &x)
conversion of a FLINT poly over Z to CanonicalForm
CanonicalForm b
Definition: cfModGcd.cc:4103

◆ convertFmpz_poly_t2FacCF()

CanonicalForm convertFmpz_poly_t2FacCF ( const fmpz_poly_t  poly,
const Variable x 
)

conversion of a FLINT poly over Z to CanonicalForm

Parameters
[in]polyan fmpz_poly_t
[in]xvariable the result should have

Definition at line 175 of file FLINTconvert.cc.

176{
178 fmpz* coeff;
179 for (int i= 0; i < fmpz_poly_length (poly); i++)
180 {
181 coeff= fmpz_poly_get_coeff_ptr (poly, i);
182 if (!fmpz_is_zero (coeff))
183 result += convertFmpz2CF (coeff)*power (x,i);
184 }
185 return result;
186}

◆ convertFq_nmod_mat_t2FacCFMatrix()

CFMatrix * convertFq_nmod_mat_t2FacCFMatrix ( const fq_nmod_mat_t  m,
const fq_nmod_ctx_t &  fq_con,
const Variable alpha 
)

conversion of a FLINT matrix over F_q to a factory matrix

Parameters
[in]mfq_nmod_mat_t
[in]fq_conFq context
[in]alphaalgebraic variable

Definition at line 663 of file FLINTconvert.cc.

666{
667 CFMatrix *res=new CFMatrix(fq_nmod_mat_nrows (m, fq_con),
668 fq_nmod_mat_ncols (m, fq_con));
669 int i,j;
670 for(i=res->rows();i>0;i--)
671 {
672 for(j=res->columns();j>0;j--)
673 {
674 (*res)(i,j)=convertFq_nmod_t2FacCF (fq_nmod_mat_entry (m, i-1, j-1),
675 alpha, fq_con);
676 }
677 }
678 return res;
679}
CanonicalForm convertFq_nmod_t2FacCF(const fq_nmod_t poly, const Variable &alpha, const fq_nmod_ctx_t)
conversion of a FLINT element of F_q to a CanonicalForm with alg. variable alpha

◆ convertFq_nmod_poly_t2FacCF()

CanonicalForm convertFq_nmod_poly_t2FacCF ( const fq_nmod_poly_t  p,
const Variable x,
const Variable alpha,
const fq_nmod_ctx_t  ctx 
)

conversion of a FLINT poly over Fq to a CanonicalForm with alg. variable alpha and polynomial variable x

Parameters
[in]pfq_nmod_poly_t
[in]xpolynomial var.
[in]alphaalgebraic var.
[in]ctxFq context

Definition at line 566 of file FLINTconvert.cc.

568{
570 fq_nmod_t coeff;
571 long n= fq_nmod_poly_length (p, ctx);
572 fq_nmod_init2 (coeff, ctx);
573 for (long i= 0; i < n; i++)
574 {
575 fq_nmod_poly_get_coeff (coeff, p, i, ctx);
576 if (fq_nmod_is_zero (coeff, ctx))
577 continue;
578 result += convertFq_nmod_t2FacCF (coeff, alpha, ctx)*power (x, i);
579 fq_nmod_zero (coeff, ctx);
580 }
581 fq_nmod_clear (coeff, ctx);
582
583 return result;
584}

◆ convertFq_nmod_t2FacCF()

CanonicalForm convertFq_nmod_t2FacCF ( const fq_nmod_t  poly,
const Variable alpha,
const  fq_nmod_ctx_t 
)

conversion of a FLINT element of F_q to a CanonicalForm with alg. variable alpha

Parameters
[in]polyfq_nmod_t
[in]alphaalgebraic variable
[in]fq_nmod_ctx_tcontext

Definition at line 481 of file FLINTconvert.cc.

482{
483 return convertnmod_poly_t2FacCF (poly, alpha);
484}

◆ convertFq_poly_t2FacCF()

CanonicalForm convertFq_poly_t2FacCF ( const fq_poly_t  p,
const Variable x,
const Variable alpha,
const fq_ctx_t  ctx 
)

conversion of a FLINT poly over Fq (for non-word size p) to a CanonicalForm with alg. variable alpha and polynomial variable x

Parameters
[in]pfq_poly_t
[in]xpolynomial variable
[in]alphaalgebraic variable
[in]ctxFq context

Definition at line 545 of file FLINTconvert.cc.

547{
549 fq_t coeff;
550 long n= fq_poly_length (p, ctx);
551 fq_init2 (coeff, ctx);
552 for (long i= 0; i < n; i++)
553 {
554 fq_poly_get_coeff (coeff, p, i, ctx);
555 if (fq_is_zero (coeff, ctx))
556 continue;
557 result += convertFq_t2FacCF (coeff, alpha)*power (x, i);
558 fq_zero (coeff, ctx);
559 }
560 fq_clear (coeff, ctx);
561
562 return result;
563}
CanonicalForm convertFq_t2FacCF(const fq_t poly, const Variable &alpha)
conversion of a FLINT element of F_q with non-word size p to a CanonicalForm with alg....

◆ convertFq_t2FacCF()

CanonicalForm convertFq_t2FacCF ( const fq_t  poly,
const Variable alpha 
)

conversion of a FLINT element of F_q with non-word size p to a CanonicalForm with alg. variable alpha

Parameters
[in]polyfq_t
[in]alphaalgebraic variable

Definition at line 505 of file FLINTconvert.cc.

506{
507 return convertFmpz_poly_t2FacCF (poly, alpha);
508}

◆ convertNmod_mat_t2FacCFMatrix()

CFMatrix * convertNmod_mat_t2FacCFMatrix ( const nmod_mat_t  m)

conversion of a FLINT matrix over Z/p to a factory matrix

Parameters
[in]mnmod_mat_t

Definition at line 632 of file FLINTconvert.cc.

633{
634 CFMatrix *res=new CFMatrix(nmod_mat_nrows (m), nmod_mat_ncols (m));
635 int i,j;
636 for(i=res->rows();i>0;i--)
637 {
638 for(j=res->columns();j>0;j--)
639 {
640 (*res)(i,j)=CanonicalForm((long) nmod_mat_entry (m, i-1, j-1));
641 }
642 }
643 return res;
644}

◆ convertnmod_poly_t2FacCF()

CanonicalForm convertnmod_poly_t2FacCF ( const nmod_poly_t  poly,
const Variable x 
)

conversion of a FLINT poly over Z/p to CanonicalForm

Parameters
[in]polya nmod_poly_t
[in]xvariable the result should have

Definition at line 211 of file FLINTconvert.cc.

212{
214 for (int i= 0; i < nmod_poly_length (poly); i++)
215 {
216 ulong coeff= nmod_poly_get_coeff_ui (poly, i);
217 if (coeff != 0)
218 result += CanonicalForm ((long)coeff)*power (x,i);
219 }
220 return result;
221}