[7bf145] | 1 | /*****************************************************************************\ |
---|
[806c18] | 2 | * Computer Algebra System SINGULAR |
---|
[7bf145] | 3 | \*****************************************************************************/ |
---|
| 4 | /** @file facFqBivar.h |
---|
[806c18] | 5 | * |
---|
[7bf145] | 6 | * This file provides functions for factorizing a bivariate polynomial over |
---|
[806c18] | 7 | * \f$ F_{p} \f$ , \f$ F_{p}(\alpha ) \f$ or GF. |
---|
[7bf145] | 8 | * |
---|
| 9 | * @author Martin Lee |
---|
| 10 | * |
---|
| 11 | **/ |
---|
| 12 | /*****************************************************************************/ |
---|
| 13 | |
---|
| 14 | #ifndef FAC_FQ_BIVAR_H |
---|
| 15 | #define FAC_FQ_BIVAR_H |
---|
| 16 | |
---|
[3c702a] | 17 | // #include "config.h" |
---|
[7bf145] | 18 | |
---|
[0851b0] | 19 | #include "timing.h" |
---|
[650f2d8] | 20 | #include "cf_assert.h" |
---|
[7bf145] | 21 | |
---|
| 22 | #include "facFqBivarUtil.h" |
---|
| 23 | #include "DegreePattern.h" |
---|
| 24 | #include "ExtensionInfo.h" |
---|
| 25 | #include "cf_util.h" |
---|
| 26 | #include "facFqSquarefree.h" |
---|
[f876a66] | 27 | #include "cf_map.h" |
---|
| 28 | #include "cfNewtonPolygon.h" |
---|
[10b5cf] | 29 | #include "fac_util.h" |
---|
[03c742] | 30 | #include "cf_algorithm.h" |
---|
[7bf145] | 31 | |
---|
[0851b0] | 32 | TIMING_DEFINE_PRINT(fac_fq_bi_sqrf) |
---|
| 33 | TIMING_DEFINE_PRINT(fac_fq_bi_factor_sqrf) |
---|
| 34 | |
---|
[33c8040] | 35 | static const double log2exp= 1.442695041; |
---|
[fd5b3a] | 36 | |
---|
[03c742] | 37 | #if defined(HAVE_NTL) || defined(HAVE_FLINT) |
---|
[806c18] | 38 | /// Factorization of a squarefree bivariate polynomials over an arbitrary finite |
---|
[7bf145] | 39 | /// field, information on the current field we work over is in @a info. @a info |
---|
| 40 | /// may also contain information about the initial field if initial and current |
---|
[806c18] | 41 | /// field do not coincide. In this case the current field is an extension of the |
---|
[7bf145] | 42 | /// initial field and the factors returned are factors of F over the initial |
---|
[806c18] | 43 | /// field. |
---|
| 44 | /// |
---|
[7bf145] | 45 | /// @return @a biFactorize returns a list of factors of F. If F is not monic |
---|
[806c18] | 46 | /// its leading coefficient is not outputted. |
---|
[7bf145] | 47 | /// @sa extBifactorize() |
---|
[806c18] | 48 | CFList |
---|
[d46cb6] | 49 | biFactorize (const CanonicalForm& F, ///< [in] a sqrfree bivariate poly |
---|
[7bf145] | 50 | const ExtensionInfo& info ///< [in] information about extension |
---|
| 51 | ); |
---|
| 52 | |
---|
[b28747] | 53 | #ifdef HAVE_NTL // biFactorize |
---|
[a60b8b] | 54 | inline CFList |
---|
[e829d1] | 55 | biSqrfFactorizeHelper (const CanonicalForm& G, const ExtensionInfo& info) |
---|
[7bf145] | 56 | { |
---|
[f876a66] | 57 | CFMap N; |
---|
| 58 | CanonicalForm F= compress (G, N); |
---|
| 59 | CanonicalForm contentX= content (F, 1); |
---|
| 60 | CanonicalForm contentY= content (F, 2); |
---|
| 61 | F /= (contentX*contentY); |
---|
| 62 | CFFList contentXFactors, contentYFactors; |
---|
[a60b8b] | 63 | if (info.getAlpha().level() != 1) |
---|
| 64 | { |
---|
| 65 | contentXFactors= factorize (contentX, info.getAlpha()); |
---|
| 66 | contentYFactors= factorize (contentY, info.getAlpha()); |
---|
| 67 | } |
---|
| 68 | else if (info.getAlpha().level() == 1 && info.getGFDegree() == 1) |
---|
| 69 | { |
---|
| 70 | contentXFactors= factorize (contentX); |
---|
| 71 | contentYFactors= factorize (contentY); |
---|
| 72 | } |
---|
| 73 | else if (info.getAlpha().level() == 1 && info.getGFDegree() != 1) |
---|
| 74 | { |
---|
| 75 | CFList bufContentX, bufContentY; |
---|
| 76 | bufContentX= biFactorize (contentX, info); |
---|
| 77 | bufContentY= biFactorize (contentY, info); |
---|
| 78 | for (CFListIterator iter= bufContentX; iter.hasItem(); iter++) |
---|
| 79 | contentXFactors.append (CFFactor (iter.getItem(), 1)); |
---|
| 80 | for (CFListIterator iter= bufContentY; iter.hasItem(); iter++) |
---|
| 81 | contentYFactors.append (CFFactor (iter.getItem(), 1)); |
---|
| 82 | } |
---|
| 83 | |
---|
[f876a66] | 84 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
| 85 | contentXFactors.removeFirst(); |
---|
| 86 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
| 87 | contentYFactors.removeFirst(); |
---|
| 88 | if (F.inCoeffDomain()) |
---|
| 89 | { |
---|
| 90 | CFList result; |
---|
| 91 | for (CFFListIterator i= contentXFactors; i.hasItem(); i++) |
---|
| 92 | result.append (N (i.getItem().factor())); |
---|
| 93 | for (CFFListIterator i= contentYFactors; i.hasItem(); i++) |
---|
| 94 | result.append (N (i.getItem().factor())); |
---|
| 95 | normalize (result); |
---|
| 96 | result.insert (Lc (G)); |
---|
| 97 | return result; |
---|
| 98 | } |
---|
[aba90e8] | 99 | mpz_t * M=new mpz_t [4]; |
---|
| 100 | mpz_init (M[0]); |
---|
| 101 | mpz_init (M[1]); |
---|
| 102 | mpz_init (M[2]); |
---|
| 103 | mpz_init (M[3]); |
---|
| 104 | |
---|
| 105 | mpz_t * S=new mpz_t [2]; |
---|
| 106 | mpz_init (S[0]); |
---|
| 107 | mpz_init (S[1]); |
---|
| 108 | |
---|
[f876a66] | 109 | F= compress (F, M, S); |
---|
[7bf145] | 110 | CFList result= biFactorize (F, info); |
---|
[f876a66] | 111 | for (CFListIterator i= result; i.hasItem(); i++) |
---|
| 112 | i.getItem()= N (decompress (i.getItem(), M, S)); |
---|
| 113 | for (CFFListIterator i= contentXFactors; i.hasItem(); i++) |
---|
| 114 | result.append (N(i.getItem().factor())); |
---|
| 115 | for (CFFListIterator i= contentYFactors; i.hasItem(); i++) |
---|
| 116 | result.append (N (i.getItem().factor())); |
---|
| 117 | normalize (result); |
---|
| 118 | result.insert (Lc(G)); |
---|
[aba90e8] | 119 | |
---|
| 120 | mpz_clear (M[0]); |
---|
| 121 | mpz_clear (M[1]); |
---|
| 122 | mpz_clear (M[2]); |
---|
| 123 | mpz_clear (M[3]); |
---|
| 124 | delete [] M; |
---|
| 125 | |
---|
| 126 | mpz_clear (S[0]); |
---|
| 127 | mpz_clear (S[1]); |
---|
| 128 | delete [] S; |
---|
| 129 | |
---|
[7bf145] | 130 | return result; |
---|
| 131 | } |
---|
[b28747] | 132 | #endif |
---|
[7bf145] | 133 | |
---|
[a60b8b] | 134 | /// factorize a squarefree bivariate polynomial over \f$ F_{p} \f$. |
---|
| 135 | /// |
---|
| 136 | /// @return @a FpBiSqrfFactorize returns a list of monic factors, the first |
---|
| 137 | /// element is the leading coefficient. |
---|
| 138 | /// @sa FqBiSqrfFactorize(), GFBiSqrfFactorize() |
---|
[b28747] | 139 | #ifdef HAVE_NTL // biSqrfFactorizeHelper, biFactorize |
---|
[a60b8b] | 140 | inline |
---|
| 141 | CFList FpBiSqrfFactorize (const CanonicalForm & G ///< [in] a bivariate poly |
---|
| 142 | ) |
---|
| 143 | { |
---|
| 144 | ExtensionInfo info= ExtensionInfo (false); |
---|
| 145 | return biSqrfFactorizeHelper (G, info); |
---|
| 146 | } |
---|
[b28747] | 147 | #endif |
---|
[a60b8b] | 148 | |
---|
[7bf145] | 149 | /// factorize a squarefree bivariate polynomial over \f$ F_{p}(\alpha ) \f$. |
---|
| 150 | /// |
---|
[806c18] | 151 | /// @return @a FqBiSqrfFactorize returns a list of monic factors, the first |
---|
| 152 | /// element is the leading coefficient. |
---|
[7bf145] | 153 | /// @sa FpBiSqrfFactorize(), GFBiSqrfFactorize() |
---|
[b28747] | 154 | #ifdef HAVE_NTL // biSqrfFactorizeHelper, biFactorize |
---|
[7bf145] | 155 | inline |
---|
[f876a66] | 156 | CFList FqBiSqrfFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
[7bf145] | 157 | const Variable& alpha ///< [in] algebraic variable |
---|
[806c18] | 158 | ) |
---|
[7bf145] | 159 | { |
---|
| 160 | ExtensionInfo info= ExtensionInfo (alpha, false); |
---|
[a60b8b] | 161 | return biSqrfFactorizeHelper (G, info); |
---|
[7bf145] | 162 | } |
---|
[b28747] | 163 | #endif |
---|
[7bf145] | 164 | |
---|
| 165 | /// factorize a squarefree bivariate polynomial over GF |
---|
| 166 | /// |
---|
[806c18] | 167 | /// @return @a GFBiSqrfFactorize returns a list of monic factors, the first |
---|
| 168 | /// element is the leading coefficient. |
---|
| 169 | /// @sa FpBiSqrfFactorize(), FqBiSqrfFactorize() |
---|
[b28747] | 170 | #ifdef HAVE_NTL // biSqrfFactorizeHelper, biFactorize |
---|
[7bf145] | 171 | inline |
---|
[f876a66] | 172 | CFList GFBiSqrfFactorize (const CanonicalForm & G ///< [in] a bivariate poly |
---|
[806c18] | 173 | ) |
---|
[7bf145] | 174 | { |
---|
[806c18] | 175 | ASSERT (CFFactory::gettype() == GaloisFieldDomain, |
---|
[7bf145] | 176 | "GF as base field expected"); |
---|
| 177 | ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false); |
---|
[a60b8b] | 178 | return biSqrfFactorizeHelper (G, info); |
---|
[7bf145] | 179 | } |
---|
[b28747] | 180 | #endif |
---|
[7bf145] | 181 | |
---|
| 182 | /// factorize a bivariate polynomial over \f$ F_{p} \f$ |
---|
| 183 | /// |
---|
[806c18] | 184 | /// @return @a FpBiFactorize returns a list of monic factors with |
---|
| 185 | /// multiplicity, the first element is the leading coefficient. |
---|
| 186 | /// @sa FqBiFactorize(), GFBiFactorize() |
---|
[b28747] | 187 | #ifdef HAVE_NTL // biFactorize |
---|
[7bf145] | 188 | inline |
---|
[f9b796e] | 189 | CFFList |
---|
| 190 | FpBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
| 191 | bool substCheck= true ///< [in] enables substitute check |
---|
| 192 | ) |
---|
[7bf145] | 193 | { |
---|
| 194 | ExtensionInfo info= ExtensionInfo (false); |
---|
[f876a66] | 195 | CFMap N; |
---|
| 196 | CanonicalForm F= compress (G, N); |
---|
[f9b796e] | 197 | |
---|
| 198 | if (substCheck) |
---|
| 199 | { |
---|
| 200 | bool foundOne= false; |
---|
[d0dbd7] | 201 | int * substDegree= NEW_ARRAY(int,F.level()); |
---|
[f9b796e] | 202 | for (int i= 1; i <= F.level(); i++) |
---|
| 203 | { |
---|
| 204 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
| 205 | if (substDegree [i-1] > 1) |
---|
| 206 | { |
---|
| 207 | foundOne= true; |
---|
| 208 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | if (foundOne) |
---|
| 212 | { |
---|
| 213 | CFFList result= FpBiFactorize (F, false); |
---|
| 214 | CFFList newResult, tmp; |
---|
| 215 | CanonicalForm tmp2; |
---|
| 216 | newResult.insert (result.getFirst()); |
---|
| 217 | result.removeFirst(); |
---|
| 218 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 219 | { |
---|
| 220 | tmp2= i.getItem().factor(); |
---|
| 221 | for (int j= 1; j <= F.level(); j++) |
---|
| 222 | { |
---|
| 223 | if (substDegree[j-1] > 1) |
---|
| 224 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
| 225 | } |
---|
| 226 | tmp= FpBiFactorize (tmp2, false); |
---|
| 227 | tmp.removeFirst(); |
---|
| 228 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
| 229 | newResult.append (CFFactor (j.getItem().factor(), |
---|
| 230 | j.getItem().exp()*i.getItem().exp())); |
---|
| 231 | } |
---|
| 232 | decompress (newResult, N); |
---|
[d0dbd7] | 233 | DELETE_ARRAY(substDegree); |
---|
[f9b796e] | 234 | return newResult; |
---|
| 235 | } |
---|
[d0dbd7] | 236 | DELETE_ARRAY(substDegree); |
---|
[f9b796e] | 237 | } |
---|
| 238 | |
---|
[806c18] | 239 | CanonicalForm LcF= Lc (F); |
---|
[f876a66] | 240 | CanonicalForm contentX= content (F, 1); |
---|
| 241 | CanonicalForm contentY= content (F, 2); |
---|
| 242 | F /= (contentX*contentY); |
---|
| 243 | CFFList contentXFactors, contentYFactors; |
---|
| 244 | contentXFactors= factorize (contentX); |
---|
| 245 | contentYFactors= factorize (contentY); |
---|
| 246 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
| 247 | contentXFactors.removeFirst(); |
---|
| 248 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
| 249 | contentYFactors.removeFirst(); |
---|
| 250 | decompress (contentXFactors, N); |
---|
| 251 | decompress (contentYFactors, N); |
---|
[d1553c] | 252 | CFFList result; |
---|
[f876a66] | 253 | if (F.inCoeffDomain()) |
---|
| 254 | { |
---|
| 255 | result= Union (contentXFactors, contentYFactors); |
---|
| 256 | normalize (result); |
---|
| 257 | result.insert (CFFactor (LcF, 1)); |
---|
| 258 | return result; |
---|
| 259 | } |
---|
[aba90e8] | 260 | mpz_t * M=new mpz_t [4]; |
---|
| 261 | mpz_init (M[0]); |
---|
| 262 | mpz_init (M[1]); |
---|
| 263 | mpz_init (M[2]); |
---|
| 264 | mpz_init (M[3]); |
---|
| 265 | |
---|
| 266 | mpz_t * S=new mpz_t [2]; |
---|
| 267 | mpz_init (S[0]); |
---|
| 268 | mpz_init (S[1]); |
---|
| 269 | |
---|
[f876a66] | 270 | F= compress (F, M, S); |
---|
[d1553c] | 271 | |
---|
[0851b0] | 272 | TIMING_START (fac_fq_bi_sqrf); |
---|
[d1553c] | 273 | CFFList sqrf= FpSqrf (F, false); |
---|
[0851b0] | 274 | TIMING_END_AND_PRINT (fac_fq_bi_sqrf, |
---|
| 275 | "time for bivariate sqrf factors over Fp: "); |
---|
[d1553c] | 276 | CFList bufResult; |
---|
| 277 | sqrf.removeFirst(); |
---|
| 278 | CFListIterator i; |
---|
| 279 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
[7bf145] | 280 | { |
---|
[0851b0] | 281 | TIMING_START (fac_fq_bi_factor_sqrf); |
---|
[d1553c] | 282 | bufResult= biFactorize (iter.getItem().factor(), info); |
---|
[0851b0] | 283 | TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, |
---|
| 284 | "time to factor bivariate sqrf factors over Fp: "); |
---|
[d1553c] | 285 | for (i= bufResult; i.hasItem(); i++) |
---|
| 286 | result.append (CFFactor (N (decompress (i.getItem(), M, S)), |
---|
| 287 | iter.getItem().exp())); |
---|
[7bf145] | 288 | } |
---|
[d1553c] | 289 | |
---|
[f876a66] | 290 | result= Union (result, contentXFactors); |
---|
| 291 | result= Union (result, contentYFactors); |
---|
| 292 | normalize (result); |
---|
[7bf145] | 293 | result.insert (CFFactor (LcF, 1)); |
---|
[aba90e8] | 294 | |
---|
| 295 | mpz_clear (M[0]); |
---|
| 296 | mpz_clear (M[1]); |
---|
| 297 | mpz_clear (M[2]); |
---|
| 298 | mpz_clear (M[3]); |
---|
| 299 | delete [] M; |
---|
| 300 | |
---|
| 301 | mpz_clear (S[0]); |
---|
| 302 | mpz_clear (S[1]); |
---|
| 303 | delete [] S; |
---|
| 304 | |
---|
[7bf145] | 305 | return result; |
---|
| 306 | } |
---|
[b28747] | 307 | #endif |
---|
[7bf145] | 308 | |
---|
| 309 | /// factorize a bivariate polynomial over \f$ F_{p}(\alpha ) \f$ |
---|
| 310 | /// |
---|
[806c18] | 311 | /// @return @a FqBiFactorize returns a list of monic factors with |
---|
| 312 | /// multiplicity, the first element is the leading coefficient. |
---|
| 313 | /// @sa FpBiFactorize(), FqBiFactorize() |
---|
[b28747] | 314 | #ifdef HAVE_NTL // biFactorize |
---|
[7bf145] | 315 | inline |
---|
[f9b796e] | 316 | CFFList |
---|
| 317 | FqBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
| 318 | const Variable & alpha, ///< [in] algebraic variable |
---|
| 319 | bool substCheck= true ///< [in] enables substitute check |
---|
| 320 | ) |
---|
[7bf145] | 321 | { |
---|
| 322 | ExtensionInfo info= ExtensionInfo (alpha, false); |
---|
[f876a66] | 323 | CFMap N; |
---|
| 324 | CanonicalForm F= compress (G, N); |
---|
[f9b796e] | 325 | |
---|
| 326 | if (substCheck) |
---|
| 327 | { |
---|
| 328 | bool foundOne= false; |
---|
[d0dbd7] | 329 | int * substDegree= NEW_ARRAY(int,F.level()); |
---|
[f9b796e] | 330 | for (int i= 1; i <= F.level(); i++) |
---|
| 331 | { |
---|
| 332 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
| 333 | if (substDegree [i-1] > 1) |
---|
| 334 | { |
---|
| 335 | foundOne= true; |
---|
| 336 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
| 337 | } |
---|
| 338 | } |
---|
| 339 | if (foundOne) |
---|
| 340 | { |
---|
| 341 | CFFList result= FqBiFactorize (F, alpha, false); |
---|
| 342 | CFFList newResult, tmp; |
---|
| 343 | CanonicalForm tmp2; |
---|
| 344 | newResult.insert (result.getFirst()); |
---|
| 345 | result.removeFirst(); |
---|
| 346 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 347 | { |
---|
| 348 | tmp2= i.getItem().factor(); |
---|
| 349 | for (int j= 1; j <= F.level(); j++) |
---|
| 350 | { |
---|
| 351 | if (substDegree[j-1] > 1) |
---|
| 352 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
| 353 | } |
---|
| 354 | tmp= FqBiFactorize (tmp2, alpha, false); |
---|
| 355 | tmp.removeFirst(); |
---|
| 356 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
| 357 | newResult.append (CFFactor (j.getItem().factor(), |
---|
| 358 | j.getItem().exp()*i.getItem().exp())); |
---|
| 359 | } |
---|
| 360 | decompress (newResult, N); |
---|
[d0dbd7] | 361 | DELETE_ARRAY(substDegree); |
---|
[f9b796e] | 362 | return newResult; |
---|
| 363 | } |
---|
[d0dbd7] | 364 | DELETE_ARRAY(substDegree); |
---|
[f9b796e] | 365 | } |
---|
| 366 | |
---|
[806c18] | 367 | CanonicalForm LcF= Lc (F); |
---|
[f876a66] | 368 | CanonicalForm contentX= content (F, 1); |
---|
| 369 | CanonicalForm contentY= content (F, 2); |
---|
| 370 | F /= (contentX*contentY); |
---|
| 371 | CFFList contentXFactors, contentYFactors; |
---|
[563364] | 372 | contentXFactors= factorize (contentX, alpha); |
---|
| 373 | contentYFactors= factorize (contentY, alpha); |
---|
[f876a66] | 374 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
| 375 | contentXFactors.removeFirst(); |
---|
| 376 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
| 377 | contentYFactors.removeFirst(); |
---|
| 378 | decompress (contentXFactors, N); |
---|
| 379 | decompress (contentYFactors, N); |
---|
[d1553c] | 380 | CFFList result; |
---|
[f876a66] | 381 | if (F.inCoeffDomain()) |
---|
| 382 | { |
---|
| 383 | result= Union (contentXFactors, contentYFactors); |
---|
| 384 | normalize (result); |
---|
| 385 | result.insert (CFFactor (LcF, 1)); |
---|
| 386 | return result; |
---|
| 387 | } |
---|
[aba90e8] | 388 | |
---|
| 389 | mpz_t * M=new mpz_t [4]; |
---|
| 390 | mpz_init (M[0]); |
---|
| 391 | mpz_init (M[1]); |
---|
| 392 | mpz_init (M[2]); |
---|
| 393 | mpz_init (M[3]); |
---|
| 394 | |
---|
| 395 | mpz_t * S=new mpz_t [2]; |
---|
| 396 | mpz_init (S[0]); |
---|
| 397 | mpz_init (S[1]); |
---|
| 398 | |
---|
[f876a66] | 399 | F= compress (F, M, S); |
---|
[d1553c] | 400 | |
---|
[0851b0] | 401 | TIMING_START (fac_fq_bi_sqrf); |
---|
[d1553c] | 402 | CFFList sqrf= FqSqrf (F, alpha, false); |
---|
[0851b0] | 403 | TIMING_END_AND_PRINT (fac_fq_bi_sqrf, |
---|
| 404 | "time for bivariate sqrf factors over Fq: "); |
---|
[d1553c] | 405 | CFList bufResult; |
---|
| 406 | sqrf.removeFirst(); |
---|
| 407 | CFListIterator i; |
---|
| 408 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
[7bf145] | 409 | { |
---|
[0851b0] | 410 | TIMING_START (fac_fq_bi_factor_sqrf); |
---|
[d1553c] | 411 | bufResult= biFactorize (iter.getItem().factor(), info); |
---|
[0851b0] | 412 | TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, |
---|
| 413 | "time to factor bivariate sqrf factors over Fq: "); |
---|
[d1553c] | 414 | for (i= bufResult; i.hasItem(); i++) |
---|
| 415 | result.append (CFFactor (N (decompress (i.getItem(), M, S)), |
---|
| 416 | iter.getItem().exp())); |
---|
[7bf145] | 417 | } |
---|
[d1553c] | 418 | |
---|
[f876a66] | 419 | result= Union (result, contentXFactors); |
---|
| 420 | result= Union (result, contentYFactors); |
---|
| 421 | normalize (result); |
---|
[7bf145] | 422 | result.insert (CFFactor (LcF, 1)); |
---|
[aba90e8] | 423 | |
---|
| 424 | mpz_clear (M[0]); |
---|
| 425 | mpz_clear (M[1]); |
---|
| 426 | mpz_clear (M[2]); |
---|
| 427 | mpz_clear (M[3]); |
---|
| 428 | delete [] M; |
---|
| 429 | |
---|
| 430 | mpz_clear (S[0]); |
---|
| 431 | mpz_clear (S[1]); |
---|
| 432 | delete [] S; |
---|
| 433 | |
---|
[7bf145] | 434 | return result; |
---|
| 435 | } |
---|
[b28747] | 436 | #endif |
---|
[7bf145] | 437 | |
---|
| 438 | /// factorize a bivariate polynomial over GF |
---|
[806c18] | 439 | /// |
---|
| 440 | /// @return @a GFBiFactorize returns a list of monic factors with |
---|
| 441 | /// multiplicity, the first element is the leading coefficient. |
---|
| 442 | /// @sa FpBiFactorize(), FqBiFactorize() |
---|
[b28747] | 443 | #ifdef HAVE_NTL // biFactorize |
---|
[7bf145] | 444 | inline |
---|
[f9b796e] | 445 | CFFList |
---|
| 446 | GFBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
| 447 | bool substCheck= true ///< [in] enables substitute check |
---|
| 448 | ) |
---|
[7bf145] | 449 | { |
---|
[806c18] | 450 | ASSERT (CFFactory::gettype() == GaloisFieldDomain, |
---|
[7bf145] | 451 | "GF as base field expected"); |
---|
| 452 | ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false); |
---|
[f876a66] | 453 | CFMap N; |
---|
| 454 | CanonicalForm F= compress (G, N); |
---|
[f9b796e] | 455 | |
---|
| 456 | if (substCheck) |
---|
| 457 | { |
---|
| 458 | bool foundOne= false; |
---|
[d0dbd7] | 459 | int * substDegree=NEW_ARRAY(int,F.level()); |
---|
[f9b796e] | 460 | for (int i= 1; i <= F.level(); i++) |
---|
| 461 | { |
---|
| 462 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
| 463 | if (substDegree [i-1] > 1) |
---|
| 464 | { |
---|
| 465 | foundOne= true; |
---|
| 466 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
| 467 | } |
---|
| 468 | } |
---|
| 469 | if (foundOne) |
---|
| 470 | { |
---|
| 471 | CFFList result= GFBiFactorize (F, false); |
---|
| 472 | CFFList newResult, tmp; |
---|
| 473 | CanonicalForm tmp2; |
---|
| 474 | newResult.insert (result.getFirst()); |
---|
| 475 | result.removeFirst(); |
---|
| 476 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 477 | { |
---|
| 478 | tmp2= i.getItem().factor(); |
---|
| 479 | for (int j= 1; j <= F.level(); j++) |
---|
| 480 | { |
---|
| 481 | if (substDegree[j-1] > 1) |
---|
| 482 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
| 483 | } |
---|
| 484 | tmp= GFBiFactorize (tmp2, false); |
---|
| 485 | tmp.removeFirst(); |
---|
| 486 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
| 487 | newResult.append (CFFactor (j.getItem().factor(), |
---|
| 488 | j.getItem().exp()*i.getItem().exp())); |
---|
| 489 | } |
---|
| 490 | decompress (newResult, N); |
---|
[d0dbd7] | 491 | DELETE_ARRAY(substDegree); |
---|
[f9b796e] | 492 | return newResult; |
---|
| 493 | } |
---|
[d0dbd7] | 494 | DELETE_ARRAY(substDegree); |
---|
[f9b796e] | 495 | } |
---|
| 496 | |
---|
[7bf145] | 497 | CanonicalForm LcF= Lc (F); |
---|
[f876a66] | 498 | CanonicalForm contentX= content (F, 1); |
---|
| 499 | CanonicalForm contentY= content (F, 2); |
---|
| 500 | F /= (contentX*contentY); |
---|
| 501 | CFFList contentXFactors, contentYFactors; |
---|
| 502 | contentXFactors= factorize (contentX); |
---|
| 503 | contentYFactors= factorize (contentY); |
---|
| 504 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
| 505 | contentXFactors.removeFirst(); |
---|
| 506 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
| 507 | contentYFactors.removeFirst(); |
---|
| 508 | decompress (contentXFactors, N); |
---|
| 509 | decompress (contentYFactors, N); |
---|
[d1553c] | 510 | CFFList result; |
---|
[f876a66] | 511 | if (F.inCoeffDomain()) |
---|
| 512 | { |
---|
| 513 | result= Union (contentXFactors, contentYFactors); |
---|
| 514 | normalize (result); |
---|
| 515 | result.insert (CFFactor (LcF, 1)); |
---|
| 516 | return result; |
---|
| 517 | } |
---|
[aba90e8] | 518 | |
---|
| 519 | mpz_t * M=new mpz_t [4]; |
---|
| 520 | mpz_init (M[0]); |
---|
| 521 | mpz_init (M[1]); |
---|
| 522 | mpz_init (M[2]); |
---|
| 523 | mpz_init (M[3]); |
---|
| 524 | |
---|
| 525 | mpz_t * S=new mpz_t [2]; |
---|
| 526 | mpz_init (S[0]); |
---|
| 527 | mpz_init (S[1]); |
---|
| 528 | |
---|
[f876a66] | 529 | F= compress (F, M, S); |
---|
[d1553c] | 530 | |
---|
[0851b0] | 531 | TIMING_START (fac_fq_bi_sqrf); |
---|
[d1553c] | 532 | CFFList sqrf= GFSqrf (F, false); |
---|
[0851b0] | 533 | TIMING_END_AND_PRINT (fac_fq_bi_sqrf, |
---|
| 534 | "time for bivariate sqrf factors over GF: "); |
---|
[d1553c] | 535 | CFList bufResult; |
---|
| 536 | sqrf.removeFirst(); |
---|
| 537 | CFListIterator i; |
---|
| 538 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
[7bf145] | 539 | { |
---|
[0851b0] | 540 | TIMING_START (fac_fq_bi_factor_sqrf); |
---|
[d1553c] | 541 | bufResult= biFactorize (iter.getItem().factor(), info); |
---|
[0851b0] | 542 | TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, |
---|
| 543 | "time to factor bivariate sqrf factors over GF: "); |
---|
[d1553c] | 544 | for (i= bufResult; i.hasItem(); i++) |
---|
| 545 | result.append (CFFactor (N (decompress (i.getItem(), M, S)), |
---|
| 546 | iter.getItem().exp())); |
---|
[7bf145] | 547 | } |
---|
[d1553c] | 548 | |
---|
[f876a66] | 549 | result= Union (result, contentXFactors); |
---|
| 550 | result= Union (result, contentYFactors); |
---|
| 551 | normalize (result); |
---|
[7bf145] | 552 | result.insert (CFFactor (LcF, 1)); |
---|
[aba90e8] | 553 | |
---|
| 554 | mpz_clear (M[0]); |
---|
| 555 | mpz_clear (M[1]); |
---|
| 556 | mpz_clear (M[2]); |
---|
| 557 | mpz_clear (M[3]); |
---|
| 558 | delete [] M; |
---|
| 559 | |
---|
| 560 | mpz_clear (S[0]); |
---|
| 561 | mpz_clear (S[1]); |
---|
| 562 | delete [] S; |
---|
| 563 | |
---|
[7bf145] | 564 | return result; |
---|
| 565 | } |
---|
[b28747] | 566 | #endif |
---|
[7bf145] | 567 | |
---|
| 568 | /// \f$ \prod_{f\in L} {f (0, x)} \ mod\ M \f$ via divide-and-conquer |
---|
| 569 | /// |
---|
| 570 | /// @return @a prodMod0 computes the above defined product |
---|
| 571 | /// @sa prodMod() |
---|
[806c18] | 572 | CanonicalForm prodMod0 (const CFList& L, ///< [in] a list of compressed, |
---|
[7bf145] | 573 | ///< bivariate polynomials |
---|
[ad0177] | 574 | const CanonicalForm& M,///< [in] a power of Variable (2) |
---|
| 575 | const modpk& b= modpk()///< [in] coeff bound |
---|
[7bf145] | 576 | ); |
---|
| 577 | |
---|
[806c18] | 578 | /// find an evaluation point p, s.t. F(p,y) is squarefree and |
---|
| 579 | /// \f$ deg_{y} (F(p,y))= deg_{y} (F(x,y)) \f$. |
---|
[7bf145] | 580 | /// |
---|
| 581 | /// @return @a evalPoint returns an evaluation point, which is valid if and only |
---|
| 582 | /// if fail == false. |
---|
[806c18] | 583 | CanonicalForm |
---|
| 584 | evalPoint (const CanonicalForm& F, ///< [in] compressed, bivariate poly |
---|
[7bf145] | 585 | CanonicalForm & eval, ///< [in,out] F (p, y) |
---|
| 586 | const Variable& alpha, ///< [in] algebraic variable |
---|
| 587 | CFList& list, ///< [in] list of points already considered |
---|
| 588 | const bool& GF, ///< [in] GaloisFieldDomain? |
---|
| 589 | bool& fail ///< [in,out] equals true, if there is no |
---|
[806c18] | 590 | ///< valid evaluation point |
---|
[7bf145] | 591 | ); |
---|
| 592 | |
---|
| 593 | /// Univariate factorization of squarefree monic polys over finite fields via |
---|
[806c18] | 594 | /// NTL. If the characteristic is even special GF2 routines of NTL are used. |
---|
[7bf145] | 595 | /// |
---|
| 596 | /// @return @a uniFactorizer returns a list of monic factors |
---|
[5f4463] | 597 | CFList |
---|
[7bf145] | 598 | uniFactorizer (const CanonicalForm& A, ///< [in] squarefree univariate poly |
---|
| 599 | const Variable& alpha, ///< [in] algebraic variable |
---|
[806c18] | 600 | const bool& GF ///< [in] GaloisFieldDomain? |
---|
[7bf145] | 601 | ); |
---|
| 602 | |
---|
[806c18] | 603 | /// naive factor recombination over an extension of the initial field. |
---|
[7bf145] | 604 | /// Uses precomputed data to exclude combinations that are not possible. |
---|
| 605 | /// |
---|
| 606 | /// @return @a extFactorRecombination returns a list of factors over the initial |
---|
[806c18] | 607 | /// field, whose shift to zero is reversed. |
---|
| 608 | /// @sa factorRecombination(), extEarlyFactorDetection() |
---|
[368602a] | 609 | CFList |
---|
[7bf145] | 610 | extFactorRecombination ( |
---|
[c1b9927] | 611 | CFList& factors, ///< [in,out] list of lifted factors that are |
---|
[11bf82] | 612 | ///< monic wrt Variable (1), |
---|
| 613 | ///< original factors-factors found |
---|
| 614 | CanonicalForm& F, ///< [in,out] poly to be factored, |
---|
| 615 | ///< F/factors found |
---|
| 616 | const CanonicalForm& M, ///< [in] Variable (2)^liftBound |
---|
[c1b9927] | 617 | const ExtensionInfo& info,///< [in] contains information about |
---|
[11bf82] | 618 | ///< extension |
---|
| 619 | DegreePattern& degs, |
---|
| 620 | const CanonicalForm& eval,///< [in] evaluation point |
---|
| 621 | int s, ///< [in] algorithm starts checking subsets |
---|
| 622 | ///< of size s |
---|
| 623 | int thres ///< [in] threshold for the size of subsets |
---|
| 624 | ///< which are checked, for a full factor |
---|
[c1b9927] | 625 | ///< recombination choose |
---|
[11bf82] | 626 | ///< thres= factors.length()/2 |
---|
[7bf145] | 627 | ); |
---|
| 628 | |
---|
[806c18] | 629 | /// naive factor recombination. |
---|
[7bf145] | 630 | /// Uses precomputed data to exclude combinations that are not possible. |
---|
| 631 | /// |
---|
| 632 | /// @return @a factorRecombination returns a list of factors of F. |
---|
| 633 | /// @sa extFactorRecombination(), earlyFactorDetectection() |
---|
[368602a] | 634 | CFList |
---|
[7bf145] | 635 | factorRecombination ( |
---|
[14e634] | 636 | CFList& factors, ///< [in,out] list of lifted factors |
---|
| 637 | ///< that are monic wrt Variable (1) |
---|
| 638 | CanonicalForm& F, ///< [in,out] poly to be factored |
---|
| 639 | const CanonicalForm& M, ///< [in] Variable (2)^liftBound |
---|
| 640 | DegreePattern& degs, ///< [in] degree pattern |
---|
[2537fa0] | 641 | const CanonicalForm& eval, ///< [in] evaluation point |
---|
[14e634] | 642 | int s, ///< [in] algorithm starts checking |
---|
| 643 | ///< subsets of size s |
---|
| 644 | int thres, ///< [in] threshold for the size of |
---|
| 645 | ///< subsets which are checked, for a |
---|
| 646 | ///< full factor recombination choose |
---|
| 647 | ///< thres= factors.length()/2 |
---|
| 648 | const modpk& b=modpk(), ///< [in] coeff bound |
---|
| 649 | const CanonicalForm& den= 1 ///< [in] bound on the den if over Q (a) |
---|
[7bf145] | 650 | ); |
---|
| 651 | |
---|
| 652 | /// chooses a field extension. |
---|
| 653 | /// |
---|
| 654 | /// @return @a chooseExtension returns an extension specified by @a beta of |
---|
| 655 | /// appropiate size |
---|
| 656 | Variable chooseExtension ( |
---|
[11bf82] | 657 | const Variable & alpha, ///< [in] some algebraic variable |
---|
| 658 | const Variable & beta, ///< [in] some algebraic variable |
---|
| 659 | int k ///< [in] some int |
---|
[7bf145] | 660 | ); |
---|
| 661 | |
---|
[34e062] | 662 | /// compute lifting precisions from the shape of the Newton polygon of F |
---|
| 663 | /// |
---|
| 664 | /// @return @a getLiftPrecisions returns lifting precisions computed from the |
---|
| 665 | /// shape of the Newton polygon of F |
---|
| 666 | int * |
---|
| 667 | getLiftPrecisions (const CanonicalForm& F, ///< [in] a bivariate poly |
---|
| 668 | int& sizeOfOutput, ///< [in,out] size of the output |
---|
| 669 | int degreeLC ///< [in] degree of the leading coeff |
---|
| 670 | ///< [in] of F wrt. Variable (1) |
---|
| 671 | ); |
---|
| 672 | |
---|
| 673 | |
---|
[7bf145] | 674 | /// detects factors of @a F at stage @a deg of Hensel lifting. |
---|
| 675 | /// No combinations of more than one factor are tested. Lift bound and possible |
---|
[806c18] | 676 | /// degree pattern are updated. |
---|
| 677 | /// |
---|
[7bf145] | 678 | /// @sa factorRecombination(), extEarlyFactorDetection() |
---|
[1a3011e] | 679 | void |
---|
[7bf145] | 680 | earlyFactorDetection ( |
---|
[1a3011e] | 681 | CFList& reconstructedFactors, ///< [in,out] list of reconstructed |
---|
| 682 | ///< factors |
---|
[7bf145] | 683 | CanonicalForm& F, ///< [in,out] poly to be factored, returns |
---|
| 684 | ///< poly divided by detected factors in case |
---|
| 685 | ///< of success |
---|
[806c18] | 686 | CFList& factors, ///< [in,out] list of factors lifted up to |
---|
[7bf145] | 687 | ///< @a deg, returns a list of factors |
---|
| 688 | ///< without detected factors |
---|
[806c18] | 689 | int& adaptedLiftBound, ///< [in,out] adapted lift bound |
---|
[1a3011e] | 690 | int*& factorsFoundIndex,///< [in,out] factors already considered |
---|
[7bf145] | 691 | DegreePattern& degs, ///< [in,out] degree pattern, is updated |
---|
| 692 | ///< whenever we find a factor |
---|
| 693 | bool& success, ///< [in,out] indicating success |
---|
[d9357b] | 694 | int deg, ///< [in] stage of Hensel lifting |
---|
[2537fa0] | 695 | const CanonicalForm& eval, ///<[in] evaluation point |
---|
| 696 | const modpk& b= modpk()///< [in] coeff bound |
---|
[7bf145] | 697 | ); |
---|
| 698 | |
---|
| 699 | /// detects factors of @a F at stage @a deg of Hensel lifting. |
---|
| 700 | /// No combinations of more than one factor are tested. Lift bound and possible |
---|
[806c18] | 701 | /// degree pattern are updated. |
---|
| 702 | /// |
---|
[7bf145] | 703 | /// @sa factorRecombination(), earlyFactorDetection() |
---|
[1a3011e] | 704 | void |
---|
[7bf145] | 705 | extEarlyFactorDetection ( |
---|
[1a3011e] | 706 | CFList& reconstructedFactors, ///< [in,out] list of reconstructed |
---|
| 707 | ///< factors |
---|
[806c18] | 708 | CanonicalForm& F, ///< [in,out] poly to be factored, returns |
---|
| 709 | ///< poly divided by detected factors in case |
---|
[7bf145] | 710 | ///< of success |
---|
[806c18] | 711 | CFList& factors, ///< [in,out] list of factors lifted up to |
---|
[7bf145] | 712 | ///< @a deg, returns a list of factors |
---|
| 713 | ///< without detected factors |
---|
| 714 | int& adaptedLiftBound, ///< [in,out] adapted lift bound |
---|
[1a3011e] | 715 | int*& factorsFoundIndex, ///< [in,out] factors already considered |
---|
[7bf145] | 716 | DegreePattern& degs, ///< [in,out] degree pattern, is updated |
---|
| 717 | ///< whenever we find a factor |
---|
| 718 | bool& success, ///< [in,out] indicating success |
---|
| 719 | const ExtensionInfo& info, ///< [in] information about extension |
---|
| 720 | const CanonicalForm& eval, ///< [in] evaluation point |
---|
| 721 | int deg ///< [in] stage of Hensel lifting |
---|
| 722 | ); |
---|
| 723 | |
---|
[806c18] | 724 | /// hensel Lifting and early factor detection |
---|
[7bf145] | 725 | /// |
---|
[806c18] | 726 | /// @return @a henselLiftAndEarly returns monic (wrt Variable (1)) lifted |
---|
[7bf145] | 727 | /// factors without factors which have been detected at an early stage |
---|
| 728 | /// of Hensel lifting |
---|
[806c18] | 729 | /// @sa earlyFactorDetection(), extEarlyFactorDetection() |
---|
[7bf145] | 730 | |
---|
[368602a] | 731 | CFList |
---|
[7bf145] | 732 | henselLiftAndEarly ( |
---|
[806c18] | 733 | CanonicalForm& A, ///< [in,out] poly to be factored, |
---|
| 734 | ///< returns poly divided by detected factors |
---|
[7bf145] | 735 | ///< in case of success |
---|
| 736 | bool& earlySuccess, ///< [in,out] indicating success |
---|
| 737 | CFList& earlyFactors, ///< [in,out] list of factors detected |
---|
[806c18] | 738 | ///< at early stage of Hensel lifting |
---|
| 739 | DegreePattern& degs, ///< [in,out] degree pattern |
---|
[7bf145] | 740 | int& liftBound, ///< [in,out] (adapted) lift bound |
---|
| 741 | const CFList& uniFactors, ///< [in] univariate factors |
---|
| 742 | const ExtensionInfo& info, ///< [in] information about extension |
---|
[d9357b] | 743 | const CanonicalForm& eval, ///< [in] evaluation point |
---|
[14e634] | 744 | modpk& b, ///< [in] coeff bound |
---|
| 745 | CanonicalForm& den ///< [in] bound on the den if over Q(a) |
---|
[69fdf90] | 746 | ); |
---|
| 747 | |
---|
| 748 | /// hensel Lifting and early factor detection |
---|
| 749 | /// |
---|
| 750 | /// @return @a henselLiftAndEarly returns monic (wrt Variable (1)) lifted |
---|
| 751 | /// factors without factors which have been detected at an early stage |
---|
| 752 | /// of Hensel lifting |
---|
| 753 | /// @sa earlyFactorDetection(), extEarlyFactorDetection() |
---|
| 754 | |
---|
| 755 | CFList |
---|
| 756 | henselLiftAndEarly ( |
---|
| 757 | CanonicalForm& A, ///< [in,out] poly to be factored, |
---|
| 758 | ///< returns poly divided by detected factors |
---|
| 759 | ///< in case of success |
---|
| 760 | bool& earlySuccess, ///< [in,out] indicating success |
---|
| 761 | CFList& earlyFactors, ///< [in,out] list of factors detected |
---|
| 762 | ///< at early stage of Hensel lifting |
---|
| 763 | DegreePattern& degs, ///< [in,out] degree pattern |
---|
| 764 | int& liftBound, ///< [in,out] (adapted) lift bound |
---|
| 765 | const CFList& uniFactors, ///< [in] univariate factors |
---|
| 766 | const ExtensionInfo& info, ///< [in] information about extension |
---|
| 767 | const CanonicalForm& eval ///< [in] evaluation point |
---|
[7bf145] | 768 | ); |
---|
| 769 | |
---|
| 770 | /// Factorization over an extension of initial field |
---|
| 771 | /// |
---|
| 772 | /// @return @a extBiFactorize returns factorization of F over initial field |
---|
| 773 | /// @sa biFactorize() |
---|
[368602a] | 774 | CFList |
---|
[806c18] | 775 | extBiFactorize (const CanonicalForm& F, ///< [in] poly to be factored |
---|
| 776 | const ExtensionInfo& info ///< [in] info about extension |
---|
[7bf145] | 777 | ); |
---|
| 778 | |
---|
[615ca8] | 779 | #endif |
---|
[7bf145] | 780 | #endif |
---|
| 781 | /* FAC_FQ_BIVAR_H */ |
---|
| 782 | |
---|