source: git/factory/facHensel.h @ 11bf82

spielwiese
Last change on this file since 11bf82 was 11bf82, checked in by Martin Lee <martinlee84@…>, 13 years ago
polynomial time bivariate factorization git-svn-id: file:///usr/local/Singular/svn/trunk@14243 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.6 KB
Line 
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR
3\*****************************************************************************/
4/** @file facHensel.h
5 *
6 * This file defines functions for Hensel lifting and modular multiplication.
7 *
8 * ABSTRACT: function are used for bi- and multivariate factorization over
9 * finite fields
10 *
11 * @author Martin Lee
12 *
13 * @internal @version \$Id$
14 *
15 **/
16/*****************************************************************************/
17
18#ifndef FAC_HENSEL_H
19#define FAC_HENSEL_H
20
21#include <config.h>
22#include "assert.h"
23#include "debug.h"
24#include "timing.h"
25
26#include "canonicalform.h"
27#include "cf_iter.h"
28#include "templates/ftmpl_functions.h"
29#include "algext.h"
30
31/// multiplication of univariate polys over a finite field using NTL, if we are
32/// in GF factory's default multiplication is used.
33///
34/// @return @a mulNTL returns F*G
35CanonicalForm
36mulNTL (const CanonicalForm& F, ///< [in] a univariate poly
37        const CanonicalForm& G  ///< [in] a univariate poly
38       );
39
40/// mod of univariate polys over a finite field using NTL, if we are
41/// in GF factory's default mod is used.
42///
43/// @return @a modNTL returns F mod G
44CanonicalForm
45modNTL (const CanonicalForm& F, ///< [in] a univariate poly
46        const CanonicalForm& G  ///< [in] a univariate poly
47       );
48
49/// division of univariate polys over a finite field using NTL, if we are
50/// in GF factory's default division is used.
51///
52/// @return @a divNTL returns F/G
53CanonicalForm
54divNTL (const CanonicalForm& F, ///< [in] a univariate poly
55        const CanonicalForm& G  ///< [in] a univariate poly
56       );
57
58/*/// division with remainder of univariate polys over a finite field using NTL,
59/// if we are in GF factory's default division with remainder is used.
60void
61divremNTL (const CanonicalForm& F, ///< [in] a univariate poly
62           const CanonicalForm& G, ///< [in] a univariate poly
63           CanonicalForm& Q,       ///< [in,out] dividend
64           CanonicalForm& R        ///< [in,out] remainder
65          );*/
66
67/// splits @a F into degree (F, x)/m polynomials each of degree less than @a m
68/// in @a x.
69///
70/// @return @a split returns a list of polynomials of degree less than @a m in
71///         @a x. If degree (F, x) <= 0, F is returned.
72/// @sa divrem32(), divrem21()
73static inline
74CFList split (const CanonicalForm& F, ///< [in] some poly
75              const int m,            ///< [in] some int
76              const Variable& x       ///< [in] some Variable
77             );
78
79/// division with remainder of @a F by
80/// @a G wrt Variable (1) modulo @a M.
81///
82/// @sa divrem(), divrem21(), divrem2()
83static inline
84void divrem32 (const CanonicalForm& F, ///< [in] poly, s.t. 3*(degree (G, 1)/2)>
85                                       ///< degree (F, 1)
86               const CanonicalForm& G, ///< [in] some poly
87               CanonicalForm& Q,       ///< [in,out] dividend
88               CanonicalForm& R,       ///< [in,out] remainder, degree (R, 1) <
89                                       ///< degree (G, 1)
90               const CFList& M         ///< [in] only contains powers of
91                                       ///< Variables of level higher than 1
92              );
93
94/// division with remainder of @a F by
95/// @a G wrt Variable (1) modulo @a M.
96///
97/// @sa divrem(), divrem32(), divrem2()
98static inline
99void divrem21 (const CanonicalForm& F, ///< [in] poly, s.t. 2*degree (G, 1) >
100                                       ///< degree (F, 1)
101               const CanonicalForm& G, ///< [in] some poly
102               CanonicalForm& Q,       ///< [in,out] dividend
103               CanonicalForm& R,       ///< [in,out] remainder, degree (R, 1) <
104                                       ///< degree (G, 1)
105               const CFList& M         ///< [in] only contains powers of
106                                       ///< Variables of level higher than 1
107              );
108
109/// division with remainder of @a F by
110/// @a G wrt Variable (1) modulo @a M.
111///
112/// @return @a Q returns the dividend, @a R returns the remainder.
113/// @sa divrem()
114void divrem2 (const CanonicalForm& F, ///< [in] bivariate, compressed polynomial
115              const CanonicalForm& G, ///< [in] bivariate, compressed polynomial
116              CanonicalForm& Q,       ///< [in,out] dividend
117              CanonicalForm& R,       ///< [in,out] remainder, degree (R, 1) <
118                                      ///< degree (G, 1)
119              const CanonicalForm& M  ///< [in] power of Variable (2)
120             );
121
122/// division with remainder of @a F by
123/// @a G wrt Variable (1) modulo @a MOD.
124///
125/// @sa divrem2()
126void divrem (
127           const CanonicalForm& F, ///< [in] multivariate, compressed polynomial
128           const CanonicalForm& G, ///< [in] multivariate, compressed polynomial
129           CanonicalForm& Q,       ///< [in,out] dividend
130           CanonicalForm& R,       ///< [in,out] remainder, degree (R, 1) <
131                                   ///< degree (G, 1)
132           const CFList& MOD       ///< [in] only contains powers of
133                                   ///< Variables of level higher than 1
134            );
135
136
137/// division with remainder of @a F by
138/// @a G wrt Variable (1) modulo @a M using Newton inversion
139///
140/// @return @a Q returns the dividend, @a R returns the remainder.
141/// @sa divrem2(), newtonDiv()
142void
143newtonDivrem (const CanonicalForm& F, ///< [in] bivariate, compressed polynomial
144              const CanonicalForm& G, ///< [in] bivariate, compressed polynomial
145                                      ///< which is monic in Variable (1)
146              CanonicalForm& Q,       ///< [in,out] dividend
147              CanonicalForm& R,       ///< [in,out] remainder, degree (R, 1) <
148                                      ///< degree (G, 1)
149              const CanonicalForm& M  ///< [in] power of Variable (2)
150             );
151
152/// division of @a F by
153/// @a G wrt Variable (1) modulo @a M using Newton inversion
154///
155/// @return @a newtonDiv returns the dividend
156/// @sa divrem2(), newtonDivrem()
157CanonicalForm
158newtonDiv (const CanonicalForm& F, ///< [in] bivariate, compressed polynomial
159           const CanonicalForm& G, ///< [in] bivariate, compressed polynomial
160                                   ///< which is monic in Variable (1)
161           const CanonicalForm& M  ///< [in] power of Variable (2)
162          );
163
164/// reduce @a F modulo elements in @a M.
165///
166/// @return @a mod returns @a F modulo @a M
167CanonicalForm mod (const CanonicalForm& F, ///< [in] compressed polynomial
168                   const CFList& M         ///< [in] list containing only
169                                           ///< univariate polynomials
170                  );
171
172/// Karatsuba style modular multiplication for bivariate polynomials.
173///
174/// @return @a mulMod2 returns @a A * @a B mod @a M.
175CanonicalForm
176mulMod2 (const CanonicalForm& A, ///< [in] bivariate, compressed polynomial
177         const CanonicalForm& B, ///< [in] bivariate, compressed polynomial
178         const CanonicalForm& M  ///< [in] power of Variable (2)
179        );
180
181/// Karatsuba style modular multiplication for multivariate polynomials.
182///
183/// @return @a mulMod2 returns @a A * @a B mod @a MOD.
184CanonicalForm
185mulMod (const CanonicalForm& A, ///< [in] multivariate, compressed polynomial
186        const CanonicalForm& B, ///< [in] multivariate, compressed polynomial
187        const CFList& MOD       ///< [in] only contains powers of
188                                ///< Variables of level higher than 1
189       );
190
191/// product of all elements in @a L modulo @a M via divide-and-conquer.
192///
193/// @return @a prodMod returns product of all elements in @a L modulo @a M.
194CanonicalForm
195prodMod (const CFList& L,       ///< [in] contains only bivariate, compressed
196                                ///< polynomials
197         const CanonicalForm& M ///< [in] power of Variable (2)
198        );
199
200/// product of all elements in @a L modulo @a M via divide-and-conquer.
201///
202/// @return @a prodMod returns product of all elements in @a L modulo @a M.
203CanonicalForm
204prodMod (const CFList& L, ///< [in] contains multivariate, compressed
205                          ///< polynomials
206         const CFList& M  ///< [in] contains only powers of Variables
207        );
208
209/// sort a list of polynomials by their degree in @a x.
210///
211void sortList (CFList& list,     ///< [in, out] list of polys, sorted list
212               const Variable& x ///< [in] some Variable
213              );
214
215/// solve the univariate diophantine equation
216/// \f$ 1\equiv \sum_{i= 1}^{r} {\delta_{i} F/g_{i}} \f$.
217/// Where \f$ F= \prod_{i= 1}^{r} {g_{i}} \f$ and \f$ F \f$ is squarefree
218/// the \f$ \delta_{i} \f$ have degree less than the degree of \f$ g_{i} \f$.
219///
220/// @return @a diophantine returns a list of polynomials \f$ \delta_{i} \f$ as
221/// specified above
222/// @sa biDiophantine(), multiRecDiophantine()
223static inline
224CFList diophantine (const CanonicalForm& F, ///< [in] compressed, bivariate
225                                            ///< polynomial
226                    const CFList& factors   ///< [in] a list of factors, as
227                                            ///< specified above, including
228                                            ///< LC (F, Variable (1)) as first
229                                            ///< element
230                   );
231
232/// Hensel lift from univariate to bivariate.
233///
234/// @sa henselLiftResume12(), henselLift23(), henselLiftResume(), henselLift()
235void
236henselLift12 (const CanonicalForm& F, ///< [in] compressed, bivariate poly
237              CFList& factors,        ///< [in, out] monic univariate factors of
238                                      ///< F, including leading coefficient as
239                                      ///< first element. Returns monic lifted
240                                      ///< factors without the leading
241                                      ///< coefficient
242              int l,                  ///< [in] lifting precision
243              CFArray& Pi,            ///< [in,out] stores intermediate results
244              CFList& diophant,       ///< [in,out] result of diophantine()
245              CFMatrix& M             ///< [in,out] stores intermediate results
246             );
247
248/// resume Hensel lift from univariate to bivariate. Assumes factors are lifted
249/// to precision Variable (2)^start and lifts them to precision Variable (2)^end
250///
251/// @sa henselLift12(), henselLift23(), henselLiftResume(), henselLift()
252void
253henselLiftResume12 (const CanonicalForm& F, ///< [in] compressed, bivariate poly
254                    CFList& factors,        ///< [in,out] monic factors of F,
255                                            ///< lifted to precision start,
256                                            ///< including leading coefficient
257                                            ///< as first element. Returns monic
258                                            ///< lifted factors without the
259                                            ///< leading coefficient
260                    int start,              ///< [in] starting precision
261                    int end,                ///< [in] end precision
262                    CFArray& Pi,            ///< [in,out] stores intermediate
263                                            ///< results
264                    const CFList& diophant, ///< [in] result of diophantine
265                    CFMatrix& M             ///< [in,out] stores intermediate
266                                            ///< results
267                   );
268
269/// solves the bivariate polynomial diophantine equation
270/// \f$ 1\equiv \sum_{i= 1}^{r} {\delta_{i} F/g_{i}} \ mod\ y^{d} \f$,
271/// where \f$ F= \prod_{i= 1}^{r} {g_{i}} \ mod\ y^{d}\f$ and
272/// \f$ F \in K[x][y]\f$ is squarefree, the \f$ \delta_{i} \f$ have degree less
273/// than the degree of \f$ g_{i} \f$ in x.
274///
275/// @return @a biDiophantine returns a list of polynomials \f$ \delta_{i} \f$ as
276///         specified above
277/// @sa diophantine(), multiRecDiophantine()
278static inline
279CFList
280biDiophantine (const CanonicalForm& F, ///< [in] compressed, bivariate poly
281               const CFList& factors,  ///< [in] list of monic bivariate factors
282                                       ///< including LC (F, Variable (1)) as
283                                       ///< first element
284               const int d             ///< [in] precision
285              );
286
287/// solve the multivariate polynomial diophantine equation
288/// \f$ 1\equiv \sum_{i= 1}^{r} {\delta_{i} F/g_{i}} \ mod\ <M,F.mvar()^{d}>\f$,
289/// where \f$ F= \prod_{i= 1}^{r} {g_{i}} \ mod\ <M,F.mvar()^{d}>\f$ and
290/// \f$ F \in K[x][x_1,\ldots , x_n]\f$ is squarefree, the \f$ \delta_{i} \f$
291/// have degree less than the degree of \f$ g_{i} \f$ in x.
292///
293/// @return @a multiDiophantine returns a list of polynomials \f$ \delta_{i} \f$
294///         as specified above
295/// @sa diophantine(), biDiophantine()
296static inline
297CFList
298multiRecDiophantine (
299               const CanonicalForm& F,   ///< [in] compressed,
300                                         ///< multivariate polynomial
301               const CFList& factors,    ///< [in] list of monic factors
302                                         ///< including LC (F, Variable (1)) as
303                                         ///< first element
304               const CFList& recResult, ///< [in] result of above equation
305                                         ///< modulo M
306               const CFList& M,          ///< [in] a list of powers of Variables
307                                         ///< of level higher than 1
308               const int d               ///< [in] precision
309                    );
310
311/// Hensel lifting from bivariate to trivariate.
312///
313/// @return @a henselLift23 returns a list of polynomials lifted to precision
314///          Variable (3)^l[1]
315/// @sa henselLift12(), henselLiftResume12(), henselLiftResume(), henselLift()
316CFList
317henselLift23 (const CFList& eval,    ///< [in] contains compressed, bivariate
318                                     ///< as first element and trivariate one as
319                                     ///< second element
320              const CFList& factors, ///< [in] monic bivariate factors,
321                                     ///< including leading coefficient
322                                     ///< as first element.
323              const int* l,          ///< [in] l[0]: precision of bivariate
324                                     ///< lifting, l[1] as above
325              CFList& diophant,      ///< [in,out] returns the result of
326                                     ///< biDiophantine()
327              CFArray& Pi,           ///< [in,out] stores intermediate results
328              CFMatrix& M            ///< [in,out] stores intermediate results
329             );
330
331/// resume Hensel lifting.
332///
333/// @sa henselLift12(), henselLiftResume12(), henselLift23(), henselLift()
334void
335henselLiftResume (
336              const CanonicalForm& F, ///< [in] compressed, multivariate poly
337              CFList& factors,        ///< [in,out] monic multivariate factors
338                                      ///< lifted to precision F.mvar()^start,
339                                      ///< including leading coefficient
340                                      ///< as first element. Returns factors
341                                      ///< lifted to precision F.mvar()^end
342              int start,              ///< [in] starting precision
343              int end,                ///< [in] end precision
344              CFArray& Pi,            ///< [in,out] stores intermediate results
345              const CFList& diophant, ///< [in] result of multiRecDiophantine()
346              CFMatrix& M,            ///< [in, out] stores intermediate results
347              const CFList& MOD       ///< [in] a list of powers of Variables
348                                      ///< of level higher than 1
349                 );
350
351/// Hensel lifting
352///
353/// @return @a henselLift returns a list of polynomials lifted to
354///          precision F.getLast().mvar()^l_new
355/// @sa henselLift12(), henselLiftResume12(), henselLift23(), henselLiftResume()
356CFList
357henselLift (const CFList& F,       ///< [in] two compressed, multivariate
358                                   ///< polys F and G
359            const CFList& factors, ///< [in] monic multivariate factors
360                                   ///< including leading coefficient
361                                   ///< as first element.
362            const CFList& MOD,     ///< [in] a list of powers of Variables
363                                   ///< of level higher than 1
364            CFList& diophant,      ///< [in,out] result of multiRecDiophantine()
365            CFArray& Pi,           ///< [in,out] stores intermediate results
366            CFMatrix& M,           ///< [in,out] stores intermediate results
367            const int lOld,       ///< [in] lifting precision of F.mvar()
368            const int lNew        ///< [in] lifting precision of G.mvar()
369           );
370
371/// Hensel lifting from bivariate to multivariate
372///
373/// @return @a henselLift returns a list of lifted factors
374/// @sa henselLift12(), henselLiftResume12(), henselLift23(), henselLiftResume()
375CFList
376henselLift (const CFList& eval,    ///< [in] a list of polynomials the last
377                                   ///< element is a compressed multivariate
378                                   ///< poly, last but one element equals the
379                                   ///< last elements modulo its main variable
380                                   ///< and so on. The first element is a
381                                   ///< compressed bivariate poly.
382            const CFList& factors, ///< [in] bivariate factors, including
383                                   ///< leading coefficient
384            const int* l,          ///< [in] lifting bounds
385            const int lLength     ///< [in] length of l
386           );
387
388/// two factor Hensel lifting from univariate to bivariate, factors need not to
389/// be monic
390void
391henselLift122 (const CanonicalForm& F,///< [in] a bivariate poly
392               CFList& factors,       ///< [in, out] a list of univariate polys
393                                      ///< lifted factors
394               int l,                 ///< [in] lift bound
395               CFArray& Pi,           ///< [in, out] stores intermediate results
396               CFList& diophant,      ///< [in, out] result of diophantine
397               CFMatrix& M,           ///< [in, out] stores intermediate results
398               const CFArray& LCs,    ///< [in] leading coefficients
399               bool sort              ///< [in] if true factors are sorted by
400                                      ///< their degree
401              );
402
403/// two factor Hensel lifting from bivariate to multivariate, factors need not
404/// to be monic
405///
406/// @return @a henselLift122 returns a list of lifted factors
407CFList
408henselLift2 (const CFList& eval,   ///< [in] a list of polynomials the last
409                                   ///< element is a compressed multivariate
410                                   ///< poly, last but one element equals the
411                                   ///< last elements modulo its main variable
412                                   ///< and so on. The first element is a
413                                   ///< compressed bivariate poly.
414             const CFList& factors,///< [in] bivariate factors
415             int* l,               ///< [in] lift bounds
416             const int lLength,    ///< [in] length of l
417             bool sort,            ///< [in] if true factors are sorted by
418                                   ///< their degree in Variable(1)
419             const CFList& LCs1,   ///< [in] a list of evaluated LC of first
420                                   ///< factor
421             const CFList& LCs2,   ///< [in] a list of evaluated LC of second
422                                   ///< factor
423             const CFArray& Pi,    ///< [in] intermediate result
424             const CFList& diophant///< [in] result of diophantine
425            );
426
427#endif
428/* FAC_HENSEL_H */
429
Note: See TracBrowser for help on using the repository browser.