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