My Project
Loading...
Searching...
No Matches
cf_factor.cc File Reference

Interface to factorization and square free factorization algorithms. More...

#include "config.h"
#include "cf_assert.h"
#include "cf_defs.h"
#include "canonicalform.h"
#include "cf_iter.h"
#include "fac_sqrfree.h"
#include "cf_algorithm.h"
#include "facFqFactorize.h"
#include "facFqSquarefree.h"
#include "cf_map.h"
#include "facAlgExt.h"
#include "facFactorize.h"
#include "singext.h"
#include "cf_util.h"
#include "fac_berlekamp.h"
#include "fac_cantzass.h"
#include "fac_univar.h"
#include "fac_multivar.h"
#include "int_int.h"
#include <cstring>
#include "NTLconvert.h"
#include "factory/cf_gmp.h"
#include "FLINTconvert.h"

Go to the source code of this file.

Functions

void find_exp (const CanonicalForm &f, int *exp_f)
int find_mvar (const CanonicalForm &f)
void out_cf (const char *s1, const CanonicalForm &f, const char *s2)
void out_cff (CFFList &L)
void test_cff (CFFList &L, const CanonicalForm &f)
bool isPurePoly_m (const CanonicalForm &f)
bool isPurePoly (const CanonicalForm &f)
Variable get_max_degree_Variable (const CanonicalForm &f)
 get_max_degree_Variable returns Variable with highest degree.
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)
CanonicalForm homogenize (const CanonicalForm &f, const Variable &x)
 homogenize homogenizes f with Variable x
CanonicalForm homogenize (const CanonicalForm &f, const Variable &x, const Variable &v1, const Variable &v2)
int cmpCF (const CFFactor &f, const CFFactor &g)
CFFList factorize (const CanonicalForm &f, bool issqrfree)
 factorization over $ F_p $ or $ Q $
CFFList factorize (const CanonicalForm &f, const Variable &alpha)
 factorization over $ F_p(\alpha) $ or $ Q(\alpha) $
CFFList sqrFree (const CanonicalForm &f, bool sort)
 squarefree factorization

Variables

VAR int singular_homog_flag =1

Detailed Description

Interface to factorization and square free factorization algorithms.

Used by: cf_irred.cc

Header file: cf_algorithm.h

Definition in file cf_factor.cc.

Function Documentation

◆ cmpCF()

int cmpCF ( const CFFactor & f,
const CFFactor & g )

Definition at line 400 of file cf_factor.cc.

401{
402 if (f.exp() > g.exp()) return 1;
403 if (f.exp() < g.exp()) return 0;
404 if (f.factor() > g.factor()) return 1;
405 return 0;
406}
g
Definition cfModGcd.cc:4098
FILE * f
Definition checklibs.c:9

◆ factorize() [1/2]

CFFList factorize ( const CanonicalForm & f,
bool issqrfree )

factorization over $ F_p $ or $ Q $

Definition at line 411 of file cf_factor.cc.

412{
413 if ( f.inCoeffDomain() )
414 return CFFList( f );
415#ifndef NOASSERT
416 Variable a;
417 ASSERT (!hasFirstAlgVar (f, a), "f has an algebraic variable use factorize \
418 ( const CanonicalForm & f, const Variable & alpha ) instead");
419#endif
420 //out_cf("factorize:",f,"==================================\n");
421 if (! f.isUnivariate() ) // preprocess homog. polys
422 {
423 if ( singular_homog_flag && f.isHomogeneous())
424 {
426 int d_xn = degree(f,xn);
427 CFMap n;
428 CanonicalForm F = compress(f(1,xn),n);
429 CFFList Intermediatelist;
430 Intermediatelist = factorize(F);
431 CFFList Homoglist;
433 for ( j=Intermediatelist; j.hasItem(); j++ )
434 {
435 Homoglist.append(
436 CFFactor( n(j.getItem().factor()), j.getItem().exp()) );
437 }
438 CFFList Unhomoglist;
439 CanonicalForm unhomogelem;
440 for ( j=Homoglist; j.hasItem(); j++ )
441 {
442 unhomogelem= homogenize(j.getItem().factor(),xn);
443 Unhomoglist.append(CFFactor(unhomogelem,j.getItem().exp()));
444 d_xn -= (degree(unhomogelem,xn)*j.getItem().exp());
445 }
446 if ( d_xn != 0 ) // have to append xn^(d_xn)
447 Unhomoglist.append(CFFactor(CanonicalForm(xn),d_xn));
448 if(isOn(SW_USE_NTL_SORT)) Unhomoglist.sort(cmpCF);
449 return Unhomoglist;
450 }
451 }
452 CFFList F;
453 if ( getCharacteristic() > 0 )
454 {
455 if (f.isUnivariate())
456 {
457#ifdef HAVE_FLINT
458#ifdef HAVE_NTL
459 if (degree (f) < 300)
460#endif
461 {
462 // use FLINT: char p, univariate
463 nmod_poly_t f1;
465 nmod_poly_factor_t result;
466 nmod_poly_factor_init (result);
467 mp_limb_t leadingCoeff= nmod_poly_factor (result, f1);
468 F= convertFLINTnmod_poly_factor2FacCFFList (result, leadingCoeff, f.mvar());
469 nmod_poly_factor_clear (result);
470 nmod_poly_clear (f1);
472 return F;
473 }
474#endif
475#ifdef HAVE_NTL
476 { // NTL char 2, univariate
477 if (getCharacteristic()==2)
478 {
479 // Specialcase characteristic==2
480 if (fac_NTL_char != 2)
481 {
482 fac_NTL_char = 2;
483 zz_p::init(2);
484 }
485 // convert to NTL using the faster conversion routine for characteristic 2
486 GF2X f1=convertFacCF2NTLGF2X(f);
487 // no make monic necessary in GF2
488 //factorize
489 vec_pair_GF2X_long factors;
490 CanZass(factors,f1);
491
492 // convert back to factory again using the faster conversion routine for vectors over GF2X
493 F=convertNTLvec_pair_GF2X_long2FacCFFList(factors,LeadCoeff(f1),f.mvar());
495 return F;
496 }
497 }
498#endif
499#ifdef HAVE_NTL
500 {
501 // use NTL char p, univariate
503 {
505 zz_p::init(getCharacteristic());
506 }
507
508 // convert to NTL
509 zz_pX f1=convertFacCF2NTLzzpX(f);
510 zz_p leadcoeff = LeadCoeff(f1);
511
512 //make monic
513 f1=f1 / LeadCoeff(f1);
514 // factorize
515 vec_pair_zz_pX_long factors;
516 CanZass(factors,f1);
517
518 F=convertNTLvec_pair_zzpX_long2FacCFFList(factors,leadcoeff,f.mvar());
519 //test_cff(F,f);
521 return F;
522 }
523#endif
524#if !defined(HAVE_NTL) && !defined(HAVE_FLINT)
525 // Use Factory without NTL and without FLINT: char p, univariate
526 {
527 if ( isOn( SW_BERLEKAMP ) )
528 F=FpFactorizeUnivariateB( f, issqrfree );
529 else
530 F=FpFactorizeUnivariateCZ( f, issqrfree, 0, Variable(), Variable() );
531 return F;
532 }
533#endif
534 }
535 else // char p, multivariate
536 {
538 {
539 #if defined(HAVE_NTL)
540 if (issqrfree)
541 {
542 CFList factors;
544 factors= GFSqrfFactorize (f);
545 for (CFListIterator i= factors; i.hasItem(); i++)
546 F.append (CFFactor (i.getItem(), 1));
547 }
548 else
549 {
551 F= GFFactorize (f);
552 }
553 #else
554 factoryError ("multivariate factorization over GF depends on NTL(missing)");
555 return CFFList (CFFactor (f, 1));
556 #endif
557 }
558 else
559 {
560 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20700) && defined(HAVE_NTL)
561 if (!isOn(SW_USE_FL_FAC_P))
562 {
563 #endif
564 #if defined(HAVE_NTL)
565 if (issqrfree)
566 {
567 CFList factors;
569 factors= FpSqrfFactorize (f);
570 for (CFListIterator i= factors; i.hasItem(); i++)
571 F.append (CFFactor (i.getItem(), 1));
572 goto end_charp;
573 }
574 else
575 {
577 F= FpFactorize (f);
578 goto end_charp;
579 }
580 #endif
581 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20700) && defined(HAVE_NTL)
582 }
583 #endif
584 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20700)
585 nmod_mpoly_ctx_t ctx;
586 nmod_mpoly_ctx_init(ctx,f.level(),ORD_LEX,getCharacteristic());
587 nmod_mpoly_t Flint_f;
588 nmod_mpoly_init(Flint_f,ctx);
589 convFactoryPFlintMP(f,Flint_f,ctx,f.level());
590 nmod_mpoly_factor_t factors;
591 nmod_mpoly_factor_init(factors,ctx);
592 int okay;
593 if (issqrfree) okay=nmod_mpoly_factor_squarefree(factors,Flint_f,ctx);
594 else okay=nmod_mpoly_factor(factors,Flint_f,ctx);
595 nmod_mpoly_t fac;
596 nmod_mpoly_init(fac,ctx);
597 CanonicalForm cf_fac;
598 int cf_exp;
599 cf_fac=nmod_mpoly_factor_get_constant_ui(factors,ctx);
600 F.append(CFFactor(cf_fac,1));
601 for(int i=nmod_mpoly_factor_length(factors,ctx)-1; i>=0; i--)
602 {
603 nmod_mpoly_factor_get_base(fac,factors,i,ctx);
604 cf_fac=convFlintMPFactoryP(fac,ctx,f.level());
605 cf_exp=nmod_mpoly_factor_get_exp_si(factors,i,ctx);
606 F.append(CFFactor(cf_fac,cf_exp));
607 }
608 nmod_mpoly_factor_clear(factors,ctx);
609 nmod_mpoly_clear(Flint_f,ctx);
610 nmod_mpoly_ctx_clear(ctx);
611 if (okay==0)
612 {
615 F=factorize(f,issqrfree);
618 }
619 #endif
620 #if !defined(HAVE_FLINT) || (__FLINT_RELEASE < 20700)
621 #ifndef HAVE_NTL
622 factoryError ("multivariate factorization depends on NTL/FLINT(missing)");
623 return CFFList (CFFactor (f, 1));
624 #endif
625 #endif
626 }
627 }
628 }
629 else // char 0
630 {
631 bool on_rational = isOn(SW_RATIONAL);
634 CanonicalForm fz = f * cd;
636 if ( f.isUnivariate() )
637 {
638 CanonicalForm ic=icontent(fz);
639 fz/=ic;
640 if (fz.degree()==1)
641 {
642 F=CFFList(CFFactor(fz,1));
643 F.insert(CFFactor(ic,1));
644 }
645 else
646 #if defined(HAVE_FLINT) && (__FLINT_RELEASE>=20503) && (__FLINT_RELEASE!= 20600)
647 {
648 // FLINT 2.6.0 has a bug:
649 // factorize x^12-13*x^10-13*x^8+13*x^4+13*x^2-1 runs forever
650 // use FLINT: char 0, univariate
651 fmpz_poly_t f1;
653 fmpz_poly_factor_t result;
654 fmpz_poly_factor_init (result);
655 fmpz_poly_factor(result, f1);
657 fmpz_poly_factor_clear (result);
658 fmpz_poly_clear (f1);
659 if ( ! ic.isOne() )
660 {
661 // according to convertFLINTfmpz_polyfactor2FcaCFFlist,
662 // first entry is in CoeffDomain
663 CFFactor new_first( F.getFirst().factor() * ic );
664 F.removeFirst();
665 F.insert( new_first );
666 }
667 }
668 goto end_char0;
669 #elif defined(HAVE_NTL)
670 {
671 //use NTL
672 ZZ c;
673 vec_pair_ZZX_long factors;
674 //factorize the converted polynomial
675 factor(c,factors,convertFacCF2NTLZZX(fz));
676
677 //convert the result back to Factory
679 if ( ! ic.isOne() )
680 {
681 // according to convertNTLvec_pair_ZZX_long2FacCFFList
682 // first entry is in CoeffDomain
683 CFFactor new_first( F.getFirst().factor() * ic );
684 F.removeFirst();
685 F.insert( new_first );
686 }
687 }
688 goto end_char0;
689 #else
690 {
691 //Use Factory without NTL: char 0, univariate
692 F = ZFactorizeUnivariate( fz, issqrfree );
693 goto end_char0;
694 }
695 #endif
696 }
697 else // multivariate, char 0
698 {
699 #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20700)
701 {
702 On (SW_RATIONAL);
703 fmpz_mpoly_ctx_t ctx;
704 fmpz_mpoly_ctx_init(ctx,f.level(),ORD_LEX);
705 fmpz_mpoly_t Flint_f;
706 fmpz_mpoly_init(Flint_f,ctx);
707 convFactoryPFlintMP(fz,Flint_f,ctx,fz.level());
708 fmpz_mpoly_factor_t factors;
709 fmpz_mpoly_factor_init(factors,ctx);
710 int rr;
711 if (issqrfree) rr=fmpz_mpoly_factor_squarefree(factors,Flint_f,ctx);
712 else rr=fmpz_mpoly_factor(factors,Flint_f,ctx);
713 if (rr==0) printf("fail\n");
714 fmpz_mpoly_t fac;
715 fmpz_mpoly_init(fac,ctx);
716 CanonicalForm cf_fac;
717 int cf_exp;
718 fmpz_t c;
719 fmpz_init(c);
720 fmpz_mpoly_factor_get_constant_fmpz(c,factors,ctx);
721 cf_fac=convertFmpz2CF(c);
722 fmpz_clear(c);
723 F.append(CFFactor(cf_fac,1));
724 for(int i=fmpz_mpoly_factor_length(factors,ctx)-1; i>=0; i--)
725 {
726 fmpz_mpoly_factor_get_base(fac,factors,i,ctx);
727 cf_fac=convFlintMPFactoryP(fac,ctx,f.level());
728 cf_exp=fmpz_mpoly_factor_get_exp_si(factors,i,ctx);
729 F.append(CFFactor(cf_fac,cf_exp));
730 }
731 fmpz_mpoly_factor_clear(factors,ctx);
732 fmpz_mpoly_clear(Flint_f,ctx);
733 fmpz_mpoly_ctx_clear(ctx);
734 goto end_char0;
735 }
736 #endif
737 #if defined(HAVE_NTL)
738 On (SW_RATIONAL);
739 if (issqrfree)
740 {
741 CFList factors= ratSqrfFactorize (fz);
742 for (CFListIterator i= factors; i.hasItem(); i++)
743 F.append (CFFactor (i.getItem(), 1));
744 }
745 else
746 {
747 F = ratFactorize (fz);
748 }
749 #endif
750 #if !defined(HAVE_FLINT) || (__FLINT_RELEASE < 20700)
751 #ifndef HAVE_NTL
752 F=ZFactorizeMultivariate(fz, issqrfree);
753 #endif
754 #endif
755 }
756
757end_char0:
758 if ( on_rational )
760 else
762 if ( ! cd.isOne() )
763 {
764 CFFactor new_first( F.getFirst().factor() / cd );
765 F.removeFirst();
766 F.insert( new_first );
767 }
768 }
769
770#if defined(HAVE_NTL)
771end_charp:
772#endif
774 return F;
775}
CanonicalForm convertFmpz2CF(const fmpz_t coefficient)
conversion of a FLINT integer to CanonicalForm
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
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)
CFFList convertNTLvec_pair_zzpX_long2FacCFFList(const vec_pair_zz_pX_long &e, const zz_p cont, const Variable &x)
zz_pX convertFacCF2NTLzzpX(const CanonicalForm &f)
VAR long fac_NTL_char
Definition NTLconvert.cc:46
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.
bool isOn(int sw)
switches
void On(int sw)
switches
void Off(int sw)
switches
CanonicalForm FACTORY_PUBLIC icontent(const CanonicalForm &f)
CanonicalForm icontent ( const CanonicalForm & f ).
Definition cf_gcd.cc:74
int degree(const CanonicalForm &f)
bool hasFirstAlgVar(const CanonicalForm &f, Variable &a)
check if poly f contains an algebraic variable a
Definition cf_ops.cc:679
ListIterator< CFFactor > CFFListIterator
ListIterator< CanonicalForm > CFListIterator
List< CFFactor > CFFList
Factor< CanonicalForm > CFFactor
List< CanonicalForm > CFList
int FACTORY_PUBLIC getCharacteristic()
Definition cf_char.cc:70
int i
Definition cfEzgcd.cc:132
CanonicalForm cd(bCommonDen(FF))
Definition cfModGcd.cc:4097
CanonicalForm bCommonDen(const CanonicalForm &f)
void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r,...
EXTERN_VAR int singular_homog_flag
#define ASSERT(expression, message)
Definition cf_assert.h:99
static const int SW_USE_FL_GCD_P
set to 1 to use Flints gcd over F_p
Definition cf_defs.h:47
static const int SW_RATIONAL
set to 1 for computations over Q
Definition cf_defs.h:31
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition cf_defs.h:39
static const int SW_USE_FL_FAC_0
set to 1 to prefer flints multivariate factorization over Z/p
Definition cf_defs.h:57
static const int SW_USE_FL_FAC_P
set to 1 to prefer flints multivariate factorization over Z/p
Definition cf_defs.h:55
static const int SW_BERLEKAMP
set to 1 to use Factorys Berlekamp alg.
Definition cf_defs.h:51
#define GaloisFieldDomain
Definition cf_defs.h:18
Variable get_max_degree_Variable(const CanonicalForm &f)
get_max_degree_Variable returns Variable with highest degree.
Definition cf_factor.cc:266
int cmpCF(const CFFactor &f, const CFFactor &g)
Definition cf_factor.cc:400
CanonicalForm homogenize(const CanonicalForm &f, const Variable &x)
homogenize homogenizes f with Variable x
Definition cf_factor.cc:319
CFFList factorize(const CanonicalForm &f, bool issqrfree)
factorization over or
Definition cf_factor.cc:411
CanonicalForm compress(const CanonicalForm &f, CFMap &m)
CanonicalForm compress ( const CanonicalForm & f, CFMap & m ).
Definition cf_map.cc:210
VAR void(* factoryError)(const char *s)
Definition cf_util.cc:80
static int gettype()
Definition cf_factory.h:28
class CFMap
Definition cf_map.h:85
factory's main class
int degree() const
Returns -1 for the zero polynomial and 0 if CO is in a base domain.
Variable mvar() const
mvar() returns the main variable of CO or Variable() if CO is in a base domain.
CF_NO_INLINE bool isOne() const
int level() const
level() returns the level of CO.
T factor() const
T getFirst() const
void removeFirst()
void sort(int(*)(const T &, const T &))
void append(const T &)
void insert(const T &)
factory's class for variables
Definition factory.h:127
Variable alpha
return result
CanonicalForm factor
Definition facAbsFact.cc:97
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
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
int j
Definition facHensel.cc:110
convertFacCF2nmod_poly_t(FLINTmipo, M)
nmod_poly_clear(FLINTmipo)
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 ZFactorizeUnivariate(const CanonicalForm &ff, bool issqrfree=false)
VAR int xn
Definition walk.cc:4509

◆ factorize() [2/2]

CFFList factorize ( const CanonicalForm & f,
const Variable & alpha )

factorization over $ F_p(\alpha) $ or $ Q(\alpha) $

Definition at line 780 of file cf_factor.cc.

781{
782 if ( f.inCoeffDomain() )
783 return CFFList( f );
784 //out_cf("factorize:",f,"==================================\n");
785 //out_cf("mipo:",getMipo(alpha),"\n");
786
787 CFFList F;
788 ASSERT( alpha.level() < 0 && getReduce (alpha), "not an algebraic extension" );
789#ifndef NOASSERT
791 if (hasFirstAlgVar(f, beta))
792 ASSERT (beta == alpha, "f has an algebraic variable that \
793 does not coincide with alpha");
794#endif
795 int ch=getCharacteristic();
796 if (ch>0)
797 {
798 if (f.isUnivariate())
799 {
800#ifdef HAVE_NTL
801 if (/*getCharacteristic()*/ch==2)
802 {
803 // special case : GF2
804
805 // remainder is two ==> nothing to do
806
807 // set minimal polynomial in NTL using the optimized conversion routines for characteristic 2
808 GF2X minPo=convertFacCF2NTLGF2X(getMipo(alpha,f.mvar()));
809 GF2E::init (minPo);
810
811 // convert to NTL again using the faster conversion routines
812 GF2EX f1;
813 if (isPurePoly(f))
814 {
815 GF2X f_tmp=convertFacCF2NTLGF2X(f);
816 f1=to_GF2EX(f_tmp);
817 }
818 else
819 f1=convertFacCF2NTLGF2EX(f,minPo);
820
821 // make monic (in Z/2(a))
822 GF2E f1_coef=LeadCoeff(f1);
823 MakeMonic(f1);
824
825 // factorize using NTL
826 vec_pair_GF2EX_long factors;
827 CanZass(factors,f1);
828
829 // return converted result
830 F=convertNTLvec_pair_GF2EX_long2FacCFFList(factors,f1_coef,f.mvar(),alpha);
832 return F;
833 }
834#endif
835#if (HAVE_FLINT && __FLINT_RELEASE >= 20400)
836 {
837 // use FLINT
838 nmod_poly_t FLINTmipo, leadingCoeff;
839 fq_nmod_ctx_t fq_con;
840
841 nmod_poly_init (FLINTmipo, ch);
842 nmod_poly_init (leadingCoeff, ch);
844
845 fq_nmod_ctx_init_modulus (fq_con, FLINTmipo, "Z");
846 fq_nmod_poly_t FLINTF;
848 fq_nmod_poly_factor_t res;
849 fq_nmod_poly_factor_init (res, fq_con);
850 fq_nmod_poly_factor (res, leadingCoeff, FLINTF, fq_con);
852 F.insert (CFFactor (Lc (f), 1));
853
854 fq_nmod_poly_factor_clear (res, fq_con);
855 fq_nmod_poly_clear (FLINTF, fq_con);
856 nmod_poly_clear (FLINTmipo);
857 nmod_poly_clear (leadingCoeff);
860 return F;
861 }
862#endif
863#ifdef HAVE_NTL
864 {
865 // use NTL
866 if (fac_NTL_char != ch)
867 {
868 fac_NTL_char = ch;
869 zz_p::init(ch);
870 }
871
872 // set minimal polynomial in NTL
873 zz_pX minPo=convertFacCF2NTLzzpX(getMipo(alpha));
874 zz_pE::init (minPo);
875
876 // convert to NTL
877 zz_pEX f1=convertFacCF2NTLzz_pEX(f,minPo);
878 zz_pE leadcoeff= LeadCoeff(f1);
879
880 //make monic
881 f1=f1 / leadcoeff; //leadcoeff==LeadCoeff(f1);
882
883 // factorize
884 vec_pair_zz_pEX_long factors;
885 CanZass(factors,f1);
886
887 // return converted result
888 F=convertNTLvec_pair_zzpEX_long2FacCFFList(factors,leadcoeff,f.mvar(),alpha);
889 //test_cff(F,f);
891 return F;
892 }
893#endif
894#if !defined(HAVE_NTL) && !defined(HAVE_FLINT)
895 // char p, extension, univariate
896 CanonicalForm c=Lc(f);
897 CanonicalForm fc=f/c;
898 F=FpFactorizeUnivariateCZ( fc, false, 1, alpha, Variable() );
899 F.insert (CFFactor (c, 1));
900#endif
901 }
902 else // char p, multivariate
903 {
904 #if (HAVE_FLINT && __FLINT_RELEASE >= 20700)
905 // use FLINT
906 nmod_poly_t FLINTmipo;
907 fq_nmod_ctx_t fq_con;
908 fq_nmod_mpoly_ctx_t ctx;
909
910 nmod_poly_init (FLINTmipo, ch);
912
913 fq_nmod_ctx_init_modulus (fq_con, FLINTmipo, "Z");
914 fq_nmod_mpoly_ctx_init(ctx,f.level(),ORD_LEX,fq_con);
915
916 fq_nmod_mpoly_t FLINTF;
917 fq_nmod_mpoly_init(FLINTF,ctx);
918 convertFacCF2Fq_nmod_mpoly_t(FLINTF,f,ctx,f.level(),fq_con);
919 fq_nmod_mpoly_factor_t res;
920 fq_nmod_mpoly_factor_init (res, ctx);
921 fq_nmod_mpoly_factor (res, FLINTF, ctx);
922 F= convertFLINTFq_nmod_mpoly_factor2FacCFFList (res, ctx,f.level(),fq_con,alpha);
923 //F.insert (CFFactor (Lc (f), 1));
924
925 fq_nmod_mpoly_factor_clear (res, ctx);
926 fq_nmod_mpoly_clear (FLINTF, ctx);
927 nmod_poly_clear (FLINTmipo);
928 fq_nmod_mpoly_ctx_clear (ctx);
931 return F;
932 #elif defined(HAVE_NTL)
933 F= FqFactorize (f, alpha);
934 #else
935 factoryError ("multivariate factorization over Z/pZ(alpha) depends on NTL/Flint(missing)");
936 return CFFList (CFFactor (f, 1));
937 #endif
938 }
939 }
940 else // Q(a)[x]
941 {
942 if (f.isUnivariate())
943 {
944 F= AlgExtFactorize (f, alpha);
945 }
946 else //Q(a)[x1,...,xn]
947 {
948 #if defined(HAVE_NTL) || defined(HAVE_FLINT)
949 F= ratFactorize (f, alpha);
950 #else
951 factoryError ("multivariate factorization over Q(alpha) depends on NTL or FLINT (missing)");
952 return CFFList (CFFactor (f, 1));
953 #endif
954 }
955 }
957 return F;
958}
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
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.
GF2EX convertFacCF2NTLGF2EX(const CanonicalForm &f, const GF2X &mipo)
CanonicalForm in Z_2(a)[X] to NTL GF2EX.
CanonicalForm Lc(const CanonicalForm &f)
bool isPurePoly(const CanonicalForm &f)
Definition cf_factor.cc:250
CanonicalForm res
Definition facAbsFact.cc:60
Variable beta
Definition facAbsFact.cc:95
CFFList AlgExtFactorize(const CanonicalForm &F, const Variable &alpha)
factorize a univariate polynomial over algebraic extension of Q
Definition facAlgExt.cc:370
CFFList FqFactorize(const CanonicalForm &G, const Variable &alpha, bool substCheck=true)
factorize a multivariate polynomial over
fq_nmod_ctx_t fq_con
Definition facHensel.cc:99
fq_nmod_ctx_clear(fq_con)
nmod_poly_init(FLINTmipo, getCharacteristic())
fq_nmod_ctx_init_modulus(fq_con, FLINTmipo, "Z")
fq_nmod_poly_clear(prod, fq_con)
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
Definition variable.cc:207
bool getReduce(const Variable &alpha)
Definition variable.cc:232

◆ find_exp()

void find_exp ( const CanonicalForm & f,
int * exp_f )

Definition at line 68 of file cf_factor.cc.

69{
70 if ( ! f.inCoeffDomain() )
71 {
72 int e=f.level();
73 CFIterator i = f;
74 if (e>=0)
75 {
76 if (i.exp() > exp_f[e]) exp_f[e]=i.exp();
77 }
78 for (; i.hasTerms(); i++ )
79 {
80 find_exp(i.coeff(), exp_f);
81 }
82 }
83}
void find_exp(const CanonicalForm &f, int *exp_f)
Definition cf_factor.cc:68
class to iterate through CanonicalForm's
Definition cf_iter.h:44

◆ find_mvar()

int find_mvar ( const CanonicalForm & f)

Definition at line 85 of file cf_factor.cc.

86{
87 int mv=f.level();
88 int *exp_f=NEW_ARRAY(int,mv+1);
89 int i;
90 for(i=mv;i>0;i--) exp_f[i]=0;
91 find_exp(f,exp_f);
92 for(i=mv;i>0;i--)
93 {
94 if ((exp_f[i]>0) && (exp_f[i]<exp_f[mv]))
95 {
96 mv=i;
97 }
98 }
99 DELETE_ARRAY(exp_f);
100 return mv;
101}
#define DELETE_ARRAY(P)
Definition cf_defs.h:65
#define NEW_ARRAY(T, N)
Definition cf_defs.h:64

◆ get_max_degree_Variable()

Variable get_max_degree_Variable ( const CanonicalForm & f)

get_max_degree_Variable returns Variable with highest degree.

We assume f is not a constant!

Definition at line 266 of file cf_factor.cc.

267{
268 ASSERT( ( ! f.inCoeffDomain() ), "no constants" );
269 int max=0, maxlevel=0, n=level(f);
270 for ( int i=1; i<=n; i++ )
271 {
272 if (degree(f,Variable(i)) >= max)
273 {
274 max= degree(f,Variable(i)); maxlevel= i;
275 }
276 }
277 return Variable(maxlevel);
278}
int level(const CanonicalForm &f)
static int max(int a, int b)
Definition fast_mult.cc:264

◆ get_Terms()

CFList get_Terms ( const CanonicalForm & f)

Definition at line 295 of file cf_factor.cc.

295 {
296 CFList result,dummy,dummy2;
299
300 if ( getNumVars(f) == 0 ) result.append(f);
301 else{
302 Variable _x(level(f));
303 for ( i=f; i.hasTerms(); i++ ){
304 getTerms(i.coeff(), 1, dummy);
305 for ( j=dummy; j.hasItem(); j++ )
306 result.append(j.getItem() * power(_x, i.exp()));
307
308 dummy= dummy2; // have to initalize new
309 }
310 }
311 return result;
312}
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
int getNumVars(const CanonicalForm &f)
int getNumVars ( const CanonicalForm & f )
Definition cf_ops.cc:314
void getTerms(const CanonicalForm &f, const CanonicalForm &t, CFList &result)
get_Terms: Split the polynomial in the containing terms.
Definition cf_factor.cc:285

◆ getTerms()

void getTerms ( const CanonicalForm & f,
const CanonicalForm & t,
CFList & result )

get_Terms: Split the polynomial in the containing terms.

getTerms: the real work is done here.

Definition at line 285 of file cf_factor.cc.

286{
287 if ( getNumVars(f) == 0 ) result.append(f*t);
288 else{
289 Variable x(level(f));
290 for ( CFIterator i=f; i.hasTerms(); i++ )
291 getTerms( i.coeff(), t*power(x,i.exp()), result);
292 }
293}
Variable x
Definition cfModGcd.cc:4090

◆ homogenize() [1/2]

CanonicalForm homogenize ( const CanonicalForm & f,
const Variable & x )

homogenize homogenizes f with Variable x

Definition at line 319 of file cf_factor.cc.

320{
321#if 0
322 int maxdeg=totaldegree(f), deg;
324 CanonicalForm elem, result(0);
325
326 for (i=f; i.hasTerms(); i++)
327 {
328 elem= i.coeff()*power(f.mvar(),i.exp());
329 deg = totaldegree(elem);
330 if ( deg < maxdeg )
331 result += elem * power(x,maxdeg-deg);
332 else
333 result+=elem;
334 }
335 return result;
336#else
337 CFList Newlist, Termlist= get_Terms(f);
338 int maxdeg=totaldegree(f), deg;
340 CanonicalForm elem, result(0);
341
342 for (i=Termlist; i.hasItem(); i++)
343 {
344 elem= i.getItem();
345 deg = totaldegree(elem);
346 if ( deg < maxdeg )
347 Newlist.append(elem * power(x,maxdeg-deg));
348 else
349 Newlist.append(elem);
350 }
351 for (i=Newlist; i.hasItem(); i++) // rebuild
352 result += i.getItem();
353
354 return result;
355#endif
356}
int totaldegree(const CanonicalForm &f)
int totaldegree ( const CanonicalForm & f )
Definition cf_ops.cc:523
CFList get_Terms(const CanonicalForm &f)
Definition cf_factor.cc:295

◆ homogenize() [2/2]

CanonicalForm homogenize ( const CanonicalForm & f,
const Variable & x,
const Variable & v1,
const Variable & v2 )

Definition at line 359 of file cf_factor.cc.

360{
361#if 0
362 int maxdeg=totaldegree(f), deg;
364 CanonicalForm elem, result(0);
365
366 for (i=f; i.hasTerms(); i++)
367 {
368 elem= i.coeff()*power(f.mvar(),i.exp());
369 deg = totaldegree(elem);
370 if ( deg < maxdeg )
371 result += elem * power(x,maxdeg-deg);
372 else
373 result+=elem;
374 }
375 return result;
376#else
377 CFList Newlist, Termlist= get_Terms(f);
378 int maxdeg=totaldegree(f), deg;
380 CanonicalForm elem, result(0);
381
382 for (i=Termlist; i.hasItem(); i++)
383 {
384 elem= i.getItem();
385 deg = totaldegree(elem,v1,v2);
386 if ( deg < maxdeg )
387 Newlist.append(elem * power(x,maxdeg-deg));
388 else
389 Newlist.append(elem);
390 }
391 for (i=Newlist; i.hasItem(); i++) // rebuild
392 result += i.getItem();
393
394 return result;
395#endif
396}

◆ isPurePoly()

bool isPurePoly ( const CanonicalForm & f)

Definition at line 250 of file cf_factor.cc.

251{
252 if (f.level()<=0) return false;
253 for (CFIterator i=f;i.hasTerms();i++)
254 {
255 if (!(i.coeff().inBaseDomain())) return false;
256 }
257 return true;
258}

◆ isPurePoly_m()

bool isPurePoly_m ( const CanonicalForm & f)

Definition at line 240 of file cf_factor.cc.

241{
242 if (f.inBaseDomain()) return true;
243 if (f.level()<0) return false;
244 for (CFIterator i=f;i.hasTerms();i++)
245 {
246 if (!isPurePoly_m(i.coeff())) return false;
247 }
248 return true;
249}
bool isPurePoly_m(const CanonicalForm &f)
Definition cf_factor.cc:240

◆ out_cf()

void out_cf ( const char * s1,
const CanonicalForm & f,
const char * s2 )

Definition at line 105 of file cf_factor.cc.

106{
107 printf("%s",s1);
108 if (f.isZero()) printf("+0");
109 //else if (! f.inCoeffDomain() )
110 else if (! f.inBaseDomain() )
111 {
112 int l = f.level();
113 for ( CFIterator i = f; i.hasTerms(); i++ )
114 {
115 int e=i.exp();
116 if (i.coeff().isOne())
117 {
118 printf("+");
119 if (e==0) printf("1");
120 else
121 {
122 printf("%c",'a'+l-1);
123 if (e!=1) printf("^%d",e);
124 }
125 }
126 else
127 {
128 out_cf("+(",i.coeff(),")");
129 if (e!=0)
130 {
131 printf("*%c",'a'+l-1);
132 if (e!=1) printf("^%d",e);
133 }
134 }
135 }
136 }
137 else
138 {
139 if ( f.isImm() )
140 {
142 {
143 long a= imm2int (f.getval());
144 if ( a == gf_q )
145 printf ("+%ld", a);
146 else if ( a == 0L )
147 printf ("+1");
148 else if ( a == 1L )
149 printf ("+%c",gf_name);
150 else
151 {
152 printf ("+%c",gf_name);
153 printf ("^%ld",a);
154 }
155 }
156 else
157 {
158 long l=f.intval();
159 if (l<0) printf("%ld",l);
160 else printf("+%ld",l);
161 }
162 }
163 else
164 {
165 #ifdef NOSTREAMIO
166 if (f.inZ())
167 {
168 mpz_t m;
170 char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
171 str = mpz_get_str( str, 10, m );
172 puts(str);
173 delete[] str;
174 mpz_clear(m);
175 }
176 else if (f.inQ())
177 {
178 mpz_t m;
180 char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
181 str = mpz_get_str( str, 10, m );
182 while(str[strlen(str)]<' ') { str[strlen(str)]='\0'; }
183 puts(str);putchar('/');
184 delete[] str;
185 mpz_clear(m);
187 str = new char[mpz_sizeinbase( m, 10 ) + 2];
188 str = mpz_get_str( str, 10, m );
189 while(str[strlen(str)]<' ') { str[strlen(str)]='\0'; }
190 puts(str);
191 delete[] str;
192 mpz_clear(m);
193 }
194 #else
195 std::cout << f;
196 #endif
197 }
198 //if (f.inZ()) printf("(Z)");
199 //else if (f.inQ()) printf("(Q)");
200 //else if (f.inFF()) printf("(FF)");
201 //else if (f.inPP()) printf("(PP)");
202 //else if (f.inGF()) printf("(PP)");
203 //else
204 if (f.inExtension()) printf("E(%d)",f.level());
205 }
206 printf("%s",s2);
207}
int l
Definition cfEzgcd.cc:100
int m
Definition cfEzgcd.cc:128
void out_cf(const char *s1, const CanonicalForm &f, const char *s2)
Definition cf_factor.cc:105
void FACTORY_PUBLIC gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:20
void FACTORY_PUBLIC gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:40
VAR int gf_q
Definition gfops.cc:47
VAR char gf_name
Definition gfops.cc:52
static long imm2int(const InternalCF *const imm)
Definition imm.h:70
char * str(leftv arg)
Definition shared.cc:699

◆ out_cff()

void out_cff ( CFFList & L)

Definition at line 208 of file cf_factor.cc.

209{
210 //int n = L.length();
211 CFFListIterator J=L;
212 int j=0;
213 for ( ; J.hasItem(); J++, j++ )
214 {
215 printf("F%d",j);out_cf(":",J.getItem().factor()," ^ ");
216 printf("%d\n", J.getItem().exp());
217 }
218}
int exp() const
T & getItem() const

◆ sqrFree()

CFFList sqrFree ( const CanonicalForm & f,
bool sort )

squarefree factorization

Definition at line 963 of file cf_factor.cc.

964{
965// ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
967
968 if ( getCharacteristic() == 0 )
969 result = sqrFreeZ( f );
970 else
971 {
973 if (hasFirstAlgVar (f, alpha))
974 result = FqSqrf( f, alpha );
975 else
976 result= FpSqrf (f);
977 }
978 if (sort)
979 {
980 CFFactor buf= result.getFirst();
981 result.removeFirst();
983 result.insert (buf);
984 }
985 return result;
986}
static void sort(int **points, int sizePoints)
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
CFFList sqrFreeZ(const CanonicalForm &a)
CFFList sortCFFList(CFFList &F)
int status int void * buf
Definition si_signals.h:69

◆ test_cff()

void test_cff ( CFFList & L,
const CanonicalForm & f )

Definition at line 219 of file cf_factor.cc.

220{
221 //int n = L.length();
222 CFFListIterator J=L;
223 CanonicalForm t=1;
224 int j=0;
225 if (!(L.getFirst().factor().inCoeffDomain()))
226 printf("first entry is not const\n");
227 for ( ; J.hasItem(); J++, j++ )
228 {
230 if (tt.inCoeffDomain() && (j!=0))
231 printf("other entry is const\n");
232 j=J.getItem().exp();
233 while(j>0) { t*=tt; j--; }
234 }
235 if (!(f-t).isZero()) { printf("problem:\n");out_cf("factor:",f," has problems\n");}
236}
bool inCoeffDomain() const
bool isZero(const CFArray &A)
checks if entries of A are zero

Variable Documentation

◆ singular_homog_flag

VAR int singular_homog_flag =1

Definition at line 398 of file cf_factor.cc.