[7bf145] | 1 | /*****************************************************************************\ |
---|
[806c18] | 2 | * Computer Algebra System SINGULAR |
---|
[7bf145] | 3 | \*****************************************************************************/ |
---|
| 4 | /** @file facFqFactorize.h |
---|
[806c18] | 5 | * |
---|
[7bf145] | 6 | * This file provides functions for factorizing a multivariate 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_FACTORIZE_H |
---|
| 15 | #define FAC_FQ_FACTORIZE_H |
---|
| 16 | |
---|
[0851b0] | 17 | #include "config.h" |
---|
| 18 | #include "timing.h" |
---|
[7bf145] | 19 | |
---|
| 20 | #include "facFqBivar.h" |
---|
| 21 | #include "DegreePattern.h" |
---|
| 22 | #include "ExtensionInfo.h" |
---|
| 23 | #include "cf_util.h" |
---|
| 24 | #include "facFqSquarefree.h" |
---|
| 25 | #include "facFqBivarUtil.h" |
---|
| 26 | |
---|
[0851b0] | 27 | |
---|
| 28 | TIMING_DEFINE_PRINT (fac_fq_squarefree) |
---|
| 29 | TIMING_DEFINE_PRINT (fac_fq_factor_squarefree) |
---|
| 30 | |
---|
[7bf145] | 31 | /// Factorization over a finite field |
---|
[806c18] | 32 | /// |
---|
[7bf145] | 33 | /// @return @a multiFactorize returns a factorization of F |
---|
| 34 | /// @sa biFactorize(), extFactorize() |
---|
[806c18] | 35 | CFList |
---|
[7bf145] | 36 | multiFactorize (const CanonicalForm& F, ///< [in] poly to be factored |
---|
| 37 | const ExtensionInfo& info ///< [in] info about extension |
---|
| 38 | ); |
---|
| 39 | |
---|
| 40 | /// factorize a squarefree multivariate polynomial over \f$ F_{p} \f$ |
---|
| 41 | /// |
---|
[806c18] | 42 | /// @return @a FpSqrfFactorize returns a list of monic factors, the first |
---|
| 43 | /// element is the leading coefficient. |
---|
[7bf145] | 44 | /// @sa FqSqrfFactorize(), GFSqrfFactorize() |
---|
[d990001] | 45 | #ifdef HAVE_NTL |
---|
[7bf145] | 46 | inline |
---|
| 47 | CFList FpSqrfFactorize (const CanonicalForm & F ///< [in] a multivariate poly |
---|
[806c18] | 48 | ) |
---|
[7bf145] | 49 | { |
---|
[f09105] | 50 | if (getNumVars (F) == 2) |
---|
| 51 | return FpBiSqrfFactorize (F); |
---|
[7bf145] | 52 | ExtensionInfo info= ExtensionInfo (false); |
---|
| 53 | CFList result= multiFactorize (F, info); |
---|
| 54 | result.insert (Lc(F)); |
---|
| 55 | return result; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /// factorize a squarefree multivariate polynomial over \f$ F_{p} (\alpha ) \f$ |
---|
| 59 | /// |
---|
[806c18] | 60 | /// @return @a FqSqrfFactorize returns a list of monic factors, the first |
---|
| 61 | /// element is the leading coefficient. |
---|
| 62 | /// @sa FpSqrfFactorize(), GFSqrfFactorize() |
---|
[7bf145] | 63 | inline |
---|
| 64 | CFList FqSqrfFactorize (const CanonicalForm & F, ///< [in] a multivariate poly |
---|
| 65 | const Variable& alpha ///< [in] algebraic variable |
---|
[806c18] | 66 | ) |
---|
[7bf145] | 67 | { |
---|
[f09105] | 68 | if (getNumVars (F) == 2) |
---|
| 69 | return FqBiSqrfFactorize (F, alpha); |
---|
[7bf145] | 70 | ExtensionInfo info= ExtensionInfo (alpha, false); |
---|
| 71 | CFList result= multiFactorize (F, info); |
---|
| 72 | result.insert (Lc(F)); |
---|
| 73 | return result; |
---|
| 74 | } |
---|
| 75 | |
---|
[806c18] | 76 | /// factorize a squarefree multivariate polynomial over GF |
---|
[7bf145] | 77 | /// |
---|
[806c18] | 78 | /// @return @a GFSqrfFactorize returns a list of monic factors, the first |
---|
| 79 | /// element is the leading coefficient. |
---|
[7bf145] | 80 | /// @sa FpSqrfFactorize(), FqSqrfFactorize() |
---|
| 81 | inline |
---|
| 82 | CFList GFSqrfFactorize (const CanonicalForm & F ///< [in] a multivariate poly |
---|
[806c18] | 83 | ) |
---|
[7bf145] | 84 | { |
---|
[806c18] | 85 | ASSERT (CFFactory::gettype() == GaloisFieldDomain, |
---|
[7bf145] | 86 | "GF as base field expected"); |
---|
[f09105] | 87 | if (getNumVars (F) == 2) |
---|
| 88 | return GFBiSqrfFactorize (F); |
---|
[7bf145] | 89 | ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false); |
---|
| 90 | CFList result= multiFactorize (F, info); |
---|
| 91 | result.insert (Lc(F)); |
---|
| 92 | return result; |
---|
| 93 | } |
---|
| 94 | |
---|
[806c18] | 95 | /// factorize a multivariate polynomial over \f$ F_{p} \f$ |
---|
[7bf145] | 96 | /// |
---|
[806c18] | 97 | /// @return @a FpFactorize returns a list of monic factors with |
---|
| 98 | /// multiplicity, the first element is the leading coefficient. |
---|
[7bf145] | 99 | /// @sa FqFactorize(), GFFactorize() |
---|
| 100 | inline |
---|
[f9b796e] | 101 | CFFList FpFactorize (const CanonicalForm& G,///< [in] a multivariate poly |
---|
| 102 | bool substCheck= true ///< [in] enables substitute check |
---|
[806c18] | 103 | ) |
---|
[7bf145] | 104 | { |
---|
[f9b796e] | 105 | if (getNumVars (G) == 2) |
---|
| 106 | return FpBiFactorize (G, substCheck); |
---|
| 107 | |
---|
| 108 | CanonicalForm F= G; |
---|
| 109 | if (substCheck) |
---|
| 110 | { |
---|
| 111 | bool foundOne= false; |
---|
| 112 | int * substDegree= new int [F.level()]; |
---|
| 113 | for (int i= 1; i <= F.level(); i++) |
---|
| 114 | { |
---|
| 115 | if (degree (F, i) > 0) |
---|
| 116 | { |
---|
| 117 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
| 118 | if (substDegree [i-1] > 1) |
---|
| 119 | { |
---|
| 120 | foundOne= true; |
---|
| 121 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | else |
---|
| 125 | substDegree[i-1]= -1; |
---|
| 126 | } |
---|
| 127 | if (foundOne) |
---|
| 128 | { |
---|
| 129 | CFFList result= FpFactorize (F, false); |
---|
| 130 | CFFList newResult, tmp; |
---|
| 131 | CanonicalForm tmp2; |
---|
| 132 | newResult.insert (result.getFirst()); |
---|
| 133 | result.removeFirst(); |
---|
| 134 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 135 | { |
---|
| 136 | tmp2= i.getItem().factor(); |
---|
| 137 | for (int j= 1; j <= G.level(); j++) |
---|
| 138 | { |
---|
| 139 | if (substDegree[j-1] > 1) |
---|
| 140 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
| 141 | } |
---|
| 142 | tmp= FpFactorize (tmp2, false); |
---|
| 143 | tmp.removeFirst(); |
---|
| 144 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
| 145 | newResult.append (CFFactor (j.getItem().factor(), |
---|
| 146 | j.getItem().exp()*i.getItem().exp())); |
---|
| 147 | } |
---|
| 148 | delete [] substDegree; |
---|
| 149 | return newResult; |
---|
| 150 | } |
---|
| 151 | delete [] substDegree; |
---|
| 152 | } |
---|
| 153 | |
---|
[7bf145] | 154 | ExtensionInfo info= ExtensionInfo (false); |
---|
| 155 | Variable a= Variable (1); |
---|
[806c18] | 156 | CanonicalForm LcF= Lc (F); |
---|
[0851b0] | 157 | TIMING_START (fac_fq_squarefree); |
---|
[8baf483] | 158 | CFFList sqrf= FpSqrf (F, false); |
---|
[0851b0] | 159 | TIMING_END_AND_PRINT (fac_fq_squarefree, |
---|
| 160 | "time for squarefree factorization over Fq: "); |
---|
[8baf483] | 161 | CFFList result; |
---|
| 162 | CFList bufResult; |
---|
| 163 | sqrf.removeFirst(); |
---|
| 164 | CFListIterator i; |
---|
| 165 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
[7bf145] | 166 | { |
---|
[0851b0] | 167 | TIMING_START (fac_fq_factor_squarefree); |
---|
[8baf483] | 168 | bufResult= multiFactorize (iter.getItem().factor(), info); |
---|
[0851b0] | 169 | TIMING_END_AND_PRINT (fac_fq_factor_squarefree, |
---|
| 170 | "time to factorize sqrfree factor over Fq: "); |
---|
[8baf483] | 171 | for (i= bufResult; i.hasItem(); i++) |
---|
| 172 | result.append (CFFactor (i.getItem(), iter.getItem().exp())); |
---|
[7bf145] | 173 | } |
---|
| 174 | result.insert (CFFactor (LcF, 1)); |
---|
| 175 | return result; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | /// factorize a multivariate polynomial over \f$ F_{p} (\alpha ) \f$ |
---|
| 179 | /// |
---|
[806c18] | 180 | /// @return @a FqFactorize returns a list of monic factors with |
---|
| 181 | /// multiplicity, the first element is the leading coefficient. |
---|
[7bf145] | 182 | /// @sa FpFactorize(), GFFactorize() |
---|
| 183 | inline |
---|
[f9b796e] | 184 | CFFList FqFactorize (const CanonicalForm& G, ///< [in] a multivariate poly |
---|
| 185 | const Variable& alpha, ///< [in] algebraic variable |
---|
| 186 | bool substCheck= true ///< [in] enables substitute check |
---|
[806c18] | 187 | ) |
---|
[7bf145] | 188 | { |
---|
[f9b796e] | 189 | if (getNumVars (G) == 2) |
---|
| 190 | return FqBiFactorize (G, alpha, substCheck); |
---|
| 191 | |
---|
| 192 | CanonicalForm F= G; |
---|
| 193 | if (substCheck) |
---|
| 194 | { |
---|
| 195 | bool foundOne= false; |
---|
| 196 | int * substDegree= new int [F.level()]; |
---|
| 197 | for (int i= 1; i <= F.level(); i++) |
---|
| 198 | { |
---|
| 199 | if (degree (F, i) > 0) |
---|
| 200 | { |
---|
| 201 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
| 202 | if (substDegree [i-1] > 1) |
---|
| 203 | { |
---|
| 204 | foundOne= true; |
---|
| 205 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | else |
---|
| 209 | substDegree[i-1]= -1; |
---|
| 210 | } |
---|
| 211 | if (foundOne) |
---|
| 212 | { |
---|
| 213 | CFFList result= FqFactorize (F, alpha, false); |
---|
| 214 | CFFList newResult, tmp; |
---|
| 215 | CanonicalForm tmp2; |
---|
| 216 | newResult.insert (result.getFirst()); |
---|
| 217 | result.removeFirst(); |
---|
| 218 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 219 | { |
---|
| 220 | tmp2= i.getItem().factor(); |
---|
| 221 | for (int j= 1; j <= G.level(); j++) |
---|
| 222 | { |
---|
| 223 | if (substDegree[j-1] > 1) |
---|
| 224 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
| 225 | } |
---|
| 226 | tmp= FqFactorize (tmp2, alpha, false); |
---|
| 227 | tmp.removeFirst(); |
---|
| 228 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
| 229 | newResult.append (CFFactor (j.getItem().factor(), |
---|
| 230 | j.getItem().exp()*i.getItem().exp())); |
---|
| 231 | } |
---|
| 232 | delete [] substDegree; |
---|
| 233 | return newResult; |
---|
| 234 | } |
---|
| 235 | delete [] substDegree; |
---|
| 236 | } |
---|
| 237 | |
---|
[806c18] | 238 | ExtensionInfo info= ExtensionInfo (alpha, false); |
---|
| 239 | CanonicalForm LcF= Lc (F); |
---|
[0851b0] | 240 | TIMING_START (fac_fq_squarefree); |
---|
[8baf483] | 241 | CFFList sqrf= FqSqrf (F, alpha, false); |
---|
[0851b0] | 242 | TIMING_END_AND_PRINT (fac_fq_squarefree, |
---|
| 243 | "time for squarefree factorization over Fq: "); |
---|
[8baf483] | 244 | CFFList result; |
---|
| 245 | CFList bufResult; |
---|
| 246 | sqrf.removeFirst(); |
---|
| 247 | CFListIterator i; |
---|
| 248 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
[806c18] | 249 | { |
---|
[0851b0] | 250 | TIMING_START (fac_fq_factor_squarefree); |
---|
[8baf483] | 251 | bufResult= multiFactorize (iter.getItem().factor(), info); |
---|
[0851b0] | 252 | TIMING_END_AND_PRINT (fac_fq_factor_squarefree, |
---|
| 253 | "time to factorize sqrfree factor over Fq: "); |
---|
[8baf483] | 254 | for (i= bufResult; i.hasItem(); i++) |
---|
| 255 | result.append (CFFactor (i.getItem(), iter.getItem().exp())); |
---|
[7bf145] | 256 | } |
---|
| 257 | result.insert (CFFactor (LcF, 1)); |
---|
| 258 | return result; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | /// factorize a multivariate polynomial over GF |
---|
| 262 | /// |
---|
[806c18] | 263 | /// @return @a GFFactorize returns a list of monic factors with |
---|
| 264 | /// multiplicity, the first element is the leading coefficient. |
---|
[7bf145] | 265 | /// @sa FpFactorize(), FqFactorize() |
---|
| 266 | inline |
---|
[f9b796e] | 267 | CFFList GFFactorize (const CanonicalForm& G, ///< [in] a multivariate poly |
---|
| 268 | bool substCheck= true ///< [in] enables substitute check |
---|
[806c18] | 269 | ) |
---|
[7bf145] | 270 | { |
---|
[806c18] | 271 | ASSERT (CFFactory::gettype() == GaloisFieldDomain, |
---|
[7bf145] | 272 | "GF as base field expected"); |
---|
[f9b796e] | 273 | if (getNumVars (G) == 2) |
---|
| 274 | return GFBiFactorize (G, substCheck); |
---|
| 275 | |
---|
| 276 | CanonicalForm F= G; |
---|
| 277 | if (substCheck) |
---|
| 278 | { |
---|
| 279 | bool foundOne= false; |
---|
| 280 | int * substDegree= new int [F.level()]; |
---|
| 281 | for (int i= 1; i <= F.level(); i++) |
---|
| 282 | { |
---|
| 283 | if (degree (F, i) > 0) |
---|
| 284 | { |
---|
| 285 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
| 286 | if (substDegree [i-1] > 1) |
---|
| 287 | { |
---|
| 288 | foundOne= true; |
---|
| 289 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | else |
---|
| 293 | substDegree[i-1]= -1; |
---|
| 294 | } |
---|
| 295 | if (foundOne) |
---|
| 296 | { |
---|
| 297 | CFFList result= GFFactorize (F, false); |
---|
| 298 | CFFList newResult, tmp; |
---|
| 299 | CanonicalForm tmp2; |
---|
| 300 | newResult.insert (result.getFirst()); |
---|
| 301 | result.removeFirst(); |
---|
| 302 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 303 | { |
---|
| 304 | tmp2= i.getItem().factor(); |
---|
| 305 | for (int j= 1; j <= G.level(); j++) |
---|
| 306 | { |
---|
| 307 | if (substDegree[j-1] > 1) |
---|
| 308 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
| 309 | } |
---|
| 310 | tmp= GFFactorize (tmp2, false); |
---|
| 311 | tmp.removeFirst(); |
---|
| 312 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
| 313 | newResult.append (CFFactor (j.getItem().factor(), |
---|
| 314 | j.getItem().exp()*i.getItem().exp())); |
---|
| 315 | } |
---|
| 316 | delete [] substDegree; |
---|
| 317 | return newResult; |
---|
| 318 | } |
---|
| 319 | delete [] substDegree; |
---|
| 320 | } |
---|
| 321 | |
---|
[7bf145] | 322 | Variable a= Variable (1); |
---|
[806c18] | 323 | ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false); |
---|
[7bf145] | 324 | CanonicalForm LcF= Lc (F); |
---|
[8baf483] | 325 | CFFList sqrf= GFSqrf (F, false); |
---|
| 326 | CFFList result; |
---|
| 327 | CFList bufResult; |
---|
| 328 | sqrf.removeFirst(); |
---|
| 329 | CFListIterator i; |
---|
| 330 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
[7bf145] | 331 | { |
---|
[8baf483] | 332 | bufResult= multiFactorize (iter.getItem().factor(), info); |
---|
| 333 | for (i= bufResult; i.hasItem(); i++) |
---|
| 334 | result.append (CFFactor (i.getItem(), iter.getItem().exp())); |
---|
[7bf145] | 335 | } |
---|
| 336 | result.insert (CFFactor (LcF, 1)); |
---|
| 337 | return result; |
---|
| 338 | } |
---|
| 339 | |
---|
[d990001] | 340 | #endif |
---|
| 341 | |
---|
[806c18] | 342 | /// Naive factor recombination for multivariate factorization over an extension |
---|
| 343 | /// of the initial field. No precomputed is used to exclude combinations. |
---|
[7bf145] | 344 | /// |
---|
| 345 | /// @return @a extFactorRecombination returns a list of factors of @a F, whose |
---|
| 346 | /// shift to zero is reversed. |
---|
[806c18] | 347 | /// @sa factorRecombination() |
---|
| 348 | CFList |
---|
[7bf145] | 349 | extFactorRecombination ( |
---|
| 350 | const CFList& factors, ///< [in] list of lifted factors |
---|
[806c18] | 351 | ///< that are monic wrt Variable (1) |
---|
[7bf145] | 352 | const CanonicalForm& F, ///< [in] poly to be factored |
---|
| 353 | const CFList& M, ///< [in] a list of powers of |
---|
[806c18] | 354 | ///< Variables |
---|
| 355 | const ExtensionInfo& info, ///< [in] info about extension |
---|
[7bf145] | 356 | const CFList& evaluation ///< [in] evaluation point |
---|
| 357 | ); |
---|
| 358 | |
---|
| 359 | /// Naive factor recombination for multivariate factorization. |
---|
| 360 | /// No precomputed is used to exclude combinations. |
---|
| 361 | /// |
---|
[806c18] | 362 | /// @return @a factorRecombination returns a list of factors of @a F |
---|
| 363 | /// @sa extFactorRecombination() |
---|
| 364 | CFList |
---|
[7bf145] | 365 | factorRecombination (const CanonicalForm& F,///< [in] poly to be factored |
---|
| 366 | const CFList& factors, ///< [in] list of lifted factors |
---|
| 367 | ///< that are monic wrt Variable (1) |
---|
| 368 | const CFList& M ///< [in] a list of powers of |
---|
| 369 | ///< Variables |
---|
| 370 | ); |
---|
| 371 | |
---|
[91788c0] | 372 | /// recombination of bivariate factors @a factors1 s. t. the result evaluated |
---|
| 373 | /// at @a evalPoint coincides with @a factors2 |
---|
| 374 | CFList |
---|
| 375 | recombination (const CFList& factors1, ///<[in] list of bivariate factors |
---|
| 376 | const CFList& factors2, ///<[in] list univariate factors |
---|
| 377 | int s, ///<[in] algorithm starts checking |
---|
| 378 | ///< subsets of size s |
---|
| 379 | int thres, ///<[in] threshold for the size of |
---|
| 380 | ///< subsets which are checked |
---|
| 381 | const CanonicalForm& evalPoint,///<[in] evaluation point |
---|
| 382 | const Variable& x ///<[in] second variable of |
---|
| 383 | ///< bivariate factors |
---|
| 384 | ); |
---|
| 385 | |
---|
[7bf145] | 386 | /// Lift bound adaption. Essentially an early factor detection but only the lift |
---|
| 387 | /// bound is adapted. |
---|
| 388 | /// |
---|
| 389 | /// @return @a liftBoundAdaption returns an adapted lift bound. |
---|
[806c18] | 390 | /// @sa earlyFactorDetect(), earlyFactorDetection() |
---|
[7bf145] | 391 | int |
---|
| 392 | liftBoundAdaption (const CanonicalForm& F, ///< [in] a poly |
---|
[806c18] | 393 | const CFList& factors, ///< [in] list of list of lifted |
---|
| 394 | ///< factors that are monic wrt |
---|
[7bf145] | 395 | ///< Variable (1) |
---|
| 396 | bool& success, ///< [in,out] indicates that no |
---|
| 397 | ///< further lifting is necessary |
---|
| 398 | const int deg, ///< [in] stage of Hensel lifting |
---|
| 399 | const CFList& MOD, ///< [in] a list of powers of |
---|
| 400 | ///< Variables |
---|
| 401 | const int bound ///< [in] initial lift bound |
---|
| 402 | ); |
---|
| 403 | |
---|
| 404 | /// Lift bound adaption over an extension of the initial field. Essentially an |
---|
| 405 | ///early factor detection but only the lift bound is adapted. |
---|
| 406 | /// |
---|
| 407 | /// @return @a liftBoundAdaption returns an adapted lift bound. |
---|
[806c18] | 408 | /// @sa earlyFactorDetect(), earlyFactorDetection() |
---|
| 409 | int |
---|
[7bf145] | 410 | extLiftBoundAdaption ( |
---|
[806c18] | 411 | const CanonicalForm& F, ///< [in] a poly |
---|
| 412 | const CFList& factors, ///< [in] list of list of lifted |
---|
| 413 | ///< factors that are monic wrt |
---|
| 414 | bool& success, ///< [in,out] indicates that no further |
---|
[7bf145] | 415 | ///< lifting is necessary |
---|
[806c18] | 416 | const ExtensionInfo& info, ///< [in] info about extension |
---|
| 417 | const CFList& eval, ///< [in] evaluation point |
---|
| 418 | const int deg, ///< [in] stage of Hensel lifting |
---|
| 419 | const CFList& MOD, ///< [in] a list of powers of |
---|
| 420 | ///< Variables |
---|
| 421 | const int bound ///< [in] initial lift bound |
---|
[7bf145] | 422 | ); |
---|
| 423 | |
---|
| 424 | /// detects factors of @a F at stage @a deg of Hensel lifting. |
---|
[806c18] | 425 | /// No combinations of more than one factor are tested. Lift bound is adapted. |
---|
| 426 | /// |
---|
| 427 | /// @return @a earlyFactorDetect returns a list of factors of F (possibly |
---|
[7bf145] | 428 | /// incomplete), in case of success. Otherwise an empty list. |
---|
| 429 | /// @sa factorRecombination(), extEarlyFactorDetect() |
---|
[806c18] | 430 | CFList |
---|
[7bf145] | 431 | earlyFactorDetect ( |
---|
[806c18] | 432 | CanonicalForm& F, ///< [in,out] poly to be factored, |
---|
[7bf145] | 433 | ///< returns poly divided by detected |
---|
| 434 | ///< factors in case of success |
---|
[806c18] | 435 | CFList& factors, ///< [in,out] list of factors lifted up |
---|
[7bf145] | 436 | ///< to @a deg, returns a list of factors |
---|
| 437 | ///< without detected factors |
---|
[806c18] | 438 | int& adaptedLiftBound, ///< [in,out] adapted lift bound |
---|
| 439 | bool& success, ///< [in,out] indicating success |
---|
| 440 | const int deg, ///< [in] stage of Hensel lifting |
---|
| 441 | const CFList& MOD, ///< [in] a list of powers of |
---|
[7bf145] | 442 | ///< Variables |
---|
[806c18] | 443 | const int bound ///< [in] initial lift bound |
---|
[7bf145] | 444 | ); |
---|
| 445 | |
---|
| 446 | /// detects factors of @a F at stage @a deg of Hensel lifting. |
---|
[806c18] | 447 | /// No combinations of more than one factor are tested. Lift bound is adapted. |
---|
| 448 | /// |
---|
| 449 | /// @return @a extEarlyFactorDetect returns a list of factors of F (possibly |
---|
[7bf145] | 450 | /// incomplete), whose shift to zero is reversed, in case of success. |
---|
[806c18] | 451 | /// Otherwise an empty list. |
---|
[7bf145] | 452 | /// @sa factorRecombination(), earlyFactorDetection() |
---|
[806c18] | 453 | CFList |
---|
[7bf145] | 454 | extEarlyFactorDetect ( |
---|
[806c18] | 455 | CanonicalForm& F, ///< [in,out] poly to be factored, |
---|
[7bf145] | 456 | ///< returns poly divided by detected |
---|
| 457 | ///< factors in case of success |
---|
[806c18] | 458 | CFList& factors, ///< [in,out] list of factors lifted up |
---|
[7bf145] | 459 | ///< to @a deg, returns a list of factors |
---|
| 460 | ///< without detected factors |
---|
[806c18] | 461 | int& adaptedLiftBound, ///< [in,out] adapted lift bound |
---|
| 462 | bool& success, ///< [in,out] indicating succes |
---|
| 463 | const ExtensionInfo& info, ///< [in] info about extension |
---|
| 464 | const CFList& eval, ///< [in] evaluation point |
---|
| 465 | const int deg, ///< [in] stage of Hensel lifting |
---|
| 466 | const CFList& MOD, ///< [in] a list of powers of Variables |
---|
| 467 | const int bound ///< [in] initial lift bound |
---|
[7bf145] | 468 | ); |
---|
| 469 | |
---|
[806c18] | 470 | /// evaluation point search for multivariate factorization, |
---|
[7bf145] | 471 | /// looks for a (F.level() - 1)-tuple such that the resulting univariate |
---|
[8c1a84] | 472 | /// polynomial has main variable Variable (1), is squarefree and its degree |
---|
[806c18] | 473 | /// coincides with degree(F) and the bivariate one is primitive wrt. |
---|
[8c1a84] | 474 | /// Variable(1), and successively evaluated polynomials have the same degree in |
---|
| 475 | /// their main variable as F has, fails if there are no valid evaluation points, |
---|
| 476 | /// eval contains the intermediate evaluated polynomials. |
---|
[7bf145] | 477 | /// |
---|
| 478 | /// @return @a evalPoints returns an evaluation point, which is valid if and |
---|
[806c18] | 479 | /// only if fail == false. |
---|
| 480 | CFList |
---|
| 481 | evalPoints (const CanonicalForm& F, ///< [in] a compressed poly |
---|
[7bf145] | 482 | CFList & eval, ///< [in,out] an empty list, returns @a F |
---|
| 483 | ///< successive evaluated |
---|
| 484 | const Variable& alpha, ///< [in] algebraic variable |
---|
| 485 | CFList& list, ///< [in,out] a list of points already |
---|
| 486 | ///< considered, a point is encoded as a |
---|
| 487 | ///< poly of degree F.level()-1 in |
---|
[806c18] | 488 | ///< Variable(1) |
---|
[7bf145] | 489 | const bool& GF, ///< [in] GF? |
---|
| 490 | bool& fail ///< [in,out] indicates failure |
---|
| 491 | ); |
---|
| 492 | |
---|
[806c18] | 493 | /// hensel Lifting and early factor detection |
---|
[7bf145] | 494 | /// |
---|
[806c18] | 495 | /// @return @a henselLiftAndEarly returns monic (wrt Variable (1)) lifted |
---|
[7bf145] | 496 | /// factors without factors which have been detected at an early stage |
---|
| 497 | /// of Hensel lifting |
---|
| 498 | /// @sa earlyFactorDetectn(), extEarlyFactorDetect() |
---|
| 499 | CFList |
---|
| 500 | henselLiftAndEarly ( |
---|
[806c18] | 501 | CanonicalForm& A, ///< [in,out] poly to be factored, |
---|
[7bf145] | 502 | ///< returns poly divided by detected |
---|
[806c18] | 503 | ///< factors, in case of success |
---|
| 504 | CFList& MOD, ///< [in,out] a list of powers of |
---|
[7bf145] | 505 | ///< Variables |
---|
[806c18] | 506 | int*& liftBounds, ///< [in,out] initial lift bounds, returns |
---|
[7bf145] | 507 | ///< adapted lift bounds |
---|
[806c18] | 508 | bool& earlySuccess, ///< [in,out] indicating success |
---|
| 509 | CFList& earlyFactors, ///< [in,out] early factors |
---|
| 510 | const CFList& Aeval, ///< [in] @a A successively evaluated at |
---|
[7bf145] | 511 | ///< elements of @a evaluation |
---|
[806c18] | 512 | const CFList& biFactors, ///< [in] bivariate factors |
---|
| 513 | const CFList& evaluation, ///< [in] evaluation point |
---|
| 514 | const ExtensionInfo& info ///< [in] info about extension |
---|
[7bf145] | 515 | ); |
---|
| 516 | |
---|
| 517 | /// Factorization over an extension of initial field |
---|
| 518 | /// |
---|
| 519 | /// @return @a extFactorize returns factorization of F over initial field |
---|
| 520 | /// @sa extBiFactorize(), multiFactorize() |
---|
[806c18] | 521 | CFList |
---|
| 522 | extFactorize (const CanonicalForm& F, ///< [in] poly to be factored |
---|
| 523 | const ExtensionInfo& info ///< [in] info about extension |
---|
| 524 | ); |
---|
[7bf145] | 525 | |
---|
[8c1a84] | 526 | /// compute the LCM of the contents of @a A wrt to each variable occuring in @a |
---|
| 527 | /// A. |
---|
| 528 | /// |
---|
| 529 | /// @return @a lcmContent returns the LCM of the contents of @a A wrt to each |
---|
| 530 | /// variable occuring in @a A. |
---|
| 531 | CanonicalForm |
---|
| 532 | lcmContent (const CanonicalForm& A, ///< [in] a compressed multivariate poly |
---|
| 533 | CFList& contentAi ///< [in,out] an empty list, returns a list |
---|
| 534 | ///< of the contents of @a A wrt to each |
---|
| 535 | ///< variable occuring in @a A starting from |
---|
| 536 | ///< @a A.mvar(). |
---|
| 537 | ); |
---|
| 538 | |
---|
| 539 | /// compress a polynomial s.t. \f$ deg_{x_{i}} (F) >= deg_{x_{i+1}} (F) \f$ and |
---|
| 540 | /// no gaps between the variables occur |
---|
| 541 | /// |
---|
| 542 | /// @return a compressed poly with the above properties |
---|
| 543 | CanonicalForm myCompress (const CanonicalForm& F, ///< [in] a poly |
---|
| 544 | CFMap& N ///< [in,out] a map to |
---|
| 545 | ///< decompress |
---|
| 546 | ); |
---|
| 547 | |
---|
| 548 | /// evaluate a poly A with main variable at level 1 at an evaluation point in |
---|
| 549 | /// K^(n-1) wrt different second variables. If this evaluation is valid (see |
---|
| 550 | /// evalPoints) then Aeval contains A successively evaluated at this point, |
---|
| 551 | /// otherwise this entry is empty |
---|
| 552 | void |
---|
| 553 | evaluationWRTDifferentSecondVars ( |
---|
| 554 | CFList*& Aeval, ///<[in,out] an array of length n-2 |
---|
| 555 | ///< if variable at level i > 2 |
---|
| 556 | ///< admits a valid evaluation |
---|
| 557 | ///< this entry contains A |
---|
| 558 | ///< successively evaluated at this |
---|
| 559 | ///< point otherwise an empty list |
---|
| 560 | const CFList& evaluation,///<[in] a valid evaluation point |
---|
| 561 | ///< for main variable at level 1 |
---|
| 562 | ///< and second variable at level 2 |
---|
| 563 | const CanonicalForm& A ///<[in] some poly |
---|
| 564 | ); |
---|
| 565 | |
---|
| 566 | /// refine a bivariate factorization of A with l factors to one with |
---|
| 567 | /// minFactorsLength |
---|
| 568 | void |
---|
| 569 | refineBiFactors (const CanonicalForm& A, ///< [in] some poly |
---|
| 570 | CFList& biFactors, ///< [in,out] list of bivariate to be |
---|
| 571 | ///< refined, returns refined factors |
---|
| 572 | CFList* const& factors, ///< [in] list of bivariate |
---|
| 573 | ///< factorizations of A wrt different |
---|
| 574 | ///< second variables |
---|
| 575 | const CFList& evaluation,///< [in] the evaluation point |
---|
| 576 | int minFactorsLength ///< [in] the minimal number of factors |
---|
| 577 | ); |
---|
| 578 | |
---|
| 579 | /// plug in evalPoint for y in a list of polys |
---|
| 580 | /// |
---|
| 581 | /// @return returns a list of the evaluated polys, these evaluated polys are |
---|
| 582 | /// made monic |
---|
| 583 | CFList |
---|
| 584 | buildUniFactors (const CFList& biFactors, ///< [in] a list of polys |
---|
| 585 | const CanonicalForm& evalPoint,///< [in] some evaluation point |
---|
| 586 | const Variable& y ///< [in] some variable |
---|
| 587 | ); |
---|
| 588 | |
---|
[772056] | 589 | |
---|
| 590 | /// sort bivariate factors in Aeval such that their corresponding univariate |
---|
| 591 | /// factors coincide with uniFactors |
---|
| 592 | void sortByUniFactors (CFList*& Aeval, ///< [in,out] array of bivariate |
---|
| 593 | ///< factors |
---|
| 594 | int AevalLength, ///< [in] length of Aeval |
---|
| 595 | const CFList& uniFactors,///< [in] univariate factors |
---|
| 596 | const CFList& evaluation ///< [in] evaluation point |
---|
| 597 | ); |
---|
| 598 | |
---|
[8c1a84] | 599 | /// extract leading coefficients wrt Variable(1) from bivariate factors obtained |
---|
| 600 | /// from factorizations of A wrt different second variables |
---|
| 601 | void |
---|
| 602 | getLeadingCoeffs (const CanonicalForm& A, ///< [in] some poly |
---|
[a0adc3] | 603 | CFList*& Aeval ///< [in,out] array of bivariate |
---|
[8c1a84] | 604 | ///< factors, returns the leading |
---|
| 605 | ///< coefficients of these factors |
---|
| 606 | ); |
---|
| 607 | |
---|
| 608 | /// normalize precomputed leading coefficients such that leading coefficients |
---|
[eefc3a] | 609 | /// evaluated at @a evaluation in K^(n-2) equal the leading coeffs wrt |
---|
| 610 | /// Variable(1) of bivariate factors |
---|
[8c1a84] | 611 | void |
---|
| 612 | prepareLeadingCoeffs (CFList*& LCs, ///<[in,out] |
---|
| 613 | int n, ///<[in] level of poly to be |
---|
| 614 | ///< factored |
---|
| 615 | const CFList& leadingCoeffs,///<[in] precomputed leading |
---|
| 616 | ///< coeffs |
---|
[eefc3a] | 617 | const CFList& biFactors, ///<[in] bivariate factors |
---|
| 618 | const CFList& evaluation ///<[in] evaluation point |
---|
[8c1a84] | 619 | ); |
---|
| 620 | |
---|
| 621 | /// obtain factors of F by reconstructing their leading coeffs |
---|
| 622 | /// |
---|
| 623 | /// @return returns the reconstructed factors |
---|
| 624 | /// @sa factorRecombination() |
---|
| 625 | CFList |
---|
| 626 | leadingCoeffReconstruction (const CanonicalForm& F,///<[in] poly to be factored |
---|
| 627 | const CFList& factors, ///<[in] factors of f monic |
---|
| 628 | ///< wrt Variable (1) |
---|
| 629 | const CFList& M ///<[in] a list of powers of |
---|
| 630 | ///< Variables |
---|
| 631 | ); |
---|
| 632 | |
---|
| 633 | /// distribute content |
---|
| 634 | /// |
---|
| 635 | /// @return returns a list result of polys such that prod (result)= prod (L) |
---|
| 636 | /// but the first entry of L may be (partially) factorized and these factors |
---|
| 637 | /// are distributed onto other entries in L |
---|
| 638 | CFList |
---|
| 639 | distributeContent ( |
---|
| 640 | const CFList& L, ///<[in] list of polys, first |
---|
| 641 | ///< entry the content to be |
---|
| 642 | ///< distributed |
---|
| 643 | const CFList* differentSecondVarFactors,///<[in] factorization wrt |
---|
| 644 | ///< different second vars |
---|
| 645 | int length ///<[in] length of |
---|
| 646 | ///<differentSecondVarFactors |
---|
| 647 | ); |
---|
| 648 | |
---|
| 649 | /// gcd free basis of two lists of factors |
---|
| 650 | void |
---|
| 651 | gcdFreeBasis (CFFList& factors1, ///< [in,out] list of factors, returns gcd free |
---|
| 652 | ///< factors |
---|
| 653 | CFFList& factors2 ///< [in,out] list of factors, returns gcd free |
---|
| 654 | ///< factors |
---|
| 655 | ); |
---|
| 656 | |
---|
[afbebe] | 657 | /// computes a list l of length length(LCFFactors)+1 of polynomials such that |
---|
| 658 | /// prod (l)=LCF, note that the first entry of l may be non constant. Intended |
---|
| 659 | /// to be used to precompute coefficients of a polynomial f from its bivariate |
---|
| 660 | /// factorizations. |
---|
| 661 | /// |
---|
| 662 | /// @return see above |
---|
| 663 | CFList |
---|
| 664 | precomputeLeadingCoeff (const CanonicalForm& LCF, ///<[in] a multivariate |
---|
| 665 | ///< poly |
---|
| 666 | const CFList& LCFFactors, ///<[in] a list of |
---|
| 667 | ///< univariate factors |
---|
| 668 | ///< of LCF of level 2 |
---|
| 669 | const Variable& alpha, ///<[in] algebraic var. |
---|
| 670 | const CFList& evaluation, ///<[in] an evaluation |
---|
| 671 | ///< point having |
---|
| 672 | ///< lSecondVarLCs+1 |
---|
| 673 | ///< components |
---|
| 674 | CFList* & differentSecondVarLCs,///<[in] LCs of factors |
---|
| 675 | ///< of f wrt different |
---|
| 676 | ///< second variables |
---|
| 677 | int lSecondVarLCs, ///<[in] length of the |
---|
| 678 | ///< above |
---|
| 679 | Variable& y ///<[in,out] if y.level() |
---|
| 680 | ///< is not 1 on output |
---|
| 681 | ///< the second variable |
---|
| 682 | ///< has been changed to |
---|
| 683 | ///< y |
---|
| 684 | ); |
---|
| 685 | |
---|
[7bf145] | 686 | #endif |
---|
| 687 | /* FAC_FQ_FACTORIZE_H */ |
---|
| 688 | |
---|