Changeset 81d96c in git
- Timestamp:
- Feb 9, 2012, 5:59:15 PM (11 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- c0851051c3f2502093559a89e463f364c0816aa0
- Parents:
- 0e2e23228417d64209e60f3d18fa1bd11233839d
- git-author:
- Martin Lee <martinlee84@web.de>2012-02-09 17:59:15+01:00
- git-committer:
- Martin Lee <martinlee84@web.de>2012-04-04 14:42:25+02:00
- Location:
- factory
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/cf_gcd_smallp.cc
r0e2e23 r81d96c 26 26 27 27 #include "canonicalform.h" 28 #include "algext.h" 28 29 #include "cf_map.h" 29 30 #include "cf_util.h" … … 4032 4033 lcs [0]= shiftedLCsEval1.getFirst(); 4033 4034 lcs [1]= shiftedLCsEval2.getFirst(); 4034 henselLift122 (UEval.getFirst(), factors, liftBound, Pi, diophant, M,4035 lcs, false);4035 nonMonicHenselLift12 (UEval.getFirst(), factors, liftBound, Pi, diophant, M, 4036 lcs, false); 4036 4037 4037 4038 for (CFListIterator i= factors; i.hasItem(); i++) … … 4049 4050 for (int i= 1; i < U.level() - 1; i++) 4050 4051 liftBounds[i]= degree (shiftedU, Variable (i + 2)) + 1; 4051 factors= henselLift2 (UEval, factors, liftBounds, U.level() - 1, false,4052 shiftedLCsEval1, shiftedLCsEval2, Pi, diophant,4053 noOneToOne);4052 factors= nonMonicHenselLift2 (UEval, factors, liftBounds, U.level() - 1, 4053 false, shiftedLCsEval1, shiftedLCsEval2, Pi, 4054 diophant, noOneToOne); 4054 4055 delete [] liftBounds; 4055 4056 if (noOneToOne) -
factory/facFactorize.cc
r0e2e23 r81d96c 481 481 CFArray Pi; 482 482 CFList diophant; 483 henselLift122 (newSqrfPartF, factors, liftBound, Pi, diophant, M,484 leadingCoeffs, false);483 nonMonicHenselLift12 (newSqrfPartF, factors, liftBound, Pi, diophant, M, 484 leadingCoeffs, false); 485 485 486 486 if (sqrfPartF.level() > 2) -
factory/facFqBivarUtil.cc
r0e2e23 r81d96c 16 16 17 17 #include "cf_map.h" 18 #include "algext.h" 18 19 #include "cf_map_ext.h" 19 20 #include "templates/ftmpl_functions.h" -
factory/facFqFactorize.cc
r0e2e23 r81d96c 1658 1658 CFArray Pi; 1659 1659 CFList diophant; 1660 henselLift122 (newSqrfPartF, factors, liftBound, Pi, diophant, M,1661 leadingCoeffs, false);1660 nonMonicHenselLift12 (newSqrfPartF, factors, liftBound, Pi, diophant, M, 1661 leadingCoeffs, false); 1662 1662 1663 1663 if (sqrfPartF.level() > 2) -
factory/facHensel.cc
r0e2e23 r81d96c 25 25 #include "timing.h" 26 26 27 #include "algext.h" 27 28 #include "facHensel.h" 28 29 #include "facMul.h" 29 #include "cf_util.h"30 30 #include "fac_util.h" 31 31 #include "cf_algorithm.h" … … 125 125 } 126 126 127 static inline127 static 128 128 CFList mapinto (const CFList& L) 129 129 { … … 134 134 } 135 135 136 static inline136 static 137 137 int mod (const CFList& L, const CanonicalForm& p) 138 138 { … … 146 146 147 147 148 static inlinevoid148 static void 149 149 chineseRemainder (const CFList & x1, const CanonicalForm & q1, 150 150 const CFList & x2, const CanonicalForm & q2, … … 162 162 } 163 163 164 static inline164 static 165 165 CFList Farey (const CFList& L, const CanonicalForm& q) 166 166 { … … 171 171 } 172 172 173 static inline173 static 174 174 CFList replacevar (const CFList& L, const Variable& a, const Variable& b) 175 175 { … … 359 359 } 360 360 361 static inline362 361 CFList diophantine (const CanonicalForm& F, const CFList& factors) 363 362 { … … 669 668 } 670 669 671 static inline672 670 CFList 673 biDiophantine (const CanonicalForm& F, const CFList& factors, constint d)671 biDiophantine (const CanonicalForm& F, const CFList& factors, int d) 674 672 { 675 673 Variable y= F.mvar(); … … 770 768 } 771 769 772 static inline773 770 CFList 774 771 multiRecDiophantine (const CanonicalForm& F, const CFList& factors, 775 const CFList& recResult, const CFList& M, constint d)772 const CFList& recResult, const CFList& M, int d) 776 773 { 777 774 Variable y= F.mvar(); … … 859 856 } 860 857 861 static inline858 static 862 859 void 863 860 henselStep (const CanonicalForm& F, const CFList& factors, CFArray& bufFactors, … … 1101 1098 1102 1099 CFList 1103 henselLift23 (const CFList& eval, const CFList& factors, constint* l, CFList&1100 henselLift23 (const CFList& eval, const CFList& factors, int* l, CFList& 1104 1101 diophant, CFArray& Pi, CFMatrix& M) 1105 1102 { … … 1168 1165 CFList 1169 1166 henselLift (const CFList& F, const CFList& factors, const CFList& MOD, CFList& 1170 diophant, CFArray& Pi, CFMatrix& M, const int lOld, const int 1171 lNew) 1167 diophant, CFArray& Pi, CFMatrix& M, int lOld, int lNew) 1172 1168 { 1173 1169 diophant= multiRecDiophantine (F.getFirst(), factors, diophant, MOD, lOld); … … 1209 1205 1210 1206 CFList 1211 henselLift (const CFList& eval, const CFList& factors, const int* l, const int1212 lLength,bool sort)1207 henselLift (const CFList& eval, const CFList& factors, int* l, int lLength, 1208 bool sort) 1213 1209 { 1214 1210 CFList diophant; … … 1243 1239 } 1244 1240 1241 // nonmonic 1242 1245 1243 void 1246 henselStep122 (const CanonicalForm& F, const CFList& factors,1247 CFArray& bufFactors, const CFList& diophant, CFMatrix& M,1248 CFArray& Pi, int j, const CFArray& /*LCs*/)1244 nonMonicHenselStep12 (const CanonicalForm& F, const CFList& factors, 1245 CFArray& bufFactors, const CFList& diophant, CFMatrix& M, 1246 CFArray& Pi, int j, const CFArray& /*LCs*/) 1249 1247 { 1250 1248 Variable x= F.mvar(); … … 1455 1453 1456 1454 void 1457 henselLift122 (const CanonicalForm& F, CFList& factors, int l, CFArray& Pi, 1458 CFList& diophant, CFMatrix& M, const CFArray& LCs, bool sort) 1455 nonMonicHenselLift12 (const CanonicalForm& F, CFList& factors, int l, 1456 CFArray& Pi, CFList& diophant, CFMatrix& M, 1457 const CFArray& LCs, bool sort) 1459 1458 { 1460 1459 if (sort) … … 1522 1521 1523 1522 for (i= 1; i < l; i++) 1524 henselStep122 (F, bufFactors2, bufFactors, diophant, M, Pi, i, LCs);1523 nonMonicHenselStep12 (F, bufFactors2, bufFactors, diophant, M, Pi, i, LCs); 1525 1524 1526 1525 factors= CFList(); … … 1533 1532 /// solve \f$ E=sum_{i= 1}^{r}{\sigma_{i}prod_{j=1, j\neq i}^{r}{f_{i}}}\f$ 1534 1533 /// mod M, products contains \f$ prod_{j=1, j\neq i}^{r}{f_{i}}} \f$ 1535 static inline1536 1534 CFList 1537 1535 diophantine (const CFList& recResult, const CFList& factors, … … 1612 1610 } 1613 1611 1614 static inline1615 1612 void 1616 henselStep2 (const CanonicalForm& F, const CFList& factors, CFArray& bufFactors, 1617 const CFList& diophant, CFMatrix& M, CFArray& Pi, 1618 const CFList& products, int j, const CFList& MOD, bool& noOneToOne) 1613 nonMonicHenselStep (const CanonicalForm& F, const CFList& factors, 1614 CFArray& bufFactors, const CFList& diophant, CFMatrix& M, 1615 CFArray& Pi, const CFList& products, int j, 1616 const CFList& MOD, bool& noOneToOne) 1619 1617 { 1620 1618 CanonicalForm E; … … 1852 1850 1853 1851 CFList 1854 henselLift232(const CFList& eval, const CFList& factors, int* l, CFList&1855 diophant, CFArray& Pi, CFMatrix& M, const CFList& LCs1,1856 const CFList& LCs2, bool& bad)1852 nonMonicHenselLift232(const CFList& eval, const CFList& factors, int* l, CFList& 1853 diophant, CFArray& Pi, CFMatrix& M, const CFList& LCs1, 1854 const CFList& LCs2, bool& bad) 1857 1855 { 1858 1856 CFList buf= factors; … … 1902 1900 for (int d= 1; d < l[1]; d++) 1903 1901 { 1904 henselStep2 (j.getItem(), buf, bufFactors, diophant, M, Pi, products, d, MOD, bad); 1902 nonMonicHenselStep (j.getItem(), buf, bufFactors, diophant, M, Pi, products, 1903 d, MOD, bad); 1905 1904 if (bad) 1906 1905 return CFList(); … … 1914 1913 1915 1914 CFList 1916 henselLift2 (const CFList& F, const CFList& factors, const CFList& MOD, CFList& 1917 diophant, CFArray& Pi, CFMatrix& M, const int lOld, int& 1918 lNew, const CFList& LCs1, const CFList& LCs2, bool& bad) 1915 nonMonicHenselLift2 (const CFList& F, const CFList& factors, const CFList& MOD, 1916 CFList& diophant, CFArray& Pi, CFMatrix& M, int lOld, 1917 int& lNew, const CFList& LCs1, const CFList& LCs2, bool& bad 1918 ) 1919 1919 { 1920 1920 int k= 0; … … 1963 1963 for (int d= 1; d < lNew; d++) 1964 1964 { 1965 henselStep2 (F.getLast(), buf, bufFactors, diophant, M, Pi, products, d, MOD, bad); 1965 nonMonicHenselStep (F.getLast(), buf, bufFactors, diophant, M, Pi, products, 1966 d, MOD, bad); 1966 1967 if (bad) 1967 1968 return CFList(); … … 1975 1976 1976 1977 CFList 1977 henselLift2 (const CFList& eval, const CFList& factors, int* l, constint1978 lLength, bool sort, const CFList& LCs1, const CFList& LCs2,1979 const CFArray& Pi, const CFList& diophant, bool& bad)1978 nonMonicHenselLift2 (const CFList& eval, const CFList& factors, int* l, int 1979 lLength, bool sort, const CFList& LCs1, const CFList& LCs2, 1980 const CFArray& Pi, const CFList& diophant, bool& bad) 1980 1981 { 1981 1982 CFList bufDiophant= diophant; … … 1985 1986 CFArray bufPi= Pi; 1986 1987 CFMatrix M= CFMatrix (l[1], factors.length()); 1987 CFList result= henselLift232(eval, buf, l, bufDiophant, bufPi, M, LCs1, LCs2,1988 1988 CFList result= 1989 nonMonicHenselLift232(eval, buf, l, bufDiophant, bufPi, M, LCs1, LCs2, bad); 1989 1990 if (bad) 1990 1991 return CFList(); … … 2014 2015 bufLCs2.append (jjj.getItem()); 2015 2016 M= CFMatrix (l[i], factors.length()); 2016 result= henselLift2 (bufEval, result, MOD, bufDiophant, bufPi, M, l[i - 1],2017 l[i], bufLCs1, bufLCs2, bad);2017 result= nonMonicHenselLift2 (bufEval, result, MOD, bufDiophant, bufPi, M, 2018 l[i - 1], l[i], bufLCs1, bufLCs2, bad); 2018 2019 if (bad) 2019 2020 return CFList(); … … 2112 2113 for (int d= 1; d < liftBound; d++) 2113 2114 { 2114 henselStep2 (F, factors, bufFactors, diophant, M, Pi, products, d, MOD, bad); 2115 nonMonicHenselStep (F, factors, bufFactors, diophant, M, Pi, products, d, 2116 MOD, bad); 2115 2117 if (bad) 2116 2118 return CFList(); … … 2125 2127 CFList 2126 2128 nonMonicHenselLift (const CFList& F, const CFList& factors, const CFList& LCs, 2127 CFList& diophant, CFArray& Pi, CFMatrix& M, constint lOld,2129 CFList& diophant, CFArray& Pi, CFMatrix& M, int lOld, 2128 2130 int& lNew, const CFList& MOD, bool& noOneToOne 2129 2131 ) … … 2192 2194 for (int d= 1; d < lNew; d++) 2193 2195 { 2194 henselStep2 (F.getLast(), factors, bufFactors, diophant, M, Pi, products, d,2195 MOD, noOneToOne);2196 nonMonicHenselStep (F.getLast(), factors, bufFactors, diophant, M, Pi, 2197 products, d, MOD, noOneToOne); 2196 2198 if (noOneToOne) 2197 2199 return CFList(); -
factory/facHensel.h
r0e2e23 r81d96c 25 25 26 26 #include "canonicalform.h" 27 #include "cf_iter.h"28 #include "templates/ftmpl_functions.h"29 #include "algext.h"30 27 31 28 #ifdef HAVE_NTL … … 87 84 ///< including leading coefficient 88 85 ///< as first element. 89 constint* l, ///< [in] l[0]: precision of bivariate86 int* l, ///< [in] l[0]: precision of bivariate 90 87 ///< lifting, l[1] as above 91 88 CFList& diophant, ///< [in,out] returns the result of … … 131 128 CFArray& Pi, ///< [in,out] stores intermediate results 132 129 CFMatrix& M, ///< [in,out] stores intermediate results 133 constint lOld, ///< [in] lifting precision of F.mvar()134 constint lNew ///< [in] lifting precision of G.mvar()130 int lOld, ///< [in] lifting precision of F.mvar() 131 int lNew ///< [in] lifting precision of G.mvar() 135 132 ); 136 133 … … 148 145 const CFList& factors, ///< [in] bivariate factors, including 149 146 ///< leading coefficient 150 constint* l, ///< [in] lifting bounds151 constint lLength, ///< [in] length of l147 int* l, ///< [in] lifting bounds 148 int lLength, ///< [in] length of l 152 149 bool sort= true ///< [in] sort factors by degree in 153 150 ///< Variable(1) 154 151 ); 155 152 156 /// two factor Hensel lifting from univariate to bivariate, factors need not to 157 /// be monic 158 void 159 henselLift122 (const CanonicalForm& F,///< [in] a bivariate poly 153 /// Hensel lifting from univariate to bivariate, factors need not to be monic 154 void 155 nonMonicHenselLift12 (const CanonicalForm& F,///< [in] a bivariate poly 160 156 CFList& factors, ///< [in, out] a list of univariate polys 161 157 ///< lifted factors … … 174 170 /// @return @a henselLift122 returns a list of lifted factors 175 171 CFList 176 henselLift2 (const CFList& eval,///< [in] a list of polynomials the last172 nonMonicHenselLift2 (const CFList& eval,///< [in] a list of polynomials the last 177 173 ///< element is a compressed multivariate 178 174 ///< poly, last but one element equals the … … 182 178 const CFList& factors,///< [in] bivariate factors 183 179 int* l, ///< [in] lift bounds 184 const int lLength,///< [in] length of l180 int lLength, ///< [in] length of l 185 181 bool sort, ///< [in] if true factors are sorted by 186 182 ///< their degree in Variable(1) -
factory/facMul.cc
r0e2e23 r81d96c 17 17 #include "facMul.h" 18 18 #include "algext.h" 19 #include "cf_util.h" 19 20 #include "templates/ftmpl_functions.h" 20 21 … … 26 27 #include "FLINTconvert.h" 27 28 #endif 29 30 // univariate polys 28 31 29 32 #ifdef HAVE_FLINT … … 48 51 49 52 CanonicalForm 50 reverseSubst (const fmpz_poly_t F, int d, const Variable& alpha,51 const CanonicalForm& den)53 reverseSubstQa (const fmpz_poly_t F, int d, const Variable& alpha, 54 const CanonicalForm& den) 52 55 { 53 56 Variable x= Variable (1); … … 111 114 112 115 denA *= denB; 113 A= reverseSubst (FLINTA, d, alpha, denA);116 A= reverseSubstQa (FLINTA, d, alpha, denA); 114 117 115 118 fmpz_poly_clear (FLINTA); … … 222 225 223 226 denA *= denB; 224 A= reverseSubst (FLINTA, d, alpha, denA);227 A= reverseSubstQa (FLINTA, d, alpha, denA); 225 228 fmpz_poly_clear (FLINTA); 226 229 fmpz_poly_clear (FLINTB); … … 570 573 } 571 574 575 // end univariate polys 576 //************************* 577 // bivariate polys 578 572 579 #ifdef HAVE_FLINT 573 580 void kronSubFp (nmod_poly_t result, const CanonicalForm& A, int d) … … 592 599 } 593 600 594 /*void kronSubQ (fmpz_poly_t result, const CanonicalForm& A, int d)595 {596 int degAy= degree (A);597 fmpz_poly_init2 (result, d*(degAy + 1));598 _fmpz_poly_set_length (result, d*(degAy+1));599 600 CFIterator j;601 for (CFIterator i= A; i.hasTerms(); i++)602 {603 if (i.coeff().inBas604 convertFacCF2Fmpz_poly_t (buf, i.coeff());605 606 int k= i.exp()*d;607 int bufRepLength= (int) fmpz_poly_length (buf);608 for (int j= 0; j < bufRepLength; j++)609 {610 fmpz_poly_get_coeff_fmpz (coeff, buf, j);611 fmpz_poly_set_coeff_fmpz (result, j + k, coeff);612 }613 fmpz_poly_clear (buf);614 }615 fmpz_clear (coeff);616 _fmpz_poly_normalise (result);617 }*/618 619 // A is a bivariate poly over Qa!!!!620 // d2= 2*deg_alpha + 1621 // d1= 2*deg_x*d2+1622 601 void kronSubQa (fmpq_poly_t result, const CanonicalForm& A, int d1, int d2) 623 602 { … … 664 643 _fmpq_poly_normalise (result); 665 644 } 666 #endif667 668 zz_pX kronSubFp (const CanonicalForm& A, int d)669 {670 int degAy= degree (A);671 zz_pX result;672 result.rep.SetLength (d*(degAy + 1));673 674 zz_p *resultp;675 resultp= result.rep.elts();676 zz_pX buf;677 zz_p *bufp;678 int j, k, bufRepLength;679 680 for (CFIterator i= A; i.hasTerms(); i++)681 {682 if (i.coeff().inCoeffDomain())683 buf= convertFacCF2NTLzzpX (i.coeff());684 else685 buf= convertFacCF2NTLzzpX (i.coeff());686 687 k= i.exp()*d;688 bufp= buf.rep.elts();689 bufRepLength= (int) buf.rep.length();690 for (j= 0; j < bufRepLength; j++)691 resultp [j + k]= bufp [j];692 }693 result.normalize();694 695 return result;696 }697 698 zz_pEX kronSub (const CanonicalForm& A, int d, const Variable& alpha)699 {700 int degAy= degree (A);701 zz_pEX result;702 result.rep.SetLength (d*(degAy + 1));703 704 Variable v;705 zz_pE *resultp;706 resultp= result.rep.elts();707 zz_pEX buf1;708 zz_pE *buf1p;709 zz_pX buf2;710 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha));711 int j, k, buf1RepLength;712 713 for (CFIterator i= A; i.hasTerms(); i++)714 {715 if (i.coeff().inCoeffDomain())716 {717 buf2= convertFacCF2NTLzzpX (i.coeff());718 buf1= to_zz_pEX (to_zz_pE (buf2));719 }720 else721 buf1= convertFacCF2NTLzz_pEX (i.coeff(), NTLMipo);722 723 k= i.exp()*d;724 buf1p= buf1.rep.elts();725 buf1RepLength= (int) buf1.rep.length();726 for (j= 0; j < buf1RepLength; j++)727 resultp [j + k]= buf1p [j];728 }729 result.normalize();730 731 return result;732 }733 645 734 646 void 735 kronSubRecipro (zz_pEX& subA1, zz_pEX& subA2,const CanonicalForm& A, int d, 736 const Variable& alpha) 737 { 738 int degAy= degree (A); 739 subA1.rep.SetLength ((long) d*(degAy + 2)); 740 subA2.rep.SetLength ((long) d*(degAy + 2)); 741 742 Variable v; 743 zz_pE *subA1p; 744 zz_pE *subA2p; 745 subA1p= subA1.rep.elts(); 746 subA2p= subA2.rep.elts(); 747 zz_pEX buf; 748 zz_pE *bufp; 749 zz_pX buf2; 750 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 751 int j, k, kk, bufRepLength; 752 753 for (CFIterator i= A; i.hasTerms(); i++) 754 { 755 if (i.coeff().inCoeffDomain()) 756 { 757 buf2= convertFacCF2NTLzzpX (i.coeff()); 758 buf= to_zz_pEX (to_zz_pE (buf2)); 759 } 760 else 761 buf= convertFacCF2NTLzz_pEX (i.coeff(), NTLMipo); 762 763 k= i.exp()*d; 764 kk= (degAy - i.exp())*d; 765 bufp= buf.rep.elts(); 766 bufRepLength= (int) buf.rep.length(); 767 for (j= 0; j < bufRepLength; j++) 768 { 769 subA1p [j + k] += bufp [j]; 770 subA2p [j + kk] += bufp [j]; 771 } 772 } 773 subA1.normalize(); 774 subA2.normalize(); 775 } 776 777 void 778 kronSubRecipro (zz_pX& subA1, zz_pX& subA2,const CanonicalForm& A, int d) 779 { 780 int degAy= degree (A); 781 subA1.rep.SetLength ((long) d*(degAy + 2)); 782 subA2.rep.SetLength ((long) d*(degAy + 2)); 783 784 zz_p *subA1p; 785 zz_p *subA2p; 786 subA1p= subA1.rep.elts(); 787 subA2p= subA2.rep.elts(); 788 zz_pX buf; 789 zz_p *bufp; 790 int j, k, kk, bufRepLength; 791 792 for (CFIterator i= A; i.hasTerms(); i++) 793 { 794 buf= convertFacCF2NTLzzpX (i.coeff()); 795 796 k= i.exp()*d; 797 kk= (degAy - i.exp())*d; 798 bufp= buf.rep.elts(); 799 bufRepLength= (int) buf.rep.length(); 800 for (j= 0; j < bufRepLength; j++) 801 { 802 subA1p [j + k] += bufp [j]; 803 subA2p [j + kk] += bufp [j]; 804 } 805 } 806 subA1.normalize(); 807 subA2.normalize(); 808 } 809 810 CanonicalForm 811 reverseSubst (const zz_pEX& F, const zz_pEX& G, int d, int k, 812 const Variable& alpha) 813 { 814 Variable y= Variable (2); 815 Variable x= Variable (1); 816 817 zz_pEX f= F; 818 zz_pEX g= G; 819 int degf= deg(f); 820 int degg= deg(g); 821 822 zz_pEX buf1; 823 zz_pEX buf2; 824 zz_pEX buf3; 825 826 zz_pE *buf1p; 827 zz_pE *buf2p; 828 zz_pE *buf3p; 829 if (f.rep.length() < (long) d*(k+1)) //zero padding 830 f.rep.SetLength ((long)d*(k+1)); 831 832 zz_pE *gp= g.rep.elts(); 833 zz_pE *fp= f.rep.elts(); 834 CanonicalForm result= 0; 835 int i= 0; 836 int lf= 0; 837 int lg= d*k; 838 int degfSubLf= degf; 839 int deggSubLg= degg-lg; 840 int repLengthBuf2, repLengthBuf1, ind, tmp; 841 zz_pE zzpEZero= zz_pE(); 842 843 while (degf >= lf || lg >= 0) 844 { 845 if (degfSubLf >= d) 846 repLengthBuf1= d; 847 else if (degfSubLf < 0) 848 repLengthBuf1= 0; 849 else 850 repLengthBuf1= degfSubLf + 1; 851 buf1.rep.SetLength((long) repLengthBuf1); 852 853 buf1p= buf1.rep.elts(); 854 for (ind= 0; ind < repLengthBuf1; ind++) 855 buf1p [ind]= fp [ind + lf]; 856 buf1.normalize(); 857 858 repLengthBuf1= buf1.rep.length(); 859 860 if (deggSubLg >= d - 1) 861 repLengthBuf2= d - 1; 862 else if (deggSubLg < 0) 863 repLengthBuf2= 0; 864 else 865 repLengthBuf2= deggSubLg + 1; 866 867 buf2.rep.SetLength ((long) repLengthBuf2); 868 buf2p= buf2.rep.elts(); 869 for (ind= 0; ind < repLengthBuf2; ind++) 870 buf2p [ind]= gp [ind + lg]; 871 buf2.normalize(); 872 873 repLengthBuf2= buf2.rep.length(); 874 875 buf3.rep.SetLength((long) repLengthBuf2 + d); 876 buf3p= buf3.rep.elts(); 877 buf2p= buf2.rep.elts(); 878 buf1p= buf1.rep.elts(); 879 for (ind= 0; ind < repLengthBuf1; ind++) 880 buf3p [ind]= buf1p [ind]; 881 for (ind= repLengthBuf1; ind < d; ind++) 882 buf3p [ind]= zzpEZero; 883 for (ind= 0; ind < repLengthBuf2; ind++) 884 buf3p [ind + d]= buf2p [ind]; 885 buf3.normalize(); 886 887 result += convertNTLzz_pEX2CF (buf3, x, alpha)*power (y, i); 888 i++; 889 890 891 lf= i*d; 892 degfSubLf= degf - lf; 893 894 lg= d*(k-i); 895 deggSubLg= degg - lg; 896 897 buf1p= buf1.rep.elts(); 898 899 if (lg >= 0 && deggSubLg > 0) 900 { 901 if (repLengthBuf2 > degfSubLf + 1) 902 degfSubLf= repLengthBuf2 - 1; 903 tmp= tmin (repLengthBuf1, deggSubLg + 1); 904 for (ind= 0; ind < tmp; ind++) 905 gp [ind + lg] -= buf1p [ind]; 906 } 907 908 if (lg < 0) 909 break; 910 911 buf2p= buf2.rep.elts(); 912 if (degfSubLf >= 0) 913 { 914 for (ind= 0; ind < repLengthBuf2; ind++) 915 fp [ind + lf] -= buf2p [ind]; 916 } 917 } 918 919 return result; 920 } 921 922 CanonicalForm 923 reverseSubst (const zz_pX& F, const zz_pX& G, int d, int k) 924 { 925 Variable y= Variable (2); 926 Variable x= Variable (1); 927 928 zz_pX f= F; 929 zz_pX g= G; 930 int degf= deg(f); 931 int degg= deg(g); 932 933 zz_pX buf1; 934 zz_pX buf2; 935 zz_pX buf3; 936 937 zz_p *buf1p; 938 zz_p *buf2p; 939 zz_p *buf3p; 940 941 if (f.rep.length() < (long) d*(k+1)) //zero padding 942 f.rep.SetLength ((long)d*(k+1)); 943 944 zz_p *gp= g.rep.elts(); 945 zz_p *fp= f.rep.elts(); 946 CanonicalForm result= 0; 947 int i= 0; 948 int lf= 0; 949 int lg= d*k; 950 int degfSubLf= degf; 951 int deggSubLg= degg-lg; 952 int repLengthBuf2, repLengthBuf1, ind, tmp; 953 zz_p zzpZero= zz_p(); 954 while (degf >= lf || lg >= 0) 955 { 956 if (degfSubLf >= d) 957 repLengthBuf1= d; 958 else if (degfSubLf < 0) 959 repLengthBuf1= 0; 960 else 961 repLengthBuf1= degfSubLf + 1; 962 buf1.rep.SetLength((long) repLengthBuf1); 963 964 buf1p= buf1.rep.elts(); 965 for (ind= 0; ind < repLengthBuf1; ind++) 966 buf1p [ind]= fp [ind + lf]; 967 buf1.normalize(); 968 969 repLengthBuf1= buf1.rep.length(); 970 971 if (deggSubLg >= d - 1) 972 repLengthBuf2= d - 1; 973 else if (deggSubLg < 0) 974 repLengthBuf2= 0; 975 else 976 repLengthBuf2= deggSubLg + 1; 977 978 buf2.rep.SetLength ((long) repLengthBuf2); 979 buf2p= buf2.rep.elts(); 980 for (ind= 0; ind < repLengthBuf2; ind++) 981 buf2p [ind]= gp [ind + lg]; 982 983 buf2.normalize(); 984 985 repLengthBuf2= buf2.rep.length(); 986 987 988 buf3.rep.SetLength((long) repLengthBuf2 + d); 989 buf3p= buf3.rep.elts(); 990 buf2p= buf2.rep.elts(); 991 buf1p= buf1.rep.elts(); 992 for (ind= 0; ind < repLengthBuf1; ind++) 993 buf3p [ind]= buf1p [ind]; 994 for (ind= repLengthBuf1; ind < d; ind++) 995 buf3p [ind]= zzpZero; 996 for (ind= 0; ind < repLengthBuf2; ind++) 997 buf3p [ind + d]= buf2p [ind]; 998 buf3.normalize(); 999 1000 result += convertNTLzzpX2CF (buf3, x)*power (y, i); 1001 i++; 1002 1003 1004 lf= i*d; 1005 degfSubLf= degf - lf; 1006 1007 lg= d*(k-i); 1008 deggSubLg= degg - lg; 1009 1010 buf1p= buf1.rep.elts(); 1011 1012 if (lg >= 0 && deggSubLg > 0) 1013 { 1014 if (repLengthBuf2 > degfSubLf + 1) 1015 degfSubLf= repLengthBuf2 - 1; 1016 tmp= tmin (repLengthBuf1, deggSubLg + 1); 1017 for (ind= 0; ind < tmp; ind++) 1018 gp [ind + lg] -= buf1p [ind]; 1019 } 1020 if (lg < 0) 1021 break; 1022 1023 buf2p= buf2.rep.elts(); 1024 if (degfSubLf >= 0) 1025 { 1026 for (ind= 0; ind < repLengthBuf2; ind++) 1027 fp [ind + lf] -= buf2p [ind]; 1028 } 1029 } 1030 1031 return result; 1032 } 1033 1034 CanonicalForm reverseSubst (const zz_pEX& F, int d, const Variable& alpha) 1035 { 1036 Variable y= Variable (2); 1037 Variable x= Variable (1); 1038 1039 zz_pEX f= F; 1040 zz_pE *fp= f.rep.elts(); 1041 1042 zz_pEX buf; 1043 zz_pE *bufp; 1044 CanonicalForm result= 0; 1045 int i= 0; 1046 int degf= deg(f); 1047 int k= 0; 1048 int degfSubK, repLength, j; 1049 while (degf >= k) 1050 { 1051 degfSubK= degf - k; 1052 if (degfSubK >= d) 1053 repLength= d; 1054 else 1055 repLength= degfSubK + 1; 1056 1057 buf.rep.SetLength ((long) repLength); 1058 bufp= buf.rep.elts(); 1059 for (j= 0; j < repLength; j++) 1060 bufp [j]= fp [j + k]; 1061 buf.normalize(); 1062 1063 result += convertNTLzz_pEX2CF (buf, x, alpha)*power (y, i); 1064 i++; 1065 k= d*i; 1066 } 1067 1068 return result; 1069 } 1070 1071 CanonicalForm reverseSubstFp (const zz_pX& F, int d) 1072 { 1073 Variable y= Variable (2); 1074 Variable x= Variable (1); 1075 1076 zz_pX f= F; 1077 zz_p *fp= f.rep.elts(); 1078 1079 zz_pX buf; 1080 zz_p *bufp; 1081 CanonicalForm result= 0; 1082 int i= 0; 1083 int degf= deg(f); 1084 int k= 0; 1085 int degfSubK, repLength, j; 1086 while (degf >= k) 1087 { 1088 degfSubK= degf - k; 1089 if (degfSubK >= d) 1090 repLength= d; 1091 else 1092 repLength= degfSubK + 1; 1093 1094 buf.rep.SetLength ((long) repLength); 1095 bufp= buf.rep.elts(); 1096 for (j= 0; j < repLength; j++) 1097 bufp [j]= fp [j + k]; 1098 buf.normalize(); 1099 1100 result += convertNTLzzpX2CF (buf, x)*power (y, i); 1101 i++; 1102 k= d*i; 1103 } 1104 1105 return result; 1106 } 1107 1108 // assumes input to be reduced mod M and to be an element of Fq not Fp 1109 CanonicalForm 1110 mulMod2NTLFpReci (const CanonicalForm& F, const CanonicalForm& G, const 1111 CanonicalForm& M) 1112 { 1113 int d1= degree (F, 1) + degree (G, 1) + 1; 1114 d1 /= 2; 1115 d1 += 1; 1116 1117 zz_pX F1, F2; 1118 kronSubRecipro (F1, F2, F, d1); 1119 zz_pX G1, G2; 1120 kronSubRecipro (G1, G2, G, d1); 1121 1122 int k= d1*degree (M); 1123 MulTrunc (F1, F1, G1, (long) k); 1124 1125 int degtailF= degree (tailcoeff (F), 1); 1126 int degtailG= degree (tailcoeff (G), 1); 1127 int taildegF= taildegree (F); 1128 int taildegG= taildegree (G); 1129 int b= k + degtailF + degtailG - d1*(2+taildegF+taildegG); 1130 1131 reverse (F2, F2); 1132 reverse (G2, G2); 1133 MulTrunc (F2, F2, G2, b + 1); 1134 reverse (F2, F2, b); 1135 1136 int d2= tmax (deg (F2)/d1, deg (F1)/d1); 1137 return reverseSubst (F1, F2, d1, d2); 1138 } 1139 1140 //Kronecker substitution 1141 CanonicalForm 1142 mulMod2NTLFp (const CanonicalForm& F, const CanonicalForm& G, const 1143 CanonicalForm& M) 1144 { 1145 CanonicalForm A= F; 1146 CanonicalForm B= G; 1147 1148 int degAx= degree (A, 1); 1149 int degAy= degree (A, 2); 1150 int degBx= degree (B, 1); 1151 int degBy= degree (B, 2); 1152 int d1= degAx + 1 + degBx; 1153 int d2= tmax (degAy, degBy); 1154 1155 if (d1 > 128 && d2 > 160 && (degAy == degBy) && (2*degAy > degree (M))) 1156 return mulMod2NTLFpReci (A, B, M); 1157 1158 zz_pX NTLA= kronSubFp (A, d1); 1159 zz_pX NTLB= kronSubFp (B, d1); 1160 1161 int k= d1*degree (M); 1162 MulTrunc (NTLA, NTLA, NTLB, (long) k); 1163 1164 A= reverseSubstFp (NTLA, d1); 1165 1166 return A; 1167 } 1168 1169 // assumes input to be reduced mod M and to be an element of Fq not Fp 1170 CanonicalForm 1171 mulMod2NTLFqReci (const CanonicalForm& F, const CanonicalForm& G, const 1172 CanonicalForm& M, const Variable& alpha) 1173 { 1174 int d1= degree (F, 1) + degree (G, 1) + 1; 1175 d1 /= 2; 1176 d1 += 1; 1177 1178 zz_pEX F1, F2; 1179 kronSubRecipro (F1, F2, F, d1, alpha); 1180 zz_pEX G1, G2; 1181 kronSubRecipro (G1, G2, G, d1, alpha); 1182 1183 int k= d1*degree (M); 1184 MulTrunc (F1, F1, G1, (long) k); 1185 1186 int degtailF= degree (tailcoeff (F), 1); 1187 int degtailG= degree (tailcoeff (G), 1); 1188 int taildegF= taildegree (F); 1189 int taildegG= taildegree (G); 1190 int b= k + degtailF + degtailG - d1*(2+taildegF+taildegG); 1191 1192 reverse (F2, F2); 1193 reverse (G2, G2); 1194 MulTrunc (F2, F2, G2, b + 1); 1195 reverse (F2, F2, b); 1196 1197 int d2= tmax (deg (F2)/d1, deg (F1)/d1); 1198 return reverseSubst (F1, F2, d1, d2, alpha); 1199 } 1200 1201 #ifdef HAVE_FLINT 1202 CanonicalForm 1203 mulMod2FLINTFp (const CanonicalForm& F, const CanonicalForm& G, const 1204 CanonicalForm& M); 1205 #endif 1206 1207 CanonicalForm 1208 mulMod2NTLFq (const CanonicalForm& F, const CanonicalForm& G, const 1209 CanonicalForm& M) 1210 { 1211 Variable alpha; 1212 CanonicalForm A= F; 1213 CanonicalForm B= G; 1214 1215 if (hasFirstAlgVar (A, alpha) || hasFirstAlgVar (B, alpha)) 1216 { 1217 int degAx= degree (A, 1); 1218 int degAy= degree (A, 2); 1219 int degBx= degree (B, 1); 1220 int degBy= degree (B, 2); 1221 int d1= degAx + degBx + 1; 1222 int d2= tmax (degAy, degBy); 1223 zz_p::init (getCharacteristic()); 1224 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 1225 zz_pE::init (NTLMipo); 1226 1227 int degMipo= degree (getMipo (alpha)); 1228 if ((d1 > 128/degMipo) && (d2 > 160/degMipo) && (degAy == degBy) && 1229 (2*degAy > degree (M))) 1230 return mulMod2NTLFqReci (A, B, M, alpha); 1231 1232 zz_pEX NTLA= kronSub (A, d1, alpha); 1233 zz_pEX NTLB= kronSub (B, d1, alpha); 1234 1235 int k= d1*degree (M); 1236 1237 MulTrunc (NTLA, NTLA, NTLB, (long) k); 1238 1239 A= reverseSubst (NTLA, d1, alpha); 1240 1241 return A; 1242 } 1243 else 1244 #ifdef HAVE_FLINT 1245 return mulMod2FLINTFp (A, B, M); 1246 #else 1247 return mulMod2NTLFp (A, B, M); 1248 #endif 1249 } 1250 1251 #ifdef HAVE_FLINT 1252 void 1253 kronSubRecipro (nmod_poly_t subA1, nmod_poly_t subA2, const CanonicalForm& A, 1254 int d) 647 kronSubReciproFp (nmod_poly_t subA1, nmod_poly_t subA2, const CanonicalForm& A, 648 int d) 1255 649 { 1256 650 int degAy= degree (A); … … 1291 685 1292 686 void 1293 kronSubRecipro (fmpz_poly_t subA1, fmpz_poly_t subA2, const CanonicalForm& A,1294 int d)687 kronSubReciproQ (fmpz_poly_t subA1, fmpz_poly_t subA2, const CanonicalForm& A, 688 int d) 1295 689 { 1296 690 int degAy= degree (A); … … 1372 766 1373 767 CanonicalForm 1374 reverseSubst (const nmod_poly_t F, const nmod_poly_t G, int d, int k)768 reverseSubstReciproFp (const nmod_poly_t F, const nmod_poly_t G, int d, int k) 1375 769 { 1376 770 Variable y= Variable (2); … … 1490 884 1491 885 CanonicalForm 1492 reverseSubst (const fmpz_poly_t F, const fmpz_poly_t G, int d, int k)886 reverseSubstReciproQ (const fmpz_poly_t F, const fmpz_poly_t G, int d, int k) 1493 887 { 1494 888 Variable y= Variable (2); … … 1674 1068 nmod_poly_init_preinv (F1, getCharacteristic(), ninv); 1675 1069 nmod_poly_init_preinv (F2, getCharacteristic(), ninv); 1676 kronSubRecipro (F1, F2, F, d1);1070 kronSubReciproFp (F1, F2, F, d1); 1677 1071 1678 1072 nmod_poly_t G1, G2; 1679 1073 nmod_poly_init_preinv (G1, getCharacteristic(), ninv); 1680 1074 nmod_poly_init_preinv (G2, getCharacteristic(), ninv); 1681 kronSubRecipro (G1, G2, G, d1);1075 kronSubReciproFp (G1, G2, G, d1); 1682 1076 1683 1077 int k= d1*degree (M); … … 1696 1090 1697 1091 1698 CanonicalForm result= reverseSubst (F1, F2, d1, d2);1092 CanonicalForm result= reverseSubstReciproFp (F1, F2, d1, d2); 1699 1093 1700 1094 nmod_poly_clear (F1); … … 1750 1144 fmpz_poly_init (F1); 1751 1145 fmpz_poly_init (F2); 1752 kronSubRecipro (F1, F2, F, d1);1146 kronSubReciproQ (F1, F2, F, d1); 1753 1147 1754 1148 fmpz_poly_t G1, G2; 1755 1149 fmpz_poly_init (G1); 1756 1150 fmpz_poly_init (G2); 1757 kronSubRecipro (G1, G2, G, d1);1151 kronSubReciproQ (G1, G2, G, d1); 1758 1152 1759 1153 int k= d1*degree (M); … … 1771 1165 int d2= tmax (fmpz_poly_degree (F2)/d1, fmpz_poly_degree (F1)/d1); 1772 1166 1773 CanonicalForm result= reverseSubst (F1, F2, d1, d2);1167 CanonicalForm result= reverseSubstReciproQ (F1, F2, d1, d2); 1774 1168 1775 1169 fmpz_poly_clear (F1); … … 1811 1205 1812 1206 #endif 1207 1208 zz_pX kronSubFp (const CanonicalForm& A, int d) 1209 { 1210 int degAy= degree (A); 1211 zz_pX result; 1212 result.rep.SetLength (d*(degAy + 1)); 1213 1214 zz_p *resultp; 1215 resultp= result.rep.elts(); 1216 zz_pX buf; 1217 zz_p *bufp; 1218 int j, k, bufRepLength; 1219 1220 for (CFIterator i= A; i.hasTerms(); i++) 1221 { 1222 if (i.coeff().inCoeffDomain()) 1223 buf= convertFacCF2NTLzzpX (i.coeff()); 1224 else 1225 buf= convertFacCF2NTLzzpX (i.coeff()); 1226 1227 k= i.exp()*d; 1228 bufp= buf.rep.elts(); 1229 bufRepLength= (int) buf.rep.length(); 1230 for (j= 0; j < bufRepLength; j++) 1231 resultp [j + k]= bufp [j]; 1232 } 1233 result.normalize(); 1234 1235 return result; 1236 } 1237 1238 zz_pEX kronSubFq (const CanonicalForm& A, int d, const Variable& alpha) 1239 { 1240 int degAy= degree (A); 1241 zz_pEX result; 1242 result.rep.SetLength (d*(degAy + 1)); 1243 1244 Variable v; 1245 zz_pE *resultp; 1246 resultp= result.rep.elts(); 1247 zz_pEX buf1; 1248 zz_pE *buf1p; 1249 zz_pX buf2; 1250 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 1251 int j, k, buf1RepLength; 1252 1253 for (CFIterator i= A; i.hasTerms(); i++) 1254 { 1255 if (i.coeff().inCoeffDomain()) 1256 { 1257 buf2= convertFacCF2NTLzzpX (i.coeff()); 1258 buf1= to_zz_pEX (to_zz_pE (buf2)); 1259 } 1260 else 1261 buf1= convertFacCF2NTLzz_pEX (i.coeff(), NTLMipo); 1262 1263 k= i.exp()*d; 1264 buf1p= buf1.rep.elts(); 1265 buf1RepLength= (int) buf1.rep.length(); 1266 for (j= 0; j < buf1RepLength; j++) 1267 resultp [j + k]= buf1p [j]; 1268 } 1269 result.normalize(); 1270 1271 return result; 1272 } 1273 1274 void 1275 kronSubReciproFq (zz_pEX& subA1, zz_pEX& subA2,const CanonicalForm& A, int d, 1276 const Variable& alpha) 1277 { 1278 int degAy= degree (A); 1279 subA1.rep.SetLength ((long) d*(degAy + 2)); 1280 subA2.rep.SetLength ((long) d*(degAy + 2)); 1281 1282 Variable v; 1283 zz_pE *subA1p; 1284 zz_pE *subA2p; 1285 subA1p= subA1.rep.elts(); 1286 subA2p= subA2.rep.elts(); 1287 zz_pEX buf; 1288 zz_pE *bufp; 1289 zz_pX buf2; 1290 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 1291 int j, k, kk, bufRepLength; 1292 1293 for (CFIterator i= A; i.hasTerms(); i++) 1294 { 1295 if (i.coeff().inCoeffDomain()) 1296 { 1297 buf2= convertFacCF2NTLzzpX (i.coeff()); 1298 buf= to_zz_pEX (to_zz_pE (buf2)); 1299 } 1300 else 1301 buf= convertFacCF2NTLzz_pEX (i.coeff(), NTLMipo); 1302 1303 k= i.exp()*d; 1304 kk= (degAy - i.exp())*d; 1305 bufp= buf.rep.elts(); 1306 bufRepLength= (int) buf.rep.length(); 1307 for (j= 0; j < bufRepLength; j++) 1308 { 1309 subA1p [j + k] += bufp [j]; 1310 subA2p [j + kk] += bufp [j]; 1311 } 1312 } 1313 subA1.normalize(); 1314 subA2.normalize(); 1315 } 1316 1317 void 1318 kronSubReciproFp (zz_pX& subA1, zz_pX& subA2, const CanonicalForm& A, int d) 1319 { 1320 int degAy= degree (A); 1321 subA1.rep.SetLength ((long) d*(degAy + 2)); 1322 subA2.rep.SetLength ((long) d*(degAy + 2)); 1323 1324 zz_p *subA1p; 1325 zz_p *subA2p; 1326 subA1p= subA1.rep.elts(); 1327 subA2p= subA2.rep.elts(); 1328 zz_pX buf; 1329 zz_p *bufp; 1330 int j, k, kk, bufRepLength; 1331 1332 for (CFIterator i= A; i.hasTerms(); i++) 1333 { 1334 buf= convertFacCF2NTLzzpX (i.coeff()); 1335 1336 k= i.exp()*d; 1337 kk= (degAy - i.exp())*d; 1338 bufp= buf.rep.elts(); 1339 bufRepLength= (int) buf.rep.length(); 1340 for (j= 0; j < bufRepLength; j++) 1341 { 1342 subA1p [j + k] += bufp [j]; 1343 subA2p [j + kk] += bufp [j]; 1344 } 1345 } 1346 subA1.normalize(); 1347 subA2.normalize(); 1348 } 1349 1350 CanonicalForm 1351 reverseSubstReciproFq (const zz_pEX& F, const zz_pEX& G, int d, int k, 1352 const Variable& alpha) 1353 { 1354 Variable y= Variable (2); 1355 Variable x= Variable (1); 1356 1357 zz_pEX f= F; 1358 zz_pEX g= G; 1359 int degf= deg(f); 1360 int degg= deg(g); 1361 1362 zz_pEX buf1; 1363 zz_pEX buf2; 1364 zz_pEX buf3; 1365 1366 zz_pE *buf1p; 1367 zz_pE *buf2p; 1368 zz_pE *buf3p; 1369 if (f.rep.length() < (long) d*(k+1)) //zero padding 1370 f.rep.SetLength ((long)d*(k+1)); 1371 1372 zz_pE *gp= g.rep.elts(); 1373 zz_pE *fp= f.rep.elts(); 1374 CanonicalForm result= 0; 1375 int i= 0; 1376 int lf= 0; 1377 int lg= d*k; 1378 int degfSubLf= degf; 1379 int deggSubLg= degg-lg; 1380 int repLengthBuf2, repLengthBuf1, ind, tmp; 1381 zz_pE zzpEZero= zz_pE(); 1382 1383 while (degf >= lf || lg >= 0) 1384 { 1385 if (degfSubLf >= d) 1386 repLengthBuf1= d; 1387 else if (degfSubLf < 0) 1388 repLengthBuf1= 0; 1389 else 1390 repLengthBuf1= degfSubLf + 1; 1391 buf1.rep.SetLength((long) repLengthBuf1); 1392 1393 buf1p= buf1.rep.elts(); 1394 for (ind= 0; ind < repLengthBuf1; ind++) 1395 buf1p [ind]= fp [ind + lf]; 1396 buf1.normalize(); 1397 1398 repLengthBuf1= buf1.rep.length(); 1399 1400 if (deggSubLg >= d - 1) 1401 repLengthBuf2= d - 1; 1402 else if (deggSubLg < 0) 1403 repLengthBuf2= 0; 1404 else 1405 repLengthBuf2= deggSubLg + 1; 1406 1407 buf2.rep.SetLength ((long) repLengthBuf2); 1408 buf2p= buf2.rep.elts(); 1409 for (ind= 0; ind < repLengthBuf2; ind++) 1410 buf2p [ind]= gp [ind + lg]; 1411 buf2.normalize(); 1412 1413 repLengthBuf2= buf2.rep.length(); 1414 1415 buf3.rep.SetLength((long) repLengthBuf2 + d); 1416 buf3p= buf3.rep.elts(); 1417 buf2p= buf2.rep.elts(); 1418 buf1p= buf1.rep.elts(); 1419 for (ind= 0; ind < repLengthBuf1; ind++) 1420 buf3p [ind]= buf1p [ind]; 1421 for (ind= repLengthBuf1; ind < d; ind++) 1422 buf3p [ind]= zzpEZero; 1423 for (ind= 0; ind < repLengthBuf2; ind++) 1424 buf3p [ind + d]= buf2p [ind]; 1425 buf3.normalize(); 1426 1427 result += convertNTLzz_pEX2CF (buf3, x, alpha)*power (y, i); 1428 i++; 1429 1430 1431 lf= i*d; 1432 degfSubLf= degf - lf; 1433 1434 lg= d*(k-i); 1435 deggSubLg= degg - lg; 1436 1437 buf1p= buf1.rep.elts(); 1438 1439 if (lg >= 0 && deggSubLg > 0) 1440 { 1441 if (repLengthBuf2 > degfSubLf + 1) 1442 degfSubLf= repLengthBuf2 - 1; 1443 tmp= tmin (repLengthBuf1, deggSubLg + 1); 1444 for (ind= 0; ind < tmp; ind++) 1445 gp [ind + lg] -= buf1p [ind]; 1446 } 1447 1448 if (lg < 0) 1449 break; 1450 1451 buf2p= buf2.rep.elts(); 1452 if (degfSubLf >= 0) 1453 { 1454 for (ind= 0; ind < repLengthBuf2; ind++) 1455 fp [ind + lf] -= buf2p [ind]; 1456 } 1457 } 1458 1459 return result; 1460 } 1461 1462 CanonicalForm 1463 reverseSubstReciproFp (const zz_pX& F, const zz_pX& G, int d, int k) 1464 { 1465 Variable y= Variable (2); 1466 Variable x= Variable (1); 1467 1468 zz_pX f= F; 1469 zz_pX g= G; 1470 int degf= deg(f); 1471 int degg= deg(g); 1472 1473 zz_pX buf1; 1474 zz_pX buf2; 1475 zz_pX buf3; 1476 1477 zz_p *buf1p; 1478 zz_p *buf2p; 1479 zz_p *buf3p; 1480 1481 if (f.rep.length() < (long) d*(k+1)) //zero padding 1482 f.rep.SetLength ((long)d*(k+1)); 1483 1484 zz_p *gp= g.rep.elts(); 1485 zz_p *fp= f.rep.elts(); 1486 CanonicalForm result= 0; 1487 int i= 0; 1488 int lf= 0; 1489 int lg= d*k; 1490 int degfSubLf= degf; 1491 int deggSubLg= degg-lg; 1492 int repLengthBuf2, repLengthBuf1, ind, tmp; 1493 zz_p zzpZero= zz_p(); 1494 while (degf >= lf || lg >= 0) 1495 { 1496 if (degfSubLf >= d) 1497 repLengthBuf1= d; 1498 else if (degfSubLf < 0) 1499 repLengthBuf1= 0; 1500 else 1501 repLengthBuf1= degfSubLf + 1; 1502 buf1.rep.SetLength((long) repLengthBuf1); 1503 1504 buf1p= buf1.rep.elts(); 1505 for (ind= 0; ind < repLengthBuf1; ind++) 1506 buf1p [ind]= fp [ind + lf]; 1507 buf1.normalize(); 1508 1509 repLengthBuf1= buf1.rep.length(); 1510 1511 if (deggSubLg >= d - 1) 1512 repLengthBuf2= d - 1; 1513 else if (deggSubLg < 0) 1514 repLengthBuf2= 0; 1515 else 1516 repLengthBuf2= deggSubLg + 1; 1517 1518 buf2.rep.SetLength ((long) repLengthBuf2); 1519 buf2p= buf2.rep.elts(); 1520 for (ind= 0; ind < repLengthBuf2; ind++) 1521 buf2p [ind]= gp [ind + lg]; 1522 1523 buf2.normalize(); 1524 1525 repLengthBuf2= buf2.rep.length(); 1526 1527 1528 buf3.rep.SetLength((long) repLengthBuf2 + d); 1529 buf3p= buf3.rep.elts(); 1530 buf2p= buf2.rep.elts(); 1531 buf1p= buf1.rep.elts(); 1532 for (ind= 0; ind < repLengthBuf1; ind++) 1533 buf3p [ind]= buf1p [ind]; 1534 for (ind= repLengthBuf1; ind < d; ind++) 1535 buf3p [ind]= zzpZero; 1536 for (ind= 0; ind < repLengthBuf2; ind++) 1537 buf3p [ind + d]= buf2p [ind]; 1538 buf3.normalize(); 1539 1540 result += convertNTLzzpX2CF (buf3, x)*power (y, i); 1541 i++; 1542 1543 1544 lf= i*d; 1545 degfSubLf= degf - lf; 1546 1547 lg= d*(k-i); 1548 deggSubLg= degg - lg; 1549 1550 buf1p= buf1.rep.elts(); 1551 1552 if (lg >= 0 && deggSubLg > 0) 1553 { 1554 if (repLengthBuf2 > degfSubLf + 1) 1555 degfSubLf= repLengthBuf2 - 1; 1556 tmp= tmin (repLengthBuf1, deggSubLg + 1); 1557 for (ind= 0; ind < tmp; ind++) 1558 gp [ind + lg] -= buf1p [ind]; 1559 } 1560 if (lg < 0) 1561 break; 1562 1563 buf2p= buf2.rep.elts(); 1564 if (degfSubLf >= 0) 1565 { 1566 for (ind= 0; ind < repLengthBuf2; ind++) 1567 fp [ind + lf] -= buf2p [ind]; 1568 } 1569 } 1570 1571 return result; 1572 } 1573 1574 CanonicalForm reverseSubstFq (const zz_pEX& F, int d, const Variable& alpha) 1575 { 1576 Variable y= Variable (2); 1577 Variable x= Variable (1); 1578 1579 zz_pEX f= F; 1580 zz_pE *fp= f.rep.elts(); 1581 1582 zz_pEX buf; 1583 zz_pE *bufp; 1584 CanonicalForm result= 0; 1585 int i= 0; 1586 int degf= deg(f); 1587 int k= 0; 1588 int degfSubK, repLength, j; 1589 while (degf >= k) 1590 { 1591 degfSubK= degf - k; 1592 if (degfSubK >= d) 1593 repLength= d; 1594 else 1595 repLength= degfSubK + 1; 1596 1597 buf.rep.SetLength ((long) repLength); 1598 bufp= buf.rep.elts(); 1599 for (j= 0; j < repLength; j++) 1600 bufp [j]= fp [j + k]; 1601 buf.normalize(); 1602 1603 result += convertNTLzz_pEX2CF (buf, x, alpha)*power (y, i); 1604 i++; 1605 k= d*i; 1606 } 1607 1608 return result; 1609 } 1610 1611 CanonicalForm reverseSubstFp (const zz_pX& F, int d) 1612 { 1613 Variable y= Variable (2); 1614 Variable x= Variable (1); 1615 1616 zz_pX f= F; 1617 zz_p *fp= f.rep.elts(); 1618 1619 zz_pX buf; 1620 zz_p *bufp; 1621 CanonicalForm result= 0; 1622 int i= 0; 1623 int degf= deg(f); 1624 int k= 0; 1625 int degfSubK, repLength, j; 1626 while (degf >= k) 1627 { 1628 degfSubK= degf - k; 1629 if (degfSubK >= d) 1630 repLength= d; 1631 else 1632 repLength= degfSubK + 1; 1633 1634 buf.rep.SetLength ((long) repLength); 1635 bufp= buf.rep.elts(); 1636 for (j= 0; j < repLength; j++) 1637 bufp [j]= fp [j + k]; 1638 buf.normalize(); 1639 1640 result += convertNTLzzpX2CF (buf, x)*power (y, i); 1641 i++; 1642 k= d*i; 1643 } 1644 1645 return result; 1646 } 1647 1648 // assumes input to be reduced mod M and to be an element of Fq not Fp 1649 CanonicalForm 1650 mulMod2NTLFpReci (const CanonicalForm& F, const CanonicalForm& G, const 1651 CanonicalForm& M) 1652 { 1653 int d1= degree (F, 1) + degree (G, 1) + 1; 1654 d1 /= 2; 1655 d1 += 1; 1656 1657 zz_pX F1, F2; 1658 kronSubReciproFp (F1, F2, F, d1); 1659 zz_pX G1, G2; 1660 kronSubReciproFp (G1, G2, G, d1); 1661 1662 int k= d1*degree (M); 1663 MulTrunc (F1, F1, G1, (long) k); 1664 1665 int degtailF= degree (tailcoeff (F), 1); 1666 int degtailG= degree (tailcoeff (G), 1); 1667 int taildegF= taildegree (F); 1668 int taildegG= taildegree (G); 1669 int b= k + degtailF + degtailG - d1*(2+taildegF+taildegG); 1670 1671 reverse (F2, F2); 1672 reverse (G2, G2); 1673 MulTrunc (F2, F2, G2, b + 1); 1674 reverse (F2, F2, b); 1675 1676 int d2= tmax (deg (F2)/d1, deg (F1)/d1); 1677 return reverseSubstReciproFp (F1, F2, d1, d2); 1678 } 1679 1680 //Kronecker substitution 1681 CanonicalForm 1682 mulMod2NTLFp (const CanonicalForm& F, const CanonicalForm& G, const 1683 CanonicalForm& M) 1684 { 1685 CanonicalForm A= F; 1686 CanonicalForm B= G; 1687 1688 int degAx= degree (A, 1); 1689 int degAy= degree (A, 2); 1690 int degBx= degree (B, 1); 1691 int degBy= degree (B, 2); 1692 int d1= degAx + 1 + degBx; 1693 int d2= tmax (degAy, degBy); 1694 1695 if (d1 > 128 && d2 > 160 && (degAy == degBy) && (2*degAy > degree (M))) 1696 return mulMod2NTLFpReci (A, B, M); 1697 1698 zz_pX NTLA= kronSubFp (A, d1); 1699 zz_pX NTLB= kronSubFp (B, d1); 1700 1701 int k= d1*degree (M); 1702 MulTrunc (NTLA, NTLA, NTLB, (long) k); 1703 1704 A= reverseSubstFp (NTLA, d1); 1705 1706 return A; 1707 } 1708 1709 // assumes input to be reduced mod M and to be an element of Fq not Fp 1710 CanonicalForm 1711 mulMod2NTLFqReci (const CanonicalForm& F, const CanonicalForm& G, const 1712 CanonicalForm& M, const Variable& alpha) 1713 { 1714 int d1= degree (F, 1) + degree (G, 1) + 1; 1715 d1 /= 2; 1716 d1 += 1; 1717 1718 zz_pEX F1, F2; 1719 kronSubReciproFq (F1, F2, F, d1, alpha); 1720 zz_pEX G1, G2; 1721 kronSubReciproFq (G1, G2, G, d1, alpha); 1722 1723 int k= d1*degree (M); 1724 MulTrunc (F1, F1, G1, (long) k); 1725 1726 int degtailF= degree (tailcoeff (F), 1); 1727 int degtailG= degree (tailcoeff (G), 1); 1728 int taildegF= taildegree (F); 1729 int taildegG= taildegree (G); 1730 int b= k + degtailF + degtailG - d1*(2+taildegF+taildegG); 1731 1732 reverse (F2, F2); 1733 reverse (G2, G2); 1734 MulTrunc (F2, F2, G2, b + 1); 1735 reverse (F2, F2, b); 1736 1737 int d2= tmax (deg (F2)/d1, deg (F1)/d1); 1738 return reverseSubstReciproFq (F1, F2, d1, d2, alpha); 1739 } 1740 1741 #ifdef HAVE_FLINT 1742 CanonicalForm 1743 mulMod2FLINTFp (const CanonicalForm& F, const CanonicalForm& G, const 1744 CanonicalForm& M); 1745 #endif 1746 1747 CanonicalForm 1748 mulMod2NTLFq (const CanonicalForm& F, const CanonicalForm& G, const 1749 CanonicalForm& M) 1750 { 1751 Variable alpha; 1752 CanonicalForm A= F; 1753 CanonicalForm B= G; 1754 1755 if (hasFirstAlgVar (A, alpha) || hasFirstAlgVar (B, alpha)) 1756 { 1757 int degAx= degree (A, 1); 1758 int degAy= degree (A, 2); 1759 int degBx= degree (B, 1); 1760 int degBy= degree (B, 2); 1761 int d1= degAx + degBx + 1; 1762 int d2= tmax (degAy, degBy); 1763 zz_p::init (getCharacteristic()); 1764 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 1765 zz_pE::init (NTLMipo); 1766 1767 int degMipo= degree (getMipo (alpha)); 1768 if ((d1 > 128/degMipo) && (d2 > 160/degMipo) && (degAy == degBy) && 1769 (2*degAy > degree (M))) 1770 return mulMod2NTLFqReci (A, B, M, alpha); 1771 1772 zz_pEX NTLA= kronSubFq (A, d1, alpha); 1773 zz_pEX NTLB= kronSubFq (B, d1, alpha); 1774 1775 int k= d1*degree (M); 1776 1777 MulTrunc (NTLA, NTLA, NTLB, (long) k); 1778 1779 A= reverseSubstFq (NTLA, d1, alpha); 1780 1781 return A; 1782 } 1783 else 1784 #ifdef HAVE_FLINT 1785 return mulMod2FLINTFp (A, B, M); 1786 #else 1787 return mulMod2NTLFp (A, B, M); 1788 #endif 1789 } 1813 1790 1814 1791 CanonicalForm mulMod2 (const CanonicalForm& A, const CanonicalForm& B, … … 1886 1863 DEBOUTLN (cerr, "fatal end in mulMod2"); 1887 1864 } 1865 1866 // end bivariate polys 1867 //********************** 1868 // multivariate polys 1888 1869 1889 1870 CanonicalForm mod (const CanonicalForm& F, const CFList& M) … … 2031 2012 } 2032 2013 2014 // end multivariate polys 2015 //*************************** 2016 // division 2017 2033 2018 CanonicalForm reverse (const CanonicalForm& F, int d) 2034 2019 { … … 2510 2495 } 2511 2496 2497 // end division 2498 2512 2499 #endif
Note: See TracChangeset
for help on using the changeset viewer.