46#if (__FLINT_RELEASE >= 20700)
47#include <flint/nmod_mpoly_factor.h>
48#include <flint/fmpq_mpoly_factor.h>
49#include <flint/fq_nmod_mpoly_factor.h>
64 if ( !
f.inCoeffDomain() )
70 if (
i.exp() > exp_f[e]) exp_f[e]=
i.exp();
72 for (;
i.hasTerms();
i++ )
84 for(
i=mv;
i>0;
i--) exp_f[
i]=0;
88 if ((exp_f[
i]>0) && (exp_f[
i]<exp_f[mv]))
102 if (
f.isZero()) printf(
"+0");
104 else if (!
f.inBaseDomain() )
110 if (
i.coeff().isOne())
113 if (e==0) printf(
"1");
116 printf(
"%c",
'a'+
l-1);
117 if (e!=1) printf(
"^%d",e);
125 printf(
"*%c",
'a'+
l-1);
126 if (e!=1) printf(
"^%d",e);
153 if (
l<0) printf(
"%ld",
l);
154 else printf(
"+%ld",
l);
164 char * str =
new char[mpz_sizeinbase(
m, 10 ) + 2];
165 str = mpz_get_str( str, 10,
m );
174 char * str =
new char[mpz_sizeinbase(
m, 10 ) + 2];
175 str = mpz_get_str( str, 10,
m );
176 while(str[strlen(str)]<
' ') { str[strlen(str)]=
'\0'; }
177 puts(str);putchar(
'/');
181 str =
new char[mpz_sizeinbase(
m, 10 ) + 2];
182 str = mpz_get_str( str, 10,
m );
183 while(str[strlen(str)]<
' ') { str[strlen(str)]=
'\0'; }
198 if (
f.inExtension()) printf(
"E(%d)",
f.level());
210 printf(
"%d\n", J.
getItem().exp());
219 if (!(L.
getFirst().factor().inCoeffDomain()))
220 printf(
"first entry is not const\n");
225 printf(
"other entry is const\n");
227 while(
j>0) { t*=tt;
j--; }
229 if (!(
f-t).
isZero()) { printf(
"problem:\n");
out_cf(
"factor:",
f,
" has problems\n");}
236 if (
f.inBaseDomain())
return true;
237 if (
f.level()<0)
return false;
246 if (
f.level()<=0)
return false;
249 if (!(
i.coeff().inBaseDomain()))
return false;
262 ASSERT( ( !
f.inCoeffDomain() ),
"no constants" );
264 for (
int i=1;
i<=n;
i++ )
297 for (
i=
f;
i.hasTerms();
i++ ){
299 for (
j=dummy;
j.hasItem();
j++ )
320 for (
i=
f;
i.hasTerms();
i++)
322 elem=
i.coeff()*
power(
f.mvar(),
i.exp());
336 for (
i=Termlist;
i.hasItem();
i++)
345 for (
i=Newlist;
i.hasItem();
i++)
360 for (
i=
f;
i.hasTerms();
i++)
362 elem=
i.coeff()*
power(
f.mvar(),
i.exp());
376 for (
i=Termlist;
i.hasItem();
i++)
385 for (
i=Newlist;
i.hasItem();
i++)
396 if (
f.exp() >
g.exp())
return 1;
397 if (
f.exp() <
g.exp())
return 0;
398 if (
f.factor() >
g.factor())
return 1;
407 if (
f.inCoeffDomain() )
412 ( const CanonicalForm & f, const Variable & alpha ) instead");
415 if (!
f.isUnivariate() )
427 for (
j=Intermediatelist;
j.hasItem();
j++ )
430 CFFactor( n(
j.getItem().factor()),
j.getItem().exp()) );
434 for (
j=Homoglist;
j.hasItem();
j++ )
438 d_xn -= (
degree(unhomogelem,
xn)*
j.getItem().exp());
449 if (
f.isUnivariate())
459 nmod_poly_factor_t
result;
460 nmod_poly_factor_init (
result);
461 mp_limb_t leadingCoeff= nmod_poly_factor (
result, f1);
463 nmod_poly_factor_clear (
result);
483 vec_pair_GF2X_long factors;
504 zz_p leadcoeff = LeadCoeff(f1);
507 f1=f1 / LeadCoeff(f1);
509 vec_pair_zz_pX_long factors;
518#if !defined(HAVE_NTL) && !defined(HAVE_FLINT)
533 #if defined(HAVE_NTL)
548 factoryError (
"multivariate factorization over GF depends on NTL(missing)");
554 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20700) && defined(HAVE_NTL)
558 #if defined(HAVE_NTL)
575 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20700) && defined(HAVE_NTL)
578 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20700)
579 nmod_mpoly_ctx_t ctx;
581 nmod_mpoly_t Flint_f;
582 nmod_mpoly_init(Flint_f,ctx);
583 convFactoryPFlintMP(
f,Flint_f,ctx,
f.level());
584 nmod_mpoly_factor_t factors;
585 nmod_mpoly_factor_init(factors,ctx);
587 if (issqrfree) okay=nmod_mpoly_factor_squarefree(factors,Flint_f,ctx);
588 else okay=nmod_mpoly_factor(factors,Flint_f,ctx);
590 nmod_mpoly_init(fac,ctx);
593 cf_fac=nmod_mpoly_factor_get_constant_ui(factors,ctx);
595 for(
int i=nmod_mpoly_factor_length(factors,ctx)-1;
i>=0;
i--)
597 nmod_mpoly_factor_get_base(fac,factors,
i,ctx);
598 cf_fac=convFlintMPFactoryP(fac,ctx,
f.level());
599 cf_exp=nmod_mpoly_factor_get_exp_si(factors,
i,ctx);
602 nmod_mpoly_factor_clear(factors,ctx);
603 nmod_mpoly_clear(Flint_f,ctx);
604 nmod_mpoly_ctx_clear(ctx);
614 #if !defined(HAVE_FLINT) || (__FLINT_RELEASE < 20700)
616 factoryError (
"multivariate factorization depends on NTL/FLINT(missing)");
630 if (
f.isUnivariate() )
640 #if defined(HAVE_FLINT) && (__FLINT_RELEASE>=20503) && (__FLINT_RELEASE!= 20600)
647 fmpz_poly_factor_t
result;
648 fmpz_poly_factor_init (
result);
649 fmpz_poly_factor(
result, f1);
651 fmpz_poly_factor_clear (
result);
652 fmpz_poly_clear (f1);
663 #elif defined(HAVE_NTL)
667 vec_pair_ZZX_long factors;
693 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20700)
697 fmpz_mpoly_ctx_t ctx;
698 fmpz_mpoly_ctx_init(ctx,
f.level(),ORD_LEX);
699 fmpz_mpoly_t Flint_f;
700 fmpz_mpoly_init(Flint_f,ctx);
701 convFactoryPFlintMP(fz,Flint_f,ctx,fz.
level());
702 fmpz_mpoly_factor_t factors;
703 fmpz_mpoly_factor_init(factors,ctx);
705 if (issqrfree) rr=fmpz_mpoly_factor_squarefree(factors,Flint_f,ctx);
706 else rr=fmpz_mpoly_factor(factors,Flint_f,ctx);
707 if (rr==0) printf(
"fail\n");
709 fmpz_mpoly_init(fac,ctx);
714 fmpz_mpoly_factor_get_constant_fmpz(c,factors,ctx);
718 for(
int i=fmpz_mpoly_factor_length(factors,ctx)-1;
i>=0;
i--)
720 fmpz_mpoly_factor_get_base(fac,factors,
i,ctx);
721 cf_fac=convFlintMPFactoryP(fac,ctx,
f.level());
722 cf_exp=fmpz_mpoly_factor_get_exp_si(factors,
i,ctx);
725 fmpz_mpoly_factor_clear(factors,ctx);
726 fmpz_mpoly_clear(Flint_f,ctx);
727 fmpz_mpoly_ctx_clear(ctx);
731 #if defined(HAVE_NTL)
744 #if !defined(HAVE_FLINT) || (__FLINT_RELEASE < 20700)
776 if (
f.inCoeffDomain() )
787 does not coincide with alpha");
792 if (
f.isUnivariate())
816 GF2E f1_coef=LeadCoeff(f1);
820 vec_pair_GF2EX_long factors;
829#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
832 nmod_poly_t FLINTmipo, leadingCoeff;
840 fq_nmod_poly_t FLINTF;
842 fq_nmod_poly_factor_t
res;
844 fq_nmod_poly_factor (
res, leadingCoeff, FLINTF,
fq_con);
872 zz_pE leadcoeff= LeadCoeff(f1);
878 vec_pair_zz_pEX_long factors;
888#if !defined(HAVE_NTL) && !defined(HAVE_FLINT)
898 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
900 nmod_poly_t FLINTmipo;
902 fq_nmod_mpoly_ctx_t ctx;
908 fq_nmod_mpoly_ctx_init(ctx,
f.level(),ORD_LEX,
fq_con);
910 fq_nmod_mpoly_t FLINTF;
911 fq_nmod_mpoly_init(FLINTF,ctx);
912 convertFacCF2Fq_nmod_mpoly_t(FLINTF,
f,ctx,
f.level(),
fq_con);
913 fq_nmod_mpoly_factor_t
res;
914 fq_nmod_mpoly_factor_init (
res, ctx);
915 fq_nmod_mpoly_factor (
res, FLINTF, ctx);
916 F= convertFLINTFq_nmod_mpoly_factor2FacCFFList (
res, ctx,
f.level(),
fq_con,
alpha);
919 fq_nmod_mpoly_factor_clear (
res, ctx);
920 fq_nmod_mpoly_clear (FLINTF, ctx);
922 fq_nmod_mpoly_ctx_clear (ctx);
926 #elif defined(HAVE_NTL)
929 factoryError (
"multivariate factorization over Z/pZ(alpha) depends on NTL/Flint(missing)");
936 if (
f.isUnivariate())
942 #if defined(HAVE_NTL) || defined(HAVE_FLINT)
945 factoryError (
"multivariate factorization over Q(alpha) depends on NTL or FLINT (missing)");
CanonicalForm convertFmpz2CF(const fmpz_t coefficient)
conversion of a FLINT integer to CanonicalForm
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
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
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
void convertFacCF2Fmpz_poly_t(fmpz_poly_t result, const CanonicalForm &f)
conversion of a factory univariate polynomial over Z to a fmpz_poly_t
This file defines functions for conversion to FLINT (www.flintlib.org) and back.
CFFList convertFLINTfmpz_poly_factor2FacCFFList(const fmpz_poly_factor_t fac, const Variable &x)
conversion of a FLINT factorization over Z to a CFFList
CFFList convertNTLvec_pair_GF2X_long2FacCFFList(const vec_pair_GF2X_long &e, GF2, const Variable &x)
NAME: convertNTLvec_pair_GF2X_long2FacCFFList.
ZZX convertFacCF2NTLZZX(const CanonicalForm &f)
zz_pEX convertFacCF2NTLzz_pEX(const CanonicalForm &f, const zz_pX &mipo)
CFFList convertNTLvec_pair_zzpEX_long2FacCFFList(const vec_pair_zz_pEX_long &e, const zz_pE &cont, const Variable &x, const Variable &alpha)
CFFList convertNTLvec_pair_GF2EX_long2FacCFFList(const vec_pair_GF2EX_long &e, const GF2E &cont, const Variable &x, const Variable &alpha)
NAME: convertNTLvec_pair_GF2EX_long2FacCFFList.
CFFList convertNTLvec_pair_zzpX_long2FacCFFList(const vec_pair_zz_pX_long &e, const zz_p cont, const Variable &x)
GF2EX convertFacCF2NTLGF2EX(const CanonicalForm &f, const GF2X &mipo)
CanonicalForm in Z_2(a)[X] to NTL GF2EX.
zz_pX convertFacCF2NTLzzpX(const CanonicalForm &f)
GF2X convertFacCF2NTLGF2X(const CanonicalForm &f)
NAME: convertFacCF2NTLGF2X.
CFFList convertNTLvec_pair_ZZX_long2FacCFFList(const vec_pair_ZZX_long &e, const ZZ &cont, const Variable &x)
NAME: convertNTLvec_pair_ZZX_long2FacCFFList.
Conversion to and from NTL.
CanonicalForm cd(bCommonDen(FF))
static void sort(int **points, int sizePoints)
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
declarations of higher level algorithms.
#define ASSERT(expression, message)
static const int SW_USE_FL_GCD_P
set to 1 to use Flints gcd over F_p
static const int SW_RATIONAL
set to 1 for computations over Q
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
static const int SW_USE_FL_FAC_0
set to 1 to prefer flints multivariate factorization over Z/p
static const int SW_USE_FL_FAC_P
set to 1 to prefer flints multivariate factorization over Z/p
static const int SW_BERLEKAMP
set to 1 to use Factorys Berlekamp alg.
#define GaloisFieldDomain
void test_cff(CFFList &L, const CanonicalForm &f)
Variable get_max_degree_Variable(const CanonicalForm &f)
get_max_degree_Variable returns Variable with highest degree.
bool isPurePoly(const CanonicalForm &f)
int cmpCF(const CFFactor &f, const CFFactor &g)
int find_mvar(const CanonicalForm &f)
bool isPurePoly_m(const CanonicalForm &f)
void getTerms(const CanonicalForm &f, const CanonicalForm &t, CFList &result)
get_Terms: Split the polynomial in the containing terms.
CFList get_Terms(const CanonicalForm &f)
VAR int singular_homog_flag
void out_cf(const char *s1, const CanonicalForm &f, const char *s2)
cf_algorithm.cc - simple mathematical algorithms.
CanonicalForm homogenize(const CanonicalForm &f, const Variable &x)
homogenize homogenizes f with Variable x
CFFList sqrFree(const CanonicalForm &f, bool sort)
squarefree factorization
void find_exp(const CanonicalForm &f, int *exp_f)
CFFList factorize(const CanonicalForm &f, bool issqrfree)
factorization over or
Iterators for CanonicalForm's.
CanonicalForm compress(const CanonicalForm &f, CFMap &m)
CanonicalForm compress ( const CanonicalForm & f, CFMap & m )
VAR void(* factoryError)(const char *s)
class to iterate through CanonicalForm's
void sort(int(*)(const T &, const T &))
factory's class for variables
CFFList AlgExtFactorize(const CanonicalForm &F, const Variable &alpha)
factorize a univariate polynomial over algebraic extension of Q
Univariate factorization over algebraic extension of Q using Trager's algorithm.
multivariate factorization over Q(a)
CFFList ratFactorize(const CanonicalForm &G, const Variable &v=Variable(1), bool substCheck=true)
factorize a multivariate polynomial over
CFList ratSqrfFactorize(const CanonicalForm &G, const Variable &v=Variable(1))
factorize a squarefree multivariate polynomial over
This file provides functions for factorizing a multivariate polynomial over , or GF.
CFList FpSqrfFactorize(const CanonicalForm &F)
factorize a squarefree multivariate polynomial over
CFFList FpFactorize(const CanonicalForm &G, bool substCheck=true)
factorize a multivariate polynomial over
CFFList GFFactorize(const CanonicalForm &G, bool substCheck=true)
factorize a multivariate polynomial over GF
CFList GFSqrfFactorize(const CanonicalForm &F)
factorize a squarefree multivariate polynomial over GF
CFFList FqFactorize(const CanonicalForm &G, const Variable &alpha, bool substCheck=true)
factorize a multivariate polynomial over
This file provides functions for squarefrees factorizing over , or GF.
CFFList FqSqrf(const CanonicalForm &F, const Variable &alpha, bool sort=true)
squarefree factorization over . If input is not monic, the leading coefficient is dropped
CFFList FpSqrf(const CanonicalForm &F, bool sort=true)
squarefree factorization over . If input is not monic, the leading coefficient is dropped
fq_nmod_ctx_clear(fq_con)
nmod_poly_init(FLINTmipo, getCharacteristic())
fq_nmod_ctx_init_modulus(fq_con, FLINTmipo, "Z")
convertFacCF2nmod_poly_t(FLINTmipo, M)
nmod_poly_clear(FLINTmipo)
fq_nmod_poly_clear(prod, fq_con)
bool isZero(const CFArray &A)
checks if entries of A are zero
CFFList FpFactorizeUnivariateB(const CanonicalForm &f, bool issqrfree=false)
CFFList FpFactorizeUnivariateCZ(const CanonicalForm &f, bool issqrfree, int numext, const Variable alpha, const Variable beta)
CFFList ZFactorizeMultivariate(const CanonicalForm &f, bool issqrfree)
CFFList sqrFreeZ(const CanonicalForm &a)
CFFList sortCFFList(CFFList &F)
squarefree part and factorization over Q, Q(a)
CFFList ZFactorizeUnivariate(const CanonicalForm &ff, bool issqrfree=false)
static int max(int a, int b)
static long imm2int(const InternalCF *const imm)
Factory's internal integers.
int status int void * buf
void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
helper functions for conversion to and from Singular
bool getReduce(const Variable &alpha)
CanonicalForm getMipo(const Variable &alpha, const Variable &x)