Changeset e71776 in git for factory/cf_factor.cc
- Timestamp:
- Mar 10, 2014, 11:59:00 AM (10 years ago)
- Branches:
- (u'spielwiese', 'a719bcf0b8dbc648b128303a49777a094b57592c')
- Children:
- c78743104173a106f27611fdf3b220e3b470d84e
- Parents:
- df8aaffd8917f49072699c87bb028454653cacc3
- git-author:
- Martin Lee <martinlee84@web.de>2014-03-10 11:59:00+01:00
- git-committer:
- Martin Lee <martinlee84@web.de>2014-03-11 11:06:26+01:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/cf_factor.cc
rdf8aaf re71776 389 389 if ( f.inCoeffDomain() ) 390 390 return CFFList( f ); 391 #ifndef NOASSERT 392 Variable a; 393 ASSERT (!hasFirstAlgVar (f, a), "f has an algebraic variable use factorize \ 394 ( const CanonicalForm & f, const Variable & alpha ) instead"); 395 #endif 391 396 //out_cf("factorize:",f,"==================================\n"); 392 397 if (! f.isUnivariate() ) … … 441 446 else 442 447 #endif 443 if (isOn(SW_USE_NTL) && (isPurePoly(f)))444 448 { 445 449 // USE NTL … … 484 488 } 485 489 } 486 else 490 #else 491 // Use Factory without NTL 492 factoryError ("univariate factorization depends on NTL(missing)"); 493 return CFFList (CFFactor (f, 1)); 487 494 #endif //HAVE_NTL 488 { // Use Factory without NTL489 factoryError ("univariate factorization depends on NTL(missing)");490 return CFFList (CFFactor (f, 1));491 }492 495 } 493 496 else … … 534 537 { 535 538 #ifdef HAVE_NTL 536 if ((isOn(SW_USE_NTL)) && (isPurePoly(f)))537 {538 //USE NTL539 CanonicalForm ic=icontent(fz);540 fz/=ic;541 ZZ c;542 vec_pair_ZZX_long factors;543 //factorize the converted polynomial 544 factor(c,factors,convertFacCF2NTLZZX(fz));545 546 //convert the result back to Factory547 F=convertNTLvec_pair_ZZX_long2FacCFFList(factors,c,fz.mvar());548 if ( ! ic.isOne() )539 //USE NTL 540 CanonicalForm ic=icontent(fz); 541 fz/=ic; 542 ZZ c; 543 vec_pair_ZZX_long factors; 544 //factorize the converted polynomial 545 factor(c,factors,convertFacCF2NTLZZX(fz)); 546 547 //convert the result back to Factory 548 F=convertNTLvec_pair_ZZX_long2FacCFFList(factors,c,fz.mvar()); 549 if ( ! ic.isOne() ) 550 { 551 if ( F.getFirst().factor().inCoeffDomain() ) 549 552 { 550 if ( F.getFirst().factor().inCoeffDomain() ) 551 { 552 CFFactor new_first( F.getFirst().factor() * ic ); 553 F.removeFirst(); 554 F.insert( new_first ); 555 } 556 else 557 F.insert( CFFactor( ic ) ); 553 CFFactor new_first( F.getFirst().factor() * ic ); 554 F.removeFirst(); 555 F.insert( new_first ); 558 556 } 559 557 else 558 F.insert( CFFactor( ic ) ); 559 } 560 else 561 { 562 if ( !F.getFirst().factor().inCoeffDomain() ) 560 563 { 561 if ( !F.getFirst().factor().inCoeffDomain() ) 562 { 563 CFFactor new_first( 1 ); 564 F.insert( new_first ); 565 } 564 CFFactor new_first( 1 ); 565 F.insert( new_first ); 566 566 } 567 567 } 568 568 #else 569 { 570 factoryError ("univariate factorization over Z depends on NTL(missing)"); 571 return CFFList (CFFactor (f, 1)); 572 } 569 factoryError ("univariate factorization over Z depends on NTL(missing)"); 570 return CFFList (CFFactor (f, 1)); 573 571 #endif 574 572 } … … 621 619 //out_cf("factorize:",f,"==================================\n"); 622 620 //out_cf("mipo:",getMipo(alpha),"\n"); 621 623 622 CFFList F; 624 ASSERT( alpha.level() < 0, "not an algebraic extension" ); 623 ASSERT( alpha.level() < 0 && getReduce (alpha), "not an algebraic extension" ); 624 #ifndef NOASSERT 625 Variable beta; 626 if (hasFirstAlgVar(f, beta)) 627 ASSERT (!hasFirstAlgVar (f, beta == alpha), "f has an algebraic variable that \ 628 does not coincide with alpha"); 629 #endif 625 630 int ch=getCharacteristic(); 626 631 if (f.isUnivariate()&& (ch>0)) 627 632 { 628 #ifdef HAVE_NTL 629 if (isOn(SW_USE_NTL)) 630 { 631 //USE NTL 632 if (ch>2) 633 { 633 #ifdef HAVE_NTL 634 //USE NTL 635 if (ch>2) 636 { 634 637 #if (HAVE_FLINT && __FLINT_VERSION_MINOR >= 4) 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 638 nmod_poly_t FLINTmipo, leadingCoeff; 639 fq_nmod_ctx_t fq_con; 640 641 nmod_poly_init (FLINTmipo, getCharacteristic()); 642 nmod_poly_init (leadingCoeff, getCharacteristic()); 643 convertFacCF2nmod_poly_t (FLINTmipo, getMipo (alpha)); 644 645 fq_nmod_ctx_init_modulus (fq_con, FLINTmipo, "Z"); 646 fq_nmod_poly_t FLINTF; 647 convertFacCF2Fq_nmod_poly_t (FLINTF, f, fq_con); 648 fq_nmod_poly_factor_t res; 649 fq_nmod_poly_factor_init (res, fq_con); 650 fq_nmod_poly_factor (res, leadingCoeff, FLINTF, fq_con); 651 F= convertFLINTFq_nmod_poly_factor2FacCFFList (res, f.mvar(), alpha, fq_con); 652 F.insert (CFFactor (Lc (f), 1)); 653 654 fq_nmod_poly_factor_clear (res, fq_con); 655 fq_nmod_poly_clear (FLINTF, fq_con); 656 nmod_poly_clear (FLINTmipo); 657 nmod_poly_clear (leadingCoeff); 658 fq_nmod_ctx_clear (fq_con); 656 659 #else 657 // First all cases with characteristic !=2 658 // set remainder 659 if (fac_NTL_char != getCharacteristic()) 660 { 661 fac_NTL_char = getCharacteristic(); 662 zz_p::init(getCharacteristic()); 663 } 664 665 // set minimal polynomial in NTL 666 zz_pX minPo=convertFacCF2NTLzzpX(getMipo(alpha)); 667 zz_pE::init (minPo); 668 669 // convert to NTL 670 zz_pEX f1=convertFacCF2NTLzz_pEX(f,minPo); 671 zz_pE leadcoeff= LeadCoeff(f1); 672 673 //make monic 674 f1=f1 / leadcoeff; 675 676 // factorize using NTL 677 vec_pair_zz_pEX_long factors; 678 CanZass(factors,f1); 679 680 // return converted result 681 F=convertNTLvec_pair_zzpEX_long2FacCFFList(factors,leadcoeff,f.mvar(),alpha); 682 #endif 683 } 684 else if (/*getCharacteristic()*/ch==2) 685 { 686 // special case : GF2 687 688 // remainder is two ==> nothing to do 689 690 // set minimal polynomial in NTL using the optimized conversion routines for characteristic 2 691 GF2X minPo=convertFacCF2NTLGF2X(getMipo(alpha,f.mvar())); 692 GF2E::init (minPo); 693 694 // convert to NTL again using the faster conversion routines 695 GF2EX f1; 696 if (isPurePoly(f)) 697 { 698 GF2X f_tmp=convertFacCF2NTLGF2X(f); 699 f1=to_GF2EX(f_tmp); 700 } 701 else 702 { 703 f1=convertFacCF2NTLGF2EX(f,minPo); 704 } 705 706 // make monic (in Z/2(a)) 707 GF2E f1_coef=LeadCoeff(f1); 708 MakeMonic(f1); 709 710 // factorize using NTL 711 vec_pair_GF2EX_long factors; 712 CanZass(factors,f1); 713 714 // return converted result 715 F=convertNTLvec_pair_GF2EX_long2FacCFFList(factors,f1_coef,f.mvar(),alpha); 660 // First all cases with characteristic !=2 661 // set remainder 662 if (fac_NTL_char != getCharacteristic()) 663 { 664 fac_NTL_char = getCharacteristic(); 665 zz_p::init(getCharacteristic()); 666 } 667 668 // set minimal polynomial in NTL 669 zz_pX minPo=convertFacCF2NTLzzpX(getMipo(alpha)); 670 zz_pE::init (minPo); 671 672 // convert to NTL 673 zz_pEX f1=convertFacCF2NTLzz_pEX(f,minPo); 674 zz_pE leadcoeff= LeadCoeff(f1); 675 676 //make monic 677 f1=f1 / leadcoeff; 678 679 // factorize using NTL 680 vec_pair_zz_pEX_long factors; 681 CanZass(factors,f1); 682 683 // return converted result 684 F=convertNTLvec_pair_zzpEX_long2FacCFFList(factors,leadcoeff,f.mvar(),alpha); 685 #endif 686 } 687 else if (/*getCharacteristic()*/ch==2) 688 { 689 // special case : GF2 690 691 // remainder is two ==> nothing to do 692 693 // set minimal polynomial in NTL using the optimized conversion routines for characteristic 2 694 GF2X minPo=convertFacCF2NTLGF2X(getMipo(alpha,f.mvar())); 695 GF2E::init (minPo); 696 697 // convert to NTL again using the faster conversion routines 698 GF2EX f1; 699 if (isPurePoly(f)) 700 { 701 GF2X f_tmp=convertFacCF2NTLGF2X(f); 702 f1=to_GF2EX(f_tmp); 716 703 } 717 704 else 718 { 719 } 720 } 721 else 722 #endif 723 { 724 factoryError ("univariate factorization depends on NTL(missing)"); 725 return CFFList (CFFactor (f, 1)); 726 } 705 f1=convertFacCF2NTLGF2EX(f,minPo); 706 707 // make monic (in Z/2(a)) 708 GF2E f1_coef=LeadCoeff(f1); 709 MakeMonic(f1); 710 711 // factorize using NTL 712 vec_pair_GF2EX_long factors; 713 CanZass(factors,f1); 714 715 // return converted result 716 F=convertNTLvec_pair_GF2EX_long2FacCFFList(factors,f1_coef,f.mvar(),alpha); 717 } 718 #else 719 factoryError ("univariate factorization depends on NTL(missing)"); 720 return CFFList (CFFactor (f, 1)); 721 #endif //HAVE_NTL 727 722 } 728 723 else if (ch>0)
Note: See TracChangeset
for help on using the changeset viewer.