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