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 | * ABSTRACT: In contrast to biFactorizer() in facFqFactorice.cc we evaluate and |
---|
10 | * factorize the polynomial in both variables. So far factor recombination is |
---|
11 | * done naive! |
---|
12 | * |
---|
13 | * @author Martin Lee |
---|
14 | * |
---|
15 | * @internal @version \$Id$ |
---|
16 | * |
---|
17 | **/ |
---|
18 | /*****************************************************************************/ |
---|
19 | |
---|
20 | #ifndef FAC_FQ_BIVAR_H |
---|
21 | #define FAC_FQ_BIVAR_H |
---|
22 | |
---|
23 | #include <config.h> |
---|
24 | |
---|
25 | #include "assert.h" |
---|
26 | |
---|
27 | #include "facFqBivarUtil.h" |
---|
28 | #include "DegreePattern.h" |
---|
29 | #include "ExtensionInfo.h" |
---|
30 | #include "cf_util.h" |
---|
31 | #include "facFqSquarefree.h" |
---|
32 | |
---|
33 | extern const double log2exp= 1.442695041; |
---|
34 | |
---|
35 | /// Factorization of a squarefree bivariate polynomials over an arbitrary finite |
---|
36 | /// field, information on the current field we work over is in @a info. @a info |
---|
37 | /// may also contain information about the initial field if initial and current |
---|
38 | /// field do not coincide. In this case the current field is an extension of the |
---|
39 | /// initial field and the factors returned are factors of F over the initial |
---|
40 | /// field. |
---|
41 | /// |
---|
42 | /// @return @a biFactorize returns a list of factors of F. If F is not monic |
---|
43 | /// its leading coefficient is not outputted. |
---|
44 | /// @sa extBifactorize() |
---|
45 | CFList |
---|
46 | biFactorize (const CanonicalForm& F, ///< [in] a bivariate poly |
---|
47 | const ExtensionInfo& info ///< [in] information about extension |
---|
48 | ); |
---|
49 | |
---|
50 | /// factorize a squarefree bivariate polynomial over \f$ F_{p} \f$. |
---|
51 | /// |
---|
52 | /// @return @a FpBiSqrfFactorize returns a list of monic factors, the first |
---|
53 | /// element is the leading coefficient. |
---|
54 | /// @sa FqBiSqrfFactorize(), GFBiSqrfFactorize() |
---|
55 | inline |
---|
56 | CFList FpBiSqrfFactorize (const CanonicalForm & F ///< [in] a bivariate poly |
---|
57 | ) |
---|
58 | { |
---|
59 | ExtensionInfo info= ExtensionInfo (false); |
---|
60 | CFList result= biFactorize (F, info); |
---|
61 | result.insert (Lc(F)); |
---|
62 | return result; |
---|
63 | } |
---|
64 | |
---|
65 | /// factorize a squarefree bivariate polynomial over \f$ F_{p}(\alpha ) \f$. |
---|
66 | /// |
---|
67 | /// @return @a FqBiSqrfFactorize returns a list of monic factors, the first |
---|
68 | /// element is the leading coefficient. |
---|
69 | /// @sa FpBiSqrfFactorize(), GFBiSqrfFactorize() |
---|
70 | inline |
---|
71 | CFList FqBiSqrfFactorize (const CanonicalForm & F, ///< [in] a bivariate poly |
---|
72 | const Variable& alpha ///< [in] algebraic variable |
---|
73 | ) |
---|
74 | { |
---|
75 | ExtensionInfo info= ExtensionInfo (alpha, false); |
---|
76 | CFList result= biFactorize (F, info); |
---|
77 | result.insert (Lc(F)); |
---|
78 | return result; |
---|
79 | } |
---|
80 | |
---|
81 | /// factorize a squarefree bivariate polynomial over GF |
---|
82 | /// |
---|
83 | /// @return @a GFBiSqrfFactorize returns a list of monic factors, the first |
---|
84 | /// element is the leading coefficient. |
---|
85 | /// @sa FpBiSqrfFactorize(), FqBiSqrfFactorize() |
---|
86 | inline |
---|
87 | CFList GFBiSqrfFactorize (const CanonicalForm & F ///< [in] a bivariate poly |
---|
88 | ) |
---|
89 | { |
---|
90 | ASSERT (CFFactory::gettype() == GaloisFieldDomain, |
---|
91 | "GF as base field expected"); |
---|
92 | ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false); |
---|
93 | CFList result= biFactorize (F, info); |
---|
94 | result.insert (Lc(F)); |
---|
95 | return result; |
---|
96 | } |
---|
97 | |
---|
98 | /// factorize a bivariate polynomial over \f$ F_{p} \f$ |
---|
99 | /// |
---|
100 | /// @return @a FpBiFactorize returns a list of monic factors with |
---|
101 | /// multiplicity, the first element is the leading coefficient. |
---|
102 | /// @sa FqBiFactorize(), GFBiFactorize() |
---|
103 | inline |
---|
104 | CFFList FpBiFactorize (const CanonicalForm & F ///< [in] a bivariate poly |
---|
105 | ) |
---|
106 | { |
---|
107 | ExtensionInfo info= ExtensionInfo (false); |
---|
108 | bool GF= false; |
---|
109 | CanonicalForm LcF= Lc (F); |
---|
110 | CanonicalForm pthRoot, A; |
---|
111 | CanonicalForm sqrfP= sqrfPart (F/Lc(F), pthRoot, info.getAlpha()); |
---|
112 | CFList buf, bufRoot; |
---|
113 | CFFList result, resultRoot; |
---|
114 | int p= getCharacteristic(); |
---|
115 | int l; |
---|
116 | if (degree (pthRoot) > 0) |
---|
117 | { |
---|
118 | pthRoot= maxpthRoot (pthRoot, p, l); |
---|
119 | result= FpBiFactorize (pthRoot); |
---|
120 | result.removeFirst(); |
---|
121 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
122 | i.getItem()= CFFactor (i.getItem().factor(), i.getItem().exp()*l*p); |
---|
123 | result.insert (CFFactor (LcF, 1)); |
---|
124 | return result; |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | buf= biFactorize (sqrfP, info); |
---|
129 | A= F/LcF; |
---|
130 | result= multiplicity (A, buf); |
---|
131 | } |
---|
132 | if (degree (A) > 0) |
---|
133 | { |
---|
134 | resultRoot= FpBiFactorize (A); |
---|
135 | resultRoot.removeFirst(); |
---|
136 | result= Union (result, resultRoot); |
---|
137 | } |
---|
138 | result.insert (CFFactor (LcF, 1)); |
---|
139 | return result; |
---|
140 | } |
---|
141 | |
---|
142 | /// factorize a bivariate polynomial over \f$ F_{p}(\alpha ) \f$ |
---|
143 | /// |
---|
144 | /// @return @a FqBiFactorize returns a list of monic factors with |
---|
145 | /// multiplicity, the first element is the leading coefficient. |
---|
146 | /// @sa FpBiFactorize(), FqBiFactorize() |
---|
147 | inline |
---|
148 | CFFList FqBiFactorize (const CanonicalForm & F, ///< [in] a bivariate poly |
---|
149 | const Variable & alpha ///< [in] algebraic variable |
---|
150 | ) |
---|
151 | { |
---|
152 | ExtensionInfo info= ExtensionInfo (alpha, false); |
---|
153 | bool GF= false; |
---|
154 | CanonicalForm LcF= Lc (F); |
---|
155 | CanonicalForm pthRoot, A; |
---|
156 | CanonicalForm sqrfP= sqrfPart (F/Lc(F), pthRoot, alpha); |
---|
157 | CFList buf, bufRoot; |
---|
158 | CFFList result, resultRoot; |
---|
159 | int p= getCharacteristic(); |
---|
160 | int q= ipower (p, degree (getMipo (alpha))); |
---|
161 | int l; |
---|
162 | if (degree (pthRoot) > 0) |
---|
163 | { |
---|
164 | pthRoot= maxpthRoot (pthRoot, q, l); |
---|
165 | result= FqBiFactorize (pthRoot, alpha); |
---|
166 | result.removeFirst(); |
---|
167 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
168 | i.getItem()= CFFactor (i.getItem().factor(), i.getItem().exp()*l*p); |
---|
169 | result.insert (CFFactor (LcF, 1)); |
---|
170 | return result; |
---|
171 | } |
---|
172 | else |
---|
173 | { |
---|
174 | buf= biFactorize (sqrfP, info); |
---|
175 | A= F/LcF; |
---|
176 | result= multiplicity (A, buf); |
---|
177 | } |
---|
178 | if (degree (A) > 0) |
---|
179 | { |
---|
180 | resultRoot= FqBiFactorize (A, alpha); |
---|
181 | resultRoot.removeFirst(); |
---|
182 | result= Union (result, resultRoot); |
---|
183 | } |
---|
184 | result.insert (CFFactor (LcF, 1)); |
---|
185 | return result; |
---|
186 | } |
---|
187 | |
---|
188 | /// factorize a bivariate polynomial over GF |
---|
189 | /// |
---|
190 | /// @return @a GFBiFactorize returns a list of monic factors with |
---|
191 | /// multiplicity, the first element is the leading coefficient. |
---|
192 | /// @sa FpBiFactorize(), FqBiFactorize() |
---|
193 | inline |
---|
194 | CFFList GFBiFactorize (const CanonicalForm & F ///< [in] a bivariate poly |
---|
195 | ) |
---|
196 | { |
---|
197 | ASSERT (CFFactory::gettype() == GaloisFieldDomain, |
---|
198 | "GF as base field expected"); |
---|
199 | ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false); |
---|
200 | bool GF= true; |
---|
201 | CanonicalForm LcF= Lc (F); |
---|
202 | CanonicalForm pthRoot, A; |
---|
203 | CanonicalForm sqrfP= sqrfPart (F/LcF, pthRoot, info.getAlpha()); |
---|
204 | CFList buf; |
---|
205 | CFFList result, resultRoot; |
---|
206 | int p= getCharacteristic(); |
---|
207 | int q= ipower (p, getGFDegree()); |
---|
208 | int l; |
---|
209 | if (degree (pthRoot) > 0) |
---|
210 | { |
---|
211 | pthRoot= maxpthRoot (pthRoot, q, l); |
---|
212 | result= GFBiFactorize (pthRoot); |
---|
213 | result.removeFirst(); |
---|
214 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
215 | i.getItem()= CFFactor (i.getItem().factor(), i.getItem().exp()*l*p); |
---|
216 | result.insert (CFFactor (LcF, 1)); |
---|
217 | return result; |
---|
218 | } |
---|
219 | else |
---|
220 | { |
---|
221 | buf= biFactorize (sqrfP, info); |
---|
222 | A= F/LcF; |
---|
223 | result= multiplicity (A, buf); |
---|
224 | } |
---|
225 | if (degree (A) > 0) |
---|
226 | { |
---|
227 | resultRoot= GFBiFactorize (A); |
---|
228 | resultRoot.removeFirst(); |
---|
229 | result= Union (result, resultRoot); |
---|
230 | } |
---|
231 | result.insert (CFFactor (LcF, 1)); |
---|
232 | return result; |
---|
233 | } |
---|
234 | |
---|
235 | /// \f$ \prod_{f\in L} {f (0, x)} \ mod\ M \f$ via divide-and-conquer |
---|
236 | /// |
---|
237 | /// @return @a prodMod0 computes the above defined product |
---|
238 | /// @sa prodMod() |
---|
239 | CanonicalForm prodMod0 (const CFList& L, ///< [in] a list of compressed, |
---|
240 | ///< bivariate polynomials |
---|
241 | const CanonicalForm& M ///< [in] a power of Variable (2) |
---|
242 | ); |
---|
243 | |
---|
244 | /// find an evaluation point p, s.t. F(p,y) is squarefree and |
---|
245 | /// \f$ deg_{y} (F(p,y))= deg_{y} (F(x,y)) \f$. |
---|
246 | /// |
---|
247 | /// @return @a evalPoint returns an evaluation point, which is valid if and only |
---|
248 | /// if fail == false. |
---|
249 | CanonicalForm |
---|
250 | evalPoint (const CanonicalForm& F, ///< [in] compressed, bivariate poly |
---|
251 | CanonicalForm & eval, ///< [in,out] F (p, y) |
---|
252 | const Variable& alpha, ///< [in] algebraic variable |
---|
253 | CFList& list, ///< [in] list of points already considered |
---|
254 | const bool& GF, ///< [in] GaloisFieldDomain? |
---|
255 | bool& fail ///< [in,out] equals true, if there is no |
---|
256 | ///< valid evaluation point |
---|
257 | ); |
---|
258 | |
---|
259 | /// Univariate factorization of squarefree monic polys over finite fields via |
---|
260 | /// NTL. If the characteristic is even special GF2 routines of NTL are used. |
---|
261 | /// |
---|
262 | /// @return @a uniFactorizer returns a list of monic factors |
---|
263 | inline CFList |
---|
264 | uniFactorizer (const CanonicalForm& A, ///< [in] squarefree univariate poly |
---|
265 | const Variable& alpha, ///< [in] algebraic variable |
---|
266 | const bool& GF ///< [in] GaloisFieldDomain? |
---|
267 | ); |
---|
268 | |
---|
269 | /// naive factor recombination over an extension of the initial field. |
---|
270 | /// Uses precomputed data to exclude combinations that are not possible. |
---|
271 | /// |
---|
272 | /// @return @a extFactorRecombination returns a list of factors over the initial |
---|
273 | /// field, whose shift to zero is reversed. |
---|
274 | /// @sa factorRecombination(), extEarlyFactorDetection() |
---|
275 | inline CFList |
---|
276 | extFactorRecombination ( |
---|
277 | const CFList& factors, ///< [in] list of lifted factors that are |
---|
278 | ///< monic wrt Variable (1) |
---|
279 | const CanonicalForm& F, ///< [in] poly to be factored |
---|
280 | const CanonicalForm& M, ///< [in] Variable (2)^liftBound |
---|
281 | const ExtensionInfo& info, ///< [in] contains information about |
---|
282 | ///< extension |
---|
283 | const CanonicalForm& eval ///< [in] evaluation point |
---|
284 | ); |
---|
285 | |
---|
286 | /// naive factor recombination. |
---|
287 | /// Uses precomputed data to exclude combinations that are not possible. |
---|
288 | /// |
---|
289 | /// @return @a factorRecombination returns a list of factors of F. |
---|
290 | /// @sa extFactorRecombination(), earlyFactorDetectection() |
---|
291 | inline CFList |
---|
292 | factorRecombination ( |
---|
293 | const CFList& factors, ///< [in] list of lifted factors |
---|
294 | ///< that are monic wrt Variable (1) |
---|
295 | const CanonicalForm& F, ///< [in] poly to be factored |
---|
296 | const CanonicalForm& M, ///< [in] Variable (2)^liftBound |
---|
297 | const DegreePattern& degs ///< [in] degree pattern |
---|
298 | ); |
---|
299 | |
---|
300 | /// chooses a field extension. |
---|
301 | /// |
---|
302 | /// @return @a chooseExtension returns an extension specified by @a beta of |
---|
303 | /// appropiate size |
---|
304 | Variable chooseExtension ( |
---|
305 | const CanonicalForm & A, ///< [in] some bivariate poly |
---|
306 | const Variable & beta ///< [in] some algebraic |
---|
307 | ///< variable |
---|
308 | ); |
---|
309 | |
---|
310 | /// detects factors of @a F at stage @a deg of Hensel lifting. |
---|
311 | /// No combinations of more than one factor are tested. Lift bound and possible |
---|
312 | /// degree pattern are updated. |
---|
313 | /// |
---|
314 | /// @return @a earlyFactorDetection returns a list of factors of F (possibly in- |
---|
315 | /// complete), in case of success. Otherwise an empty list. |
---|
316 | /// @sa factorRecombination(), extEarlyFactorDetection() |
---|
317 | inline CFList |
---|
318 | earlyFactorDetection ( |
---|
319 | CanonicalForm& F, ///< [in,out] poly to be factored, returns |
---|
320 | ///< poly divided by detected factors in case |
---|
321 | ///< of success |
---|
322 | CFList& factors, ///< [in,out] list of factors lifted up to |
---|
323 | ///< @a deg, returns a list of factors |
---|
324 | ///< without detected factors |
---|
325 | int& adaptedLiftBound, ///< [in,out] adapted lift bound |
---|
326 | DegreePattern& degs, ///< [in,out] degree pattern, is updated |
---|
327 | ///< whenever we find a factor |
---|
328 | bool& success, ///< [in,out] indicating success |
---|
329 | int deg ///< [in] stage of Hensel lifting |
---|
330 | ); |
---|
331 | |
---|
332 | /// detects factors of @a F at stage @a deg of Hensel lifting. |
---|
333 | /// No combinations of more than one factor are tested. Lift bound and possible |
---|
334 | /// degree pattern are updated. |
---|
335 | /// |
---|
336 | /// @return @a extEarlyFactorDetection returns a list of factors of F (possibly |
---|
337 | /// incomplete), whose shift to zero is reversed, in case of success. |
---|
338 | /// Otherwise an empty list. |
---|
339 | /// @sa factorRecombination(), earlyFactorDetection() |
---|
340 | inline CFList |
---|
341 | extEarlyFactorDetection ( |
---|
342 | CanonicalForm& F, ///< [in,out] poly to be factored, returns |
---|
343 | ///< poly divided by detected factors in case |
---|
344 | ///< of success |
---|
345 | CFList& factors, ///< [in,out] list of factors lifted up to |
---|
346 | ///< @a deg, returns a list of factors |
---|
347 | ///< without detected factors |
---|
348 | int& adaptedLiftBound, ///< [in,out] adapted lift bound |
---|
349 | DegreePattern& degs, ///< [in,out] degree pattern, is updated |
---|
350 | ///< whenever we find a factor |
---|
351 | bool& success, ///< [in,out] indicating success |
---|
352 | const ExtensionInfo& info, ///< [in] information about extension |
---|
353 | const CanonicalForm& eval, ///< [in] evaluation point |
---|
354 | int deg ///< [in] stage of Hensel lifting |
---|
355 | ); |
---|
356 | |
---|
357 | /// hensel Lifting and early factor detection |
---|
358 | /// |
---|
359 | /// @return @a henselLiftAndEarly returns monic (wrt Variable (1)) lifted |
---|
360 | /// factors without factors which have been detected at an early stage |
---|
361 | /// of Hensel lifting |
---|
362 | /// @sa earlyFactorDetection(), extEarlyFactorDetection() |
---|
363 | |
---|
364 | inline CFList |
---|
365 | henselLiftAndEarly ( |
---|
366 | CanonicalForm& A, ///< [in,out] poly to be factored, |
---|
367 | ///< returns poly divided by detected factors |
---|
368 | ///< in case of success |
---|
369 | bool& earlySuccess, ///< [in,out] indicating success |
---|
370 | CFList& earlyFactors, ///< [in,out] list of factors detected |
---|
371 | ///< at early stage of Hensel lifting |
---|
372 | DegreePattern& degs, ///< [in,out] degree pattern |
---|
373 | int& liftBound, ///< [in,out] (adapted) lift bound |
---|
374 | const CFList& uniFactors, ///< [in] univariate factors |
---|
375 | const ExtensionInfo& info, ///< [in] information about extension |
---|
376 | const CanonicalForm& eval ///< [in] evaluation point |
---|
377 | ); |
---|
378 | |
---|
379 | /// Factorization over an extension of initial field |
---|
380 | /// |
---|
381 | /// @return @a extBiFactorize returns factorization of F over initial field |
---|
382 | /// @sa biFactorize() |
---|
383 | inline CFList |
---|
384 | extBiFactorize (const CanonicalForm& F, ///< [in] poly to be factored |
---|
385 | const ExtensionInfo& info ///< [in] info about extension |
---|
386 | ); |
---|
387 | |
---|
388 | |
---|
389 | #endif |
---|
390 | /* FAC_FQ_BIVAR_H */ |
---|
391 | |
---|