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