1 | /*****************************************************************************\ |
---|
2 | * Computer Algebra System SINGULAR |
---|
3 | \*****************************************************************************/ |
---|
4 | /** @file facFqBivar.h |
---|
5 | * |
---|
6 | * This file provides functions for factorizing a bivariate polynomial over |
---|
7 | * \f$ F_{p} \f$ , \f$ F_{p}(\alpha ) \f$ or GF. |
---|
8 | * |
---|
9 | * @author Martin Lee |
---|
10 | * |
---|
11 | **/ |
---|
12 | /*****************************************************************************/ |
---|
13 | |
---|
14 | #ifndef FAC_FQ_BIVAR_H |
---|
15 | #define FAC_FQ_BIVAR_H |
---|
16 | |
---|
17 | // #include "config.h" |
---|
18 | |
---|
19 | #include "timing.h" |
---|
20 | #include "cf_assert.h" |
---|
21 | |
---|
22 | #include "facFqBivarUtil.h" |
---|
23 | #include "DegreePattern.h" |
---|
24 | #include "ExtensionInfo.h" |
---|
25 | #include "cf_util.h" |
---|
26 | #include "facFqSquarefree.h" |
---|
27 | #include "cf_map.h" |
---|
28 | #include "cfNewtonPolygon.h" |
---|
29 | |
---|
30 | TIMING_DEFINE_PRINT(fac_fq_bi_sqrf) |
---|
31 | TIMING_DEFINE_PRINT(fac_fq_bi_factor_sqrf) |
---|
32 | |
---|
33 | static const double log2exp= 1.442695041; |
---|
34 | |
---|
35 | #ifdef HAVE_NTL |
---|
36 | /// Factorization of a squarefree bivariate polynomials over an arbitrary finite |
---|
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 |
---|
39 | /// field do not coincide. In this case the current field is an extension of the |
---|
40 | /// initial field and the factors returned are factors of F over the initial |
---|
41 | /// field. |
---|
42 | /// |
---|
43 | /// @return @a biFactorize returns a list of factors of F. If F is not monic |
---|
44 | /// its leading coefficient is not outputted. |
---|
45 | /// @sa extBifactorize() |
---|
46 | CFList |
---|
47 | biFactorize (const CanonicalForm& F, ///< [in] a bivariate poly |
---|
48 | const ExtensionInfo& info ///< [in] information about extension |
---|
49 | ); |
---|
50 | |
---|
51 | inline CFList |
---|
52 | biSqrfFactorizeHelper (const CanonicalForm& G, ExtensionInfo& info) |
---|
53 | { |
---|
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; |
---|
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 | |
---|
81 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
82 | contentXFactors.removeFirst(); |
---|
83 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
84 | contentYFactors.removeFirst(); |
---|
85 | if (F.inCoeffDomain()) |
---|
86 | { |
---|
87 | CFList result; |
---|
88 | for (CFFListIterator i= contentXFactors; i.hasItem(); i++) |
---|
89 | result.append (N (i.getItem().factor())); |
---|
90 | for (CFFListIterator i= contentYFactors; i.hasItem(); i++) |
---|
91 | result.append (N (i.getItem().factor())); |
---|
92 | normalize (result); |
---|
93 | result.insert (Lc (G)); |
---|
94 | return result; |
---|
95 | } |
---|
96 | 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 | |
---|
106 | F= compress (F, M, S); |
---|
107 | CFList result= biFactorize (F, info); |
---|
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)); |
---|
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 | |
---|
127 | return result; |
---|
128 | } |
---|
129 | |
---|
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 | |
---|
143 | /// factorize a squarefree bivariate polynomial over \f$ F_{p}(\alpha ) \f$. |
---|
144 | /// |
---|
145 | /// @return @a FqBiSqrfFactorize returns a list of monic factors, the first |
---|
146 | /// element is the leading coefficient. |
---|
147 | /// @sa FpBiSqrfFactorize(), GFBiSqrfFactorize() |
---|
148 | inline |
---|
149 | CFList FqBiSqrfFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
150 | const Variable& alpha ///< [in] algebraic variable |
---|
151 | ) |
---|
152 | { |
---|
153 | ExtensionInfo info= ExtensionInfo (alpha, false); |
---|
154 | return biSqrfFactorizeHelper (G, info); |
---|
155 | } |
---|
156 | |
---|
157 | /// factorize a squarefree bivariate polynomial over GF |
---|
158 | /// |
---|
159 | /// @return @a GFBiSqrfFactorize returns a list of monic factors, the first |
---|
160 | /// element is the leading coefficient. |
---|
161 | /// @sa FpBiSqrfFactorize(), FqBiSqrfFactorize() |
---|
162 | inline |
---|
163 | CFList GFBiSqrfFactorize (const CanonicalForm & G ///< [in] a bivariate poly |
---|
164 | ) |
---|
165 | { |
---|
166 | ASSERT (CFFactory::gettype() == GaloisFieldDomain, |
---|
167 | "GF as base field expected"); |
---|
168 | ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false); |
---|
169 | return biSqrfFactorizeHelper (G, info); |
---|
170 | } |
---|
171 | |
---|
172 | /// factorize a bivariate polynomial over \f$ F_{p} \f$ |
---|
173 | /// |
---|
174 | /// @return @a FpBiFactorize returns a list of monic factors with |
---|
175 | /// multiplicity, the first element is the leading coefficient. |
---|
176 | /// @sa FqBiFactorize(), GFBiFactorize() |
---|
177 | inline |
---|
178 | CFFList |
---|
179 | FpBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
180 | bool substCheck= true ///< [in] enables substitute check |
---|
181 | ) |
---|
182 | { |
---|
183 | ExtensionInfo info= ExtensionInfo (false); |
---|
184 | CFMap N; |
---|
185 | CanonicalForm F= compress (G, N); |
---|
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 | |
---|
228 | CanonicalForm LcF= Lc (F); |
---|
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); |
---|
241 | CFFList result; |
---|
242 | if (F.inCoeffDomain()) |
---|
243 | { |
---|
244 | result= Union (contentXFactors, contentYFactors); |
---|
245 | normalize (result); |
---|
246 | result.insert (CFFactor (LcF, 1)); |
---|
247 | return result; |
---|
248 | } |
---|
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 | |
---|
259 | F= compress (F, M, S); |
---|
260 | |
---|
261 | TIMING_START (fac_fq_bi_sqrf); |
---|
262 | CFFList sqrf= FpSqrf (F, false); |
---|
263 | TIMING_END_AND_PRINT (fac_fq_bi_sqrf, |
---|
264 | "time for bivariate sqrf factors over Fp: "); |
---|
265 | CFList bufResult; |
---|
266 | sqrf.removeFirst(); |
---|
267 | CFListIterator i; |
---|
268 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
269 | { |
---|
270 | TIMING_START (fac_fq_bi_factor_sqrf); |
---|
271 | bufResult= biFactorize (iter.getItem().factor(), info); |
---|
272 | TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, |
---|
273 | "time to factor bivariate sqrf factors over Fp: "); |
---|
274 | for (i= bufResult; i.hasItem(); i++) |
---|
275 | result.append (CFFactor (N (decompress (i.getItem(), M, S)), |
---|
276 | iter.getItem().exp())); |
---|
277 | } |
---|
278 | |
---|
279 | result= Union (result, contentXFactors); |
---|
280 | result= Union (result, contentYFactors); |
---|
281 | normalize (result); |
---|
282 | result.insert (CFFactor (LcF, 1)); |
---|
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 | |
---|
294 | return result; |
---|
295 | } |
---|
296 | |
---|
297 | /// factorize a bivariate polynomial over \f$ F_{p}(\alpha ) \f$ |
---|
298 | /// |
---|
299 | /// @return @a FqBiFactorize returns a list of monic factors with |
---|
300 | /// multiplicity, the first element is the leading coefficient. |
---|
301 | /// @sa FpBiFactorize(), FqBiFactorize() |
---|
302 | inline |
---|
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 | ) |
---|
308 | { |
---|
309 | ExtensionInfo info= ExtensionInfo (alpha, false); |
---|
310 | CFMap N; |
---|
311 | CanonicalForm F= compress (G, N); |
---|
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 | |
---|
354 | CanonicalForm LcF= Lc (F); |
---|
355 | CanonicalForm contentX= content (F, 1); |
---|
356 | CanonicalForm contentY= content (F, 2); |
---|
357 | F /= (contentX*contentY); |
---|
358 | CFFList contentXFactors, contentYFactors; |
---|
359 | contentXFactors= factorize (contentX, alpha); |
---|
360 | contentYFactors= factorize (contentY, alpha); |
---|
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); |
---|
367 | CFFList result; |
---|
368 | if (F.inCoeffDomain()) |
---|
369 | { |
---|
370 | result= Union (contentXFactors, contentYFactors); |
---|
371 | normalize (result); |
---|
372 | result.insert (CFFactor (LcF, 1)); |
---|
373 | return result; |
---|
374 | } |
---|
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 | |
---|
386 | F= compress (F, M, S); |
---|
387 | |
---|
388 | TIMING_START (fac_fq_bi_sqrf); |
---|
389 | CFFList sqrf= FqSqrf (F, alpha, false); |
---|
390 | TIMING_END_AND_PRINT (fac_fq_bi_sqrf, |
---|
391 | "time for bivariate sqrf factors over Fq: "); |
---|
392 | CFList bufResult; |
---|
393 | sqrf.removeFirst(); |
---|
394 | CFListIterator i; |
---|
395 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
396 | { |
---|
397 | TIMING_START (fac_fq_bi_factor_sqrf); |
---|
398 | bufResult= biFactorize (iter.getItem().factor(), info); |
---|
399 | TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, |
---|
400 | "time to factor bivariate sqrf factors over Fq: "); |
---|
401 | for (i= bufResult; i.hasItem(); i++) |
---|
402 | result.append (CFFactor (N (decompress (i.getItem(), M, S)), |
---|
403 | iter.getItem().exp())); |
---|
404 | } |
---|
405 | |
---|
406 | result= Union (result, contentXFactors); |
---|
407 | result= Union (result, contentYFactors); |
---|
408 | normalize (result); |
---|
409 | result.insert (CFFactor (LcF, 1)); |
---|
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 | |
---|
421 | return result; |
---|
422 | } |
---|
423 | |
---|
424 | /// factorize a bivariate polynomial over GF |
---|
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() |
---|
429 | inline |
---|
430 | CFFList |
---|
431 | GFBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
432 | bool substCheck= true ///< [in] enables substitute check |
---|
433 | ) |
---|
434 | { |
---|
435 | ASSERT (CFFactory::gettype() == GaloisFieldDomain, |
---|
436 | "GF as base field expected"); |
---|
437 | ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false); |
---|
438 | CFMap N; |
---|
439 | CanonicalForm F= compress (G, N); |
---|
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 | |
---|
482 | CanonicalForm LcF= Lc (F); |
---|
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); |
---|
495 | CFFList result; |
---|
496 | if (F.inCoeffDomain()) |
---|
497 | { |
---|
498 | result= Union (contentXFactors, contentYFactors); |
---|
499 | normalize (result); |
---|
500 | result.insert (CFFactor (LcF, 1)); |
---|
501 | return result; |
---|
502 | } |
---|
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 | |
---|
514 | F= compress (F, M, S); |
---|
515 | |
---|
516 | TIMING_START (fac_fq_bi_sqrf); |
---|
517 | CFFList sqrf= GFSqrf (F, false); |
---|
518 | TIMING_END_AND_PRINT (fac_fq_bi_sqrf, |
---|
519 | "time for bivariate sqrf factors over GF: "); |
---|
520 | CFList bufResult; |
---|
521 | sqrf.removeFirst(); |
---|
522 | CFListIterator i; |
---|
523 | for (CFFListIterator iter= sqrf; iter.hasItem(); iter++) |
---|
524 | { |
---|
525 | TIMING_START (fac_fq_bi_factor_sqrf); |
---|
526 | bufResult= biFactorize (iter.getItem().factor(), info); |
---|
527 | TIMING_END_AND_PRINT (fac_fq_bi_factor_sqrf, |
---|
528 | "time to factor bivariate sqrf factors over GF: "); |
---|
529 | for (i= bufResult; i.hasItem(); i++) |
---|
530 | result.append (CFFactor (N (decompress (i.getItem(), M, S)), |
---|
531 | iter.getItem().exp())); |
---|
532 | } |
---|
533 | |
---|
534 | result= Union (result, contentXFactors); |
---|
535 | result= Union (result, contentYFactors); |
---|
536 | normalize (result); |
---|
537 | result.insert (CFFactor (LcF, 1)); |
---|
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 | |
---|
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() |
---|
556 | CanonicalForm prodMod0 (const CFList& L, ///< [in] a list of compressed, |
---|
557 | ///< bivariate polynomials |
---|
558 | const CanonicalForm& M,///< [in] a power of Variable (2) |
---|
559 | const modpk& b= modpk()///< [in] coeff bound |
---|
560 | ); |
---|
561 | |
---|
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$. |
---|
564 | /// |
---|
565 | /// @return @a evalPoint returns an evaluation point, which is valid if and only |
---|
566 | /// if fail == false. |
---|
567 | CanonicalForm |
---|
568 | evalPoint (const CanonicalForm& F, ///< [in] compressed, bivariate poly |
---|
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 |
---|
574 | ///< valid evaluation point |
---|
575 | ); |
---|
576 | |
---|
577 | /// Univariate factorization of squarefree monic polys over finite fields via |
---|
578 | /// NTL. If the characteristic is even special GF2 routines of NTL are used. |
---|
579 | /// |
---|
580 | /// @return @a uniFactorizer returns a list of monic factors |
---|
581 | CFList |
---|
582 | uniFactorizer (const CanonicalForm& A, ///< [in] squarefree univariate poly |
---|
583 | const Variable& alpha, ///< [in] algebraic variable |
---|
584 | const bool& GF ///< [in] GaloisFieldDomain? |
---|
585 | ); |
---|
586 | |
---|
587 | /// naive factor recombination over an extension of the initial field. |
---|
588 | /// Uses precomputed data to exclude combinations that are not possible. |
---|
589 | /// |
---|
590 | /// @return @a extFactorRecombination returns a list of factors over the initial |
---|
591 | /// field, whose shift to zero is reversed. |
---|
592 | /// @sa factorRecombination(), extEarlyFactorDetection() |
---|
593 | CFList |
---|
594 | extFactorRecombination ( |
---|
595 | CFList& factors, ///< [in,out] list of lifted factors that are |
---|
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 |
---|
601 | const ExtensionInfo& info,///< [in] contains information about |
---|
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 |
---|
609 | ///< recombination choose |
---|
610 | ///< thres= factors.length()/2 |
---|
611 | ); |
---|
612 | |
---|
613 | /// naive factor recombination. |
---|
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() |
---|
618 | CFList |
---|
619 | factorRecombination ( |
---|
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 |
---|
625 | const CanonicalForm& eval, ///< [in] evaluation point |
---|
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) |
---|
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 ( |
---|
641 | const Variable & alpha, ///< [in] some algebraic variable |
---|
642 | const Variable & beta, ///< [in] some algebraic variable |
---|
643 | int k ///< [in] some int |
---|
644 | ); |
---|
645 | |
---|
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 | |
---|
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 |
---|
660 | /// degree pattern are updated. |
---|
661 | /// |
---|
662 | /// @sa factorRecombination(), extEarlyFactorDetection() |
---|
663 | void |
---|
664 | earlyFactorDetection ( |
---|
665 | CFList& reconstructedFactors, ///< [in,out] list of reconstructed |
---|
666 | ///< factors |
---|
667 | CanonicalForm& F, ///< [in,out] poly to be factored, returns |
---|
668 | ///< poly divided by detected factors in case |
---|
669 | ///< of success |
---|
670 | CFList& factors, ///< [in,out] list of factors lifted up to |
---|
671 | ///< @a deg, returns a list of factors |
---|
672 | ///< without detected factors |
---|
673 | int& adaptedLiftBound, ///< [in,out] adapted lift bound |
---|
674 | int*& factorsFoundIndex,///< [in,out] factors already considered |
---|
675 | DegreePattern& degs, ///< [in,out] degree pattern, is updated |
---|
676 | ///< whenever we find a factor |
---|
677 | bool& success, ///< [in,out] indicating success |
---|
678 | int deg, ///< [in] stage of Hensel lifting |
---|
679 | const CanonicalForm& eval, ///<[in] evaluation point |
---|
680 | const modpk& b= modpk()///< [in] coeff bound |
---|
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 |
---|
685 | /// degree pattern are updated. |
---|
686 | /// |
---|
687 | /// @sa factorRecombination(), earlyFactorDetection() |
---|
688 | void |
---|
689 | extEarlyFactorDetection ( |
---|
690 | CFList& reconstructedFactors, ///< [in,out] list of reconstructed |
---|
691 | ///< factors |
---|
692 | CanonicalForm& F, ///< [in,out] poly to be factored, returns |
---|
693 | ///< poly divided by detected factors in case |
---|
694 | ///< of success |
---|
695 | CFList& factors, ///< [in,out] list of factors lifted up to |
---|
696 | ///< @a deg, returns a list of factors |
---|
697 | ///< without detected factors |
---|
698 | int& adaptedLiftBound, ///< [in,out] adapted lift bound |
---|
699 | int*& factorsFoundIndex, ///< [in,out] factors already considered |
---|
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 | |
---|
708 | /// hensel Lifting and early factor detection |
---|
709 | /// |
---|
710 | /// @return @a henselLiftAndEarly returns monic (wrt Variable (1)) lifted |
---|
711 | /// factors without factors which have been detected at an early stage |
---|
712 | /// of Hensel lifting |
---|
713 | /// @sa earlyFactorDetection(), extEarlyFactorDetection() |
---|
714 | |
---|
715 | CFList |
---|
716 | henselLiftAndEarly ( |
---|
717 | CanonicalForm& A, ///< [in,out] poly to be factored, |
---|
718 | ///< returns poly divided by detected factors |
---|
719 | ///< in case of success |
---|
720 | bool& earlySuccess, ///< [in,out] indicating success |
---|
721 | CFList& earlyFactors, ///< [in,out] list of factors detected |
---|
722 | ///< at early stage of Hensel lifting |
---|
723 | DegreePattern& degs, ///< [in,out] degree pattern |
---|
724 | int& liftBound, ///< [in,out] (adapted) lift bound |
---|
725 | const CFList& uniFactors, ///< [in] univariate factors |
---|
726 | const ExtensionInfo& info, ///< [in] information about extension |
---|
727 | const CanonicalForm& eval, ///< [in] evaluation point |
---|
728 | modpk& b, ///< [in] coeff bound |
---|
729 | CanonicalForm& den ///< [in] bound on the den if over Q(a) |
---|
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 |
---|
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() |
---|
758 | CFList |
---|
759 | extBiFactorize (const CanonicalForm& F, ///< [in] poly to be factored |
---|
760 | const ExtensionInfo& info ///< [in] info about extension |
---|
761 | ); |
---|
762 | |
---|
763 | #endif |
---|
764 | #endif |
---|
765 | /* FAC_FQ_BIVAR_H */ |
---|
766 | |
---|