1 | /*****************************************************************************\ |
---|
2 | * Computer Algebra System SINGULAR |
---|
3 | \*****************************************************************************/ |
---|
4 | /** @file facFqBivar.cc |
---|
5 | * |
---|
6 | * This file provides functions for factorizing a bivariate polynomial over |
---|
7 | * \f$ F_{p} \f$ , \f$ F_{p}(\alpha ) \f$ or GF, based on "Modern Computer |
---|
8 | * Algebra, Chapter 15" by J. von zur Gathen & J. Gerhard and "Factoring |
---|
9 | * multivariate polynomials over a finite field" by L. Bernardin. |
---|
10 | * Factor Recombination is described in "Factoring polynomials over global |
---|
11 | * fields" by K. Belabas, M. van Hoeij, J. Klueners, A. Steel |
---|
12 | * |
---|
13 | * |
---|
14 | * @author Martin Lee |
---|
15 | * |
---|
16 | **/ |
---|
17 | /*****************************************************************************/ |
---|
18 | |
---|
19 | |
---|
20 | #include "config.h" |
---|
21 | |
---|
22 | |
---|
23 | #include "cf_assert.h" |
---|
24 | #include "debug.h" |
---|
25 | #include "timing.h" |
---|
26 | |
---|
27 | #include "canonicalform.h" |
---|
28 | #include "cf_defs.h" |
---|
29 | #include "cf_map_ext.h" |
---|
30 | #include "cf_random.h" |
---|
31 | #include "facHensel.h" |
---|
32 | #include "facMul.h" |
---|
33 | #include "cf_map.h" |
---|
34 | #include "cf_irred.h" |
---|
35 | #include "facFqBivarUtil.h" |
---|
36 | #include "facFqBivar.h" |
---|
37 | #include "cfNewtonPolygon.h" |
---|
38 | |
---|
39 | #ifdef HAVE_NTL |
---|
40 | #include "NTLconvert.h" |
---|
41 | |
---|
42 | #ifdef HAVE_FLINT |
---|
43 | #include "FLINTconvert.h" |
---|
44 | #endif |
---|
45 | |
---|
46 | TIMING_DEFINE_PRINT(fac_fq_uni_factorizer) |
---|
47 | TIMING_DEFINE_PRINT(fac_fq_bi_hensel_lift) |
---|
48 | TIMING_DEFINE_PRINT(fac_fq_bi_factor_recombination) |
---|
49 | TIMING_DEFINE_PRINT(fac_fq_bi_evaluation) |
---|
50 | TIMING_DEFINE_PRINT(fac_fq_bi_shift_to_zero) |
---|
51 | TIMING_DEFINE_PRINT(fac_fq_logarithmic) |
---|
52 | TIMING_DEFINE_PRINT(fac_fq_compute_lattice_lift) |
---|
53 | TIMING_DEFINE_PRINT(fac_fq_till_reduced) |
---|
54 | TIMING_DEFINE_PRINT(fac_fq_reconstruction) |
---|
55 | TIMING_DEFINE_PRINT(fac_fq_lift) |
---|
56 | TIMING_DEFINE_PRINT(fac_fq_uni_total) |
---|
57 | |
---|
58 | CanonicalForm prodMod0 (const CFList& L, const CanonicalForm& M, const modpk& b) |
---|
59 | { |
---|
60 | if (L.isEmpty()) |
---|
61 | return 1; |
---|
62 | else if (L.length() == 1) |
---|
63 | return mod (L.getFirst()(0, 1) , M); |
---|
64 | else if (L.length() == 2) |
---|
65 | return mod (mulNTL (L.getFirst()(0, 1),L.getLast()(0, 1), b), M); |
---|
66 | else |
---|
67 | { |
---|
68 | int l= L.length()/2; |
---|
69 | CFListIterator i= L; |
---|
70 | CFList tmp1, tmp2; |
---|
71 | CanonicalForm buf1, buf2; |
---|
72 | for (int j= 1; j <= l; j++, i++) |
---|
73 | tmp1.append (i.getItem()); |
---|
74 | tmp2= Difference (L, tmp1); |
---|
75 | buf1= prodMod0 (tmp1, M, b); |
---|
76 | buf2= prodMod0 (tmp2, M, b); |
---|
77 | return mod (mulNTL (buf1,buf2, b), M); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | CanonicalForm evalPoint (const CanonicalForm& F, CanonicalForm & eval, |
---|
82 | const Variable& alpha, CFList& list, const bool& GF, |
---|
83 | bool& fail) |
---|
84 | { |
---|
85 | fail= false; |
---|
86 | Variable x= Variable(2); |
---|
87 | Variable y= Variable(1); |
---|
88 | FFRandom genFF; |
---|
89 | GFRandom genGF; |
---|
90 | CanonicalForm random, mipo; |
---|
91 | double bound; |
---|
92 | int p= getCharacteristic (); |
---|
93 | if (alpha.level() != 1) |
---|
94 | { |
---|
95 | mipo= getMipo (alpha); |
---|
96 | int d= degree (mipo); |
---|
97 | bound= pow ((double) p, (double) d); |
---|
98 | } |
---|
99 | else if (GF) |
---|
100 | { |
---|
101 | int d= getGFDegree(); |
---|
102 | bound= ipower (p, d); |
---|
103 | } |
---|
104 | else |
---|
105 | bound= p; |
---|
106 | |
---|
107 | random= 0; |
---|
108 | do |
---|
109 | { |
---|
110 | if (list.length() >= bound) |
---|
111 | { |
---|
112 | fail= true; |
---|
113 | break; |
---|
114 | } |
---|
115 | if (list.isEmpty()) |
---|
116 | random= 0; |
---|
117 | else if (GF) |
---|
118 | { |
---|
119 | if (list.length() == 1) |
---|
120 | random= getGFGenerator(); |
---|
121 | else |
---|
122 | random= genGF.generate(); |
---|
123 | } |
---|
124 | else if (list.length() < p || alpha.level() == 1) |
---|
125 | random= genFF.generate(); |
---|
126 | else if (alpha != x && list.length() >= p) |
---|
127 | { |
---|
128 | if (list.length() == p) |
---|
129 | random= alpha; |
---|
130 | else |
---|
131 | { |
---|
132 | AlgExtRandomF genAlgExt (alpha); |
---|
133 | random= genAlgExt.generate(); |
---|
134 | } |
---|
135 | } |
---|
136 | if (find (list, random)) continue; |
---|
137 | eval= F (random, x); |
---|
138 | if (degree (eval) != degree (F, y)) |
---|
139 | { //leading coeff vanishes |
---|
140 | if (!find (list, random)) |
---|
141 | list.append (random); |
---|
142 | continue; |
---|
143 | } |
---|
144 | if (degree (gcd (deriv (eval, eval.mvar()), eval), eval.mvar()) > 0) |
---|
145 | { //evaluated polynomial is not squarefree |
---|
146 | if (!find (list, random)) |
---|
147 | list.append (random); |
---|
148 | continue; |
---|
149 | } |
---|
150 | } while (find (list, random)); |
---|
151 | |
---|
152 | return random; |
---|
153 | } |
---|
154 | |
---|
155 | CFList |
---|
156 | uniFactorizer (const CanonicalForm& A, const Variable& alpha, const bool& GF) |
---|
157 | { |
---|
158 | Variable x= A.mvar(); |
---|
159 | if (A.inCoeffDomain()) |
---|
160 | return CFList(); |
---|
161 | ASSERT (A.isUnivariate(), |
---|
162 | "univariate polynomial expected or constant expected"); |
---|
163 | CFFList factorsA; |
---|
164 | if (GF) |
---|
165 | { |
---|
166 | int k= getGFDegree(); |
---|
167 | char cGFName= gf_name; |
---|
168 | CanonicalForm mipo= gf_mipo; |
---|
169 | setCharacteristic (getCharacteristic()); |
---|
170 | Variable beta= rootOf (mipo.mapinto()); |
---|
171 | CanonicalForm buf= GF2FalphaRep (A, beta); |
---|
172 | if (getCharacteristic() > 2) |
---|
173 | { |
---|
174 | #if (HAVE_FLINT && __FLINT_VERSION_MINOR >= 4) |
---|
175 | nmod_poly_t FLINTmipo, leadingCoeff; |
---|
176 | fq_nmod_ctx_t fq_con; |
---|
177 | fq_nmod_poly_t FLINTA; |
---|
178 | fq_nmod_poly_factor_t FLINTFactorsA; |
---|
179 | |
---|
180 | nmod_poly_init (FLINTmipo, getCharacteristic()); |
---|
181 | convertFacCF2nmod_poly_t (FLINTmipo, mipo.mapinto()); |
---|
182 | |
---|
183 | fq_nmod_ctx_init_modulus (fq_con, FLINTmipo, "Z"); |
---|
184 | |
---|
185 | convertFacCF2Fq_nmod_poly_t (FLINTA, buf, fq_con); |
---|
186 | fq_nmod_poly_make_monic (FLINTA, FLINTA, fq_con); |
---|
187 | |
---|
188 | fq_nmod_poly_factor_init (FLINTFactorsA, fq_con); |
---|
189 | nmod_poly_init (leadingCoeff, getCharacteristic()); |
---|
190 | |
---|
191 | fq_nmod_poly_factor (FLINTFactorsA, leadingCoeff, FLINTA, fq_con); |
---|
192 | |
---|
193 | factorsA= convertFLINTFq_nmod_poly_factor2FacCFFList (FLINTFactorsA, x, |
---|
194 | beta, fq_con); |
---|
195 | |
---|
196 | fq_nmod_poly_factor_clear (FLINTFactorsA, fq_con); |
---|
197 | fq_nmod_poly_clear (FLINTA, fq_con); |
---|
198 | nmod_poly_clear (FLINTmipo); |
---|
199 | nmod_poly_clear (leadingCoeff); |
---|
200 | fq_nmod_ctx_clear (fq_con); |
---|
201 | #else |
---|
202 | if (fac_NTL_char != getCharacteristic()) |
---|
203 | { |
---|
204 | fac_NTL_char= getCharacteristic(); |
---|
205 | zz_p::init (getCharacteristic()); |
---|
206 | } |
---|
207 | zz_pX NTLMipo= convertFacCF2NTLzzpX (mipo.mapinto()); |
---|
208 | zz_pE::init (NTLMipo); |
---|
209 | zz_pEX NTLA= convertFacCF2NTLzz_pEX (buf, NTLMipo); |
---|
210 | MakeMonic (NTLA); |
---|
211 | vec_pair_zz_pEX_long NTLFactorsA= CanZass (NTLA); |
---|
212 | zz_pE multi= to_zz_pE (1); |
---|
213 | factorsA= convertNTLvec_pair_zzpEX_long2FacCFFList (NTLFactorsA, multi, |
---|
214 | x, beta); |
---|
215 | #endif |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | GF2X NTLMipo= convertFacCF2NTLGF2X (mipo.mapinto()); |
---|
220 | GF2E::init (NTLMipo); |
---|
221 | GF2EX NTLA= convertFacCF2NTLGF2EX (buf, NTLMipo); |
---|
222 | MakeMonic (NTLA); |
---|
223 | vec_pair_GF2EX_long NTLFactorsA= CanZass (NTLA); |
---|
224 | GF2E multi= to_GF2E (1); |
---|
225 | factorsA= convertNTLvec_pair_GF2EX_long2FacCFFList (NTLFactorsA, multi, |
---|
226 | x, beta); |
---|
227 | } |
---|
228 | setCharacteristic (getCharacteristic(), k, cGFName); |
---|
229 | for (CFFListIterator i= factorsA; i.hasItem(); i++) |
---|
230 | { |
---|
231 | buf= i.getItem().factor(); |
---|
232 | buf= Falpha2GFRep (buf); |
---|
233 | i.getItem()= CFFactor (buf, i.getItem().exp()); |
---|
234 | } |
---|
235 | prune (beta); |
---|
236 | } |
---|
237 | else if (alpha.level() != 1) |
---|
238 | { |
---|
239 | if (getCharacteristic() > 2) |
---|
240 | { |
---|
241 | #if (HAVE_FLINT && __FLINT_VERSION_MINOR >= 4) |
---|
242 | nmod_poly_t FLINTmipo, leadingCoeff; |
---|
243 | fq_nmod_ctx_t fq_con; |
---|
244 | fq_nmod_poly_t FLINTA; |
---|
245 | fq_nmod_poly_factor_t FLINTFactorsA; |
---|
246 | |
---|
247 | nmod_poly_init (FLINTmipo, getCharacteristic()); |
---|
248 | convertFacCF2nmod_poly_t (FLINTmipo, getMipo (alpha)); |
---|
249 | |
---|
250 | fq_nmod_ctx_init_modulus (fq_con, FLINTmipo, "Z"); |
---|
251 | |
---|
252 | convertFacCF2Fq_nmod_poly_t (FLINTA, A, fq_con); |
---|
253 | fq_nmod_poly_make_monic (FLINTA, FLINTA, fq_con); |
---|
254 | |
---|
255 | fq_nmod_poly_factor_init (FLINTFactorsA, fq_con); |
---|
256 | nmod_poly_init (leadingCoeff, getCharacteristic()); |
---|
257 | |
---|
258 | fq_nmod_poly_factor (FLINTFactorsA, leadingCoeff, FLINTA, fq_con); |
---|
259 | |
---|
260 | factorsA= convertFLINTFq_nmod_poly_factor2FacCFFList (FLINTFactorsA, x, |
---|
261 | alpha, fq_con); |
---|
262 | |
---|
263 | fq_nmod_poly_factor_clear (FLINTFactorsA, fq_con); |
---|
264 | fq_nmod_poly_clear (FLINTA, fq_con); |
---|
265 | nmod_poly_clear (FLINTmipo); |
---|
266 | nmod_poly_clear (leadingCoeff); |
---|
267 | fq_nmod_ctx_clear (fq_con); |
---|
268 | #else |
---|
269 | if (fac_NTL_char != getCharacteristic()) |
---|
270 | { |
---|
271 | fac_NTL_char= getCharacteristic(); |
---|
272 | zz_p::init (getCharacteristic()); |
---|
273 | } |
---|
274 | zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); |
---|
275 | zz_pE::init (NTLMipo); |
---|
276 | zz_pEX NTLA= convertFacCF2NTLzz_pEX (A, NTLMipo); |
---|
277 | MakeMonic (NTLA); |
---|
278 | vec_pair_zz_pEX_long NTLFactorsA= CanZass (NTLA); |
---|
279 | zz_pE multi= to_zz_pE (1); |
---|
280 | factorsA= convertNTLvec_pair_zzpEX_long2FacCFFList (NTLFactorsA, multi, |
---|
281 | x, alpha); |
---|
282 | #endif |
---|
283 | } |
---|
284 | else |
---|
285 | { |
---|
286 | GF2X NTLMipo= convertFacCF2NTLGF2X (getMipo (alpha)); |
---|
287 | GF2E::init (NTLMipo); |
---|
288 | GF2EX NTLA= convertFacCF2NTLGF2EX (A, NTLMipo); |
---|
289 | MakeMonic (NTLA); |
---|
290 | vec_pair_GF2EX_long NTLFactorsA= CanZass (NTLA); |
---|
291 | GF2E multi= to_GF2E (1); |
---|
292 | factorsA= convertNTLvec_pair_GF2EX_long2FacCFFList (NTLFactorsA, multi, |
---|
293 | x, alpha); |
---|
294 | } |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | #ifdef HAVE_FLINT |
---|
299 | if (degree (A) < 300) |
---|
300 | { |
---|
301 | nmod_poly_t FLINTA; |
---|
302 | convertFacCF2nmod_poly_t (FLINTA, A); |
---|
303 | nmod_poly_factor_t result; |
---|
304 | nmod_poly_factor_init (result); |
---|
305 | mp_limb_t leadingCoeff= nmod_poly_factor (result, FLINTA); |
---|
306 | factorsA= convertFLINTnmod_poly_factor2FacCFFList (result, leadingCoeff, x); |
---|
307 | if (factorsA.getFirst().factor().inCoeffDomain()) |
---|
308 | factorsA.removeFirst(); |
---|
309 | nmod_poly_factor_clear (result); |
---|
310 | nmod_poly_clear (FLINTA); |
---|
311 | } |
---|
312 | else |
---|
313 | #endif |
---|
314 | if (getCharacteristic() > 2) |
---|
315 | { |
---|
316 | if (fac_NTL_char != getCharacteristic()) |
---|
317 | { |
---|
318 | fac_NTL_char= getCharacteristic(); |
---|
319 | zz_p::init (getCharacteristic()); |
---|
320 | } |
---|
321 | zz_pX NTLA= convertFacCF2NTLzzpX (A); |
---|
322 | MakeMonic (NTLA); |
---|
323 | vec_pair_zz_pX_long NTLFactorsA= CanZass (NTLA); |
---|
324 | zz_p multi= to_zz_p (1); |
---|
325 | factorsA= convertNTLvec_pair_zzpX_long2FacCFFList (NTLFactorsA, multi, |
---|
326 | x); |
---|
327 | } |
---|
328 | else |
---|
329 | { |
---|
330 | GF2X NTLA= convertFacCF2NTLGF2X (A); |
---|
331 | vec_pair_GF2X_long NTLFactorsA= CanZass (NTLA); |
---|
332 | GF2 multi= to_GF2 (1); |
---|
333 | factorsA= convertNTLvec_pair_GF2X_long2FacCFFList (NTLFactorsA, multi, |
---|
334 | x); |
---|
335 | } |
---|
336 | } |
---|
337 | CFList uniFactors; |
---|
338 | for (CFFListIterator i= factorsA; i.hasItem(); i++) |
---|
339 | uniFactors.append (i.getItem().factor()); |
---|
340 | return uniFactors; |
---|
341 | } |
---|
342 | |
---|
343 | /// naive factor recombination as decribed in "Factoring |
---|
344 | /// multivariate polynomials over a finite field" by L Bernardin. |
---|
345 | CFList |
---|
346 | extFactorRecombination (CFList& factors, CanonicalForm& F, |
---|
347 | const CanonicalForm& N, const ExtensionInfo& info, |
---|
348 | DegreePattern& degs, const CanonicalForm& eval, int s, |
---|
349 | int thres) |
---|
350 | { |
---|
351 | if (factors.length() == 0) |
---|
352 | { |
---|
353 | F= 1; |
---|
354 | return CFList(); |
---|
355 | } |
---|
356 | if (F.inCoeffDomain()) |
---|
357 | return CFList(); |
---|
358 | |
---|
359 | Variable alpha= info.getAlpha(); |
---|
360 | Variable beta= info.getBeta(); |
---|
361 | CanonicalForm gamma= info.getGamma(); |
---|
362 | CanonicalForm delta= info.getDelta(); |
---|
363 | int k= info.getGFDegree(); |
---|
364 | |
---|
365 | CanonicalForm M= N; |
---|
366 | int l= degree (N); |
---|
367 | Variable y= F.mvar(); |
---|
368 | Variable x= Variable (1); |
---|
369 | CFList source, dest; |
---|
370 | if (degs.getLength() <= 1 || factors.length() == 1) |
---|
371 | { |
---|
372 | CFList result= CFList(mapDown (F(y-eval, y), info, source, dest)); |
---|
373 | F= 1; |
---|
374 | return result; |
---|
375 | } |
---|
376 | |
---|
377 | DEBOUTLN (cerr, "LC (F, 1)*prodMod (factors, M) == F " << |
---|
378 | (mod (LC (F, 1)*prodMod (factors, M), M)/Lc (mod (LC (F, 1)*prodMod (factors, M), M)) == F/Lc (F))); |
---|
379 | int degMipoBeta= 1; |
---|
380 | if (!k && beta.level() != 1) |
---|
381 | degMipoBeta= degree (getMipo (beta)); |
---|
382 | |
---|
383 | CFList T, S, Diff; |
---|
384 | T= factors; |
---|
385 | |
---|
386 | CFList result; |
---|
387 | CanonicalForm buf, buf2, quot; |
---|
388 | |
---|
389 | buf= F; |
---|
390 | |
---|
391 | CanonicalForm g, LCBuf= LC (buf, x); |
---|
392 | int * v= new int [T.length()]; |
---|
393 | for (int i= 0; i < T.length(); i++) |
---|
394 | v[i]= 0; |
---|
395 | |
---|
396 | CFArray TT; |
---|
397 | DegreePattern bufDegs1, bufDegs2; |
---|
398 | bufDegs1= degs; |
---|
399 | int subsetDeg; |
---|
400 | TT= copy (factors); |
---|
401 | bool nosubset= false; |
---|
402 | bool recombination= false; |
---|
403 | bool trueFactor= false; |
---|
404 | CanonicalForm test; |
---|
405 | CanonicalForm buf0= buf (0, x)*LCBuf; |
---|
406 | while (T.length() >= 2*s && s <= thres) |
---|
407 | { |
---|
408 | while (nosubset == false) |
---|
409 | { |
---|
410 | if (T.length() == s) |
---|
411 | { |
---|
412 | delete [] v; |
---|
413 | if (recombination) |
---|
414 | { |
---|
415 | T.insert (LCBuf); |
---|
416 | g= prodMod (T, M); |
---|
417 | T.removeFirst(); |
---|
418 | g /= content(g); |
---|
419 | g= g (y - eval, y); |
---|
420 | g /= Lc (g); |
---|
421 | appendTestMapDown (result, g, info, source, dest); |
---|
422 | F= 1; |
---|
423 | return result; |
---|
424 | } |
---|
425 | else |
---|
426 | { |
---|
427 | appendMapDown (result, F (y - eval, y), info, source, dest); |
---|
428 | F= 1; |
---|
429 | return result; |
---|
430 | } |
---|
431 | } |
---|
432 | S= subset (v, s, TT, nosubset); |
---|
433 | if (nosubset) break; |
---|
434 | subsetDeg= subsetDegree (S); |
---|
435 | // skip those combinations that are not possible |
---|
436 | if (!degs.find (subsetDeg)) |
---|
437 | continue; |
---|
438 | else |
---|
439 | { |
---|
440 | test= prodMod0 (S, M); |
---|
441 | test *= LCBuf; |
---|
442 | test = mod (test, M); |
---|
443 | if (fdivides (test, buf0)) |
---|
444 | { |
---|
445 | S.insert (LCBuf); |
---|
446 | g= prodMod (S, M); |
---|
447 | S.removeFirst(); |
---|
448 | g /= content (g, x); |
---|
449 | if (fdivides (g, buf, quot)) |
---|
450 | { |
---|
451 | buf2= g (y - eval, y); |
---|
452 | buf2 /= Lc (buf2); |
---|
453 | |
---|
454 | if (!k && beta.level() == 1) |
---|
455 | { |
---|
456 | if (degree (buf2, alpha) < degMipoBeta) |
---|
457 | { |
---|
458 | buf= quot; |
---|
459 | LCBuf= LC (buf, x); |
---|
460 | recombination= true; |
---|
461 | appendTestMapDown (result, buf2, info, source, dest); |
---|
462 | trueFactor= true; |
---|
463 | } |
---|
464 | } |
---|
465 | else |
---|
466 | { |
---|
467 | if (!isInExtension (buf2, gamma, k, delta, source, dest)) |
---|
468 | { |
---|
469 | buf= quot; |
---|
470 | LCBuf= LC (buf, x); |
---|
471 | recombination= true; |
---|
472 | appendTestMapDown (result, buf2, info, source, dest); |
---|
473 | trueFactor= true; |
---|
474 | } |
---|
475 | } |
---|
476 | if (trueFactor) |
---|
477 | { |
---|
478 | T= Difference (T, S); |
---|
479 | l -= degree (g); |
---|
480 | M= power (y, l); |
---|
481 | buf0= buf (0, x)*LCBuf; |
---|
482 | |
---|
483 | // compute new possible degree pattern |
---|
484 | bufDegs2= DegreePattern (T); |
---|
485 | bufDegs1.intersect (bufDegs2); |
---|
486 | bufDegs1.refine (); |
---|
487 | if (T.length() < 2*s || T.length() == s || |
---|
488 | bufDegs1.getLength() == 1) |
---|
489 | { |
---|
490 | delete [] v; |
---|
491 | if (recombination) |
---|
492 | { |
---|
493 | buf= buf (y-eval,y); |
---|
494 | buf /= Lc (buf); |
---|
495 | appendTestMapDown (result, buf, info, source, |
---|
496 | dest); |
---|
497 | F= 1; |
---|
498 | return result; |
---|
499 | } |
---|
500 | else |
---|
501 | { |
---|
502 | appendMapDown (result, F (y - eval, y), info, source, dest); |
---|
503 | F= 1; |
---|
504 | return result; |
---|
505 | } |
---|
506 | } |
---|
507 | trueFactor= false; |
---|
508 | TT= copy (T); |
---|
509 | indexUpdate (v, s, T.length(), nosubset); |
---|
510 | if (nosubset) break; |
---|
511 | } |
---|
512 | } |
---|
513 | } |
---|
514 | } |
---|
515 | } |
---|
516 | s++; |
---|
517 | if (T.length() < 2*s || T.length() == s) |
---|
518 | { |
---|
519 | delete [] v; |
---|
520 | if (recombination) |
---|
521 | { |
---|
522 | buf= buf (y-eval,y); |
---|
523 | buf /= Lc (buf); |
---|
524 | appendTestMapDown (result, buf, info, source, dest); |
---|
525 | F= 1; |
---|
526 | return result; |
---|
527 | } |
---|
528 | else |
---|
529 | { |
---|
530 | appendMapDown (result, F (y - eval, y), info, source, dest); |
---|
531 | F= 1; |
---|
532 | return result; |
---|
533 | } |
---|
534 | } |
---|
535 | for (int i= 0; i < T.length(); i++) |
---|
536 | v[i]= 0; |
---|
537 | nosubset= false; |
---|
538 | } |
---|
539 | if (T.length() < 2*s) |
---|
540 | { |
---|
541 | appendMapDown (result, F (y - eval, y), info, source, dest); |
---|
542 | F= 1; |
---|
543 | delete [] v; |
---|
544 | return result; |
---|
545 | } |
---|
546 | |
---|
547 | if (s > thres) |
---|
548 | { |
---|
549 | factors= T; |
---|
550 | F= buf; |
---|
551 | degs= bufDegs1; |
---|
552 | } |
---|
553 | |
---|
554 | delete [] v; |
---|
555 | return result; |
---|
556 | } |
---|
557 | |
---|
558 | /// naive factor recombination as decribed in "Factoring |
---|
559 | /// multivariate polynomials over a finite field" by L Bernardin. |
---|
560 | CFList |
---|
561 | factorRecombination (CFList& factors, CanonicalForm& F, |
---|
562 | const CanonicalForm& N, DegreePattern& degs, const |
---|
563 | CanonicalForm& eval, int s, int thres, const modpk& b, |
---|
564 | const CanonicalForm& den |
---|
565 | ) |
---|
566 | { |
---|
567 | if (factors.length() == 0) |
---|
568 | { |
---|
569 | F= 1; |
---|
570 | return CFList (); |
---|
571 | } |
---|
572 | if (F.inCoeffDomain()) |
---|
573 | return CFList(); |
---|
574 | Variable y= Variable (2); |
---|
575 | if (degs.getLength() <= 1 || factors.length() == 1) |
---|
576 | { |
---|
577 | CFList result= CFList (F(y-eval,y)); |
---|
578 | F= 1; |
---|
579 | return result; |
---|
580 | } |
---|
581 | #ifdef DEBUGOUTPUT |
---|
582 | if (b.getp() == 0) |
---|
583 | DEBOUTLN (cerr, "LC (F, 1)*prodMod (factors, N) == F " << |
---|
584 | (mod (LC (F, 1)*prodMod (factors, N),N)/Lc (mod (LC (F, 1)*prodMod (factors, N),N)) == F/Lc(F))); |
---|
585 | else |
---|
586 | DEBOUTLN (cerr, "LC (F, 1)*prodMod (factors, N) == F " << |
---|
587 | (mod (b(LC (F, 1)*prodMod (factors, N)),N)/Lc (mod (b(LC (F, 1)*prodMod (factors, N)),N)) == F/Lc(F))); |
---|
588 | #endif |
---|
589 | |
---|
590 | CFList T, S; |
---|
591 | |
---|
592 | CanonicalForm M= N; |
---|
593 | int l= degree (N); |
---|
594 | T= factors; |
---|
595 | CFList result; |
---|
596 | Variable x= Variable (1); |
---|
597 | CanonicalForm denom= den, denQuot; |
---|
598 | CanonicalForm LCBuf= LC (F, x)*denom; |
---|
599 | CanonicalForm g, quot, buf= F; |
---|
600 | int * v= new int [T.length()]; |
---|
601 | for (int i= 0; i < T.length(); i++) |
---|
602 | v[i]= 0; |
---|
603 | bool nosubset= false; |
---|
604 | CFArray TT; |
---|
605 | DegreePattern bufDegs1, bufDegs2; |
---|
606 | bufDegs1= degs; |
---|
607 | int subsetDeg; |
---|
608 | TT= copy (factors); |
---|
609 | bool recombination= false; |
---|
610 | CanonicalForm test; |
---|
611 | bool isRat= (isOn (SW_RATIONAL) && getCharacteristic() == 0) || |
---|
612 | getCharacteristic() > 0; |
---|
613 | if (!isRat) |
---|
614 | On (SW_RATIONAL); |
---|
615 | CanonicalForm buf0= mulNTL (buf (0, x), LCBuf); |
---|
616 | if (!isRat) |
---|
617 | Off (SW_RATIONAL); |
---|
618 | while (T.length() >= 2*s && s <= thres) |
---|
619 | { |
---|
620 | while (nosubset == false) |
---|
621 | { |
---|
622 | if (T.length() == s) |
---|
623 | { |
---|
624 | delete [] v; |
---|
625 | if (recombination) |
---|
626 | { |
---|
627 | T.insert (LCBuf); |
---|
628 | g= prodMod (T, M); |
---|
629 | if (b.getp() != 0) |
---|
630 | g= b(g); |
---|
631 | T.removeFirst(); |
---|
632 | g /= content (g,x); |
---|
633 | result.append (g(y-eval,y)); |
---|
634 | F= 1; |
---|
635 | return result; |
---|
636 | } |
---|
637 | else |
---|
638 | { |
---|
639 | result= CFList (F(y-eval,y)); |
---|
640 | F= 1; |
---|
641 | return result; |
---|
642 | } |
---|
643 | } |
---|
644 | S= subset (v, s, TT, nosubset); |
---|
645 | if (nosubset) break; |
---|
646 | subsetDeg= subsetDegree (S); |
---|
647 | // skip those combinations that are not possible |
---|
648 | if (!degs.find (subsetDeg)) |
---|
649 | continue; |
---|
650 | else |
---|
651 | { |
---|
652 | if (!isRat) |
---|
653 | On (SW_RATIONAL); |
---|
654 | test= prodMod0 (S, M); |
---|
655 | if (!isRat) |
---|
656 | { |
---|
657 | test *= bCommonDen (test); |
---|
658 | Off (SW_RATIONAL); |
---|
659 | } |
---|
660 | test= mulNTL (test, LCBuf, b); |
---|
661 | test= mod (test, M); |
---|
662 | if (uniFdivides (test, buf0)) |
---|
663 | { |
---|
664 | if (!isRat) |
---|
665 | On (SW_RATIONAL); |
---|
666 | S.insert (LCBuf); |
---|
667 | g= prodMod (S, M); |
---|
668 | S.removeFirst(); |
---|
669 | if (!isRat) |
---|
670 | { |
---|
671 | g *= bCommonDen(g); |
---|
672 | Off (SW_RATIONAL); |
---|
673 | } |
---|
674 | if (b.getp() != 0) |
---|
675 | g= b(g); |
---|
676 | if (!isRat) |
---|
677 | On (SW_RATIONAL); |
---|
678 | g /= content (g, x); |
---|
679 | if (!isRat) |
---|
680 | { |
---|
681 | On (SW_RATIONAL); |
---|
682 | if (!Lc (g).inBaseDomain()) |
---|
683 | g /= Lc (g); |
---|
684 | g *= bCommonDen (g); |
---|
685 | Off (SW_RATIONAL); |
---|
686 | g /= icontent (g); |
---|
687 | On (SW_RATIONAL); |
---|
688 | } |
---|
689 | if (fdivides (g, buf, quot)) |
---|
690 | { |
---|
691 | denom *= abs (lc (g)); |
---|
692 | recombination= true; |
---|
693 | result.append (g (y-eval,y)); |
---|
694 | if (b.getp() != 0) |
---|
695 | { |
---|
696 | denQuot= bCommonDen (quot); |
---|
697 | buf= quot*denQuot; |
---|
698 | Off (SW_RATIONAL); |
---|
699 | denom /= gcd (denom, denQuot); |
---|
700 | On (SW_RATIONAL); |
---|
701 | } |
---|
702 | else |
---|
703 | buf= quot; |
---|
704 | LCBuf= LC (buf, x)*denom; |
---|
705 | T= Difference (T, S); |
---|
706 | l -= degree (g); |
---|
707 | M= power (y, l); |
---|
708 | buf0= mulNTL (buf (0, x), LCBuf); |
---|
709 | if (!isRat) |
---|
710 | Off (SW_RATIONAL); |
---|
711 | // compute new possible degree pattern |
---|
712 | bufDegs2= DegreePattern (T); |
---|
713 | bufDegs1.intersect (bufDegs2); |
---|
714 | bufDegs1.refine (); |
---|
715 | if (T.length() < 2*s || T.length() == s || |
---|
716 | bufDegs1.getLength() == 1) |
---|
717 | { |
---|
718 | delete [] v; |
---|
719 | if (recombination) |
---|
720 | { |
---|
721 | result.append (buf (y-eval,y)); |
---|
722 | F= 1; |
---|
723 | return result; |
---|
724 | } |
---|
725 | else |
---|
726 | { |
---|
727 | result= CFList (F (y-eval,y)); |
---|
728 | F= 1; |
---|
729 | return result; |
---|
730 | } |
---|
731 | } |
---|
732 | TT= copy (T); |
---|
733 | indexUpdate (v, s, T.length(), nosubset); |
---|
734 | if (nosubset) break; |
---|
735 | } |
---|
736 | if (!isRat) |
---|
737 | Off (SW_RATIONAL); |
---|
738 | } |
---|
739 | } |
---|
740 | } |
---|
741 | s++; |
---|
742 | if (T.length() < 2*s || T.length() == s) |
---|
743 | { |
---|
744 | delete [] v; |
---|
745 | if (recombination) |
---|
746 | { |
---|
747 | result.append (buf(y-eval,y)); |
---|
748 | F= 1; |
---|
749 | return result; |
---|
750 | } |
---|
751 | else |
---|
752 | { |
---|
753 | result= CFList (F(y-eval,y)); |
---|
754 | F= 1; |
---|
755 | return result; |
---|
756 | } |
---|
757 | } |
---|
758 | for (int i= 0; i < T.length(); i++) |
---|
759 | v[i]= 0; |
---|
760 | nosubset= false; |
---|
761 | } |
---|
762 | delete [] v; |
---|
763 | if (T.length() < 2*s) |
---|
764 | { |
---|
765 | result.append (F(y-eval,y)); |
---|
766 | F= 1; |
---|
767 | return result; |
---|
768 | } |
---|
769 | |
---|
770 | if (s > thres) |
---|
771 | { |
---|
772 | factors= T; |
---|
773 | F= buf; |
---|
774 | degs= bufDegs1; |
---|
775 | } |
---|
776 | |
---|
777 | return result; |
---|
778 | } |
---|
779 | |
---|
780 | Variable chooseExtension (const Variable & alpha, const Variable& beta, int k) |
---|
781 | { |
---|
782 | if (fac_NTL_char != getCharacteristic()) |
---|
783 | { |
---|
784 | fac_NTL_char= getCharacteristic(); |
---|
785 | zz_p::init (getCharacteristic()); |
---|
786 | } |
---|
787 | zz_pX NTLIrredpoly; |
---|
788 | int i=1, m= 2; |
---|
789 | // extension of F_p needed |
---|
790 | if (alpha.level() == 1 && beta.level() == 1 && k == 1) |
---|
791 | { |
---|
792 | i= 1; |
---|
793 | m= 2; |
---|
794 | } //extension of F_p(alpha) needed but want to factorize over F_p |
---|
795 | else if (alpha.level() != 1 && beta.level() == 1 && k == 1) |
---|
796 | { |
---|
797 | i= 1; |
---|
798 | m= degree (getMipo (alpha)) + 1; |
---|
799 | } //extension of F_p(alpha) needed for first time |
---|
800 | else if (alpha.level() != 1 && beta.level() == 1 && k != 1) |
---|
801 | { |
---|
802 | i= 2; |
---|
803 | m= degree (getMipo (alpha)); |
---|
804 | } |
---|
805 | else if (alpha.level() != 1 && beta.level() != 1 && k != 1) |
---|
806 | { |
---|
807 | m= degree (getMipo (beta)); |
---|
808 | i= degree (getMipo (alpha))/m + 1; |
---|
809 | } |
---|
810 | BuildIrred (NTLIrredpoly, i*m); |
---|
811 | CanonicalForm newMipo= convertNTLzzpX2CF (NTLIrredpoly, Variable (1)); |
---|
812 | return rootOf (newMipo); |
---|
813 | } |
---|
814 | |
---|
815 | void |
---|
816 | earlyFactorDetection (CFList& reconstructedFactors, CanonicalForm& F, CFList& |
---|
817 | factors, int& adaptedLiftBound, int*& factorsFoundIndex, |
---|
818 | DegreePattern& degs, bool& success, int deg, const |
---|
819 | CanonicalForm& eval, const modpk& b, CanonicalForm& den) |
---|
820 | { |
---|
821 | DegreePattern bufDegs1= degs; |
---|
822 | DegreePattern bufDegs2; |
---|
823 | CFList T= factors; |
---|
824 | CanonicalForm buf= F; |
---|
825 | Variable x= Variable (1); |
---|
826 | Variable y= Variable (2); |
---|
827 | CanonicalForm g, quot; |
---|
828 | CanonicalForm M= power (F.mvar(), deg); |
---|
829 | adaptedLiftBound= 0; |
---|
830 | int d= degree (F), l= 0; |
---|
831 | bool isRat= (isOn (SW_RATIONAL) && getCharacteristic() == 0) || |
---|
832 | getCharacteristic() > 0; |
---|
833 | if (!isRat) |
---|
834 | On (SW_RATIONAL); |
---|
835 | if (b.getp() != 0) |
---|
836 | buf *= bCommonDen (buf); |
---|
837 | CanonicalForm LCBuf= LC (buf, x)*den; |
---|
838 | CanonicalForm buf0= mulNTL (buf (0,x), LCBuf); |
---|
839 | CanonicalForm buf1= mulNTL (buf (1,x), LCBuf); |
---|
840 | if (!isRat) |
---|
841 | Off (SW_RATIONAL); |
---|
842 | CanonicalForm test0, test1; |
---|
843 | CanonicalForm denQuot; |
---|
844 | |
---|
845 | for (CFListIterator i= factors; i.hasItem(); i++, l++) |
---|
846 | { |
---|
847 | if (!bufDegs1.find (degree (i.getItem(), 1)) || factorsFoundIndex[l] == 1) |
---|
848 | continue; |
---|
849 | else |
---|
850 | { |
---|
851 | test1= mod (mulNTL (i.getItem() (1,x), LCBuf, b), M); |
---|
852 | if (uniFdivides (test1, buf1)) |
---|
853 | { |
---|
854 | test0= mod (mulNTL (i.getItem() (0,x), LCBuf, b), M); |
---|
855 | if (uniFdivides (test0, buf0)) |
---|
856 | { |
---|
857 | if (!isRat) |
---|
858 | On (SW_RATIONAL); |
---|
859 | g= mulMod2 (i.getItem(), LCBuf, M); |
---|
860 | if (!isRat) |
---|
861 | { |
---|
862 | g *= bCommonDen(g); |
---|
863 | Off (SW_RATIONAL); |
---|
864 | } |
---|
865 | if (b.getp() != 0) |
---|
866 | g= b(g); |
---|
867 | if (!isRat) |
---|
868 | On (SW_RATIONAL); |
---|
869 | g /= content (g, x); |
---|
870 | if (!isRat) |
---|
871 | { |
---|
872 | On (SW_RATIONAL); |
---|
873 | if (!Lc (g).inBaseDomain()) |
---|
874 | g /= Lc (g); |
---|
875 | g *= bCommonDen (g); |
---|
876 | Off (SW_RATIONAL); |
---|
877 | g /= icontent (g); |
---|
878 | On (SW_RATIONAL); |
---|
879 | } |
---|
880 | if (fdivides (g, buf, quot)) |
---|
881 | { |
---|
882 | den *= abs (lc (g)); |
---|
883 | reconstructedFactors.append (g (y-eval,y)); |
---|
884 | factorsFoundIndex[l]= 1; |
---|
885 | if (b.getp() != 0) |
---|
886 | { |
---|
887 | denQuot= bCommonDen (quot); |
---|
888 | buf= quot*denQuot; |
---|
889 | Off (SW_RATIONAL); |
---|
890 | den /= gcd (den, denQuot); |
---|
891 | On (SW_RATIONAL); |
---|
892 | } |
---|
893 | else |
---|
894 | buf= quot; |
---|
895 | d -= degree (g); |
---|
896 | LCBuf= LC (buf, x)*den; |
---|
897 | buf0= mulNTL (buf (0,x), LCBuf); |
---|
898 | buf1= mulNTL (buf (1,x), LCBuf); |
---|
899 | if (!isRat) |
---|
900 | Off (SW_RATIONAL); |
---|
901 | T= Difference (T, CFList (i.getItem())); |
---|
902 | F= buf; |
---|
903 | |
---|
904 | // compute new possible degree pattern |
---|
905 | bufDegs2= DegreePattern (T); |
---|
906 | bufDegs1.intersect (bufDegs2); |
---|
907 | bufDegs1.refine (); |
---|
908 | if (bufDegs1.getLength() <= 1) |
---|
909 | { |
---|
910 | if (!buf.inCoeffDomain()) |
---|
911 | { |
---|
912 | reconstructedFactors.append (buf (y-eval,y)); |
---|
913 | F= 1; |
---|
914 | } |
---|
915 | break; |
---|
916 | } |
---|
917 | } |
---|
918 | if (!isRat) |
---|
919 | Off (SW_RATIONAL); |
---|
920 | } |
---|
921 | } |
---|
922 | } |
---|
923 | } |
---|
924 | adaptedLiftBound= d + 1; |
---|
925 | if (adaptedLiftBound < deg) |
---|
926 | { |
---|
927 | degs= bufDegs1; |
---|
928 | success= true; |
---|
929 | } |
---|
930 | if (bufDegs1.getLength() <= 1) |
---|
931 | degs= bufDegs1; |
---|
932 | } |
---|
933 | |
---|
934 | void |
---|
935 | earlyFactorDetection (CFList& reconstructedFactors, CanonicalForm& F, CFList& |
---|
936 | factors, int& adaptedLiftBound, int*& factorsFoundIndex, |
---|
937 | DegreePattern& degs, bool& success, int deg, const |
---|
938 | CanonicalForm& eval, const modpk& b) |
---|
939 | { |
---|
940 | CanonicalForm den= 1; |
---|
941 | earlyFactorDetection (reconstructedFactors, F, factors, adaptedLiftBound, |
---|
942 | factorsFoundIndex, degs, success, deg, eval, b, den); |
---|
943 | } |
---|
944 | |
---|
945 | void |
---|
946 | extEarlyFactorDetection (CFList& reconstructedFactors, CanonicalForm& F, CFList& |
---|
947 | factors,int& adaptedLiftBound, int*& factorsFoundIndex, |
---|
948 | DegreePattern& degs, bool& success, const |
---|
949 | ExtensionInfo& info, const CanonicalForm& eval, int deg |
---|
950 | ) |
---|
951 | { |
---|
952 | Variable alpha= info.getAlpha(); |
---|
953 | Variable beta= info.getBeta(); |
---|
954 | CanonicalForm gamma= info.getGamma(); |
---|
955 | CanonicalForm delta= info.getDelta(); |
---|
956 | int k= info.getGFDegree(); |
---|
957 | DegreePattern bufDegs1= degs, bufDegs2; |
---|
958 | CFList result; |
---|
959 | CFList T= factors; |
---|
960 | Variable y= F.mvar(); |
---|
961 | Variable x= Variable (1); |
---|
962 | CanonicalForm buf= F, LCBuf= LC (buf, x), g, buf2; |
---|
963 | CanonicalForm M= power (y, deg); |
---|
964 | adaptedLiftBound= 0; |
---|
965 | bool trueFactor= false; |
---|
966 | int d= degree (F), l= 0; |
---|
967 | CFList source, dest; |
---|
968 | int degMipoBeta= 1; |
---|
969 | if (!k && beta.level() != 1) |
---|
970 | degMipoBeta= degree (getMipo (beta)); |
---|
971 | CanonicalForm quot; |
---|
972 | for (CFListIterator i= factors; i.hasItem(); i++, l++) |
---|
973 | { |
---|
974 | if (!bufDegs1.find (degree (i.getItem(), 1)) || factorsFoundIndex[l] == 1) |
---|
975 | continue; |
---|
976 | else |
---|
977 | { |
---|
978 | g= mulMod2 (i.getItem(), LCBuf, M); |
---|
979 | g /= content (g, x); |
---|
980 | if (fdivides (g, buf, quot)) |
---|
981 | { |
---|
982 | buf2= g (y - eval, y); |
---|
983 | buf2 /= Lc (buf2); |
---|
984 | |
---|
985 | if (!k && beta == x) |
---|
986 | { |
---|
987 | if (degree (buf2, alpha) < degMipoBeta) |
---|
988 | { |
---|
989 | appendTestMapDown (reconstructedFactors, buf2, info, source, dest); |
---|
990 | factorsFoundIndex[l]= 1; |
---|
991 | buf= quot; |
---|
992 | d -= degree (g); |
---|
993 | LCBuf= LC (buf, x); |
---|
994 | trueFactor= true; |
---|
995 | } |
---|
996 | } |
---|
997 | else |
---|
998 | { |
---|
999 | if (!isInExtension (buf2, gamma, k, delta, source, dest)) |
---|
1000 | { |
---|
1001 | appendTestMapDown (reconstructedFactors, buf2, info, source, dest); |
---|
1002 | factorsFoundIndex[l]= 1; |
---|
1003 | buf= quot; |
---|
1004 | d -= degree (g); |
---|
1005 | LCBuf= LC (buf, x); |
---|
1006 | trueFactor= true; |
---|
1007 | } |
---|
1008 | } |
---|
1009 | if (trueFactor) |
---|
1010 | { |
---|
1011 | T= Difference (T, CFList (i.getItem())); |
---|
1012 | F= buf; |
---|
1013 | |
---|
1014 | // compute new possible degree pattern |
---|
1015 | bufDegs2= DegreePattern (T); |
---|
1016 | bufDegs1.intersect (bufDegs2); |
---|
1017 | bufDegs1.refine (); |
---|
1018 | trueFactor= false; |
---|
1019 | if (bufDegs1.getLength() <= 1) |
---|
1020 | { |
---|
1021 | if (!buf.inCoeffDomain()) |
---|
1022 | { |
---|
1023 | buf= buf (y - eval, y); |
---|
1024 | buf /= Lc (buf); |
---|
1025 | appendMapDown (reconstructedFactors, buf, info, source, dest); |
---|
1026 | F= 1; |
---|
1027 | } |
---|
1028 | break; |
---|
1029 | } |
---|
1030 | } |
---|
1031 | } |
---|
1032 | } |
---|
1033 | } |
---|
1034 | adaptedLiftBound= d + 1; |
---|
1035 | if (adaptedLiftBound < deg) |
---|
1036 | { |
---|
1037 | degs= bufDegs1; |
---|
1038 | success= true; |
---|
1039 | } |
---|
1040 | if (bufDegs1.getLength() <= 1) |
---|
1041 | degs= bufDegs1; |
---|
1042 | } |
---|
1043 | |
---|
1044 | int* |
---|
1045 | getCombinations (int * rightSide, int sizeOfRightSide, int& sizeOfOutput, |
---|
1046 | int degreeLC) |
---|
1047 | { |
---|
1048 | Variable x= Variable (1); |
---|
1049 | int p= getCharacteristic(); |
---|
1050 | int d= getGFDegree(); |
---|
1051 | char cGFName= gf_name; |
---|
1052 | setCharacteristic(0); |
---|
1053 | CanonicalForm buf= 1; |
---|
1054 | for (int i= 0; i < sizeOfRightSide; i++) |
---|
1055 | buf *= (power (x, rightSide [i]) + 1); |
---|
1056 | |
---|
1057 | int j= 0; |
---|
1058 | for (CFIterator i= buf; i.hasTerms(); i++, j++) |
---|
1059 | { |
---|
1060 | if (i.exp() < degreeLC) |
---|
1061 | { |
---|
1062 | j++; |
---|
1063 | break; |
---|
1064 | } |
---|
1065 | } |
---|
1066 | |
---|
1067 | ASSERT ( j > 1, "j > 1 expected" ); |
---|
1068 | |
---|
1069 | int* result = new int [j - 1]; |
---|
1070 | sizeOfOutput= j - 1; |
---|
1071 | |
---|
1072 | int i= 0; |
---|
1073 | for (CFIterator m = buf; i < j - 1; i++, m++) |
---|
1074 | result [i]= m.exp(); |
---|
1075 | |
---|
1076 | if (d > 1) |
---|
1077 | setCharacteristic (p, d, cGFName); |
---|
1078 | else |
---|
1079 | setCharacteristic (p); |
---|
1080 | return result; |
---|
1081 | } |
---|
1082 | |
---|
1083 | int * |
---|
1084 | getLiftPrecisions (const CanonicalForm& F, int& sizeOfOutput, int degreeLC) |
---|
1085 | { |
---|
1086 | int sizeOfNewtonPoly; |
---|
1087 | int ** newtonPolyg= newtonPolygon (F, sizeOfNewtonPoly); |
---|
1088 | int sizeOfRightSide; |
---|
1089 | int * rightSide= getRightSide(newtonPolyg, sizeOfNewtonPoly, sizeOfRightSide); |
---|
1090 | int * result= getCombinations(rightSide, sizeOfRightSide, sizeOfOutput, |
---|
1091 | degreeLC); |
---|
1092 | delete [] rightSide; |
---|
1093 | for (int i= 0; i < sizeOfNewtonPoly; i++) |
---|
1094 | delete [] newtonPolyg[i]; |
---|
1095 | delete [] newtonPolyg; |
---|
1096 | return result; |
---|
1097 | } |
---|
1098 | |
---|
1099 | void |
---|
1100 | deleteFactors (CFList& factors, int* factorsFoundIndex) |
---|
1101 | { |
---|
1102 | CFList result; |
---|
1103 | int i= 0; |
---|
1104 | for (CFListIterator iter= factors; iter.hasItem(); iter++, i++) |
---|
1105 | { |
---|
1106 | if (factorsFoundIndex[i] == 1) |
---|
1107 | continue; |
---|
1108 | else |
---|
1109 | result.append (iter.getItem()); |
---|
1110 | } |
---|
1111 | factors= result; |
---|
1112 | } |
---|
1113 | |
---|
1114 | CFList |
---|
1115 | henselLiftAndEarly (CanonicalForm& A, bool& earlySuccess, CFList& |
---|
1116 | earlyFactors, DegreePattern& degs, int& liftBound, |
---|
1117 | const CFList& uniFactors, const ExtensionInfo& info, |
---|
1118 | const CanonicalForm& eval,modpk& b, CanonicalForm& den) |
---|
1119 | { |
---|
1120 | Variable alpha= info.getAlpha(); |
---|
1121 | Variable beta= info.getBeta(); |
---|
1122 | CanonicalForm gamma= info.getGamma(); |
---|
1123 | CanonicalForm delta= info.getDelta(); |
---|
1124 | bool extension= info.isInExtension(); |
---|
1125 | |
---|
1126 | int sizeOfLiftPre; |
---|
1127 | int * liftPre= getLiftPrecisions (A, sizeOfLiftPre, degree (LC (A, 1), 2)); |
---|
1128 | |
---|
1129 | Variable x= Variable (1); |
---|
1130 | Variable y= Variable (2); |
---|
1131 | CFArray Pi; |
---|
1132 | CFList diophant; |
---|
1133 | CFList bufUniFactors= uniFactors; |
---|
1134 | On (SW_RATIONAL); |
---|
1135 | CanonicalForm bufA= A; |
---|
1136 | if (!Lc (A).inBaseDomain()) |
---|
1137 | { |
---|
1138 | bufA /= Lc (A); |
---|
1139 | CanonicalForm denBufA= bCommonDen (bufA); |
---|
1140 | bufA *= denBufA; |
---|
1141 | Off (SW_RATIONAL); |
---|
1142 | den /= gcd (den, denBufA); |
---|
1143 | } |
---|
1144 | else |
---|
1145 | { |
---|
1146 | bufA= A; |
---|
1147 | Off (SW_RATIONAL); |
---|
1148 | den /= gcd (den, Lc (A)); |
---|
1149 | } |
---|
1150 | CanonicalForm lcA0= 0; |
---|
1151 | bool mipoHasDen= false; |
---|
1152 | if (getCharacteristic() == 0 && b.getp() != 0) |
---|
1153 | { |
---|
1154 | if (alpha.level() == 1) |
---|
1155 | { |
---|
1156 | lcA0= lc (A (0, 2)); |
---|
1157 | A *= b.inverse (lcA0); |
---|
1158 | A= b (A); |
---|
1159 | for (CFListIterator i= bufUniFactors; i.hasItem(); i++) |
---|
1160 | i.getItem()= b (i.getItem()*b.inverse (lc (i.getItem()))); |
---|
1161 | } |
---|
1162 | else |
---|
1163 | { |
---|
1164 | lcA0= Lc (A (0,2)); |
---|
1165 | On (SW_RATIONAL); |
---|
1166 | mipoHasDen= !bCommonDen(getMipo(alpha)).isOne(); |
---|
1167 | Off (SW_RATIONAL); |
---|
1168 | CanonicalForm lcA0inverse= b.inverse (lcA0); |
---|
1169 | A *= lcA0inverse; |
---|
1170 | A= b (A); |
---|
1171 | // Lc of bufUniFactors is in Z |
---|
1172 | for (CFListIterator i= bufUniFactors; i.hasItem(); i++) |
---|
1173 | i.getItem()= b (i.getItem()*b.inverse (lc (i.getItem()))); |
---|
1174 | } |
---|
1175 | } |
---|
1176 | bufUniFactors.insert (LC (A, x)); |
---|
1177 | CFMatrix M= CFMatrix (liftBound, bufUniFactors.length() - 1); |
---|
1178 | earlySuccess= false; |
---|
1179 | int newLiftBound= 0; |
---|
1180 | |
---|
1181 | int smallFactorDeg= tmin (11, liftPre [sizeOfLiftPre- 1] + 1);//this is a tunable parameter |
---|
1182 | int dummy; |
---|
1183 | int * factorsFoundIndex= new int [uniFactors.length()]; |
---|
1184 | for (int i= 0; i < uniFactors.length(); i++) |
---|
1185 | factorsFoundIndex [i]= 0; |
---|
1186 | |
---|
1187 | CFList bufBufUniFactors; |
---|
1188 | Variable v= alpha; |
---|
1189 | if (smallFactorDeg >= liftBound || degree (A,y) <= 4) |
---|
1190 | henselLift12 (A, bufUniFactors, liftBound, Pi, diophant, M, b, true); |
---|
1191 | else if (sizeOfLiftPre > 1 && sizeOfLiftPre < 30) |
---|
1192 | { |
---|
1193 | henselLift12 (A, bufUniFactors, smallFactorDeg, Pi, diophant, M, b, true); |
---|
1194 | if (mipoHasDen) |
---|
1195 | { |
---|
1196 | for (CFListIterator iter= bufUniFactors; iter.hasItem(); iter++) |
---|
1197 | if (hasFirstAlgVar (iter.getItem(), v)) |
---|
1198 | break; |
---|
1199 | if (v != alpha) |
---|
1200 | { |
---|
1201 | bufBufUniFactors= bufUniFactors; |
---|
1202 | for (CFListIterator iter= bufBufUniFactors; iter.hasItem(); iter++) |
---|
1203 | iter.getItem()= replacevar (iter.getItem(), v, alpha); |
---|
1204 | A= replacevar (A, alpha, v); |
---|
1205 | } |
---|
1206 | } |
---|
1207 | |
---|
1208 | if (!extension) |
---|
1209 | { |
---|
1210 | if (v==alpha) |
---|
1211 | earlyFactorDetection (earlyFactors, bufA, bufUniFactors, newLiftBound, |
---|
1212 | factorsFoundIndex, degs, earlySuccess, |
---|
1213 | smallFactorDeg, eval, b, den); |
---|
1214 | else |
---|
1215 | earlyFactorDetection(earlyFactors, bufA, bufBufUniFactors, newLiftBound, |
---|
1216 | factorsFoundIndex, degs, earlySuccess, |
---|
1217 | smallFactorDeg, eval, b, den); |
---|
1218 | } |
---|
1219 | else |
---|
1220 | extEarlyFactorDetection (earlyFactors, bufA, bufUniFactors, newLiftBound, |
---|
1221 | factorsFoundIndex, degs, earlySuccess, info, |
---|
1222 | eval, smallFactorDeg); |
---|
1223 | if (degs.getLength() > 1 && !earlySuccess && |
---|
1224 | smallFactorDeg != liftPre [sizeOfLiftPre-1] + 1) |
---|
1225 | { |
---|
1226 | if (newLiftBound >= liftPre[sizeOfLiftPre-1]+1) |
---|
1227 | { |
---|
1228 | bufUniFactors.insert (LC (A, x)); |
---|
1229 | henselLiftResume12 (A, bufUniFactors, smallFactorDeg, |
---|
1230 | liftPre[sizeOfLiftPre-1] + 1, Pi, diophant, M, b); |
---|
1231 | if (v!=alpha) |
---|
1232 | { |
---|
1233 | bufBufUniFactors= bufUniFactors; |
---|
1234 | for (CFListIterator iter= bufBufUniFactors; iter.hasItem(); iter++) |
---|
1235 | iter.getItem()= replacevar (iter.getItem(), v, alpha); |
---|
1236 | } |
---|
1237 | if (!extension) |
---|
1238 | { |
---|
1239 | if (v==alpha) |
---|
1240 | earlyFactorDetection (earlyFactors, bufA, bufUniFactors, newLiftBound, |
---|
1241 | factorsFoundIndex, degs, earlySuccess, |
---|
1242 | liftPre[sizeOfLiftPre-1] + 1, eval, b, den); |
---|
1243 | else |
---|
1244 | earlyFactorDetection (earlyFactors,bufA,bufBufUniFactors,newLiftBound, |
---|
1245 | factorsFoundIndex, degs, earlySuccess, |
---|
1246 | liftPre[sizeOfLiftPre-1] + 1, eval, b, den); |
---|
1247 | } |
---|
1248 | else |
---|
1249 | extEarlyFactorDetection (earlyFactors,bufA,bufUniFactors,newLiftBound, |
---|
1250 | factorsFoundIndex, degs, earlySuccess, info, |
---|
1251 | eval, liftPre[sizeOfLiftPre-1] + 1); |
---|
1252 | } |
---|
1253 | } |
---|
1254 | else if (earlySuccess) |
---|
1255 | liftBound= newLiftBound; |
---|
1256 | |
---|
1257 | int i= sizeOfLiftPre - 1; |
---|
1258 | while (degs.getLength() > 1 && !earlySuccess && i - 1 >= 0) |
---|
1259 | { |
---|
1260 | if (newLiftBound >= liftPre[i] + 1) |
---|
1261 | { |
---|
1262 | bufUniFactors.insert (LC (A, x)); |
---|
1263 | henselLiftResume12 (A, bufUniFactors, liftPre[i] + 1, |
---|
1264 | liftPre[i-1] + 1, Pi, diophant, M, b); |
---|
1265 | if (v!=alpha) |
---|
1266 | { |
---|
1267 | bufBufUniFactors= bufUniFactors; |
---|
1268 | for (CFListIterator iter= bufBufUniFactors; iter.hasItem(); iter++) |
---|
1269 | iter.getItem()= replacevar (iter.getItem(), v, alpha); |
---|
1270 | } |
---|
1271 | if (!extension) |
---|
1272 | { |
---|
1273 | if (v==alpha) |
---|
1274 | earlyFactorDetection (earlyFactors, bufA, bufUniFactors, newLiftBound, |
---|
1275 | factorsFoundIndex, degs, earlySuccess, |
---|
1276 | liftPre[i-1] + 1, eval, b, den); |
---|
1277 | else |
---|
1278 | earlyFactorDetection (earlyFactors,bufA,bufBufUniFactors,newLiftBound, |
---|
1279 | factorsFoundIndex, degs, earlySuccess, |
---|
1280 | liftPre[i-1] + 1, eval, b, den); |
---|
1281 | } |
---|
1282 | else |
---|
1283 | extEarlyFactorDetection (earlyFactors,bufA,bufUniFactors,newLiftBound, |
---|
1284 | factorsFoundIndex, degs, earlySuccess, info, |
---|
1285 | eval, liftPre[i-1] + 1); |
---|
1286 | } |
---|
1287 | else |
---|
1288 | { |
---|
1289 | liftBound= newLiftBound; |
---|
1290 | break; |
---|
1291 | } |
---|
1292 | i--; |
---|
1293 | } |
---|
1294 | if (earlySuccess) |
---|
1295 | liftBound= newLiftBound; |
---|
1296 | //after here all factors are lifted to liftPre[sizeOfLiftPre-1] |
---|
1297 | } |
---|
1298 | else |
---|
1299 | { |
---|
1300 | henselLift12 (A, bufUniFactors, smallFactorDeg, Pi, diophant, M, b, true); |
---|
1301 | if (mipoHasDen) |
---|
1302 | { |
---|
1303 | for (CFListIterator iter= bufUniFactors; iter.hasItem(); iter++) |
---|
1304 | if (hasFirstAlgVar (iter.getItem(), v)) |
---|
1305 | break; |
---|
1306 | if (v != alpha) |
---|
1307 | { |
---|
1308 | bufBufUniFactors= bufUniFactors; |
---|
1309 | for (CFListIterator iter= bufBufUniFactors; iter.hasItem(); iter++) |
---|
1310 | iter.getItem()= replacevar (iter.getItem(), v, alpha); |
---|
1311 | A= replacevar (A, alpha, v); |
---|
1312 | } |
---|
1313 | } |
---|
1314 | if (!extension) |
---|
1315 | { |
---|
1316 | if (v==alpha) |
---|
1317 | earlyFactorDetection (earlyFactors, bufA, bufUniFactors, newLiftBound, |
---|
1318 | factorsFoundIndex, degs, earlySuccess, |
---|
1319 | smallFactorDeg, eval, b, den); |
---|
1320 | else |
---|
1321 | earlyFactorDetection (earlyFactors, bufA, bufBufUniFactors, newLiftBound, |
---|
1322 | factorsFoundIndex, degs, earlySuccess, |
---|
1323 | smallFactorDeg, eval, b, den); |
---|
1324 | } |
---|
1325 | else |
---|
1326 | extEarlyFactorDetection (earlyFactors, bufA, bufUniFactors, newLiftBound, |
---|
1327 | factorsFoundIndex, degs, earlySuccess, info, |
---|
1328 | eval, smallFactorDeg); |
---|
1329 | int i= 1; |
---|
1330 | while ((degree (A,y)/4)*i + 4 <= smallFactorDeg) |
---|
1331 | i++; |
---|
1332 | dummy= tmin (degree (A,y)+1, (degree (A,y)/4)*i+4); |
---|
1333 | if (degs.getLength() > 1 && !earlySuccess && dummy > smallFactorDeg) |
---|
1334 | { |
---|
1335 | bufUniFactors.insert (LC (A, x)); |
---|
1336 | henselLiftResume12 (A, bufUniFactors, smallFactorDeg, |
---|
1337 | dummy, Pi, diophant, M, b); |
---|
1338 | if (v!=alpha) |
---|
1339 | { |
---|
1340 | bufBufUniFactors= bufUniFactors; |
---|
1341 | for (CFListIterator iter= bufBufUniFactors; iter.hasItem(); iter++) |
---|
1342 | iter.getItem()= replacevar (iter.getItem(), v, alpha); |
---|
1343 | } |
---|
1344 | if (!extension) |
---|
1345 | { |
---|
1346 | if (v==alpha) |
---|
1347 | earlyFactorDetection (earlyFactors, bufA, bufUniFactors, newLiftBound, |
---|
1348 | factorsFoundIndex, degs, earlySuccess, dummy,eval, |
---|
1349 | b, den); |
---|
1350 | else |
---|
1351 | earlyFactorDetection (earlyFactors, bufA,bufBufUniFactors, newLiftBound, |
---|
1352 | factorsFoundIndex, degs, earlySuccess, dummy,eval, |
---|
1353 | b, den); |
---|
1354 | } |
---|
1355 | else |
---|
1356 | extEarlyFactorDetection (earlyFactors, bufA,bufUniFactors, newLiftBound, |
---|
1357 | factorsFoundIndex, degs, earlySuccess, info, |
---|
1358 | eval, dummy); |
---|
1359 | } |
---|
1360 | while (degs.getLength() > 1 && !earlySuccess && i < 4) |
---|
1361 | { |
---|
1362 | if (newLiftBound >= dummy) |
---|
1363 | { |
---|
1364 | bufUniFactors.insert (LC (A, x)); |
---|
1365 | dummy= tmin (degree (A,y)+1, (degree (A,y)/4)*(i+1)+4); |
---|
1366 | henselLiftResume12 (A, bufUniFactors, (degree (A,y)/4)*i + 4, |
---|
1367 | dummy, Pi, diophant, M, b); |
---|
1368 | if (v!=alpha) |
---|
1369 | { |
---|
1370 | bufBufUniFactors= bufUniFactors; |
---|
1371 | for (CFListIterator iter= bufBufUniFactors; iter.hasItem(); iter++) |
---|
1372 | iter.getItem()= replacevar (iter.getItem(), v, alpha); |
---|
1373 | } |
---|
1374 | if (!extension) |
---|
1375 | { |
---|
1376 | if (v==alpha) |
---|
1377 | earlyFactorDetection (earlyFactors, bufA, bufUniFactors, newLiftBound, |
---|
1378 | factorsFoundIndex, degs, earlySuccess, dummy, |
---|
1379 | eval, b, den); |
---|
1380 | else |
---|
1381 | earlyFactorDetection (earlyFactors,bufA,bufBufUniFactors,newLiftBound, |
---|
1382 | factorsFoundIndex, degs, earlySuccess, dummy, |
---|
1383 | eval, b, den); |
---|
1384 | } |
---|
1385 | else |
---|
1386 | extEarlyFactorDetection (earlyFactors,bufA,bufUniFactors,newLiftBound, |
---|
1387 | factorsFoundIndex, degs, earlySuccess, info, |
---|
1388 | eval, dummy); |
---|
1389 | } |
---|
1390 | else |
---|
1391 | { |
---|
1392 | liftBound= newLiftBound; |
---|
1393 | break; |
---|
1394 | } |
---|
1395 | i++; |
---|
1396 | } |
---|
1397 | if (earlySuccess) |
---|
1398 | liftBound= newLiftBound; |
---|
1399 | } |
---|
1400 | |
---|
1401 | A= bufA; |
---|
1402 | if (earlyFactors.length() > 0 && degs.getLength() > 1) |
---|
1403 | { |
---|
1404 | liftBound= degree (A,y) + 1; |
---|
1405 | earlySuccess= true; |
---|
1406 | deleteFactors (bufUniFactors, factorsFoundIndex); |
---|
1407 | } |
---|
1408 | |
---|
1409 | delete [] factorsFoundIndex; |
---|
1410 | delete [] liftPre; |
---|
1411 | |
---|
1412 | return bufUniFactors; |
---|
1413 | } |
---|
1414 | |
---|
1415 | CFList |
---|
1416 | henselLiftAndEarly (CanonicalForm& A, bool& earlySuccess, CFList& |
---|
1417 | earlyFactors, DegreePattern& degs, int& liftBound, |
---|
1418 | const CFList& uniFactors, const ExtensionInfo& info, |
---|
1419 | const CanonicalForm& eval) |
---|
1420 | { |
---|
1421 | modpk dummy= modpk(); |
---|
1422 | CanonicalForm den= 1; |
---|
1423 | return henselLiftAndEarly (A, earlySuccess, earlyFactors, degs, liftBound, |
---|
1424 | uniFactors, info, eval, dummy, den); |
---|
1425 | } |
---|
1426 | |
---|
1427 | #ifndef HAVE_FLINT |
---|
1428 | long isReduced (const mat_zz_p& M) |
---|
1429 | { |
---|
1430 | long i, j, nonZero; |
---|
1431 | for (i = 1; i <= M.NumRows(); i++) |
---|
1432 | { |
---|
1433 | nonZero= 0; |
---|
1434 | for (j = 1; j <= M.NumCols(); j++) |
---|
1435 | { |
---|
1436 | if (!IsZero (M (i,j))) |
---|
1437 | nonZero++; |
---|
1438 | } |
---|
1439 | if (nonZero != 1) |
---|
1440 | return 0; |
---|
1441 | } |
---|
1442 | return 1; |
---|
1443 | } |
---|
1444 | #endif |
---|
1445 | |
---|
1446 | #ifdef HAVE_FLINT |
---|
1447 | long isReduced (const nmod_mat_t M) |
---|
1448 | { |
---|
1449 | long i, j, nonZero; |
---|
1450 | for (i = 1; i <= nmod_mat_nrows(M); i++) |
---|
1451 | { |
---|
1452 | nonZero= 0; |
---|
1453 | for (j = 1; j <= nmod_mat_ncols (M); j++) |
---|
1454 | { |
---|
1455 | if (!(nmod_mat_entry (M, i-1, j-1)==0)) |
---|
1456 | nonZero++; |
---|
1457 | } |
---|
1458 | if (nonZero != 1) |
---|
1459 | return 0; |
---|
1460 | } |
---|
1461 | return 1; |
---|
1462 | } |
---|
1463 | #endif |
---|
1464 | |
---|
1465 | long isReduced (const mat_zz_pE& M) |
---|
1466 | { |
---|
1467 | long i, j, nonZero; |
---|
1468 | for (i = 1; i <= M.NumRows(); i++) |
---|
1469 | { |
---|
1470 | nonZero= 0; |
---|
1471 | for (j = 1; j <= M.NumCols(); j++) |
---|
1472 | { |
---|
1473 | if (!IsZero (M (i,j))) |
---|
1474 | nonZero++; |
---|
1475 | } |
---|
1476 | if (nonZero != 1) |
---|
1477 | return 0; |
---|
1478 | } |
---|
1479 | return 1; |
---|
1480 | } |
---|
1481 | |
---|
1482 | #ifndef HAVE_FLINT |
---|
1483 | int * extractZeroOneVecs (const mat_zz_p& M) |
---|
1484 | { |
---|
1485 | long i, j; |
---|
1486 | bool nonZeroOne= false; |
---|
1487 | int * result= new int [M.NumCols()]; |
---|
1488 | for (i = 1; i <= M.NumCols(); i++) |
---|
1489 | { |
---|
1490 | for (j = 1; j <= M.NumRows(); j++) |
---|
1491 | { |
---|
1492 | if (!(IsOne (M (j,i)) || IsZero (M (j,i)))) |
---|
1493 | { |
---|
1494 | nonZeroOne= true; |
---|
1495 | break; |
---|
1496 | } |
---|
1497 | } |
---|
1498 | if (!nonZeroOne) |
---|
1499 | result [i - 1]= 1; |
---|
1500 | else |
---|
1501 | result [i - 1]= 0; |
---|
1502 | nonZeroOne= false; |
---|
1503 | } |
---|
1504 | return result; |
---|
1505 | } |
---|
1506 | #endif |
---|
1507 | |
---|
1508 | #ifdef HAVE_FLINT |
---|
1509 | int * extractZeroOneVecs (const nmod_mat_t M) |
---|
1510 | { |
---|
1511 | long i, j; |
---|
1512 | bool nonZeroOne= false; |
---|
1513 | int * result= new int [nmod_mat_ncols (M)]; |
---|
1514 | for (i = 0; i < nmod_mat_ncols (M); i++) |
---|
1515 | { |
---|
1516 | for (j = 0; j < nmod_mat_nrows (M); j++) |
---|
1517 | { |
---|
1518 | if (!((nmod_mat_entry (M, j, i) == 1) || (nmod_mat_entry (M, j,i) == 0))) |
---|
1519 | { |
---|
1520 | nonZeroOne= true; |
---|
1521 | break; |
---|
1522 | } |
---|
1523 | } |
---|
1524 | if (!nonZeroOne) |
---|
1525 | result [i]= 1; |
---|
1526 | else |
---|
1527 | result [i]= 0; |
---|
1528 | nonZeroOne= false; |
---|
1529 | } |
---|
1530 | return result; |
---|
1531 | } |
---|
1532 | #endif |
---|
1533 | |
---|
1534 | int * extractZeroOneVecs (const mat_zz_pE& M) |
---|
1535 | { |
---|
1536 | long i, j; |
---|
1537 | bool nonZeroOne= false; |
---|
1538 | int * result= new int [M.NumCols()]; |
---|
1539 | for (i = 1; i <= M.NumCols(); i++) |
---|
1540 | { |
---|
1541 | for (j = 1; j <= M.NumRows(); j++) |
---|
1542 | { |
---|
1543 | if (!(IsOne (M (j,i)) || IsZero (M (j,i)))) |
---|
1544 | { |
---|
1545 | nonZeroOne= true; |
---|
1546 | break; |
---|
1547 | } |
---|
1548 | } |
---|
1549 | if (!nonZeroOne) |
---|
1550 | result [i - 1]= 1; |
---|
1551 | else |
---|
1552 | result [i - 1]= 0; |
---|
1553 | nonZeroOne= false; |
---|
1554 | } |
---|
1555 | return result; |
---|
1556 | } |
---|
1557 | |
---|
1558 | void |
---|
1559 | reconstructionTry (CFList& reconstructedFactors, CanonicalForm& F, const CFList& |
---|
1560 | factors, const int liftBound, int& factorsFound, int*& |
---|
1561 | factorsFoundIndex, mat_zz_pE& N, const CanonicalForm& eval, |
---|
1562 | bool beenInThres |
---|
1563 | ) |
---|
1564 | { |
---|
1565 | Variable y= Variable (2); |
---|
1566 | Variable x= Variable (1); |
---|
1567 | CanonicalForm yToL= power (y, liftBound); |
---|
1568 | CanonicalForm bufF= F (y-eval, y); |
---|
1569 | if (factors.length() == 2) |
---|
1570 | { |
---|
1571 | CanonicalForm tmp1, tmp2, tmp3; |
---|
1572 | tmp1= factors.getFirst(); |
---|
1573 | tmp2= factors.getLast(); |
---|
1574 | tmp1= mulMod2 (tmp1, LC (F,x), yToL); |
---|
1575 | tmp1 /= content (tmp1, x); |
---|
1576 | tmp1= tmp1 (y-eval, y); |
---|
1577 | tmp2= mulMod2 (tmp2, LC (F,x), yToL); |
---|
1578 | tmp2 /= content (tmp2, x); |
---|
1579 | tmp2= tmp2 (y-eval, y); |
---|
1580 | tmp3 = tmp1*tmp2; |
---|
1581 | if (tmp3/Lc (tmp3) == bufF/Lc (bufF)) |
---|
1582 | { |
---|
1583 | factorsFound++; |
---|
1584 | F= 1; |
---|
1585 | reconstructedFactors.append (tmp1); |
---|
1586 | reconstructedFactors.append (tmp2); |
---|
1587 | return; |
---|
1588 | } |
---|
1589 | } |
---|
1590 | CanonicalForm quot, buf; |
---|
1591 | CFListIterator iter; |
---|
1592 | for (long i= 1; i <= N.NumCols(); i++) |
---|
1593 | { |
---|
1594 | if (factorsFoundIndex [i - 1] == 1) |
---|
1595 | continue; |
---|
1596 | iter= factors; |
---|
1597 | if (beenInThres) |
---|
1598 | { |
---|
1599 | int count= 1; |
---|
1600 | while (count < i) |
---|
1601 | { |
---|
1602 | count++; |
---|
1603 | iter++; |
---|
1604 | } |
---|
1605 | buf= iter.getItem(); |
---|
1606 | } |
---|
1607 | else |
---|
1608 | { |
---|
1609 | buf= 1; |
---|
1610 | for (long j= 1; j <= N.NumRows(); j++, iter++) |
---|
1611 | { |
---|
1612 | if (!IsZero (N (j,i))) |
---|
1613 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
1614 | } |
---|
1615 | } |
---|
1616 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
1617 | buf /= content (buf, x); |
---|
1618 | buf= buf (y-eval,y); |
---|
1619 | if (fdivides (buf, bufF, quot)) |
---|
1620 | { |
---|
1621 | factorsFoundIndex[i - 1]= 1; |
---|
1622 | factorsFound++; |
---|
1623 | bufF= quot; |
---|
1624 | bufF /= Lc (bufF); |
---|
1625 | reconstructedFactors.append (buf); |
---|
1626 | } |
---|
1627 | if (degree (bufF) <= 0) |
---|
1628 | return; |
---|
1629 | if (factorsFound + 1 == N.NumCols()) |
---|
1630 | { |
---|
1631 | reconstructedFactors.append (bufF); |
---|
1632 | F= 1; |
---|
1633 | return; |
---|
1634 | } |
---|
1635 | } |
---|
1636 | if (reconstructedFactors.length() != 0) |
---|
1637 | F= bufF (y+eval,y); |
---|
1638 | } |
---|
1639 | |
---|
1640 | #ifndef HAVE_FLINT |
---|
1641 | void |
---|
1642 | reconstructionTry (CFList& reconstructedFactors, CanonicalForm& F, const CFList& |
---|
1643 | factors, const int liftBound, int& factorsFound, int*& |
---|
1644 | factorsFoundIndex, mat_zz_p& N, const CanonicalForm& eval, |
---|
1645 | bool beenInThres |
---|
1646 | ) |
---|
1647 | { |
---|
1648 | Variable y= Variable (2); |
---|
1649 | Variable x= Variable (1); |
---|
1650 | CanonicalForm yToL= power (y, liftBound); |
---|
1651 | CanonicalForm bufF= F (y-eval, y); |
---|
1652 | if (factors.length() == 2) |
---|
1653 | { |
---|
1654 | CanonicalForm tmp1, tmp2, tmp3; |
---|
1655 | tmp1= factors.getFirst(); |
---|
1656 | tmp2= factors.getLast(); |
---|
1657 | tmp1= mulMod2 (tmp1, LC (F,x), yToL); |
---|
1658 | tmp1 /= content (tmp1, x); |
---|
1659 | tmp1= tmp1 (y-eval, y); |
---|
1660 | tmp2= mulMod2 (tmp2, LC (F,x), yToL); |
---|
1661 | tmp2 /= content (tmp2, x); |
---|
1662 | tmp2= tmp2 (y-eval,y); |
---|
1663 | tmp3 = tmp1*tmp2; |
---|
1664 | if (tmp3/Lc (tmp3) == bufF/Lc (bufF)) |
---|
1665 | { |
---|
1666 | factorsFound++; |
---|
1667 | F= 1; |
---|
1668 | reconstructedFactors.append (tmp1); |
---|
1669 | reconstructedFactors.append (tmp2); |
---|
1670 | return; |
---|
1671 | } |
---|
1672 | } |
---|
1673 | CanonicalForm quot, buf; |
---|
1674 | CFListIterator iter; |
---|
1675 | for (long i= 1; i <= N.NumCols(); i++) |
---|
1676 | { |
---|
1677 | if (factorsFoundIndex [i - 1] == 1) |
---|
1678 | continue; |
---|
1679 | iter= factors; |
---|
1680 | if (beenInThres) |
---|
1681 | { |
---|
1682 | int count= 1; |
---|
1683 | while (count < i) |
---|
1684 | { |
---|
1685 | count++; |
---|
1686 | iter++; |
---|
1687 | } |
---|
1688 | buf= iter.getItem(); |
---|
1689 | } |
---|
1690 | else |
---|
1691 | { |
---|
1692 | buf= 1; |
---|
1693 | for (long j= 1; j <= N.NumRows(); j++, iter++) |
---|
1694 | { |
---|
1695 | if (!IsZero (N (j,i))) |
---|
1696 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
1697 | } |
---|
1698 | } |
---|
1699 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
1700 | buf /= content (buf, x); |
---|
1701 | buf= buf (y-eval,y); |
---|
1702 | if (fdivides (buf, bufF, quot)) |
---|
1703 | { |
---|
1704 | factorsFoundIndex[i - 1]= 1; |
---|
1705 | factorsFound++; |
---|
1706 | bufF= quot; |
---|
1707 | bufF /= Lc (bufF); |
---|
1708 | reconstructedFactors.append (buf); |
---|
1709 | } |
---|
1710 | if (degree (bufF) <= 0) |
---|
1711 | return; |
---|
1712 | if (factorsFound + 1 == N.NumCols()) |
---|
1713 | { |
---|
1714 | reconstructedFactors.append (bufF); |
---|
1715 | F=1; |
---|
1716 | return; |
---|
1717 | } |
---|
1718 | } |
---|
1719 | if (reconstructedFactors.length() != 0) |
---|
1720 | F= bufF (y+eval,y); |
---|
1721 | } |
---|
1722 | #endif |
---|
1723 | |
---|
1724 | #ifdef HAVE_FLINT |
---|
1725 | void |
---|
1726 | reconstructionTry (CFList& reconstructedFactors, CanonicalForm& F, const CFList& |
---|
1727 | factors, const int liftBound, int& factorsFound, int*& |
---|
1728 | factorsFoundIndex, nmod_mat_t N, const CanonicalForm& eval, |
---|
1729 | bool beenInThres |
---|
1730 | ) |
---|
1731 | { |
---|
1732 | Variable y= Variable (2); |
---|
1733 | Variable x= Variable (1); |
---|
1734 | CanonicalForm yToL= power (y, liftBound); |
---|
1735 | CanonicalForm bufF= F (y-eval, y); |
---|
1736 | if (factors.length() == 2) |
---|
1737 | { |
---|
1738 | CanonicalForm tmp1, tmp2, tmp3; |
---|
1739 | tmp1= factors.getFirst(); |
---|
1740 | tmp2= factors.getLast(); |
---|
1741 | tmp1= mulMod2 (tmp1, LC (F,x), yToL); |
---|
1742 | tmp1 /= content (tmp1, x); |
---|
1743 | tmp1= tmp1 (y-eval, y); |
---|
1744 | tmp2= mulMod2 (tmp2, LC (F,x), yToL); |
---|
1745 | tmp2 /= content (tmp2, x); |
---|
1746 | tmp2= tmp2 (y-eval, y); |
---|
1747 | tmp3 = tmp1*tmp2; |
---|
1748 | if (tmp3/Lc (tmp3) == bufF/Lc (bufF)) |
---|
1749 | { |
---|
1750 | factorsFound++; |
---|
1751 | F= 1; |
---|
1752 | reconstructedFactors.append (tmp1); |
---|
1753 | reconstructedFactors.append (tmp2); |
---|
1754 | return; |
---|
1755 | } |
---|
1756 | } |
---|
1757 | CanonicalForm quot, buf; |
---|
1758 | CFListIterator iter; |
---|
1759 | for (long i= 0; i < nmod_mat_ncols (N); i++) |
---|
1760 | { |
---|
1761 | if (factorsFoundIndex [i] == 1) |
---|
1762 | continue; |
---|
1763 | iter= factors; |
---|
1764 | if (beenInThres) |
---|
1765 | { |
---|
1766 | int count= 0; |
---|
1767 | while (count < i) |
---|
1768 | { |
---|
1769 | count++; |
---|
1770 | iter++; |
---|
1771 | } |
---|
1772 | buf= iter.getItem(); |
---|
1773 | } |
---|
1774 | else |
---|
1775 | { |
---|
1776 | buf= 1; |
---|
1777 | for (long j= 0; j < nmod_mat_nrows (N); j++, iter++) |
---|
1778 | { |
---|
1779 | if (!(nmod_mat_entry (N, j, i) == 0)) |
---|
1780 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
1781 | } |
---|
1782 | } |
---|
1783 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
1784 | buf /= content (buf, x); |
---|
1785 | buf= buf (y-eval,y); |
---|
1786 | if (fdivides (buf, bufF, quot)) |
---|
1787 | { |
---|
1788 | factorsFoundIndex[i]= 1; |
---|
1789 | factorsFound++; |
---|
1790 | bufF= quot; |
---|
1791 | bufF /= Lc (bufF); |
---|
1792 | reconstructedFactors.append (buf); |
---|
1793 | } |
---|
1794 | if (degree (F) <= 0) |
---|
1795 | return; |
---|
1796 | if (factorsFound + 1 == nmod_mat_ncols (N)) |
---|
1797 | { |
---|
1798 | F= 1; |
---|
1799 | reconstructedFactors.append (bufF); |
---|
1800 | return; |
---|
1801 | } |
---|
1802 | } |
---|
1803 | if (reconstructedFactors.length() != 0) |
---|
1804 | F= bufF (y+eval,y); |
---|
1805 | } |
---|
1806 | #endif |
---|
1807 | |
---|
1808 | CFList |
---|
1809 | reconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs, int |
---|
1810 | precision, const mat_zz_pE& N, const CanonicalForm& eval |
---|
1811 | ) |
---|
1812 | { |
---|
1813 | Variable y= Variable (2); |
---|
1814 | Variable x= Variable (1); |
---|
1815 | CanonicalForm F= G; |
---|
1816 | CanonicalForm yToL= power (y, precision); |
---|
1817 | CanonicalForm quot, buf; |
---|
1818 | CFList result, factorsConsidered; |
---|
1819 | CFList bufFactors= factors; |
---|
1820 | CFListIterator iter; |
---|
1821 | for (long i= 1; i <= N.NumCols(); i++) |
---|
1822 | { |
---|
1823 | if (zeroOneVecs [i - 1] == 0) |
---|
1824 | continue; |
---|
1825 | iter= factors; |
---|
1826 | buf= 1; |
---|
1827 | factorsConsidered= CFList(); |
---|
1828 | for (long j= 1; j <= N.NumRows(); j++, iter++) |
---|
1829 | { |
---|
1830 | if (!IsZero (N (j,i))) |
---|
1831 | { |
---|
1832 | factorsConsidered.append (iter.getItem()); |
---|
1833 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
1834 | } |
---|
1835 | } |
---|
1836 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
1837 | buf /= content (buf, x); |
---|
1838 | if (fdivides (buf, F, quot)) |
---|
1839 | { |
---|
1840 | F= quot; |
---|
1841 | F /= Lc (F); |
---|
1842 | result.append (buf (y-eval,y)); |
---|
1843 | bufFactors= Difference (bufFactors, factorsConsidered); |
---|
1844 | } |
---|
1845 | if (degree (F) <= 0) |
---|
1846 | { |
---|
1847 | G= F; |
---|
1848 | factors= bufFactors; |
---|
1849 | return result; |
---|
1850 | } |
---|
1851 | } |
---|
1852 | G= F; |
---|
1853 | factors= bufFactors; |
---|
1854 | return result; |
---|
1855 | } |
---|
1856 | |
---|
1857 | CFList |
---|
1858 | monicReconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs, |
---|
1859 | int precision, const mat_zz_pE& N |
---|
1860 | ) |
---|
1861 | { |
---|
1862 | Variable y= Variable (2); |
---|
1863 | Variable x= Variable (1); |
---|
1864 | CanonicalForm F= G; |
---|
1865 | CanonicalForm yToL= power (y, precision); |
---|
1866 | CanonicalForm quot, buf, buf2; |
---|
1867 | CFList result; |
---|
1868 | CFList bufFactors= factors; |
---|
1869 | CFList factorsConsidered; |
---|
1870 | CFListIterator iter; |
---|
1871 | for (long i= 1; i <= N.NumCols(); i++) |
---|
1872 | { |
---|
1873 | if (zeroOneVecs [i - 1] == 0) |
---|
1874 | continue; |
---|
1875 | iter= factors; |
---|
1876 | buf= 1; |
---|
1877 | factorsConsidered= CFList(); |
---|
1878 | for (long j= 1; j <= N.NumRows(); j++, iter++) |
---|
1879 | { |
---|
1880 | if (!IsZero (N (j,i))) |
---|
1881 | { |
---|
1882 | factorsConsidered.append (iter.getItem()); |
---|
1883 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
1884 | } |
---|
1885 | } |
---|
1886 | buf2= buf; |
---|
1887 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
1888 | buf /= content (buf, x); |
---|
1889 | if (fdivides (buf, F, quot)) |
---|
1890 | { |
---|
1891 | F= quot; |
---|
1892 | F /= Lc (F); |
---|
1893 | result.append (buf2); |
---|
1894 | bufFactors= Difference (bufFactors, factorsConsidered); |
---|
1895 | } |
---|
1896 | if (degree (F) <= 0) |
---|
1897 | { |
---|
1898 | G= F; |
---|
1899 | factors= bufFactors; |
---|
1900 | return result; |
---|
1901 | } |
---|
1902 | } |
---|
1903 | G= F; |
---|
1904 | factors= bufFactors; |
---|
1905 | return result; |
---|
1906 | } |
---|
1907 | |
---|
1908 | #ifndef HAVE_FLINT |
---|
1909 | CFList |
---|
1910 | extReconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs, int |
---|
1911 | precision, const mat_zz_p& N, const ExtensionInfo& info, |
---|
1912 | const CanonicalForm& evaluation |
---|
1913 | ) |
---|
1914 | { |
---|
1915 | Variable y= Variable (2); |
---|
1916 | Variable x= Variable (1); |
---|
1917 | Variable alpha= info.getAlpha(); |
---|
1918 | Variable beta= info.getBeta(); |
---|
1919 | int k= info.getGFDegree(); |
---|
1920 | CanonicalForm gamma= info.getGamma(); |
---|
1921 | CanonicalForm delta= info.getDelta(); |
---|
1922 | CanonicalForm F= G; |
---|
1923 | CanonicalForm yToL= power (y, precision); |
---|
1924 | CFList result; |
---|
1925 | CFList bufFactors= factors; |
---|
1926 | CFList factorsConsidered; |
---|
1927 | CanonicalForm buf2, quot, buf; |
---|
1928 | CFListIterator iter; |
---|
1929 | for (long i= 1; i <= N.NumCols(); i++) |
---|
1930 | { |
---|
1931 | if (zeroOneVecs [i - 1] == 0) |
---|
1932 | continue; |
---|
1933 | iter= factors; |
---|
1934 | buf= 1; |
---|
1935 | factorsConsidered= CFList(); |
---|
1936 | for (long j= 1; j <= N.NumRows(); j++, iter++) |
---|
1937 | { |
---|
1938 | if (!IsZero (N (j,i))) |
---|
1939 | { |
---|
1940 | factorsConsidered.append (iter.getItem()); |
---|
1941 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
1942 | } |
---|
1943 | } |
---|
1944 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
1945 | buf /= content (buf, x); |
---|
1946 | buf2= buf (y-evaluation, y); |
---|
1947 | buf2 /= Lc (buf2); |
---|
1948 | if (!k && beta == x) |
---|
1949 | { |
---|
1950 | if (degree (buf2, alpha) < 1) |
---|
1951 | { |
---|
1952 | if (fdivides (buf, F, quot)) |
---|
1953 | { |
---|
1954 | F= quot; |
---|
1955 | F /= Lc (F); |
---|
1956 | result.append (buf2); |
---|
1957 | bufFactors= Difference (bufFactors, factorsConsidered); |
---|
1958 | } |
---|
1959 | } |
---|
1960 | } |
---|
1961 | else |
---|
1962 | { |
---|
1963 | CFList source, dest; |
---|
1964 | |
---|
1965 | if (!isInExtension (buf2, gamma, k, delta, source, dest)) |
---|
1966 | { |
---|
1967 | if (fdivides (buf, F, quot)) |
---|
1968 | { |
---|
1969 | F= quot; |
---|
1970 | F /= Lc (F); |
---|
1971 | result.append (buf2); |
---|
1972 | bufFactors= Difference (bufFactors, factorsConsidered); |
---|
1973 | } |
---|
1974 | } |
---|
1975 | } |
---|
1976 | if (degree (F) <= 0) |
---|
1977 | { |
---|
1978 | G= F; |
---|
1979 | factors= bufFactors; |
---|
1980 | return result; |
---|
1981 | } |
---|
1982 | } |
---|
1983 | G= F; |
---|
1984 | factors= bufFactors; |
---|
1985 | return result; |
---|
1986 | } |
---|
1987 | #endif |
---|
1988 | |
---|
1989 | #ifdef HAVE_FLINT |
---|
1990 | CFList |
---|
1991 | extReconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs, int |
---|
1992 | precision, const nmod_mat_t N, const ExtensionInfo& info, |
---|
1993 | const CanonicalForm& evaluation |
---|
1994 | ) |
---|
1995 | { |
---|
1996 | Variable y= Variable (2); |
---|
1997 | Variable x= Variable (1); |
---|
1998 | Variable alpha= info.getAlpha(); |
---|
1999 | Variable beta= info.getBeta(); |
---|
2000 | int k= info.getGFDegree(); |
---|
2001 | CanonicalForm gamma= info.getGamma(); |
---|
2002 | CanonicalForm delta= info.getDelta(); |
---|
2003 | CanonicalForm F= G; |
---|
2004 | CanonicalForm yToL= power (y, precision); |
---|
2005 | CFList result; |
---|
2006 | CFList bufFactors= factors; |
---|
2007 | CFList factorsConsidered; |
---|
2008 | CanonicalForm buf2, quot, buf; |
---|
2009 | CFListIterator iter; |
---|
2010 | for (long i= 0; i < nmod_mat_ncols(N); i++) |
---|
2011 | { |
---|
2012 | if (zeroOneVecs [i] == 0) |
---|
2013 | continue; |
---|
2014 | iter= factors; |
---|
2015 | buf= 1; |
---|
2016 | factorsConsidered= CFList(); |
---|
2017 | for (long j= 0; j < nmod_mat_nrows(N); j++, iter++) |
---|
2018 | { |
---|
2019 | if (!(nmod_mat_entry (N, j, i) == 0)) |
---|
2020 | { |
---|
2021 | factorsConsidered.append (iter.getItem()); |
---|
2022 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
2023 | } |
---|
2024 | } |
---|
2025 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
2026 | buf /= content (buf, x); |
---|
2027 | buf2= buf (y-evaluation, y); |
---|
2028 | buf2 /= Lc (buf2); |
---|
2029 | if (!k && beta == x) |
---|
2030 | { |
---|
2031 | if (degree (buf2, alpha) < 1) |
---|
2032 | { |
---|
2033 | if (fdivides (buf, F, quot)) |
---|
2034 | { |
---|
2035 | F= quot; |
---|
2036 | F /= Lc (F); |
---|
2037 | result.append (buf2); |
---|
2038 | bufFactors= Difference (bufFactors, factorsConsidered); |
---|
2039 | } |
---|
2040 | } |
---|
2041 | } |
---|
2042 | else |
---|
2043 | { |
---|
2044 | CFList source, dest; |
---|
2045 | |
---|
2046 | if (!isInExtension (buf2, gamma, k, delta, source, dest)) |
---|
2047 | { |
---|
2048 | if (fdivides (buf, F, quot)) |
---|
2049 | { |
---|
2050 | F= quot; |
---|
2051 | F /= Lc (F); |
---|
2052 | result.append (buf2); |
---|
2053 | bufFactors= Difference (bufFactors, factorsConsidered); |
---|
2054 | } |
---|
2055 | } |
---|
2056 | } |
---|
2057 | if (degree (F) <= 0) |
---|
2058 | { |
---|
2059 | G= F; |
---|
2060 | factors= bufFactors; |
---|
2061 | return result; |
---|
2062 | } |
---|
2063 | } |
---|
2064 | G= F; |
---|
2065 | factors= bufFactors; |
---|
2066 | return result; |
---|
2067 | } |
---|
2068 | #endif |
---|
2069 | |
---|
2070 | #ifndef HAVE_FLINT |
---|
2071 | CFList |
---|
2072 | reconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs, |
---|
2073 | int precision, const mat_zz_p& N, const CanonicalForm& eval) |
---|
2074 | { |
---|
2075 | Variable y= Variable (2); |
---|
2076 | Variable x= Variable (1); |
---|
2077 | CanonicalForm F= G; |
---|
2078 | CanonicalForm yToL= power (y, precision); |
---|
2079 | CanonicalForm quot, buf; |
---|
2080 | CFList result; |
---|
2081 | CFList bufFactors= factors; |
---|
2082 | CFList factorsConsidered; |
---|
2083 | CFListIterator iter; |
---|
2084 | for (long i= 1; i <= N.NumCols(); i++) |
---|
2085 | { |
---|
2086 | if (zeroOneVecs [i - 1] == 0) |
---|
2087 | continue; |
---|
2088 | iter= factors; |
---|
2089 | buf= 1; |
---|
2090 | factorsConsidered= CFList(); |
---|
2091 | for (long j= 1; j <= N.NumRows(); j++, iter++) |
---|
2092 | { |
---|
2093 | if (!IsZero (N (j,i))) |
---|
2094 | { |
---|
2095 | factorsConsidered.append (iter.getItem()); |
---|
2096 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
2097 | } |
---|
2098 | } |
---|
2099 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
2100 | buf /= content (buf, x); |
---|
2101 | if (fdivides (buf, F, quot)) |
---|
2102 | { |
---|
2103 | F= quot; |
---|
2104 | F /= Lc (F); |
---|
2105 | result.append (buf (y-eval,y)); |
---|
2106 | bufFactors= Difference (bufFactors, factorsConsidered); |
---|
2107 | } |
---|
2108 | if (degree (F) <= 0) |
---|
2109 | { |
---|
2110 | G= F; |
---|
2111 | factors= bufFactors; |
---|
2112 | return result; |
---|
2113 | } |
---|
2114 | } |
---|
2115 | G= F; |
---|
2116 | factors= bufFactors; |
---|
2117 | return result; |
---|
2118 | } |
---|
2119 | #endif |
---|
2120 | |
---|
2121 | #ifdef HAVE_FLINT |
---|
2122 | CFList |
---|
2123 | reconstruction (CanonicalForm& G, CFList& factors, int* zeroOneVecs, |
---|
2124 | int precision, const nmod_mat_t N, const CanonicalForm& eval) |
---|
2125 | { |
---|
2126 | Variable y= Variable (2); |
---|
2127 | Variable x= Variable (1); |
---|
2128 | CanonicalForm F= G; |
---|
2129 | CanonicalForm yToL= power (y, precision); |
---|
2130 | CanonicalForm quot, buf; |
---|
2131 | CFList result; |
---|
2132 | CFList bufFactors= factors; |
---|
2133 | CFList factorsConsidered; |
---|
2134 | CFListIterator iter; |
---|
2135 | for (long i= 0; i < nmod_mat_ncols (N); i++) |
---|
2136 | { |
---|
2137 | if (zeroOneVecs [i] == 0) |
---|
2138 | continue; |
---|
2139 | iter= factors; |
---|
2140 | buf= 1; |
---|
2141 | factorsConsidered= CFList(); |
---|
2142 | for (long j= 0; j < nmod_mat_nrows (N); j++, iter++) |
---|
2143 | { |
---|
2144 | if (!(nmod_mat_entry (N, j, i) == 0)) |
---|
2145 | { |
---|
2146 | factorsConsidered.append (iter.getItem()); |
---|
2147 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
2148 | } |
---|
2149 | } |
---|
2150 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
2151 | buf /= content (buf, x); |
---|
2152 | if (fdivides (buf, F, quot)) |
---|
2153 | { |
---|
2154 | F= quot; |
---|
2155 | F /= Lc (F); |
---|
2156 | result.append (buf (y-eval,y)); |
---|
2157 | bufFactors= Difference (bufFactors, factorsConsidered); |
---|
2158 | } |
---|
2159 | if (degree (F) <= 0) |
---|
2160 | { |
---|
2161 | G= F; |
---|
2162 | factors= bufFactors; |
---|
2163 | return result; |
---|
2164 | } |
---|
2165 | } |
---|
2166 | G= F; |
---|
2167 | factors= bufFactors; |
---|
2168 | return result; |
---|
2169 | } |
---|
2170 | #endif |
---|
2171 | |
---|
2172 | #ifndef HAVE_FLINT |
---|
2173 | void |
---|
2174 | extReconstructionTry (CFList& reconstructedFactors, CanonicalForm& F, const |
---|
2175 | CFList& factors, const int liftBound, int& factorsFound, |
---|
2176 | int*& factorsFoundIndex, mat_zz_p& N, bool beenInThres, |
---|
2177 | const ExtensionInfo& info, const CanonicalForm& evaluation |
---|
2178 | ) |
---|
2179 | { |
---|
2180 | Variable y= Variable (2); |
---|
2181 | Variable x= Variable (1); |
---|
2182 | Variable alpha= info.getAlpha(); |
---|
2183 | Variable beta= info.getBeta(); |
---|
2184 | int k= info.getGFDegree(); |
---|
2185 | CanonicalForm gamma= info.getGamma(); |
---|
2186 | CanonicalForm delta= info.getDelta(); |
---|
2187 | CanonicalForm yToL= power (y, liftBound); |
---|
2188 | CFList source, dest; |
---|
2189 | if (factors.length() == 2) |
---|
2190 | { |
---|
2191 | CanonicalForm tmp1, tmp2, tmp3; |
---|
2192 | tmp1= factors.getFirst(); |
---|
2193 | tmp2= factors.getLast(); |
---|
2194 | tmp1= mulMod2 (tmp1, LC (F,x), yToL); |
---|
2195 | tmp1 /= content (tmp1, x); |
---|
2196 | tmp2= mulMod2 (tmp2, LC (F,x), yToL); |
---|
2197 | tmp2 /= content (tmp2, x); |
---|
2198 | tmp3 = tmp1*tmp2; |
---|
2199 | if (tmp3/Lc (tmp3) == F/Lc (F)) |
---|
2200 | { |
---|
2201 | tmp1= tmp1 (y - evaluation, y); |
---|
2202 | tmp2= tmp2 (y - evaluation, y); |
---|
2203 | tmp1 /= Lc (tmp1); |
---|
2204 | tmp2 /= Lc (tmp2); |
---|
2205 | if (!k && beta == x && degree (tmp2, alpha) < 1 && |
---|
2206 | degree (tmp1, alpha) < 1) |
---|
2207 | { |
---|
2208 | factorsFound++; |
---|
2209 | F= 1; |
---|
2210 | tmp1= mapDown (tmp1, info, source, dest); |
---|
2211 | tmp2= mapDown (tmp2, info, source, dest); |
---|
2212 | reconstructedFactors.append (tmp1); |
---|
2213 | reconstructedFactors.append (tmp2); |
---|
2214 | return; |
---|
2215 | } |
---|
2216 | else if (!isInExtension (tmp2, gamma, k, delta, source, dest) && |
---|
2217 | !isInExtension (tmp1, gamma, k, delta, source, dest)) |
---|
2218 | { |
---|
2219 | factorsFound++; |
---|
2220 | F= 1; |
---|
2221 | tmp1= mapDown (tmp1, info, source, dest); |
---|
2222 | tmp2= mapDown (tmp2, info, source, dest); |
---|
2223 | reconstructedFactors.append (tmp1); |
---|
2224 | reconstructedFactors.append (tmp2); |
---|
2225 | return; |
---|
2226 | } |
---|
2227 | } |
---|
2228 | } |
---|
2229 | CanonicalForm quot, buf, buf2; |
---|
2230 | CFListIterator iter; |
---|
2231 | for (long i= 1; i <= N.NumCols(); i++) |
---|
2232 | { |
---|
2233 | if (factorsFoundIndex [i - 1] == 1) |
---|
2234 | continue; |
---|
2235 | iter= factors; |
---|
2236 | if (beenInThres) |
---|
2237 | { |
---|
2238 | int count= 1; |
---|
2239 | while (count < i) |
---|
2240 | { |
---|
2241 | count++; |
---|
2242 | iter++; |
---|
2243 | } |
---|
2244 | buf= iter.getItem(); |
---|
2245 | } |
---|
2246 | else |
---|
2247 | { |
---|
2248 | buf= 1; |
---|
2249 | for (long j= 1; j <= N.NumRows(); j++, iter++) |
---|
2250 | { |
---|
2251 | if (!IsZero (N (j,i))) |
---|
2252 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
2253 | } |
---|
2254 | } |
---|
2255 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
2256 | buf /= content (buf, x); |
---|
2257 | buf2= buf (y - evaluation, y); |
---|
2258 | buf2 /= Lc (buf2); |
---|
2259 | if (!k && beta == x) |
---|
2260 | { |
---|
2261 | if (degree (buf2, alpha) < 1) |
---|
2262 | { |
---|
2263 | if (fdivides (buf, F, quot)) |
---|
2264 | { |
---|
2265 | factorsFoundIndex[i - 1]= 1; |
---|
2266 | factorsFound++; |
---|
2267 | F= quot; |
---|
2268 | F /= Lc (F); |
---|
2269 | buf2= mapDown (buf2, info, source, dest); |
---|
2270 | reconstructedFactors.append (buf2); |
---|
2271 | } |
---|
2272 | } |
---|
2273 | } |
---|
2274 | else |
---|
2275 | { |
---|
2276 | if (!isInExtension (buf2, gamma, k, delta, source, dest)) |
---|
2277 | { |
---|
2278 | if (fdivides (buf, F, quot)) |
---|
2279 | { |
---|
2280 | factorsFoundIndex[i - 1]= 1; |
---|
2281 | factorsFound++; |
---|
2282 | F= quot; |
---|
2283 | F /= Lc (F); |
---|
2284 | buf2= mapDown (buf2, info, source, dest); |
---|
2285 | reconstructedFactors.append (buf2); |
---|
2286 | } |
---|
2287 | } |
---|
2288 | } |
---|
2289 | if (degree (F) <= 0) |
---|
2290 | return; |
---|
2291 | if (factorsFound + 1 == N.NumCols()) |
---|
2292 | { |
---|
2293 | CanonicalForm tmp= F (y - evaluation, y); |
---|
2294 | tmp= mapDown (tmp, info, source, dest); |
---|
2295 | reconstructedFactors.append (tmp); |
---|
2296 | return; |
---|
2297 | } |
---|
2298 | } |
---|
2299 | } |
---|
2300 | #endif |
---|
2301 | |
---|
2302 | #ifdef HAVE_FLINT |
---|
2303 | void |
---|
2304 | extReconstructionTry (CFList& reconstructedFactors, CanonicalForm& F, const |
---|
2305 | CFList& factors, const int liftBound, int& factorsFound, |
---|
2306 | int*& factorsFoundIndex, nmod_mat_t N, bool beenInThres, |
---|
2307 | const ExtensionInfo& info, const CanonicalForm& evaluation |
---|
2308 | ) |
---|
2309 | { |
---|
2310 | Variable y= Variable (2); |
---|
2311 | Variable x= Variable (1); |
---|
2312 | Variable alpha= info.getAlpha(); |
---|
2313 | Variable beta= info.getBeta(); |
---|
2314 | int k= info.getGFDegree(); |
---|
2315 | CanonicalForm gamma= info.getGamma(); |
---|
2316 | CanonicalForm delta= info.getDelta(); |
---|
2317 | CanonicalForm yToL= power (y, liftBound); |
---|
2318 | CFList source, dest; |
---|
2319 | if (factors.length() == 2) |
---|
2320 | { |
---|
2321 | CanonicalForm tmp1, tmp2, tmp3; |
---|
2322 | tmp1= factors.getFirst(); |
---|
2323 | tmp2= factors.getLast(); |
---|
2324 | tmp1= mulMod2 (tmp1, LC (F,x), yToL); |
---|
2325 | tmp1 /= content (tmp1, x); |
---|
2326 | tmp2= mulMod2 (tmp2, LC (F,x), yToL); |
---|
2327 | tmp2 /= content (tmp2, x); |
---|
2328 | tmp3 = tmp1*tmp2; |
---|
2329 | if (tmp3/Lc (tmp3) == F/Lc (F)) |
---|
2330 | { |
---|
2331 | tmp1= tmp1 (y - evaluation, y); |
---|
2332 | tmp2= tmp2 (y - evaluation, y); |
---|
2333 | tmp1 /= Lc (tmp1); |
---|
2334 | tmp2 /= Lc (tmp2); |
---|
2335 | if (!k && beta == x && degree (tmp2, alpha) < 1 && |
---|
2336 | degree (tmp1, alpha) < 1) |
---|
2337 | { |
---|
2338 | factorsFound++; |
---|
2339 | F= 1; |
---|
2340 | tmp1= mapDown (tmp1, info, source, dest); |
---|
2341 | tmp2= mapDown (tmp2, info, source, dest); |
---|
2342 | reconstructedFactors.append (tmp1); |
---|
2343 | reconstructedFactors.append (tmp2); |
---|
2344 | return; |
---|
2345 | } |
---|
2346 | else if (!isInExtension (tmp2, gamma, k, delta, source, dest) && |
---|
2347 | !isInExtension (tmp1, gamma, k, delta, source, dest)) |
---|
2348 | { |
---|
2349 | factorsFound++; |
---|
2350 | F= 1; |
---|
2351 | tmp1= mapDown (tmp1, info, source, dest); |
---|
2352 | tmp2= mapDown (tmp2, info, source, dest); |
---|
2353 | reconstructedFactors.append (tmp1); |
---|
2354 | reconstructedFactors.append (tmp2); |
---|
2355 | return; |
---|
2356 | } |
---|
2357 | } |
---|
2358 | } |
---|
2359 | CanonicalForm quot, buf, buf2; |
---|
2360 | CFListIterator iter; |
---|
2361 | for (long i= 0; i < nmod_mat_ncols (N); i++) |
---|
2362 | { |
---|
2363 | if (factorsFoundIndex [i] == 1) |
---|
2364 | continue; |
---|
2365 | iter= factors; |
---|
2366 | if (beenInThres) |
---|
2367 | { |
---|
2368 | int count= 0; |
---|
2369 | while (count < i) |
---|
2370 | { |
---|
2371 | count++; |
---|
2372 | iter++; |
---|
2373 | } |
---|
2374 | buf= iter.getItem(); |
---|
2375 | } |
---|
2376 | else |
---|
2377 | { |
---|
2378 | buf= 1; |
---|
2379 | for (long j= 0; j < nmod_mat_nrows (N); j++, iter++) |
---|
2380 | { |
---|
2381 | if (!(nmod_mat_entry (N, j, i) == 0)) |
---|
2382 | buf= mulMod2 (buf, iter.getItem(), yToL); |
---|
2383 | } |
---|
2384 | } |
---|
2385 | buf= mulMod2 (buf, LC (F,x), yToL); |
---|
2386 | buf /= content (buf, x); |
---|
2387 | buf2= buf (y - evaluation, y); |
---|
2388 | buf2 /= Lc (buf2); |
---|
2389 | if (!k && beta == x) |
---|
2390 | { |
---|
2391 | if (degree (buf2, alpha) < 1) |
---|
2392 | { |
---|
2393 | if (fdivides (buf, F, quot)) |
---|
2394 | { |
---|
2395 | factorsFoundIndex[i]= 1; |
---|
2396 | factorsFound++; |
---|
2397 | F= quot; |
---|
2398 | F /= Lc (F); |
---|
2399 | buf2= mapDown (buf2, info, source, dest); |
---|
2400 | reconstructedFactors.append (buf2); |
---|
2401 | } |
---|
2402 | } |
---|
2403 | } |
---|
2404 | else |
---|
2405 | { |
---|
2406 | if (!isInExtension (buf2, gamma, k, delta, source, dest)) |
---|
2407 | { |
---|
2408 | if (fdivides (buf, F, quot)) |
---|
2409 | { |
---|
2410 | factorsFoundIndex[i]= 1; |
---|
2411 | factorsFound++; |
---|
2412 | F= quot; |
---|
2413 | F /= Lc (F); |
---|
2414 | buf2= mapDown (buf2, info, source, dest); |
---|
2415 | reconstructedFactors.append (buf2); |
---|
2416 | } |
---|
2417 | } |
---|
2418 | } |
---|
2419 | if (degree (F) <= 0) |
---|
2420 | return; |
---|
2421 | if (factorsFound + 1 == nmod_mat_nrows (N)) |
---|
2422 | { |
---|
2423 | CanonicalForm tmp= F (y - evaluation, y); |
---|
2424 | tmp= mapDown (tmp, info, source, dest); |
---|
2425 | reconstructedFactors.append (tmp); |
---|
2426 | return; |
---|
2427 | } |
---|
2428 | } |
---|
2429 | } |
---|
2430 | #endif |
---|
2431 | |
---|
2432 | #ifndef HAVE_FLINT |
---|
2433 | //over Fp |
---|
2434 | int |
---|
2435 | liftAndComputeLattice (const CanonicalForm& F, int* bounds, int sizeBounds, int |
---|
2436 | start, int liftBound, int minBound, CFList& factors, |
---|
2437 | mat_zz_p& NTLN, CFList& diophant, CFMatrix& M, CFArray& |
---|
2438 | Pi, CFArray& bufQ, bool& irreducible |
---|
2439 | ) |
---|
2440 | { |
---|
2441 | CanonicalForm LCF= LC (F, 1); |
---|
2442 | CFArray *A= new CFArray [factors.length() - 1]; |
---|
2443 | bool wasInBounds= false; |
---|
2444 | bool hitBound= false; |
---|
2445 | int l= (minBound+1)*2; |
---|
2446 | int stepSize= 2; |
---|
2447 | int oldL= l/2; |
---|
2448 | bool reduced= false; |
---|
2449 | mat_zz_p NTLK, *NTLC; |
---|
2450 | CFMatrix C; |
---|
2451 | CFArray buf; |
---|
2452 | CFListIterator j; |
---|
2453 | CanonicalForm truncF; |
---|
2454 | Variable y= F.mvar(); |
---|
2455 | while (l <= liftBound) |
---|
2456 | { |
---|
2457 | TIMING_START (fac_fq_compute_lattice_lift); |
---|
2458 | if (start) |
---|
2459 | { |
---|
2460 | henselLiftResume12 (F, factors, start, l, Pi, diophant, M); |
---|
2461 | start= 0; |
---|
2462 | } |
---|
2463 | else |
---|
2464 | { |
---|
2465 | if (wasInBounds) |
---|
2466 | henselLiftResume12 (F, factors, oldL, l, Pi, diophant, M); |
---|
2467 | else |
---|
2468 | henselLift12 (F, factors, l, Pi, diophant, M); |
---|
2469 | } |
---|
2470 | TIMING_END_AND_PRINT (fac_fq_compute_lattice_lift, |
---|
2471 | "time to lift in compute lattice: "); |
---|
2472 | |
---|
2473 | factors.insert (LCF); |
---|
2474 | j= factors; |
---|
2475 | j++; |
---|
2476 | |
---|
2477 | truncF= mod (F, power (y, l)); |
---|
2478 | TIMING_START (fac_fq_logarithmic); |
---|
2479 | for (int i= 0; i < factors.length() - 1; i++, j++) |
---|
2480 | { |
---|
2481 | if (!wasInBounds) |
---|
2482 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ[i]); |
---|
2483 | else |
---|
2484 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
2485 | bufQ[i]); |
---|
2486 | } |
---|
2487 | TIMING_END_AND_PRINT (fac_fq_logarithmic, |
---|
2488 | "time to compute logarithmic derivative: "); |
---|
2489 | |
---|
2490 | for (int i= 0; i < sizeBounds; i++) |
---|
2491 | { |
---|
2492 | if (bounds [i] + 1 <= l/2) |
---|
2493 | { |
---|
2494 | wasInBounds= true; |
---|
2495 | int k= tmin (bounds [i] + 1, l/2); |
---|
2496 | C= CFMatrix (l - k, factors.length() - 1); |
---|
2497 | for (int ii= 0; ii < factors.length() - 1; ii++) |
---|
2498 | { |
---|
2499 | if (A[ii].size() - 1 >= i) |
---|
2500 | { |
---|
2501 | buf= getCoeffs (A[ii] [i], k); |
---|
2502 | writeInMatrix (C, buf, ii + 1, 0); |
---|
2503 | } |
---|
2504 | } |
---|
2505 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
2506 | NTLK= (*NTLC)*NTLN; |
---|
2507 | transpose (NTLK, NTLK); |
---|
2508 | kernel (NTLK, NTLK); |
---|
2509 | transpose (NTLK, NTLK); |
---|
2510 | NTLN *= NTLK; |
---|
2511 | delete NTLC; |
---|
2512 | |
---|
2513 | if (NTLN.NumCols() == 1) |
---|
2514 | { |
---|
2515 | irreducible= true; |
---|
2516 | break; |
---|
2517 | } |
---|
2518 | if (isReduced (NTLN) && l > (minBound+1)*2) |
---|
2519 | { |
---|
2520 | reduced= true; |
---|
2521 | break; |
---|
2522 | } |
---|
2523 | } |
---|
2524 | } |
---|
2525 | |
---|
2526 | if (irreducible) |
---|
2527 | break; |
---|
2528 | if (reduced) |
---|
2529 | break; |
---|
2530 | oldL= l; |
---|
2531 | l += stepSize; |
---|
2532 | stepSize *= 2; |
---|
2533 | if (l > liftBound) |
---|
2534 | { |
---|
2535 | if (!hitBound) |
---|
2536 | { |
---|
2537 | l= liftBound; |
---|
2538 | hitBound= true; |
---|
2539 | } |
---|
2540 | else |
---|
2541 | break; |
---|
2542 | } |
---|
2543 | } |
---|
2544 | delete [] A; |
---|
2545 | if (!wasInBounds) |
---|
2546 | { |
---|
2547 | if (start) |
---|
2548 | henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); |
---|
2549 | else |
---|
2550 | henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); |
---|
2551 | factors.insert (LCF); |
---|
2552 | } |
---|
2553 | return l; |
---|
2554 | } |
---|
2555 | #endif |
---|
2556 | |
---|
2557 | #ifdef HAVE_FLINT |
---|
2558 | int |
---|
2559 | liftAndComputeLattice (const CanonicalForm& F, int* bounds, int sizeBounds, int |
---|
2560 | start, int liftBound, int minBound, CFList& factors, |
---|
2561 | nmod_mat_t FLINTN, CFList& diophant, CFMatrix& M,CFArray& |
---|
2562 | Pi, CFArray& bufQ, bool& irreducible |
---|
2563 | ) |
---|
2564 | { |
---|
2565 | CanonicalForm LCF= LC (F, 1); |
---|
2566 | CFArray *A= new CFArray [factors.length() - 1]; |
---|
2567 | bool wasInBounds= false; |
---|
2568 | bool hitBound= false; |
---|
2569 | int l= (minBound+1)*2; |
---|
2570 | int stepSize= 2; |
---|
2571 | int oldL= l/2; |
---|
2572 | bool reduced= false; |
---|
2573 | long rank; |
---|
2574 | nmod_mat_t FLINTK, FLINTC, null; |
---|
2575 | CFMatrix C; |
---|
2576 | CFArray buf; |
---|
2577 | CFListIterator j; |
---|
2578 | CanonicalForm truncF; |
---|
2579 | Variable y= F.mvar(); |
---|
2580 | while (l <= liftBound) |
---|
2581 | { |
---|
2582 | TIMING_START (fac_fq_compute_lattice_lift); |
---|
2583 | if (start) |
---|
2584 | { |
---|
2585 | henselLiftResume12 (F, factors, start, l, Pi, diophant, M); |
---|
2586 | start= 0; |
---|
2587 | } |
---|
2588 | else |
---|
2589 | { |
---|
2590 | if (wasInBounds) |
---|
2591 | henselLiftResume12 (F, factors, oldL, l, Pi, diophant, M); |
---|
2592 | else |
---|
2593 | henselLift12 (F, factors, l, Pi, diophant, M); |
---|
2594 | } |
---|
2595 | TIMING_END_AND_PRINT (fac_fq_compute_lattice_lift, |
---|
2596 | "time to lift in compute lattice: "); |
---|
2597 | |
---|
2598 | factors.insert (LCF); |
---|
2599 | j= factors; |
---|
2600 | j++; |
---|
2601 | |
---|
2602 | truncF= mod (F, power (y, l)); |
---|
2603 | TIMING_START (fac_fq_logarithmic); |
---|
2604 | for (int i= 0; i < factors.length() - 1; i++, j++) |
---|
2605 | { |
---|
2606 | if (!wasInBounds) |
---|
2607 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ[i]); |
---|
2608 | else |
---|
2609 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
2610 | bufQ[i]); |
---|
2611 | } |
---|
2612 | TIMING_END_AND_PRINT (fac_fq_logarithmic, |
---|
2613 | "time to compute logarithmic derivative: "); |
---|
2614 | |
---|
2615 | for (int i= 0; i < sizeBounds; i++) |
---|
2616 | { |
---|
2617 | if (bounds [i] + 1 <= l/2) |
---|
2618 | { |
---|
2619 | wasInBounds= true; |
---|
2620 | int k= tmin (bounds [i] + 1, l/2); |
---|
2621 | C= CFMatrix (l - k, factors.length() - 1); |
---|
2622 | for (int ii= 0; ii < factors.length() - 1; ii++) |
---|
2623 | { |
---|
2624 | if (A[ii].size() - 1 >= i) |
---|
2625 | { |
---|
2626 | buf= getCoeffs (A[ii] [i], k); |
---|
2627 | writeInMatrix (C, buf, ii + 1, 0); |
---|
2628 | } |
---|
2629 | } |
---|
2630 | |
---|
2631 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
2632 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
2633 | getCharacteristic()); |
---|
2634 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
2635 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
2636 | getCharacteristic()); |
---|
2637 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
2638 | nmod_mat_clear (FLINTK); |
---|
2639 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
2640 | nmod_mat_clear (FLINTC); |
---|
2641 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
2642 | nmod_mat_clear (FLINTN); |
---|
2643 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
2644 | getCharacteristic()); |
---|
2645 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
2646 | |
---|
2647 | nmod_mat_clear (FLINTC); |
---|
2648 | nmod_mat_window_clear (FLINTK); |
---|
2649 | nmod_mat_clear (null); |
---|
2650 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
2651 | { |
---|
2652 | irreducible= true; |
---|
2653 | break; |
---|
2654 | } |
---|
2655 | if (isReduced (FLINTN) && l > (minBound+1)*2) |
---|
2656 | { |
---|
2657 | reduced= true; |
---|
2658 | break; |
---|
2659 | } |
---|
2660 | } |
---|
2661 | } |
---|
2662 | |
---|
2663 | if (irreducible) |
---|
2664 | break; |
---|
2665 | if (reduced) |
---|
2666 | break; |
---|
2667 | oldL= l; |
---|
2668 | l += stepSize; |
---|
2669 | stepSize *= 2; |
---|
2670 | if (l > liftBound) |
---|
2671 | { |
---|
2672 | if (!hitBound) |
---|
2673 | { |
---|
2674 | l= liftBound; |
---|
2675 | hitBound= true; |
---|
2676 | } |
---|
2677 | else |
---|
2678 | break; |
---|
2679 | } |
---|
2680 | } |
---|
2681 | delete [] A; |
---|
2682 | if (!wasInBounds) |
---|
2683 | { |
---|
2684 | if (start) |
---|
2685 | henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); |
---|
2686 | else |
---|
2687 | henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); |
---|
2688 | factors.insert (LCF); |
---|
2689 | } |
---|
2690 | return l; |
---|
2691 | } |
---|
2692 | #endif |
---|
2693 | |
---|
2694 | #ifndef HAVE_FLINT |
---|
2695 | //over field extension |
---|
2696 | int |
---|
2697 | extLiftAndComputeLattice (const CanonicalForm& F, int* bounds, int sizeBounds, |
---|
2698 | int liftBound, int minBound, int start, CFList& |
---|
2699 | factors, mat_zz_p& NTLN, CFList& diophant, |
---|
2700 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, bool& |
---|
2701 | irreducible, const CanonicalForm& evaluation, const |
---|
2702 | ExtensionInfo& info, CFList& source, CFList& dest |
---|
2703 | ) |
---|
2704 | { |
---|
2705 | bool GF= (CFFactory::gettype()==GaloisFieldDomain); |
---|
2706 | CanonicalForm LCF= LC (F, 1); |
---|
2707 | CFArray *A= new CFArray [factors.length() - 1]; |
---|
2708 | bool wasInBounds= false; |
---|
2709 | bool hitBound= false; |
---|
2710 | int degMipo; |
---|
2711 | Variable alpha; |
---|
2712 | alpha= info.getAlpha(); |
---|
2713 | degMipo= degree (getMipo (alpha)); |
---|
2714 | |
---|
2715 | Variable gamma= info.getBeta(); |
---|
2716 | CanonicalForm primElemAlpha= info.getGamma(); |
---|
2717 | CanonicalForm imPrimElemAlpha= info.getDelta(); |
---|
2718 | |
---|
2719 | int stepSize= 2; |
---|
2720 | int l= ((minBound+1)/degMipo+1)*2; |
---|
2721 | l= tmax (l, 2); |
---|
2722 | if (start > l) |
---|
2723 | l= start; |
---|
2724 | int oldL= l/2; |
---|
2725 | bool reduced= false; |
---|
2726 | Variable y= F.mvar(); |
---|
2727 | Variable x= Variable (1); |
---|
2728 | CanonicalForm powX, imBasis, truncF; |
---|
2729 | CFMatrix Mat, C; |
---|
2730 | CFArray buf; |
---|
2731 | CFIterator iter; |
---|
2732 | mat_zz_p* NTLMat, *NTLC, NTLK; |
---|
2733 | CFListIterator j; |
---|
2734 | while (l <= liftBound) |
---|
2735 | { |
---|
2736 | TIMING_START (fac_fq_compute_lattice_lift); |
---|
2737 | if (start) |
---|
2738 | { |
---|
2739 | henselLiftResume12 (F, factors, start, l, Pi, diophant, M); |
---|
2740 | start= 0; |
---|
2741 | } |
---|
2742 | else |
---|
2743 | { |
---|
2744 | if (wasInBounds) |
---|
2745 | henselLiftResume12 (F, factors, oldL, l, Pi, diophant, M); |
---|
2746 | else |
---|
2747 | henselLift12 (F, factors, l, Pi, diophant, M); |
---|
2748 | } |
---|
2749 | TIMING_END_AND_PRINT (fac_fq_compute_lattice_lift, |
---|
2750 | "time to lift in compute lattice: "); |
---|
2751 | |
---|
2752 | factors.insert (LCF); |
---|
2753 | |
---|
2754 | if (GF) |
---|
2755 | setCharacteristic (getCharacteristic()); |
---|
2756 | |
---|
2757 | powX= power (y-gamma, l); |
---|
2758 | Mat= CFMatrix (l*degMipo, l*degMipo); |
---|
2759 | for (int i= 0; i < l*degMipo; i++) |
---|
2760 | { |
---|
2761 | imBasis= mod (power (y, i), powX); |
---|
2762 | imBasis= imBasis (power (y, degMipo), y); |
---|
2763 | imBasis= imBasis (y, gamma); |
---|
2764 | iter= imBasis; |
---|
2765 | for (; iter.hasTerms(); iter++) |
---|
2766 | Mat (iter.exp()+ 1, i+1)= iter.coeff(); |
---|
2767 | } |
---|
2768 | |
---|
2769 | NTLMat= convertFacCFMatrix2NTLmat_zz_p (Mat); |
---|
2770 | *NTLMat= inv (*NTLMat); |
---|
2771 | |
---|
2772 | if (GF) |
---|
2773 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
2774 | |
---|
2775 | j= factors; |
---|
2776 | j++; |
---|
2777 | |
---|
2778 | truncF= mod (F, power (y, l)); |
---|
2779 | TIMING_START (fac_fq_logarithmic); |
---|
2780 | for (int i= 0; i < factors.length() - 1; i++, j++) |
---|
2781 | { |
---|
2782 | if (!wasInBounds) |
---|
2783 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ[i]); |
---|
2784 | else |
---|
2785 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
2786 | bufQ[i]); |
---|
2787 | } |
---|
2788 | TIMING_END_AND_PRINT (fac_fq_logarithmic, |
---|
2789 | "time to compute logarithmic derivative: "); |
---|
2790 | |
---|
2791 | for (int i= 0; i < sizeBounds; i++) |
---|
2792 | { |
---|
2793 | if (bounds [i] + 1 <= (l/2)*degMipo) |
---|
2794 | { |
---|
2795 | wasInBounds= true; |
---|
2796 | int k= tmin (bounds [i] + 1, (l/2)*degMipo); |
---|
2797 | C= CFMatrix (l*degMipo - k, factors.length() - 1); |
---|
2798 | |
---|
2799 | for (int ii= 0; ii < factors.length() - 1; ii++) |
---|
2800 | { |
---|
2801 | if (A[ii].size() - 1 >= i) |
---|
2802 | { |
---|
2803 | if (GF) |
---|
2804 | { |
---|
2805 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
2806 | setCharacteristic (getCharacteristic()); |
---|
2807 | A[ii] [i]= GF2FalphaRep (A[ii] [i], alpha); |
---|
2808 | if (alpha != gamma) |
---|
2809 | A [ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
2810 | gamma, source, dest |
---|
2811 | ); |
---|
2812 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, *NTLMat); |
---|
2813 | } |
---|
2814 | else |
---|
2815 | { |
---|
2816 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
2817 | if (alpha != gamma) |
---|
2818 | A[ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
2819 | gamma, source, dest |
---|
2820 | ); |
---|
2821 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, *NTLMat); |
---|
2822 | } |
---|
2823 | writeInMatrix (C, buf, ii + 1, 0); |
---|
2824 | } |
---|
2825 | if (GF) |
---|
2826 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
2827 | } |
---|
2828 | |
---|
2829 | if (GF) |
---|
2830 | setCharacteristic(getCharacteristic()); |
---|
2831 | |
---|
2832 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
2833 | NTLK= (*NTLC)*NTLN; |
---|
2834 | transpose (NTLK, NTLK); |
---|
2835 | kernel (NTLK, NTLK); |
---|
2836 | transpose (NTLK, NTLK); |
---|
2837 | NTLN *= NTLK; |
---|
2838 | delete NTLC; |
---|
2839 | |
---|
2840 | if (GF) |
---|
2841 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
2842 | |
---|
2843 | if (NTLN.NumCols() == 1) |
---|
2844 | { |
---|
2845 | irreducible= true; |
---|
2846 | break; |
---|
2847 | } |
---|
2848 | if (isReduced (NTLN)) |
---|
2849 | { |
---|
2850 | reduced= true; |
---|
2851 | break; |
---|
2852 | } |
---|
2853 | } |
---|
2854 | } |
---|
2855 | |
---|
2856 | delete NTLMat; |
---|
2857 | |
---|
2858 | if (NTLN.NumCols() == 1) |
---|
2859 | { |
---|
2860 | irreducible= true; |
---|
2861 | break; |
---|
2862 | } |
---|
2863 | if (reduced) |
---|
2864 | break; |
---|
2865 | oldL= l; |
---|
2866 | l += stepSize; |
---|
2867 | stepSize *= 2; |
---|
2868 | if (l > liftBound) |
---|
2869 | { |
---|
2870 | if (!hitBound) |
---|
2871 | { |
---|
2872 | l= liftBound; |
---|
2873 | hitBound= true; |
---|
2874 | } |
---|
2875 | else |
---|
2876 | break; |
---|
2877 | } |
---|
2878 | } |
---|
2879 | delete [] A; |
---|
2880 | if (!wasInBounds) |
---|
2881 | { |
---|
2882 | if (start) |
---|
2883 | henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); |
---|
2884 | else |
---|
2885 | henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); |
---|
2886 | factors.insert (LCF); |
---|
2887 | } |
---|
2888 | return l; |
---|
2889 | } |
---|
2890 | #endif |
---|
2891 | |
---|
2892 | #ifdef HAVE_FLINT |
---|
2893 | //over field extension |
---|
2894 | int |
---|
2895 | extLiftAndComputeLattice (const CanonicalForm& F, int* bounds, int sizeBounds, |
---|
2896 | int liftBound, int minBound, int start, CFList& |
---|
2897 | factors, nmod_mat_t FLINTN, CFList& diophant, |
---|
2898 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, bool& |
---|
2899 | irreducible, const CanonicalForm& evaluation, const |
---|
2900 | ExtensionInfo& info, CFList& source, CFList& dest |
---|
2901 | ) |
---|
2902 | { |
---|
2903 | bool GF= (CFFactory::gettype()==GaloisFieldDomain); |
---|
2904 | CanonicalForm LCF= LC (F, 1); |
---|
2905 | CFArray *A= new CFArray [factors.length() - 1]; |
---|
2906 | bool wasInBounds= false; |
---|
2907 | bool hitBound= false; |
---|
2908 | int degMipo; |
---|
2909 | Variable alpha; |
---|
2910 | alpha= info.getAlpha(); |
---|
2911 | degMipo= degree (getMipo (alpha)); |
---|
2912 | |
---|
2913 | Variable gamma= info.getBeta(); |
---|
2914 | CanonicalForm primElemAlpha= info.getGamma(); |
---|
2915 | CanonicalForm imPrimElemAlpha= info.getDelta(); |
---|
2916 | |
---|
2917 | int stepSize= 2; |
---|
2918 | int l= ((minBound+1)/degMipo+1)*2; |
---|
2919 | l= tmax (l, 2); |
---|
2920 | if (start > l) |
---|
2921 | l= start; |
---|
2922 | int oldL= l/2; |
---|
2923 | bool reduced= false; |
---|
2924 | Variable y= F.mvar(); |
---|
2925 | Variable x= Variable (1); |
---|
2926 | CanonicalForm powX, imBasis, truncF; |
---|
2927 | CFMatrix Mat, C; |
---|
2928 | CFArray buf; |
---|
2929 | CFIterator iter; |
---|
2930 | long rank; |
---|
2931 | nmod_mat_t FLINTMat, FLINTMatInv, FLINTC, FLINTK, null; |
---|
2932 | CFListIterator j; |
---|
2933 | while (l <= liftBound) |
---|
2934 | { |
---|
2935 | if (start) |
---|
2936 | { |
---|
2937 | henselLiftResume12 (F, factors, start, l, Pi, diophant, M); |
---|
2938 | start= 0; |
---|
2939 | } |
---|
2940 | else |
---|
2941 | { |
---|
2942 | if (wasInBounds) |
---|
2943 | henselLiftResume12 (F, factors, oldL, l, Pi, diophant, M); |
---|
2944 | else |
---|
2945 | henselLift12 (F, factors, l, Pi, diophant, M); |
---|
2946 | } |
---|
2947 | |
---|
2948 | factors.insert (LCF); |
---|
2949 | |
---|
2950 | if (GF) |
---|
2951 | setCharacteristic (getCharacteristic()); |
---|
2952 | |
---|
2953 | powX= power (y-gamma, l); |
---|
2954 | Mat= CFMatrix (l*degMipo, l*degMipo); |
---|
2955 | for (int i= 0; i < l*degMipo; i++) |
---|
2956 | { |
---|
2957 | imBasis= mod (power (y, i), powX); |
---|
2958 | imBasis= imBasis (power (y, degMipo), y); |
---|
2959 | imBasis= imBasis (y, gamma); |
---|
2960 | iter= imBasis; |
---|
2961 | for (; iter.hasTerms(); iter++) |
---|
2962 | Mat (iter.exp()+ 1, i+1)= iter.coeff(); |
---|
2963 | } |
---|
2964 | |
---|
2965 | convertFacCFMatrix2nmod_mat_t (FLINTMat, Mat); |
---|
2966 | nmod_mat_init (FLINTMatInv, nmod_mat_nrows (FLINTMat), |
---|
2967 | nmod_mat_nrows (FLINTMat), getCharacteristic()); |
---|
2968 | nmod_mat_inv (FLINTMatInv, FLINTMat); |
---|
2969 | |
---|
2970 | if (GF) |
---|
2971 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
2972 | |
---|
2973 | j= factors; |
---|
2974 | j++; |
---|
2975 | |
---|
2976 | truncF= mod (F, power (y, l)); |
---|
2977 | for (int i= 0; i < factors.length() - 1; i++, j++) |
---|
2978 | { |
---|
2979 | if (!wasInBounds) |
---|
2980 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ[i]); |
---|
2981 | else |
---|
2982 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
2983 | bufQ[i]); |
---|
2984 | } |
---|
2985 | |
---|
2986 | for (int i= 0; i < sizeBounds; i++) |
---|
2987 | { |
---|
2988 | if (bounds [i] + 1 <= (l/2)*degMipo) |
---|
2989 | { |
---|
2990 | wasInBounds= true; |
---|
2991 | int k= tmin (bounds [i] + 1, (l/2)*degMipo); |
---|
2992 | C= CFMatrix (l*degMipo - k, factors.length() - 1); |
---|
2993 | |
---|
2994 | for (int ii= 0; ii < factors.length() - 1; ii++) |
---|
2995 | { |
---|
2996 | if (A[ii].size() - 1 >= i) |
---|
2997 | { |
---|
2998 | if (GF) |
---|
2999 | { |
---|
3000 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
3001 | setCharacteristic (getCharacteristic()); |
---|
3002 | A[ii] [i]= GF2FalphaRep (A[ii] [i], alpha); |
---|
3003 | if (alpha != gamma) |
---|
3004 | A [ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
3005 | gamma, source, dest |
---|
3006 | ); |
---|
3007 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, FLINTMatInv); |
---|
3008 | } |
---|
3009 | else |
---|
3010 | { |
---|
3011 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
3012 | if (alpha != gamma) |
---|
3013 | A[ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
3014 | gamma, source, dest |
---|
3015 | ); |
---|
3016 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, FLINTMatInv); |
---|
3017 | } |
---|
3018 | writeInMatrix (C, buf, ii + 1, 0); |
---|
3019 | } |
---|
3020 | if (GF) |
---|
3021 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
3022 | } |
---|
3023 | |
---|
3024 | if (GF) |
---|
3025 | setCharacteristic(getCharacteristic()); |
---|
3026 | |
---|
3027 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
3028 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
3029 | getCharacteristic()); |
---|
3030 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
3031 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
3032 | getCharacteristic()); |
---|
3033 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
3034 | nmod_mat_clear (FLINTK); |
---|
3035 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
3036 | nmod_mat_clear (FLINTC); |
---|
3037 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
3038 | nmod_mat_clear (FLINTN); |
---|
3039 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
3040 | getCharacteristic()); |
---|
3041 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
3042 | |
---|
3043 | nmod_mat_clear (FLINTC); |
---|
3044 | nmod_mat_window_clear (FLINTK); |
---|
3045 | nmod_mat_clear (null); |
---|
3046 | |
---|
3047 | if (GF) |
---|
3048 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
3049 | |
---|
3050 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
3051 | { |
---|
3052 | irreducible= true; |
---|
3053 | break; |
---|
3054 | } |
---|
3055 | if (isReduced (FLINTN)) |
---|
3056 | { |
---|
3057 | reduced= true; |
---|
3058 | break; |
---|
3059 | } |
---|
3060 | } |
---|
3061 | } |
---|
3062 | |
---|
3063 | nmod_mat_clear (FLINTMat); |
---|
3064 | nmod_mat_clear (FLINTMatInv); |
---|
3065 | |
---|
3066 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
3067 | { |
---|
3068 | irreducible= true; |
---|
3069 | break; |
---|
3070 | } |
---|
3071 | if (reduced) |
---|
3072 | break; |
---|
3073 | oldL= l; |
---|
3074 | l += stepSize; |
---|
3075 | stepSize *= 2; |
---|
3076 | if (l > liftBound) |
---|
3077 | { |
---|
3078 | if (!hitBound) |
---|
3079 | { |
---|
3080 | l= liftBound; |
---|
3081 | hitBound= true; |
---|
3082 | } |
---|
3083 | else |
---|
3084 | break; |
---|
3085 | } |
---|
3086 | } |
---|
3087 | delete [] A; |
---|
3088 | if (!wasInBounds) |
---|
3089 | { |
---|
3090 | if (start) |
---|
3091 | henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); |
---|
3092 | else |
---|
3093 | henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); |
---|
3094 | factors.insert (LCF); |
---|
3095 | } |
---|
3096 | return l; |
---|
3097 | } |
---|
3098 | #endif |
---|
3099 | |
---|
3100 | // over Fq |
---|
3101 | int |
---|
3102 | liftAndComputeLattice (const CanonicalForm& F, int* bounds, int sizeBounds, |
---|
3103 | int start, int liftBound, int minBound, CFList& factors, |
---|
3104 | mat_zz_pE& NTLN, CFList& diophant, CFMatrix& M, CFArray& |
---|
3105 | Pi, CFArray& bufQ, bool& irreducible |
---|
3106 | ) |
---|
3107 | { |
---|
3108 | CanonicalForm LCF= LC (F, 1); |
---|
3109 | CFArray *A= new CFArray [factors.length() - 1]; |
---|
3110 | bool wasInBounds= false; |
---|
3111 | bool hitBound= false; |
---|
3112 | int l= (minBound+1)*2; |
---|
3113 | int stepSize= 2; |
---|
3114 | int oldL= l/2; |
---|
3115 | bool reduced= false; |
---|
3116 | CFListIterator j; |
---|
3117 | mat_zz_pE* NTLC, NTLK; |
---|
3118 | CFArray buf; |
---|
3119 | CFMatrix C; |
---|
3120 | Variable y= F.mvar(); |
---|
3121 | CanonicalForm truncF; |
---|
3122 | while (l <= liftBound) |
---|
3123 | { |
---|
3124 | TIMING_START (fac_fq_compute_lattice_lift); |
---|
3125 | if (start) |
---|
3126 | { |
---|
3127 | henselLiftResume12 (F, factors, start, l, Pi, diophant, M); |
---|
3128 | start= 0; |
---|
3129 | } |
---|
3130 | else |
---|
3131 | { |
---|
3132 | if (wasInBounds) |
---|
3133 | henselLiftResume12 (F, factors, oldL, l, Pi, diophant, M); |
---|
3134 | else |
---|
3135 | henselLift12 (F, factors, l, Pi, diophant, M); |
---|
3136 | } |
---|
3137 | TIMING_END_AND_PRINT (fac_fq_compute_lattice_lift, |
---|
3138 | "time to lift in compute lattice: "); |
---|
3139 | |
---|
3140 | factors.insert (LCF); |
---|
3141 | j= factors; |
---|
3142 | j++; |
---|
3143 | |
---|
3144 | truncF= mod (F, power (y,l)); |
---|
3145 | TIMING_START (fac_fq_logarithmic); |
---|
3146 | for (int i= 0; i < factors.length() - 1; i++, j++) |
---|
3147 | { |
---|
3148 | if (l == (minBound+1)*2) |
---|
3149 | { |
---|
3150 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ[i]); |
---|
3151 | } |
---|
3152 | else |
---|
3153 | { |
---|
3154 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
3155 | bufQ[i] |
---|
3156 | ); |
---|
3157 | } |
---|
3158 | } |
---|
3159 | TIMING_END_AND_PRINT (fac_fq_logarithmic, |
---|
3160 | "time to compute logarithmic derivative: "); |
---|
3161 | |
---|
3162 | for (int i= 0; i < sizeBounds; i++) |
---|
3163 | { |
---|
3164 | if (bounds [i] + 1 <= l/2) |
---|
3165 | { |
---|
3166 | wasInBounds= true; |
---|
3167 | int k= tmin (bounds [i] + 1, l/2); |
---|
3168 | C= CFMatrix (l - k, factors.length() - 1); |
---|
3169 | for (int ii= 0; ii < factors.length() - 1; ii++) |
---|
3170 | { |
---|
3171 | |
---|
3172 | if (A[ii].size() - 1 >= i) |
---|
3173 | { |
---|
3174 | buf= getCoeffs (A[ii] [i], k); |
---|
3175 | writeInMatrix (C, buf, ii + 1, 0); |
---|
3176 | } |
---|
3177 | } |
---|
3178 | |
---|
3179 | NTLC= convertFacCFMatrix2NTLmat_zz_pE(C); |
---|
3180 | NTLK= (*NTLC)*NTLN; |
---|
3181 | transpose (NTLK, NTLK); |
---|
3182 | kernel (NTLK, NTLK); |
---|
3183 | transpose (NTLK, NTLK); |
---|
3184 | NTLN *= NTLK; |
---|
3185 | delete NTLC; |
---|
3186 | |
---|
3187 | if (NTLN.NumCols() == 1) |
---|
3188 | { |
---|
3189 | irreducible= true; |
---|
3190 | break; |
---|
3191 | } |
---|
3192 | if (isReduced (NTLN) && l > (minBound+1)*2) |
---|
3193 | { |
---|
3194 | reduced= true; |
---|
3195 | break; |
---|
3196 | } |
---|
3197 | } |
---|
3198 | } |
---|
3199 | |
---|
3200 | if (NTLN.NumCols() == 1) |
---|
3201 | { |
---|
3202 | irreducible= true; |
---|
3203 | break; |
---|
3204 | } |
---|
3205 | if (reduced) |
---|
3206 | break; |
---|
3207 | oldL= l; |
---|
3208 | l += stepSize; |
---|
3209 | stepSize *= 2; |
---|
3210 | if (l > liftBound) |
---|
3211 | { |
---|
3212 | if (!hitBound) |
---|
3213 | { |
---|
3214 | l= liftBound; |
---|
3215 | hitBound= true; |
---|
3216 | } |
---|
3217 | else |
---|
3218 | break; |
---|
3219 | } |
---|
3220 | } |
---|
3221 | delete [] A; |
---|
3222 | if (!wasInBounds) |
---|
3223 | { |
---|
3224 | if (start) |
---|
3225 | henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); |
---|
3226 | else |
---|
3227 | henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); |
---|
3228 | factors.insert (LCF); |
---|
3229 | } |
---|
3230 | return l; |
---|
3231 | } |
---|
3232 | |
---|
3233 | #ifdef HAVE_FLINT |
---|
3234 | int |
---|
3235 | liftAndComputeLatticeFq2Fp (const CanonicalForm& F, int* bounds, int sizeBounds, |
---|
3236 | int start, int liftBound, int minBound, CFList& |
---|
3237 | factors, nmod_mat_t FLINTN, CFList& diophant, |
---|
3238 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, bool& |
---|
3239 | irreducible, const Variable& alpha |
---|
3240 | ) |
---|
3241 | #else |
---|
3242 | int |
---|
3243 | liftAndComputeLatticeFq2Fp (const CanonicalForm& F, int* bounds, int sizeBounds, |
---|
3244 | int start, int liftBound, int minBound, CFList& |
---|
3245 | factors, mat_zz_p& NTLN, CFList& diophant, CFMatrix& |
---|
3246 | M, CFArray& Pi, CFArray& bufQ, bool& irreducible, |
---|
3247 | const Variable& alpha |
---|
3248 | ) |
---|
3249 | #endif |
---|
3250 | { |
---|
3251 | CanonicalForm LCF= LC (F, 1); |
---|
3252 | CFArray *A= new CFArray [factors.length() - 1]; |
---|
3253 | bool wasInBounds= false; |
---|
3254 | int l= (minBound+1)*2; |
---|
3255 | int oldL= l/2; |
---|
3256 | int stepSize= 2; |
---|
3257 | bool hitBound= false; |
---|
3258 | int extensionDeg= degree (getMipo (alpha)); |
---|
3259 | bool reduced= false; |
---|
3260 | CFListIterator j; |
---|
3261 | CFMatrix C; |
---|
3262 | CFArray buf; |
---|
3263 | #ifdef HAVE_FLINT |
---|
3264 | long rank; |
---|
3265 | nmod_mat_t FLINTC, FLINTK, null; |
---|
3266 | #else |
---|
3267 | mat_zz_p* NTLC, NTLK; |
---|
3268 | #endif |
---|
3269 | Variable y= F.mvar(); |
---|
3270 | CanonicalForm truncF; |
---|
3271 | while (l <= liftBound) |
---|
3272 | { |
---|
3273 | TIMING_START (fac_fq_compute_lattice_lift); |
---|
3274 | if (start) |
---|
3275 | { |
---|
3276 | henselLiftResume12 (F, factors, start, l, Pi, diophant, M); |
---|
3277 | start= 0; |
---|
3278 | } |
---|
3279 | else |
---|
3280 | { |
---|
3281 | if (wasInBounds) |
---|
3282 | henselLiftResume12 (F, factors, oldL, l, Pi, diophant, M); |
---|
3283 | else |
---|
3284 | henselLift12 (F, factors, l, Pi, diophant, M); |
---|
3285 | } |
---|
3286 | TIMING_END_AND_PRINT (fac_fq_compute_lattice_lift, |
---|
3287 | "time to lift in compute lattice: "); |
---|
3288 | |
---|
3289 | factors.insert (LCF); |
---|
3290 | j= factors; |
---|
3291 | j++; |
---|
3292 | |
---|
3293 | truncF= mod (F, power (y,l)); |
---|
3294 | TIMING_START (fac_fq_logarithmic); |
---|
3295 | for (int i= 0; i < factors.length() - 1; i++, j++) |
---|
3296 | { |
---|
3297 | if (l == (minBound+1)*2) |
---|
3298 | { |
---|
3299 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ[i]); |
---|
3300 | } |
---|
3301 | else |
---|
3302 | { |
---|
3303 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
3304 | bufQ[i] |
---|
3305 | ); |
---|
3306 | } |
---|
3307 | } |
---|
3308 | TIMING_END_AND_PRINT (fac_fq_logarithmic, |
---|
3309 | "time to compute logarithmic derivative: "); |
---|
3310 | |
---|
3311 | for (int i= 0; i < sizeBounds; i++) |
---|
3312 | { |
---|
3313 | if (bounds [i] + 1 <= l/2) |
---|
3314 | { |
---|
3315 | wasInBounds= true; |
---|
3316 | int k= tmin (bounds [i] + 1, l/2); |
---|
3317 | C= CFMatrix ((l - k)*extensionDeg, factors.length() - 1); |
---|
3318 | for (int ii= 0; ii < factors.length() - 1; ii++) |
---|
3319 | { |
---|
3320 | if (A[ii].size() - 1 >= i) |
---|
3321 | { |
---|
3322 | buf= getCoeffs (A[ii] [i], k, alpha); |
---|
3323 | writeInMatrix (C, buf, ii + 1, 0); |
---|
3324 | } |
---|
3325 | } |
---|
3326 | |
---|
3327 | #ifdef HAVE_FLINT |
---|
3328 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
3329 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
3330 | getCharacteristic()); |
---|
3331 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
3332 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
3333 | getCharacteristic()); |
---|
3334 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
3335 | nmod_mat_clear (FLINTK); |
---|
3336 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
3337 | nmod_mat_clear (FLINTC); |
---|
3338 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
3339 | nmod_mat_clear (FLINTN); |
---|
3340 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
3341 | getCharacteristic()); |
---|
3342 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
3343 | |
---|
3344 | nmod_mat_clear (FLINTC); |
---|
3345 | nmod_mat_window_clear (FLINTK); |
---|
3346 | nmod_mat_clear (null); |
---|
3347 | #else |
---|
3348 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
3349 | NTLK= (*NTLC)*NTLN; |
---|
3350 | transpose (NTLK, NTLK); |
---|
3351 | kernel (NTLK, NTLK); |
---|
3352 | transpose (NTLK, NTLK); |
---|
3353 | NTLN *= NTLK; |
---|
3354 | delete NTLC; |
---|
3355 | #endif |
---|
3356 | |
---|
3357 | #ifdef HAVE_FLINT |
---|
3358 | if (nmod_mat_nrows (FLINTN) == 1) |
---|
3359 | #else |
---|
3360 | if (NTLN.NumCols() == 1) |
---|
3361 | #endif |
---|
3362 | { |
---|
3363 | irreducible= true; |
---|
3364 | break; |
---|
3365 | } |
---|
3366 | #ifdef HAVE_FLINT |
---|
3367 | if (isReduced (FLINTN) && l > (minBound+1)*2) |
---|
3368 | #else |
---|
3369 | if (isReduced (NTLN) && l > (minBound+1)*2) |
---|
3370 | #endif |
---|
3371 | { |
---|
3372 | reduced= true; |
---|
3373 | break; |
---|
3374 | } |
---|
3375 | } |
---|
3376 | } |
---|
3377 | |
---|
3378 | #ifdef HAVE_FLINT |
---|
3379 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
3380 | #else |
---|
3381 | if (NTLN.NumCols() == 1) |
---|
3382 | #endif |
---|
3383 | { |
---|
3384 | irreducible= true; |
---|
3385 | break; |
---|
3386 | } |
---|
3387 | if (reduced) |
---|
3388 | break; |
---|
3389 | oldL= l; |
---|
3390 | l += stepSize; |
---|
3391 | stepSize *= 2; |
---|
3392 | if (l > liftBound) |
---|
3393 | { |
---|
3394 | if (!hitBound) |
---|
3395 | { |
---|
3396 | l= liftBound; |
---|
3397 | hitBound= true; |
---|
3398 | } |
---|
3399 | else |
---|
3400 | break; |
---|
3401 | } |
---|
3402 | } |
---|
3403 | delete [] A; |
---|
3404 | if (!wasInBounds) |
---|
3405 | { |
---|
3406 | if (start) |
---|
3407 | henselLiftResume12 (F, factors, start, degree (F) + 1, Pi, diophant, M); |
---|
3408 | else |
---|
3409 | henselLift12 (F, factors, degree (F) + 1, Pi, diophant, M); |
---|
3410 | factors.insert (LCF); |
---|
3411 | } |
---|
3412 | return l; |
---|
3413 | } |
---|
3414 | |
---|
3415 | CFList |
---|
3416 | increasePrecision (CanonicalForm& F, CFList& factors, int factorsFound, |
---|
3417 | int oldNumCols, int oldL, int precision, |
---|
3418 | const CanonicalForm& eval |
---|
3419 | ) |
---|
3420 | { |
---|
3421 | int d; |
---|
3422 | bool isIrreducible= false; |
---|
3423 | int* bounds= computeBounds (F, d, isIrreducible); |
---|
3424 | Variable y= F.mvar(); |
---|
3425 | if (isIrreducible) |
---|
3426 | { |
---|
3427 | delete [] bounds; |
---|
3428 | CanonicalForm G= F; |
---|
3429 | F= 1; |
---|
3430 | return CFList (G (y-eval, y)); |
---|
3431 | } |
---|
3432 | CFArray * A= new CFArray [factors.length()]; |
---|
3433 | CFArray bufQ= CFArray (factors.length()); |
---|
3434 | #ifdef HAVE_FLINT |
---|
3435 | nmod_mat_t FLINTN; |
---|
3436 | nmod_mat_init (FLINTN,factors.length(),factors.length(), getCharacteristic()); |
---|
3437 | for (long i=factors.length()-1; i >= 0; i--) |
---|
3438 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
3439 | #else |
---|
3440 | mat_zz_p NTLN; |
---|
3441 | ident (NTLN, factors.length()); |
---|
3442 | #endif |
---|
3443 | int minBound= bounds[0]; |
---|
3444 | for (int i= 1; i < d; i++) |
---|
3445 | { |
---|
3446 | if (bounds[i] != 0) |
---|
3447 | minBound= tmin (minBound, bounds[i]); |
---|
3448 | } |
---|
3449 | int l= tmax (2*(minBound + 1), oldL); |
---|
3450 | int oldL2= l/2; |
---|
3451 | int stepSize= 2; |
---|
3452 | bool useOldQs= false; |
---|
3453 | bool hitBound= false; |
---|
3454 | CFListIterator j; |
---|
3455 | CFMatrix C; |
---|
3456 | CFArray buf; |
---|
3457 | #ifdef HAVE_FLINT |
---|
3458 | long rank; |
---|
3459 | nmod_mat_t FLINTC, FLINTK, null; |
---|
3460 | #else |
---|
3461 | mat_zz_p* NTLC, NTLK; |
---|
3462 | #endif |
---|
3463 | CanonicalForm truncF; |
---|
3464 | while (l <= precision) |
---|
3465 | { |
---|
3466 | j= factors; |
---|
3467 | truncF= mod (F, power (y,l)); |
---|
3468 | if (useOldQs) |
---|
3469 | { |
---|
3470 | for (int i= 0; i < factors.length(); i++, j++) |
---|
3471 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL2, bufQ[i], |
---|
3472 | bufQ[i] |
---|
3473 | ); |
---|
3474 | } |
---|
3475 | else |
---|
3476 | { |
---|
3477 | for (int i= 0; i < factors.length(); i++, j++) |
---|
3478 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
3479 | } |
---|
3480 | useOldQs= true; |
---|
3481 | for (int i= 0; i < d; i++) |
---|
3482 | { |
---|
3483 | if (bounds [i] + 1 <= l/2) |
---|
3484 | { |
---|
3485 | int k= tmin (bounds [i] + 1, l/2); |
---|
3486 | C= CFMatrix (l - k, factors.length()); |
---|
3487 | for (int ii= 0; ii < factors.length(); ii++) |
---|
3488 | { |
---|
3489 | if (A[ii].size() - 1 >= i) |
---|
3490 | { |
---|
3491 | buf= getCoeffs (A[ii] [i], k); |
---|
3492 | writeInMatrix (C, buf, ii + 1, 0); |
---|
3493 | } |
---|
3494 | } |
---|
3495 | #ifdef HAVE_FLINT |
---|
3496 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
3497 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
3498 | getCharacteristic()); |
---|
3499 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
3500 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
3501 | getCharacteristic()); |
---|
3502 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
3503 | nmod_mat_clear (FLINTK); |
---|
3504 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
3505 | nmod_mat_clear (FLINTC); |
---|
3506 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
3507 | nmod_mat_clear (FLINTN); |
---|
3508 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
3509 | getCharacteristic()); |
---|
3510 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
3511 | |
---|
3512 | nmod_mat_clear (FLINTC); |
---|
3513 | nmod_mat_window_clear (FLINTK); |
---|
3514 | nmod_mat_clear (null); |
---|
3515 | #else |
---|
3516 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
3517 | NTLK= (*NTLC)*NTLN; |
---|
3518 | transpose (NTLK, NTLK); |
---|
3519 | kernel (NTLK, NTLK); |
---|
3520 | transpose (NTLK, NTLK); |
---|
3521 | NTLN *= NTLK; |
---|
3522 | delete NTLC; |
---|
3523 | #endif |
---|
3524 | #ifdef HAVE_FLINT |
---|
3525 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
3526 | { |
---|
3527 | nmod_mat_clear (FLINTN); |
---|
3528 | #else |
---|
3529 | if (NTLN.NumCols() == 1) |
---|
3530 | { |
---|
3531 | #endif |
---|
3532 | delete [] A; |
---|
3533 | delete [] bounds; |
---|
3534 | CanonicalForm G= F; |
---|
3535 | F= 1; |
---|
3536 | return CFList (G (y-eval,y)); |
---|
3537 | } |
---|
3538 | } |
---|
3539 | } |
---|
3540 | |
---|
3541 | #ifdef HAVE_FLINT |
---|
3542 | if (nmod_mat_ncols (FLINTN) < oldNumCols - factorsFound) |
---|
3543 | { |
---|
3544 | if (isReduced (FLINTN)) |
---|
3545 | { |
---|
3546 | int * factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)]; |
---|
3547 | for (long i= 0; i < nmod_mat_ncols (FLINTN); i++) |
---|
3548 | #else |
---|
3549 | if (NTLN.NumCols() < oldNumCols - factorsFound) |
---|
3550 | { |
---|
3551 | if (isReduced (NTLN)) |
---|
3552 | { |
---|
3553 | int * factorsFoundIndex= new int [NTLN.NumCols()]; |
---|
3554 | for (long i= 0; i < NTLN.NumCols(); i++) |
---|
3555 | #endif |
---|
3556 | factorsFoundIndex[i]= 0; |
---|
3557 | int factorsFound2= 0; |
---|
3558 | CFList result; |
---|
3559 | CanonicalForm bufF= F; |
---|
3560 | #ifdef HAVE_FLINT |
---|
3561 | reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2, |
---|
3562 | factorsFoundIndex, FLINTN, eval, false |
---|
3563 | ); |
---|
3564 | if (result.length() == nmod_mat_ncols (FLINTN)) |
---|
3565 | { |
---|
3566 | nmod_mat_clear (FLINTN); |
---|
3567 | #else |
---|
3568 | reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2, |
---|
3569 | factorsFoundIndex, NTLN, eval, false |
---|
3570 | ); |
---|
3571 | if (result.length() == NTLN.NumCols()) |
---|
3572 | { |
---|
3573 | #endif |
---|
3574 | delete [] factorsFoundIndex; |
---|
3575 | delete [] A; |
---|
3576 | delete [] bounds; |
---|
3577 | F= 1; |
---|
3578 | return result; |
---|
3579 | } |
---|
3580 | delete [] factorsFoundIndex; |
---|
3581 | } |
---|
3582 | else if (l == precision) |
---|
3583 | { |
---|
3584 | CanonicalForm bufF= F; |
---|
3585 | #ifdef HAVE_FLINT |
---|
3586 | int * zeroOne= extractZeroOneVecs (FLINTN); |
---|
3587 | CFList result= reconstruction (bufF,factors,zeroOne,precision,FLINTN, eval); |
---|
3588 | nmod_mat_clear (FLINTN); |
---|
3589 | #else |
---|
3590 | int * zeroOne= extractZeroOneVecs (NTLN); |
---|
3591 | CFList result= reconstruction (bufF, factors, zeroOne, precision, NTLN, eval); |
---|
3592 | #endif |
---|
3593 | F= bufF; |
---|
3594 | delete [] zeroOne; |
---|
3595 | delete [] A; |
---|
3596 | delete [] bounds; |
---|
3597 | return result; |
---|
3598 | } |
---|
3599 | } |
---|
3600 | oldL2= l; |
---|
3601 | l += stepSize; |
---|
3602 | stepSize *= 2; |
---|
3603 | if (l > precision) |
---|
3604 | { |
---|
3605 | if (!hitBound) |
---|
3606 | { |
---|
3607 | l= precision; |
---|
3608 | hitBound= true; |
---|
3609 | } |
---|
3610 | else |
---|
3611 | break; |
---|
3612 | } |
---|
3613 | } |
---|
3614 | #ifdef HAVE_FLINT |
---|
3615 | nmod_mat_clear (FLINTN); |
---|
3616 | #endif |
---|
3617 | delete [] bounds; |
---|
3618 | delete [] A; |
---|
3619 | return CFList(); |
---|
3620 | } |
---|
3621 | |
---|
3622 | CFList |
---|
3623 | increasePrecision (CanonicalForm& F, CFList& factors, int factorsFound, |
---|
3624 | int oldNumCols, int oldL, const Variable&, |
---|
3625 | int precision, const CanonicalForm& eval |
---|
3626 | ) |
---|
3627 | { |
---|
3628 | int d; |
---|
3629 | bool isIrreducible= false; |
---|
3630 | Variable y= F.mvar(); |
---|
3631 | int* bounds= computeBounds (F, d, isIrreducible); |
---|
3632 | if (isIrreducible) |
---|
3633 | { |
---|
3634 | delete [] bounds; |
---|
3635 | CanonicalForm G= F; |
---|
3636 | F= 1; |
---|
3637 | return CFList (G (y-eval,y)); |
---|
3638 | } |
---|
3639 | CFArray * A= new CFArray [factors.length()]; |
---|
3640 | CFArray bufQ= CFArray (factors.length()); |
---|
3641 | mat_zz_pE NTLN; |
---|
3642 | ident (NTLN, factors.length()); |
---|
3643 | int minBound= bounds[0]; |
---|
3644 | for (int i= 1; i < d; i++) |
---|
3645 | { |
---|
3646 | if (bounds[i] != 0) |
---|
3647 | minBound= tmin (minBound, bounds[i]); |
---|
3648 | } |
---|
3649 | int l= tmax (2*(minBound + 1), oldL); |
---|
3650 | int oldL2= l/2; |
---|
3651 | int stepSize= 2; |
---|
3652 | bool useOldQs= false; |
---|
3653 | bool hitBound= false; |
---|
3654 | CFListIterator j; |
---|
3655 | CFMatrix C; |
---|
3656 | mat_zz_pE* NTLC, NTLK; |
---|
3657 | CFArray buf; |
---|
3658 | CanonicalForm truncF; |
---|
3659 | while (l <= precision) |
---|
3660 | { |
---|
3661 | j= factors; |
---|
3662 | truncF= mod (F, power (y,l)); |
---|
3663 | if (useOldQs) |
---|
3664 | { |
---|
3665 | for (int i= 0; i < factors.length(); i++, j++) |
---|
3666 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL2, bufQ[i], |
---|
3667 | bufQ[i] |
---|
3668 | ); |
---|
3669 | } |
---|
3670 | else |
---|
3671 | { |
---|
3672 | for (int i= 0; i < factors.length(); i++, j++) |
---|
3673 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
3674 | } |
---|
3675 | useOldQs= true; |
---|
3676 | for (int i= 0; i < d; i++) |
---|
3677 | { |
---|
3678 | if (bounds [i] + 1 <= l/2) |
---|
3679 | { |
---|
3680 | int k= tmin (bounds [i] + 1, l/2); |
---|
3681 | C= CFMatrix (l - k, factors.length()); |
---|
3682 | for (int ii= 0; ii < factors.length(); ii++) |
---|
3683 | { |
---|
3684 | if (A[ii].size() - 1 >= i) |
---|
3685 | { |
---|
3686 | buf= getCoeffs (A[ii] [i], k); |
---|
3687 | writeInMatrix (C, buf, ii + 1, 0); |
---|
3688 | } |
---|
3689 | } |
---|
3690 | NTLC= convertFacCFMatrix2NTLmat_zz_pE(C); |
---|
3691 | NTLK= (*NTLC)*NTLN; |
---|
3692 | transpose (NTLK, NTLK); |
---|
3693 | kernel (NTLK, NTLK); |
---|
3694 | transpose (NTLK, NTLK); |
---|
3695 | NTLN *= NTLK; |
---|
3696 | delete NTLC; |
---|
3697 | if (NTLN.NumCols() == 1) |
---|
3698 | { |
---|
3699 | delete [] A; |
---|
3700 | delete [] bounds; |
---|
3701 | CanonicalForm G= F; |
---|
3702 | F= 1; |
---|
3703 | return CFList (G (y-eval,y)); |
---|
3704 | } |
---|
3705 | } |
---|
3706 | } |
---|
3707 | |
---|
3708 | if (NTLN.NumCols() < oldNumCols - factorsFound) |
---|
3709 | { |
---|
3710 | if (isReduced (NTLN)) |
---|
3711 | { |
---|
3712 | int * factorsFoundIndex= new int [NTLN.NumCols()]; |
---|
3713 | for (long i= 0; i < NTLN.NumCols(); i++) |
---|
3714 | factorsFoundIndex[i]= 0; |
---|
3715 | int factorsFound2= 0; |
---|
3716 | CFList result; |
---|
3717 | CanonicalForm bufF= F; |
---|
3718 | reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2, |
---|
3719 | factorsFoundIndex, NTLN, eval, false); |
---|
3720 | if (result.length() == NTLN.NumCols()) |
---|
3721 | { |
---|
3722 | delete [] factorsFoundIndex; |
---|
3723 | delete [] A; |
---|
3724 | delete [] bounds; |
---|
3725 | F= 1; |
---|
3726 | return result; |
---|
3727 | } |
---|
3728 | delete [] factorsFoundIndex; |
---|
3729 | } |
---|
3730 | else if (l == precision) |
---|
3731 | { |
---|
3732 | CanonicalForm bufF= F; |
---|
3733 | int * zeroOne= extractZeroOneVecs (NTLN); |
---|
3734 | CFList result= reconstruction (bufF, factors, zeroOne, precision, NTLN, eval); |
---|
3735 | F= bufF; |
---|
3736 | delete [] zeroOne; |
---|
3737 | delete [] A; |
---|
3738 | delete [] bounds; |
---|
3739 | return result; |
---|
3740 | } |
---|
3741 | } |
---|
3742 | oldL2= l; |
---|
3743 | l += stepSize; |
---|
3744 | stepSize *= 2; |
---|
3745 | if (l > precision) |
---|
3746 | { |
---|
3747 | if (!hitBound) |
---|
3748 | { |
---|
3749 | l= precision; |
---|
3750 | hitBound= true; |
---|
3751 | } |
---|
3752 | else |
---|
3753 | break; |
---|
3754 | } |
---|
3755 | } |
---|
3756 | delete [] bounds; |
---|
3757 | delete [] A; |
---|
3758 | return CFList(); |
---|
3759 | } |
---|
3760 | |
---|
3761 | //over field extension |
---|
3762 | CFList |
---|
3763 | extIncreasePrecision (CanonicalForm& F, CFList& factors, int factorsFound, |
---|
3764 | int oldNumCols, int oldL, const CanonicalForm& evaluation, |
---|
3765 | const ExtensionInfo& info, CFList& source, CFList& dest, |
---|
3766 | int precision |
---|
3767 | ) |
---|
3768 | { |
---|
3769 | bool GF= (CFFactory::gettype()==GaloisFieldDomain); |
---|
3770 | int degMipo= degree (getMipo (info.getAlpha())); |
---|
3771 | Variable alpha= info.getAlpha(); |
---|
3772 | int d; |
---|
3773 | bool isIrreducible= false; |
---|
3774 | int* bounds= computeBounds (F, d, isIrreducible); |
---|
3775 | if (isIrreducible) |
---|
3776 | { |
---|
3777 | delete [] bounds; |
---|
3778 | Variable y= Variable (2); |
---|
3779 | CanonicalForm tmp= F (y - evaluation, y); |
---|
3780 | CFList source, dest; |
---|
3781 | tmp= mapDown (tmp, info, source, dest); |
---|
3782 | F= 1; |
---|
3783 | return CFList (tmp); |
---|
3784 | } |
---|
3785 | |
---|
3786 | CFArray * A= new CFArray [factors.length()]; |
---|
3787 | CFArray bufQ= CFArray (factors.length()); |
---|
3788 | #ifdef HAVE_FLINT |
---|
3789 | nmod_mat_t FLINTN; |
---|
3790 | nmod_mat_init (FLINTN,factors.length(),factors.length(), getCharacteristic()); |
---|
3791 | for (long i=factors.length()-1; i >= 0; i--) |
---|
3792 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
3793 | #else |
---|
3794 | if (fac_NTL_char != getCharacteristic()) |
---|
3795 | { |
---|
3796 | fac_NTL_char= getCharacteristic(); |
---|
3797 | zz_p::init (getCharacteristic()); |
---|
3798 | } |
---|
3799 | mat_zz_p NTLN; |
---|
3800 | ident (NTLN, factors.length()); |
---|
3801 | #endif |
---|
3802 | int minBound= bounds[0]; |
---|
3803 | for (int i= 1; i < d; i++) |
---|
3804 | { |
---|
3805 | if (bounds[i] != 0) |
---|
3806 | minBound= tmin (minBound, bounds[i]); |
---|
3807 | } |
---|
3808 | int l= tmax (oldL, 2*((minBound+1)/degMipo+1)); |
---|
3809 | int oldL2= l/2; |
---|
3810 | int stepSize= 2; |
---|
3811 | bool useOldQs= false; |
---|
3812 | bool hitBound= false; |
---|
3813 | Variable gamma= info.getBeta(); |
---|
3814 | CanonicalForm primElemAlpha= info.getGamma(); |
---|
3815 | CanonicalForm imPrimElemAlpha= info.getDelta(); |
---|
3816 | CFListIterator j; |
---|
3817 | Variable y= F.mvar(); |
---|
3818 | CanonicalForm powX, imBasis, truncF; |
---|
3819 | CFMatrix Mat, C; |
---|
3820 | CFIterator iter; |
---|
3821 | #ifdef HAVE_FLINT |
---|
3822 | long rank; |
---|
3823 | nmod_mat_t FLINTMat, FLINTMatInv, FLINTC, FLINTK, null; |
---|
3824 | #else |
---|
3825 | mat_zz_p* NTLMat,*NTLC, NTLK; |
---|
3826 | #endif |
---|
3827 | CFArray buf; |
---|
3828 | while (l <= precision) |
---|
3829 | { |
---|
3830 | j= factors; |
---|
3831 | if (GF) |
---|
3832 | setCharacteristic (getCharacteristic()); |
---|
3833 | powX= power (y-gamma, l); |
---|
3834 | Mat= CFMatrix (l*degMipo, l*degMipo); |
---|
3835 | for (int i= 0; i < l*degMipo; i++) |
---|
3836 | { |
---|
3837 | imBasis= mod (power (y, i), powX); |
---|
3838 | imBasis= imBasis (power (y, degMipo), y); |
---|
3839 | imBasis= imBasis (y, gamma); |
---|
3840 | iter= imBasis; |
---|
3841 | for (; iter.hasTerms(); iter++) |
---|
3842 | Mat (iter.exp()+ 1, i+1)= iter.coeff(); |
---|
3843 | } |
---|
3844 | |
---|
3845 | #ifdef HAVE_FLINT |
---|
3846 | convertFacCFMatrix2nmod_mat_t (FLINTMat, Mat); |
---|
3847 | nmod_mat_init (FLINTMatInv, nmod_mat_nrows (FLINTMat), |
---|
3848 | nmod_mat_nrows (FLINTMat), getCharacteristic()); |
---|
3849 | nmod_mat_inv (FLINTMatInv, FLINTMat); |
---|
3850 | #else |
---|
3851 | NTLMat= convertFacCFMatrix2NTLmat_zz_p (Mat); |
---|
3852 | *NTLMat= inv (*NTLMat); |
---|
3853 | #endif |
---|
3854 | |
---|
3855 | if (GF) |
---|
3856 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
3857 | |
---|
3858 | truncF= mod (F, power (y, l)); |
---|
3859 | if (useOldQs) |
---|
3860 | { |
---|
3861 | for (int i= 0; i < factors.length(); i++, j++) |
---|
3862 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL2, bufQ[i], |
---|
3863 | bufQ[i] |
---|
3864 | ); |
---|
3865 | } |
---|
3866 | else |
---|
3867 | { |
---|
3868 | for (int i= 0; i < factors.length(); i++, j++) |
---|
3869 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
3870 | } |
---|
3871 | useOldQs= true; |
---|
3872 | for (int i= 0; i < d; i++) |
---|
3873 | { |
---|
3874 | if (bounds [i] + 1 <= (l/2)*degMipo) |
---|
3875 | { |
---|
3876 | int k= tmin (bounds [i] + 1, (l/2)*degMipo); |
---|
3877 | C= CFMatrix (l*degMipo - k, factors.length()); |
---|
3878 | for (int ii= 0; ii < factors.length(); ii++) |
---|
3879 | { |
---|
3880 | if (A[ii].size() - 1 >= i) |
---|
3881 | { |
---|
3882 | if (GF) |
---|
3883 | { |
---|
3884 | A[ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
3885 | setCharacteristic (getCharacteristic()); |
---|
3886 | A[ii] [i]= GF2FalphaRep (A[ii] [i], alpha); |
---|
3887 | if (alpha != gamma) |
---|
3888 | A [ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
3889 | gamma, source, dest |
---|
3890 | ); |
---|
3891 | #ifdef HAVE_FLINT |
---|
3892 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, FLINTMatInv); |
---|
3893 | #else |
---|
3894 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, *NTLMat); |
---|
3895 | #endif |
---|
3896 | } |
---|
3897 | else |
---|
3898 | { |
---|
3899 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
3900 | if (alpha != gamma) |
---|
3901 | A[ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
3902 | gamma, source, dest |
---|
3903 | ); |
---|
3904 | #ifdef HAVE_FLINT |
---|
3905 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, FLINTMatInv); |
---|
3906 | #else |
---|
3907 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, *NTLMat); |
---|
3908 | #endif |
---|
3909 | } |
---|
3910 | writeInMatrix (C, buf, ii + 1, 0); |
---|
3911 | } |
---|
3912 | if (GF) |
---|
3913 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
3914 | } |
---|
3915 | |
---|
3916 | if (GF) |
---|
3917 | setCharacteristic(getCharacteristic()); |
---|
3918 | |
---|
3919 | #ifdef HAVE_FLINT |
---|
3920 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
3921 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
3922 | getCharacteristic()); |
---|
3923 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
3924 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
3925 | getCharacteristic()); |
---|
3926 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
3927 | nmod_mat_clear (FLINTK); |
---|
3928 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
3929 | nmod_mat_clear (FLINTC); |
---|
3930 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
3931 | nmod_mat_clear (FLINTN); |
---|
3932 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
3933 | getCharacteristic()); |
---|
3934 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
3935 | |
---|
3936 | nmod_mat_clear (FLINTC); |
---|
3937 | nmod_mat_window_clear (FLINTK); |
---|
3938 | nmod_mat_clear (null); |
---|
3939 | #else |
---|
3940 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
3941 | NTLK= (*NTLC)*NTLN; |
---|
3942 | transpose (NTLK, NTLK); |
---|
3943 | kernel (NTLK, NTLK); |
---|
3944 | transpose (NTLK, NTLK); |
---|
3945 | NTLN *= NTLK; |
---|
3946 | delete NTLC; |
---|
3947 | #endif |
---|
3948 | |
---|
3949 | if (GF) |
---|
3950 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
3951 | |
---|
3952 | #ifdef HAVE_FLINT |
---|
3953 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
3954 | { |
---|
3955 | nmod_mat_clear (FLINTMat); |
---|
3956 | nmod_mat_clear (FLINTMatInv); |
---|
3957 | nmod_mat_clear (FLINTN); |
---|
3958 | #else |
---|
3959 | if (NTLN.NumCols() == 1) |
---|
3960 | { |
---|
3961 | delete NTLMat; |
---|
3962 | #endif |
---|
3963 | Variable y= Variable (2); |
---|
3964 | CanonicalForm tmp= F (y - evaluation, y); |
---|
3965 | CFList source, dest; |
---|
3966 | tmp= mapDown (tmp, info, source, dest); |
---|
3967 | delete [] A; |
---|
3968 | delete [] bounds; |
---|
3969 | F= 1; |
---|
3970 | return CFList (tmp); |
---|
3971 | } |
---|
3972 | } |
---|
3973 | } |
---|
3974 | |
---|
3975 | #ifdef HAVE_FLINT |
---|
3976 | nmod_mat_clear (FLINTMat); |
---|
3977 | nmod_mat_clear (FLINTMatInv); |
---|
3978 | #else |
---|
3979 | delete NTLMat; |
---|
3980 | #endif |
---|
3981 | |
---|
3982 | #ifdef HAVE_FLINT |
---|
3983 | if (nmod_mat_ncols (FLINTN) < oldNumCols - factorsFound) |
---|
3984 | { |
---|
3985 | if (isReduced (FLINTN)) |
---|
3986 | { |
---|
3987 | int * factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)]; |
---|
3988 | for (long i= 0; i < nmod_mat_ncols (FLINTN); i++) |
---|
3989 | #else |
---|
3990 | if (NTLN.NumCols() < oldNumCols - factorsFound) |
---|
3991 | { |
---|
3992 | if (isReduced (NTLN)) |
---|
3993 | { |
---|
3994 | int * factorsFoundIndex= new int [NTLN.NumCols()]; |
---|
3995 | for (long i= 0; i < NTLN.NumCols(); i++) |
---|
3996 | #endif |
---|
3997 | factorsFoundIndex[i]= 0; |
---|
3998 | int factorsFound2= 0; |
---|
3999 | CFList result; |
---|
4000 | CanonicalForm bufF= F; |
---|
4001 | #ifdef HAVE_FLINT |
---|
4002 | extReconstructionTry (result, bufF, factors,degree (F)+1, factorsFound2, |
---|
4003 | factorsFoundIndex, FLINTN, false, info, evaluation |
---|
4004 | ); |
---|
4005 | if (result.length() == nmod_mat_ncols (FLINTN)) |
---|
4006 | { |
---|
4007 | nmod_mat_clear (FLINTN); |
---|
4008 | #else |
---|
4009 | extReconstructionTry (result, bufF, factors,degree (F)+1, factorsFound2, |
---|
4010 | factorsFoundIndex, NTLN, false, info, evaluation |
---|
4011 | ); |
---|
4012 | if (result.length() == NTLN.NumCols()) |
---|
4013 | { |
---|
4014 | #endif |
---|
4015 | delete [] factorsFoundIndex; |
---|
4016 | delete [] A; |
---|
4017 | delete [] bounds; |
---|
4018 | F= 1; |
---|
4019 | return result; |
---|
4020 | } |
---|
4021 | delete [] factorsFoundIndex; |
---|
4022 | } |
---|
4023 | else if (l == precision) |
---|
4024 | { |
---|
4025 | CanonicalForm bufF= F; |
---|
4026 | #ifdef HAVE_FLINT |
---|
4027 | int * zeroOne= extractZeroOneVecs (FLINTN); |
---|
4028 | CFList result= extReconstruction (bufF, factors, zeroOne, precision, |
---|
4029 | FLINTN, info, evaluation |
---|
4030 | ); |
---|
4031 | nmod_mat_clear (FLINTN); |
---|
4032 | #else |
---|
4033 | int * zeroOne= extractZeroOneVecs (NTLN); |
---|
4034 | CFList result= extReconstruction (bufF, factors, zeroOne, precision, |
---|
4035 | NTLN, info, evaluation |
---|
4036 | ); |
---|
4037 | #endif |
---|
4038 | F= bufF; |
---|
4039 | delete [] zeroOne; |
---|
4040 | delete [] A; |
---|
4041 | delete [] bounds; |
---|
4042 | return result; |
---|
4043 | } |
---|
4044 | } |
---|
4045 | oldL2= l; |
---|
4046 | l += stepSize; |
---|
4047 | stepSize *= 2; |
---|
4048 | if (l > precision) |
---|
4049 | { |
---|
4050 | if (!hitBound) |
---|
4051 | { |
---|
4052 | hitBound= true; |
---|
4053 | l= precision; |
---|
4054 | } |
---|
4055 | else |
---|
4056 | break; |
---|
4057 | } |
---|
4058 | } |
---|
4059 | |
---|
4060 | #ifdef HAVE_FLINT |
---|
4061 | nmod_mat_clear (FLINTN); |
---|
4062 | #endif |
---|
4063 | delete [] bounds; |
---|
4064 | delete [] A; |
---|
4065 | return CFList(); |
---|
4066 | } |
---|
4067 | |
---|
4068 | CFList |
---|
4069 | increasePrecision2 (const CanonicalForm& F, CFList& factors, |
---|
4070 | const Variable& alpha, int precision) |
---|
4071 | { |
---|
4072 | int d; |
---|
4073 | bool isIrreducible= false; |
---|
4074 | int* bounds= computeBounds (F, d, isIrreducible); |
---|
4075 | if (isIrreducible) |
---|
4076 | { |
---|
4077 | delete [] bounds; |
---|
4078 | return CFList (F); |
---|
4079 | } |
---|
4080 | CFArray * A= new CFArray [factors.length()]; |
---|
4081 | CFArray bufQ= CFArray (factors.length()); |
---|
4082 | if (fac_NTL_char != getCharacteristic()) |
---|
4083 | { |
---|
4084 | fac_NTL_char= getCharacteristic(); |
---|
4085 | zz_p::init (getCharacteristic()); |
---|
4086 | } |
---|
4087 | zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); |
---|
4088 | zz_pE::init (NTLMipo); |
---|
4089 | mat_zz_pE NTLN; |
---|
4090 | ident (NTLN, factors.length()); |
---|
4091 | int minBound= bounds[0]; |
---|
4092 | for (int i= 1; i < d; i++) |
---|
4093 | { |
---|
4094 | if (bounds[i] != 0) |
---|
4095 | minBound= tmin (minBound, bounds[i]); |
---|
4096 | } |
---|
4097 | int l= tmin (2*(minBound + 1), precision); |
---|
4098 | int oldL= l/2; |
---|
4099 | int stepSize= 2; |
---|
4100 | bool useOldQs= false; |
---|
4101 | bool hitBound= false; |
---|
4102 | CFListIterator j; |
---|
4103 | CFMatrix C; |
---|
4104 | CFArray buf; |
---|
4105 | mat_zz_pE* NTLC, NTLK; |
---|
4106 | Variable y= F.mvar(); |
---|
4107 | CanonicalForm truncF; |
---|
4108 | while (l <= precision) |
---|
4109 | { |
---|
4110 | j= factors; |
---|
4111 | truncF= mod (F, power (y, l)); |
---|
4112 | if (useOldQs) |
---|
4113 | { |
---|
4114 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4115 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], bufQ[i]); |
---|
4116 | } |
---|
4117 | else |
---|
4118 | { |
---|
4119 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4120 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
4121 | } |
---|
4122 | useOldQs= true; |
---|
4123 | for (int i= 0; i < d; i++) |
---|
4124 | { |
---|
4125 | if (bounds [i] + 1 <= l/2) |
---|
4126 | { |
---|
4127 | int k= tmin (bounds [i] + 1, l/2); |
---|
4128 | C= CFMatrix (l - k, factors.length()); |
---|
4129 | for (int ii= 0; ii < factors.length(); ii++) |
---|
4130 | { |
---|
4131 | if (A[ii].size() - 1 >= i) |
---|
4132 | { |
---|
4133 | buf= getCoeffs (A[ii] [i], k); |
---|
4134 | writeInMatrix (C, buf, ii + 1, 0); |
---|
4135 | } |
---|
4136 | } |
---|
4137 | NTLC= convertFacCFMatrix2NTLmat_zz_pE(C); |
---|
4138 | NTLK= (*NTLC)*NTLN; |
---|
4139 | transpose (NTLK, NTLK); |
---|
4140 | kernel (NTLK, NTLK); |
---|
4141 | transpose (NTLK, NTLK); |
---|
4142 | NTLN *= NTLK; |
---|
4143 | delete NTLC; |
---|
4144 | |
---|
4145 | if (NTLN.NumCols() == 1) |
---|
4146 | { |
---|
4147 | delete [] A; |
---|
4148 | delete [] bounds; |
---|
4149 | return CFList (F); |
---|
4150 | } |
---|
4151 | } |
---|
4152 | } |
---|
4153 | |
---|
4154 | if (isReduced (NTLN) || l == precision) |
---|
4155 | { |
---|
4156 | CanonicalForm bufF= F; |
---|
4157 | int * zeroOne= extractZeroOneVecs (NTLN); |
---|
4158 | CFList bufFactors= factors; |
---|
4159 | CFList result= monicReconstruction (bufF, factors, zeroOne, precision, |
---|
4160 | NTLN |
---|
4161 | ); |
---|
4162 | if (result.length() != NTLN.NumCols() && l != precision) |
---|
4163 | factors= bufFactors; |
---|
4164 | if (result.length() == NTLN.NumCols()) |
---|
4165 | { |
---|
4166 | delete [] zeroOne; |
---|
4167 | delete [] A; |
---|
4168 | delete [] bounds; |
---|
4169 | return result; |
---|
4170 | } |
---|
4171 | if (l == precision) |
---|
4172 | { |
---|
4173 | delete [] zeroOne; |
---|
4174 | delete [] A; |
---|
4175 | delete [] bounds; |
---|
4176 | return Union (result, factors); |
---|
4177 | } |
---|
4178 | delete [] zeroOne; |
---|
4179 | } |
---|
4180 | oldL= l; |
---|
4181 | l += stepSize; |
---|
4182 | stepSize *= 2; |
---|
4183 | if (l > precision) |
---|
4184 | { |
---|
4185 | if (!hitBound) |
---|
4186 | { |
---|
4187 | l= precision; |
---|
4188 | hitBound= true; |
---|
4189 | } |
---|
4190 | else |
---|
4191 | break; |
---|
4192 | } |
---|
4193 | } |
---|
4194 | delete [] bounds; |
---|
4195 | delete [] A; |
---|
4196 | return CFList(); |
---|
4197 | } |
---|
4198 | |
---|
4199 | CFList |
---|
4200 | increasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int factorsFound, |
---|
4201 | int oldNumCols, int oldL, const Variable& alpha, |
---|
4202 | int precision, const CanonicalForm& eval |
---|
4203 | ) |
---|
4204 | { |
---|
4205 | int d; |
---|
4206 | bool isIrreducible= false; |
---|
4207 | Variable y= F.mvar(); |
---|
4208 | int* bounds= computeBounds (F, d, isIrreducible); |
---|
4209 | if (isIrreducible) |
---|
4210 | { |
---|
4211 | delete [] bounds; |
---|
4212 | CanonicalForm G= F; |
---|
4213 | F= 1; |
---|
4214 | return CFList (G (y-eval,y)); |
---|
4215 | } |
---|
4216 | int extensionDeg= degree (getMipo (alpha)); |
---|
4217 | CFArray * A= new CFArray [factors.length()]; |
---|
4218 | CFArray bufQ= CFArray (factors.length()); |
---|
4219 | #ifdef HAVE_FLINT |
---|
4220 | nmod_mat_t FLINTN; |
---|
4221 | nmod_mat_init (FLINTN,factors.length(),factors.length(), getCharacteristic()); |
---|
4222 | for (long i=factors.length()-1; i >= 0; i--) |
---|
4223 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
4224 | #else |
---|
4225 | mat_zz_p NTLN; |
---|
4226 | ident (NTLN, factors.length()); |
---|
4227 | #endif |
---|
4228 | int minBound= bounds[0]; |
---|
4229 | for (int i= 1; i < d; i++) |
---|
4230 | { |
---|
4231 | if (bounds[i] != 0) |
---|
4232 | minBound= tmin (minBound, bounds[i]); |
---|
4233 | } |
---|
4234 | int l= tmax (2*(minBound + 1), oldL); |
---|
4235 | int oldL2= l/2; |
---|
4236 | int stepSize= 2; |
---|
4237 | bool useOldQs= false; |
---|
4238 | bool hitBound= false; |
---|
4239 | CFListIterator j; |
---|
4240 | CFMatrix C; |
---|
4241 | #ifdef HAVE_FLINT |
---|
4242 | long rank; |
---|
4243 | nmod_mat_t FLINTC, FLINTK, null; |
---|
4244 | #else |
---|
4245 | mat_zz_p* NTLC, NTLK; |
---|
4246 | #endif |
---|
4247 | CFArray buf; |
---|
4248 | CanonicalForm truncF; |
---|
4249 | while (l <= precision) |
---|
4250 | { |
---|
4251 | j= factors; |
---|
4252 | truncF= mod (F, power (y, l)); |
---|
4253 | if (useOldQs) |
---|
4254 | { |
---|
4255 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4256 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL2, bufQ[i], |
---|
4257 | bufQ[i] |
---|
4258 | ); |
---|
4259 | } |
---|
4260 | else |
---|
4261 | { |
---|
4262 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4263 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
4264 | } |
---|
4265 | useOldQs= true; |
---|
4266 | for (int i= 0; i < d; i++) |
---|
4267 | { |
---|
4268 | if (bounds [i] + 1 <= l/2) |
---|
4269 | { |
---|
4270 | int k= tmin (bounds [i] + 1, l/2); |
---|
4271 | C= CFMatrix ((l - k)*extensionDeg, factors.length()); |
---|
4272 | for (int ii= 0; ii < factors.length(); ii++) |
---|
4273 | { |
---|
4274 | if (A[ii].size() - 1 >= i) |
---|
4275 | { |
---|
4276 | buf= getCoeffs (A[ii] [i], k, alpha); |
---|
4277 | writeInMatrix (C, buf, ii + 1, 0); |
---|
4278 | } |
---|
4279 | } |
---|
4280 | #ifdef HAVE_FLINT |
---|
4281 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
4282 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
4283 | getCharacteristic()); |
---|
4284 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
4285 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
4286 | getCharacteristic()); |
---|
4287 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
4288 | nmod_mat_clear (FLINTK); |
---|
4289 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
4290 | nmod_mat_clear (FLINTC); |
---|
4291 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
4292 | nmod_mat_clear (FLINTN); |
---|
4293 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
4294 | getCharacteristic()); |
---|
4295 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
4296 | |
---|
4297 | nmod_mat_clear (FLINTC); |
---|
4298 | nmod_mat_window_clear (FLINTK); |
---|
4299 | nmod_mat_clear (null); |
---|
4300 | #else |
---|
4301 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
4302 | NTLK= (*NTLC)*NTLN; |
---|
4303 | transpose (NTLK, NTLK); |
---|
4304 | kernel (NTLK, NTLK); |
---|
4305 | transpose (NTLK, NTLK); |
---|
4306 | NTLN *= NTLK; |
---|
4307 | delete NTLC; |
---|
4308 | #endif |
---|
4309 | #ifdef HAVE_FLINT |
---|
4310 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
4311 | { |
---|
4312 | nmod_mat_clear (FLINTN); |
---|
4313 | #else |
---|
4314 | if (NTLN.NumCols() == 1) |
---|
4315 | { |
---|
4316 | #endif |
---|
4317 | delete [] A; |
---|
4318 | delete [] bounds; |
---|
4319 | CanonicalForm G= F; |
---|
4320 | F= 1; |
---|
4321 | return CFList (G (y-eval,y)); |
---|
4322 | } |
---|
4323 | } |
---|
4324 | } |
---|
4325 | |
---|
4326 | #ifdef HAVE_FLINT |
---|
4327 | if (nmod_mat_ncols (FLINTN) < oldNumCols - factorsFound) |
---|
4328 | { |
---|
4329 | if (isReduced (FLINTN)) |
---|
4330 | { |
---|
4331 | int * factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)]; |
---|
4332 | for (long i= 0; i < nmod_mat_ncols (FLINTN); i++) |
---|
4333 | #else |
---|
4334 | if (NTLN.NumCols() < oldNumCols - factorsFound) |
---|
4335 | { |
---|
4336 | if (isReduced (NTLN)) |
---|
4337 | { |
---|
4338 | int * factorsFoundIndex= new int [NTLN.NumCols()]; |
---|
4339 | for (long i= 0; i < NTLN.NumCols(); i++) |
---|
4340 | #endif |
---|
4341 | factorsFoundIndex[i]= 0; |
---|
4342 | int factorsFound2= 0; |
---|
4343 | CFList result; |
---|
4344 | CanonicalForm bufF= F; |
---|
4345 | #ifdef HAVE_FLINT |
---|
4346 | reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2, |
---|
4347 | factorsFoundIndex, FLINTN, eval, false |
---|
4348 | ); |
---|
4349 | if (result.length() == nmod_mat_ncols (FLINTN)) |
---|
4350 | { |
---|
4351 | nmod_mat_clear (FLINTN); |
---|
4352 | #else |
---|
4353 | reconstructionTry (result, bufF, factors, degree (F) + 1, factorsFound2, |
---|
4354 | factorsFoundIndex, NTLN, eval, false |
---|
4355 | ); |
---|
4356 | if (result.length() == NTLN.NumCols()) |
---|
4357 | { |
---|
4358 | #endif |
---|
4359 | delete [] factorsFoundIndex; |
---|
4360 | delete [] A; |
---|
4361 | delete [] bounds; |
---|
4362 | F= 1; |
---|
4363 | return result; |
---|
4364 | } |
---|
4365 | delete [] factorsFoundIndex; |
---|
4366 | } |
---|
4367 | else if (l == precision) |
---|
4368 | { |
---|
4369 | CanonicalForm bufF= F; |
---|
4370 | #ifdef HAVE_FLINT |
---|
4371 | int * zeroOne= extractZeroOneVecs (FLINTN); |
---|
4372 | CFList result= reconstruction (bufF,factors,zeroOne,precision,FLINTN, eval); |
---|
4373 | nmod_mat_clear (FLINTN); |
---|
4374 | #else |
---|
4375 | int * zeroOne= extractZeroOneVecs (NTLN); |
---|
4376 | CFList result= reconstruction (bufF, factors, zeroOne, precision, NTLN, eval); |
---|
4377 | #endif |
---|
4378 | F= bufF; |
---|
4379 | delete [] zeroOne; |
---|
4380 | delete [] A; |
---|
4381 | delete [] bounds; |
---|
4382 | return result; |
---|
4383 | } |
---|
4384 | } |
---|
4385 | oldL2= l; |
---|
4386 | l += stepSize; |
---|
4387 | stepSize *= 2; |
---|
4388 | if (l > precision) |
---|
4389 | { |
---|
4390 | if (!hitBound) |
---|
4391 | { |
---|
4392 | hitBound= true; |
---|
4393 | l= precision; |
---|
4394 | } |
---|
4395 | else |
---|
4396 | break; |
---|
4397 | } |
---|
4398 | } |
---|
4399 | #ifdef HAVE_FLINT |
---|
4400 | nmod_mat_clear (FLINTN); |
---|
4401 | #endif |
---|
4402 | delete [] bounds; |
---|
4403 | delete [] A; |
---|
4404 | return CFList(); |
---|
4405 | } |
---|
4406 | |
---|
4407 | #ifdef HAVE_FLINT |
---|
4408 | CFList |
---|
4409 | increasePrecision (CanonicalForm& F, CFList& factors, int oldL, int |
---|
4410 | l, int d, int* bounds, CFArray& bufQ, nmod_mat_t FLINTN, |
---|
4411 | const CanonicalForm& eval |
---|
4412 | ) |
---|
4413 | #else |
---|
4414 | CFList |
---|
4415 | increasePrecision (CanonicalForm& F, CFList& factors, int oldL, int |
---|
4416 | l, int d, int* bounds, CFArray& bufQ, mat_zz_p& NTLN, |
---|
4417 | const CanonicalForm& eval |
---|
4418 | ) |
---|
4419 | #endif |
---|
4420 | { |
---|
4421 | CFList result= CFList(); |
---|
4422 | CFArray * A= new CFArray [factors.length()]; |
---|
4423 | int oldL2= oldL/2; |
---|
4424 | bool hitBound= false; |
---|
4425 | #ifdef HAVE_FLINT |
---|
4426 | if (nmod_mat_nrows (FLINTN) != factors.length()) //refined factors |
---|
4427 | { |
---|
4428 | nmod_mat_clear (FLINTN); |
---|
4429 | nmod_mat_init(FLINTN,factors.length(),factors.length(),getCharacteristic()); |
---|
4430 | for (long i=factors.length()-1; i >= 0; i--) |
---|
4431 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
4432 | bufQ= CFArray (factors.length()); |
---|
4433 | } |
---|
4434 | #else |
---|
4435 | if (NTLN.NumRows() != factors.length()) //refined factors |
---|
4436 | { |
---|
4437 | ident (NTLN, factors.length()); |
---|
4438 | bufQ= CFArray (factors.length()); |
---|
4439 | } |
---|
4440 | #endif |
---|
4441 | bool useOldQs= false; |
---|
4442 | CFListIterator j; |
---|
4443 | CFMatrix C; |
---|
4444 | CFArray buf; |
---|
4445 | #ifdef HAVE_FLINT |
---|
4446 | long rank; |
---|
4447 | nmod_mat_t FLINTC, FLINTK, null; |
---|
4448 | #else |
---|
4449 | mat_zz_p* NTLC, NTLK; |
---|
4450 | #endif |
---|
4451 | CanonicalForm bufF, truncF; |
---|
4452 | CFList bufUniFactors; |
---|
4453 | Variable y= F.mvar(); |
---|
4454 | while (oldL <= l) |
---|
4455 | { |
---|
4456 | j= factors; |
---|
4457 | truncF= mod (F, power (y, oldL)); |
---|
4458 | if (useOldQs) |
---|
4459 | { |
---|
4460 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4461 | A[i]= logarithmicDerivative (truncF, j.getItem(), oldL, oldL2, bufQ[i], |
---|
4462 | bufQ[i] |
---|
4463 | ); |
---|
4464 | } |
---|
4465 | else |
---|
4466 | { |
---|
4467 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4468 | A[i]= logarithmicDerivative (truncF, j.getItem(), oldL, bufQ [i]); |
---|
4469 | } |
---|
4470 | useOldQs= true; |
---|
4471 | |
---|
4472 | for (int i= 0; i < d; i++) |
---|
4473 | { |
---|
4474 | if (bounds [i] + 1 <= oldL/2) |
---|
4475 | { |
---|
4476 | int k= tmin (bounds [i] + 1, oldL/2); |
---|
4477 | C= CFMatrix (oldL - k, factors.length()); |
---|
4478 | for (int ii= 0; ii < factors.length(); ii++) |
---|
4479 | { |
---|
4480 | if (A[ii].size() - 1 >= i) |
---|
4481 | { |
---|
4482 | buf= getCoeffs (A[ii] [i], k); |
---|
4483 | writeInMatrix (C, buf, ii + 1, 0); |
---|
4484 | } |
---|
4485 | } |
---|
4486 | #ifdef HAVE_FLINT |
---|
4487 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
4488 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
4489 | getCharacteristic()); |
---|
4490 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
4491 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
4492 | getCharacteristic()); |
---|
4493 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
4494 | nmod_mat_clear (FLINTK); |
---|
4495 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
4496 | nmod_mat_clear (FLINTC); |
---|
4497 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
4498 | nmod_mat_clear (FLINTN); |
---|
4499 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
4500 | getCharacteristic()); |
---|
4501 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
4502 | |
---|
4503 | nmod_mat_clear (FLINTC); |
---|
4504 | nmod_mat_window_clear (FLINTK); |
---|
4505 | nmod_mat_clear (null); |
---|
4506 | #else |
---|
4507 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
4508 | NTLK= (*NTLC)*NTLN; |
---|
4509 | transpose (NTLK, NTLK); |
---|
4510 | kernel (NTLK, NTLK); |
---|
4511 | transpose (NTLK, NTLK); |
---|
4512 | NTLN *= NTLK; |
---|
4513 | delete NTLC; |
---|
4514 | #endif |
---|
4515 | #ifdef HAVE_FLINT |
---|
4516 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
4517 | #else |
---|
4518 | if (NTLN.NumCols() == 1) |
---|
4519 | #endif |
---|
4520 | { |
---|
4521 | delete [] A; |
---|
4522 | return CFList (F (y-eval,y)); |
---|
4523 | } |
---|
4524 | } |
---|
4525 | } |
---|
4526 | #ifdef HAVE_FLINT |
---|
4527 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
4528 | #else |
---|
4529 | if (NTLN.NumCols() == 1) |
---|
4530 | #endif |
---|
4531 | { |
---|
4532 | delete [] A; |
---|
4533 | return CFList (F (y-eval,y)); |
---|
4534 | } |
---|
4535 | int * zeroOneVecs; |
---|
4536 | #ifdef HAVE_FLINT |
---|
4537 | zeroOneVecs= extractZeroOneVecs (FLINTN); |
---|
4538 | #else |
---|
4539 | zeroOneVecs= extractZeroOneVecs (NTLN); |
---|
4540 | #endif |
---|
4541 | bufF= F; |
---|
4542 | bufUniFactors= factors; |
---|
4543 | #ifdef HAVE_FLINT |
---|
4544 | result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, FLINTN, eval); |
---|
4545 | #else |
---|
4546 | result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, NTLN, eval); |
---|
4547 | #endif |
---|
4548 | delete [] zeroOneVecs; |
---|
4549 | if (degree (bufF) + 1 + degree (LC (bufF, 1)) < oldL && result.length() > 0) |
---|
4550 | { |
---|
4551 | F= bufF; |
---|
4552 | factors= bufUniFactors; |
---|
4553 | delete [] A; |
---|
4554 | return result; |
---|
4555 | } |
---|
4556 | |
---|
4557 | result= CFList(); |
---|
4558 | oldL2= oldL; |
---|
4559 | oldL *= 2; |
---|
4560 | if (oldL > l) |
---|
4561 | { |
---|
4562 | if (!hitBound) |
---|
4563 | { |
---|
4564 | oldL= l; |
---|
4565 | hitBound= true; |
---|
4566 | } |
---|
4567 | else |
---|
4568 | break; |
---|
4569 | } |
---|
4570 | } |
---|
4571 | delete [] A; |
---|
4572 | return result; |
---|
4573 | } |
---|
4574 | |
---|
4575 | CFList |
---|
4576 | increasePrecision (CanonicalForm& F, CFList& factors, int oldL, int |
---|
4577 | l, int d, int* bounds, CFArray& bufQ, mat_zz_pE& NTLN, |
---|
4578 | const CanonicalForm& eval |
---|
4579 | ) |
---|
4580 | { |
---|
4581 | CFList result= CFList(); |
---|
4582 | CFArray * A= new CFArray [factors.length()]; |
---|
4583 | int oldL2= oldL/2; |
---|
4584 | bool hitBound= false; |
---|
4585 | bool useOldQs= false; |
---|
4586 | if (NTLN.NumRows() != factors.length()) //refined factors |
---|
4587 | ident (NTLN, factors.length()); |
---|
4588 | CFListIterator j; |
---|
4589 | CFMatrix C; |
---|
4590 | CFArray buf; |
---|
4591 | mat_zz_pE* NTLC, NTLK; |
---|
4592 | CanonicalForm bufF, truncF; |
---|
4593 | CFList bufUniFactors; |
---|
4594 | Variable y= F.mvar(); |
---|
4595 | while (oldL <= l) |
---|
4596 | { |
---|
4597 | j= factors; |
---|
4598 | truncF= mod (F, power (y, oldL)); |
---|
4599 | if (useOldQs) |
---|
4600 | { |
---|
4601 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4602 | A[i]= logarithmicDerivative (truncF, j.getItem(), oldL, oldL2, bufQ[i], |
---|
4603 | bufQ[i] |
---|
4604 | ); |
---|
4605 | } |
---|
4606 | else |
---|
4607 | { |
---|
4608 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4609 | A[i]= logarithmicDerivative (truncF, j.getItem(), oldL, bufQ [i]); |
---|
4610 | } |
---|
4611 | useOldQs= true; |
---|
4612 | |
---|
4613 | for (int i= 0; i < d; i++) |
---|
4614 | { |
---|
4615 | if (bounds [i] + 1 <= oldL/2) |
---|
4616 | { |
---|
4617 | int k= tmin (bounds [i] + 1, oldL/2); |
---|
4618 | C= CFMatrix (oldL - k, factors.length()); |
---|
4619 | for (int ii= 0; ii < factors.length(); ii++) |
---|
4620 | { |
---|
4621 | if (A[ii].size() - 1 >= i) |
---|
4622 | { |
---|
4623 | buf= getCoeffs (A[ii] [i], k); |
---|
4624 | writeInMatrix (C, buf, ii + 1, 0); |
---|
4625 | } |
---|
4626 | } |
---|
4627 | NTLC= convertFacCFMatrix2NTLmat_zz_pE(C); |
---|
4628 | NTLK= (*NTLC)*NTLN; |
---|
4629 | transpose (NTLK, NTLK); |
---|
4630 | kernel (NTLK, NTLK); |
---|
4631 | transpose (NTLK, NTLK); |
---|
4632 | NTLN *= NTLK; |
---|
4633 | delete NTLC; |
---|
4634 | |
---|
4635 | if (NTLN.NumCols() == 1) |
---|
4636 | { |
---|
4637 | delete [] A; |
---|
4638 | return CFList (F (y-eval,y)); |
---|
4639 | } |
---|
4640 | } |
---|
4641 | } |
---|
4642 | if (NTLN.NumCols() == 1) |
---|
4643 | { |
---|
4644 | delete [] A; |
---|
4645 | return CFList (F (y-eval,y)); |
---|
4646 | } |
---|
4647 | |
---|
4648 | int * zeroOneVecs; |
---|
4649 | zeroOneVecs= extractZeroOneVecs (NTLN); |
---|
4650 | bufF= F; |
---|
4651 | bufUniFactors= factors; |
---|
4652 | result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, NTLN, eval); |
---|
4653 | delete [] zeroOneVecs; |
---|
4654 | if (degree (bufF) + 1 + degree (LC (bufF, 1)) < l && result.length() > 0) |
---|
4655 | { |
---|
4656 | F= bufF; |
---|
4657 | factors= bufUniFactors; |
---|
4658 | delete [] A; |
---|
4659 | return result; |
---|
4660 | } |
---|
4661 | |
---|
4662 | result= CFList(); |
---|
4663 | oldL2= oldL; |
---|
4664 | oldL *= 2; |
---|
4665 | if (oldL > l) |
---|
4666 | { |
---|
4667 | if (!hitBound) |
---|
4668 | { |
---|
4669 | oldL= l; |
---|
4670 | hitBound= true; |
---|
4671 | } |
---|
4672 | else |
---|
4673 | break; |
---|
4674 | } |
---|
4675 | } |
---|
4676 | delete [] A; |
---|
4677 | return result; |
---|
4678 | } |
---|
4679 | |
---|
4680 | //over field extension |
---|
4681 | #ifdef HAVE_FLINT |
---|
4682 | CFList |
---|
4683 | extIncreasePrecision (CanonicalForm& F, CFList& factors, int oldL, int l, int d, |
---|
4684 | int* bounds, CFArray& bufQ, nmod_mat_t FLINTN, const |
---|
4685 | CanonicalForm& evaluation, const ExtensionInfo& info, |
---|
4686 | CFList& source, CFList& dest |
---|
4687 | ) |
---|
4688 | #else |
---|
4689 | CFList |
---|
4690 | extIncreasePrecision (CanonicalForm& F, CFList& factors, int oldL, int l, int d, |
---|
4691 | int* bounds, CFArray& bufQ, mat_zz_p& NTLN, const |
---|
4692 | CanonicalForm& evaluation, const ExtensionInfo& info, |
---|
4693 | CFList& source, CFList& dest |
---|
4694 | ) |
---|
4695 | #endif |
---|
4696 | { |
---|
4697 | CFList result= CFList(); |
---|
4698 | CFArray * A= new CFArray [factors.length()]; |
---|
4699 | int oldL2= oldL/2; //be careful |
---|
4700 | bool hitBound= false; |
---|
4701 | bool useOldQs= false; |
---|
4702 | bool GF= (CFFactory::gettype()==GaloisFieldDomain); |
---|
4703 | int degMipo= degree (getMipo (info.getAlpha())); |
---|
4704 | Variable alpha= info.getAlpha(); |
---|
4705 | |
---|
4706 | Variable gamma= info.getBeta(); |
---|
4707 | CanonicalForm primElemAlpha= info.getGamma(); |
---|
4708 | CanonicalForm imPrimElemAlpha= info.getDelta(); |
---|
4709 | #ifdef HAVE_FLINT |
---|
4710 | nmod_mat_clear (FLINTN); |
---|
4711 | nmod_mat_init (FLINTN,factors.length(),factors.length(), getCharacteristic()); |
---|
4712 | for (long i=factors.length()-1; i >= 0; i--) |
---|
4713 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
4714 | #else |
---|
4715 | if (NTLN.NumRows() != factors.length()) //refined factors |
---|
4716 | ident (NTLN, factors.length()); |
---|
4717 | #endif |
---|
4718 | Variable y= F.mvar(); |
---|
4719 | CFListIterator j; |
---|
4720 | CanonicalForm powX, imBasis, bufF, truncF; |
---|
4721 | CFMatrix Mat, C; |
---|
4722 | CFIterator iter; |
---|
4723 | CFArray buf; |
---|
4724 | #ifdef HAVE_FLINT |
---|
4725 | long rank; |
---|
4726 | nmod_mat_t FLINTMat, FLINTMatInv, FLINTC, FLINTK, null; |
---|
4727 | #else |
---|
4728 | mat_zz_p* NTLC, NTLK, *NTLMat; |
---|
4729 | #endif |
---|
4730 | CFList bufUniFactors; |
---|
4731 | while (oldL <= l) |
---|
4732 | { |
---|
4733 | j= factors; |
---|
4734 | if (GF) |
---|
4735 | setCharacteristic (getCharacteristic()); |
---|
4736 | |
---|
4737 | powX= power (y-gamma, oldL); |
---|
4738 | Mat= CFMatrix (oldL*degMipo, oldL*degMipo); |
---|
4739 | for (int i= 0; i < oldL*degMipo; i++) |
---|
4740 | { |
---|
4741 | imBasis= mod (power (y, i), powX); |
---|
4742 | imBasis= imBasis (power (y, degMipo), y); |
---|
4743 | imBasis= imBasis (y, gamma); |
---|
4744 | iter= imBasis; |
---|
4745 | for (; iter.hasTerms(); iter++) |
---|
4746 | Mat (iter.exp()+ 1, i+1)= iter.coeff(); |
---|
4747 | } |
---|
4748 | |
---|
4749 | #ifdef HAVE_FLINT |
---|
4750 | convertFacCFMatrix2nmod_mat_t (FLINTMat, Mat); |
---|
4751 | nmod_mat_init (FLINTMatInv, nmod_mat_nrows (FLINTMat), |
---|
4752 | nmod_mat_nrows (FLINTMat), getCharacteristic()); |
---|
4753 | nmod_mat_inv (FLINTMatInv, FLINTMat); |
---|
4754 | #else |
---|
4755 | NTLMat= convertFacCFMatrix2NTLmat_zz_p (Mat); |
---|
4756 | *NTLMat= inv (*NTLMat); |
---|
4757 | #endif |
---|
4758 | |
---|
4759 | if (GF) |
---|
4760 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
4761 | |
---|
4762 | truncF= mod (F, power (y, oldL)); |
---|
4763 | if (useOldQs) |
---|
4764 | { |
---|
4765 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4766 | A[i]= logarithmicDerivative (truncF, j.getItem(), oldL, oldL2, bufQ[i], |
---|
4767 | bufQ[i]); |
---|
4768 | } |
---|
4769 | else |
---|
4770 | { |
---|
4771 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4772 | A[i]= logarithmicDerivative (truncF, j.getItem(), oldL, bufQ [i]); |
---|
4773 | } |
---|
4774 | useOldQs= true; |
---|
4775 | |
---|
4776 | for (int i= 0; i < d; i++) |
---|
4777 | { |
---|
4778 | if (bounds [i] + 1 <= oldL/2) |
---|
4779 | { |
---|
4780 | int k= tmin (bounds [i] + 1, oldL/2); |
---|
4781 | C= CFMatrix (oldL*degMipo - k, factors.length()); |
---|
4782 | for (int ii= 0; ii < factors.length(); ii++) |
---|
4783 | { |
---|
4784 | if (A[ii].size() - 1 >= i) |
---|
4785 | { |
---|
4786 | if (GF) |
---|
4787 | { |
---|
4788 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
4789 | setCharacteristic (getCharacteristic()); |
---|
4790 | A[ii] [i]= GF2FalphaRep (A[ii] [i], alpha); |
---|
4791 | if (alpha != gamma) |
---|
4792 | A [ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
4793 | gamma, source, dest |
---|
4794 | ); |
---|
4795 | #ifdef HAVE_FLINT |
---|
4796 | buf= getCoeffs (A[ii] [i], k, oldL, degMipo, gamma, 0, FLINTMatInv); |
---|
4797 | #else |
---|
4798 | buf= getCoeffs (A[ii] [i], k, oldL, degMipo, gamma, 0, *NTLMat); |
---|
4799 | #endif |
---|
4800 | } |
---|
4801 | else |
---|
4802 | { |
---|
4803 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
4804 | if (alpha != gamma) |
---|
4805 | A[ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
4806 | gamma, source, dest |
---|
4807 | ); |
---|
4808 | #ifdef HAVE_FLINT |
---|
4809 | buf= getCoeffs (A[ii] [i], k, oldL, degMipo, gamma, 0, FLINTMatInv); |
---|
4810 | #else |
---|
4811 | buf= getCoeffs (A[ii] [i], k, oldL, degMipo, gamma, 0, *NTLMat); |
---|
4812 | #endif |
---|
4813 | } |
---|
4814 | writeInMatrix (C, buf, ii + 1, 0); |
---|
4815 | } |
---|
4816 | if (GF) |
---|
4817 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
4818 | } |
---|
4819 | |
---|
4820 | if (GF) |
---|
4821 | setCharacteristic(getCharacteristic()); |
---|
4822 | |
---|
4823 | #ifdef HAVE_FLINT |
---|
4824 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
4825 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
4826 | getCharacteristic()); |
---|
4827 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
4828 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
4829 | getCharacteristic()); |
---|
4830 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
4831 | nmod_mat_clear (FLINTK); |
---|
4832 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
4833 | nmod_mat_clear (FLINTC); |
---|
4834 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
4835 | nmod_mat_clear (FLINTN); |
---|
4836 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
4837 | getCharacteristic()); |
---|
4838 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
4839 | |
---|
4840 | nmod_mat_clear (FLINTC); |
---|
4841 | nmod_mat_window_clear (FLINTK); |
---|
4842 | nmod_mat_clear (null); |
---|
4843 | #else |
---|
4844 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
4845 | NTLK= (*NTLC)*NTLN; |
---|
4846 | transpose (NTLK, NTLK); |
---|
4847 | kernel (NTLK, NTLK); |
---|
4848 | transpose (NTLK, NTLK); |
---|
4849 | NTLN *= NTLK; |
---|
4850 | delete NTLC; |
---|
4851 | #endif |
---|
4852 | |
---|
4853 | if (GF) |
---|
4854 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
4855 | |
---|
4856 | #ifdef HAVE_FLINT |
---|
4857 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
4858 | { |
---|
4859 | nmod_mat_clear (FLINTMat); |
---|
4860 | nmod_mat_clear (FLINTMatInv); |
---|
4861 | #else |
---|
4862 | if (NTLN.NumCols() == 1) |
---|
4863 | { |
---|
4864 | delete NTLMat; |
---|
4865 | #endif |
---|
4866 | Variable y= Variable (2); |
---|
4867 | CanonicalForm tmp= F (y - evaluation, y); |
---|
4868 | CFList source, dest; |
---|
4869 | tmp= mapDown (tmp, info, source, dest); |
---|
4870 | delete [] A; |
---|
4871 | return CFList (tmp); |
---|
4872 | } |
---|
4873 | } |
---|
4874 | } |
---|
4875 | |
---|
4876 | #ifdef HAVE_FLINT |
---|
4877 | nmod_mat_clear (FLINTMat); |
---|
4878 | nmod_mat_clear (FLINTMatInv); |
---|
4879 | #else |
---|
4880 | delete NTLMat; |
---|
4881 | #endif |
---|
4882 | |
---|
4883 | #ifdef HAVE_FLINT |
---|
4884 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
4885 | #else |
---|
4886 | if (NTLN.NumCols() == 1) |
---|
4887 | #endif |
---|
4888 | { |
---|
4889 | Variable y= Variable (2); |
---|
4890 | CanonicalForm tmp= F (y - evaluation, y); |
---|
4891 | CFList source, dest; |
---|
4892 | tmp= mapDown (tmp, info, source, dest); |
---|
4893 | delete [] A; |
---|
4894 | return CFList (tmp); |
---|
4895 | } |
---|
4896 | |
---|
4897 | int * zeroOneVecs; |
---|
4898 | bufF= F; |
---|
4899 | bufUniFactors= factors; |
---|
4900 | #ifdef HAVE_FLINT |
---|
4901 | zeroOneVecs= extractZeroOneVecs (FLINTN); |
---|
4902 | result= extReconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, FLINTN, |
---|
4903 | info, evaluation |
---|
4904 | ); |
---|
4905 | #else |
---|
4906 | zeroOneVecs= extractZeroOneVecs (NTLN); |
---|
4907 | result= extReconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, NTLN, |
---|
4908 | info, evaluation |
---|
4909 | ); |
---|
4910 | #endif |
---|
4911 | delete [] zeroOneVecs; |
---|
4912 | if (degree (bufF) + 1 + degree (LC (bufF, 1)) < l && result.length() > 0) |
---|
4913 | { |
---|
4914 | F= bufF; |
---|
4915 | factors= bufUniFactors; |
---|
4916 | return result; |
---|
4917 | } |
---|
4918 | |
---|
4919 | result= CFList(); |
---|
4920 | oldL2= oldL; |
---|
4921 | oldL *= 2; |
---|
4922 | if (oldL > l) |
---|
4923 | { |
---|
4924 | if (!hitBound) |
---|
4925 | { |
---|
4926 | oldL= l; |
---|
4927 | hitBound= true; |
---|
4928 | } |
---|
4929 | else |
---|
4930 | break; |
---|
4931 | } |
---|
4932 | } |
---|
4933 | delete [] A; |
---|
4934 | return result; |
---|
4935 | } |
---|
4936 | |
---|
4937 | #ifdef HAVE_FLINT |
---|
4938 | CFList |
---|
4939 | increasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int oldL, int l, |
---|
4940 | int d, int* bounds, CFArray& bufQ, nmod_mat_t FLINTN, |
---|
4941 | const Variable& alpha, const CanonicalForm& eval |
---|
4942 | ) |
---|
4943 | #else |
---|
4944 | CFList |
---|
4945 | increasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int oldL, int l, |
---|
4946 | int d, int* bounds, CFArray& bufQ, mat_zz_p& NTLN, |
---|
4947 | const Variable& alpha, const CanonicalForm& eval |
---|
4948 | ) |
---|
4949 | #endif |
---|
4950 | { |
---|
4951 | CFList result= CFList(); |
---|
4952 | CFArray * A= new CFArray [factors.length()]; |
---|
4953 | int extensionDeg= degree (getMipo (alpha)); |
---|
4954 | int oldL2= oldL/2; |
---|
4955 | bool hitBound= false; |
---|
4956 | bool useOldQs= false; |
---|
4957 | #ifdef HAVE_FLINT |
---|
4958 | if (nmod_mat_nrows (FLINTN) != factors.length()) //refined factors |
---|
4959 | { |
---|
4960 | nmod_mat_clear (FLINTN); |
---|
4961 | nmod_mat_init(FLINTN,factors.length(),factors.length(),getCharacteristic()); |
---|
4962 | for (long i=factors.length()-1; i >= 0; i--) |
---|
4963 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
4964 | } |
---|
4965 | #else |
---|
4966 | if (NTLN.NumRows() != factors.length()) //refined factors |
---|
4967 | ident (NTLN, factors.length()); |
---|
4968 | #endif |
---|
4969 | CFListIterator j; |
---|
4970 | CFMatrix C; |
---|
4971 | CFArray buf; |
---|
4972 | #ifdef HAVE_FLINT |
---|
4973 | long rank; |
---|
4974 | nmod_mat_t FLINTC, FLINTK, null; |
---|
4975 | #else |
---|
4976 | mat_zz_p* NTLC, NTLK; |
---|
4977 | #endif |
---|
4978 | CanonicalForm bufF, truncF; |
---|
4979 | CFList bufUniFactors; |
---|
4980 | Variable y= F.mvar(); |
---|
4981 | while (oldL <= l) |
---|
4982 | { |
---|
4983 | j= factors; |
---|
4984 | truncF= mod (F, power (y, oldL)); |
---|
4985 | if (useOldQs) |
---|
4986 | { |
---|
4987 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4988 | A[i]= logarithmicDerivative (truncF, j.getItem(), oldL, oldL2, bufQ[i], |
---|
4989 | bufQ[i] |
---|
4990 | ); |
---|
4991 | } |
---|
4992 | else |
---|
4993 | { |
---|
4994 | for (int i= 0; i < factors.length(); i++, j++) |
---|
4995 | A[i]= logarithmicDerivative (truncF, j.getItem(), oldL, bufQ [i]); |
---|
4996 | } |
---|
4997 | useOldQs= true; |
---|
4998 | |
---|
4999 | for (int i= 0; i < d; i++) |
---|
5000 | { |
---|
5001 | if (bounds [i] + 1 <= oldL/2) |
---|
5002 | { |
---|
5003 | int k= tmin (bounds [i] + 1, oldL/2); |
---|
5004 | C= CFMatrix ((oldL - k)*extensionDeg, factors.length()); |
---|
5005 | for (int ii= 0; ii < factors.length(); ii++) |
---|
5006 | { |
---|
5007 | if (A[ii].size() - 1 >= i) |
---|
5008 | { |
---|
5009 | buf= getCoeffs (A[ii] [i], k, alpha); |
---|
5010 | writeInMatrix (C, buf, ii + 1, 0); |
---|
5011 | } |
---|
5012 | } |
---|
5013 | #ifdef HAVE_FLINT |
---|
5014 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
5015 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
5016 | getCharacteristic()); |
---|
5017 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
5018 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
5019 | getCharacteristic()); |
---|
5020 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
5021 | nmod_mat_clear (FLINTK); |
---|
5022 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
5023 | nmod_mat_clear (FLINTC); |
---|
5024 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
5025 | nmod_mat_clear (FLINTN); |
---|
5026 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
5027 | getCharacteristic()); |
---|
5028 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
5029 | |
---|
5030 | nmod_mat_clear (FLINTC); |
---|
5031 | nmod_mat_window_clear (FLINTK); |
---|
5032 | nmod_mat_clear (null); |
---|
5033 | #else |
---|
5034 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
5035 | NTLK= (*NTLC)*NTLN; |
---|
5036 | transpose (NTLK, NTLK); |
---|
5037 | kernel (NTLK, NTLK); |
---|
5038 | transpose (NTLK, NTLK); |
---|
5039 | NTLN *= NTLK; |
---|
5040 | delete NTLC; |
---|
5041 | #endif |
---|
5042 | #ifdef HAVE_FLINT |
---|
5043 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
5044 | #else |
---|
5045 | if (NTLN.NumCols() == 1) |
---|
5046 | #endif |
---|
5047 | { |
---|
5048 | delete [] A; |
---|
5049 | return CFList (F(y-eval,y)); |
---|
5050 | } |
---|
5051 | } |
---|
5052 | } |
---|
5053 | |
---|
5054 | int * zeroOneVecs; |
---|
5055 | #ifdef HAVE_FLINT |
---|
5056 | zeroOneVecs= extractZeroOneVecs (FLINTN); |
---|
5057 | #else |
---|
5058 | zeroOneVecs= extractZeroOneVecs (NTLN); |
---|
5059 | #endif |
---|
5060 | |
---|
5061 | bufF= F; |
---|
5062 | bufUniFactors= factors; |
---|
5063 | #ifdef HAVE_FLINT |
---|
5064 | result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, FLINTN, eval); |
---|
5065 | #else |
---|
5066 | result= reconstruction (bufF, bufUniFactors, zeroOneVecs, oldL, NTLN, eval); |
---|
5067 | #endif |
---|
5068 | delete [] zeroOneVecs; |
---|
5069 | if (degree (bufF) + 1 + degree (LC (bufF, 1)) < l && result.length() > 0) |
---|
5070 | { |
---|
5071 | F= bufF; |
---|
5072 | factors= bufUniFactors; |
---|
5073 | delete [] A; |
---|
5074 | return result; |
---|
5075 | } |
---|
5076 | |
---|
5077 | result= CFList(); |
---|
5078 | oldL2= oldL; |
---|
5079 | oldL *= 2; |
---|
5080 | if (oldL > l) |
---|
5081 | { |
---|
5082 | if (!hitBound) |
---|
5083 | { |
---|
5084 | oldL= l; |
---|
5085 | hitBound= true; |
---|
5086 | } |
---|
5087 | else |
---|
5088 | break; |
---|
5089 | } |
---|
5090 | } |
---|
5091 | delete [] A; |
---|
5092 | return result; |
---|
5093 | } |
---|
5094 | |
---|
5095 | #ifdef HAVE_FLINT |
---|
5096 | CFList |
---|
5097 | furtherLiftingAndIncreasePrecision (CanonicalForm& F, CFList& |
---|
5098 | factors, int l, int liftBound, int d, int* |
---|
5099 | bounds, nmod_mat_t FLINTN, CFList& diophant, |
---|
5100 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, |
---|
5101 | const CanonicalForm& eval |
---|
5102 | ) |
---|
5103 | #else |
---|
5104 | CFList |
---|
5105 | furtherLiftingAndIncreasePrecision (CanonicalForm& F, CFList& |
---|
5106 | factors, int l, int liftBound, int d, int* |
---|
5107 | bounds, mat_zz_p& NTLN, CFList& diophant, |
---|
5108 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, |
---|
5109 | const CanonicalForm& eval |
---|
5110 | ) |
---|
5111 | #endif |
---|
5112 | { |
---|
5113 | CanonicalForm LCF= LC (F, 1); |
---|
5114 | CFList result; |
---|
5115 | bool irreducible= false; |
---|
5116 | CFList bufFactors= factors; |
---|
5117 | CFList bufBufFactors; |
---|
5118 | CFArray *A = new CFArray [bufFactors.length()]; |
---|
5119 | bool useOldQs= false; |
---|
5120 | bool hitBound= false; |
---|
5121 | int oldL= l; |
---|
5122 | int stepSize= 8; //TODO choose better step size? |
---|
5123 | l += tmax (tmin (8, degree (F) + 1 + degree (LC (F, 1))-l), 2); |
---|
5124 | #ifdef HAVE_FLINT |
---|
5125 | if (nmod_mat_nrows (FLINTN) != factors.length()) //refined factors |
---|
5126 | { |
---|
5127 | nmod_mat_clear (FLINTN); |
---|
5128 | nmod_mat_init(FLINTN,factors.length(),factors.length(),getCharacteristic()); |
---|
5129 | for (long i=factors.length()-1; i >= 0; i--) |
---|
5130 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
5131 | } |
---|
5132 | #else |
---|
5133 | if (NTLN.NumRows() != factors.length()) //refined factors |
---|
5134 | ident (NTLN, factors.length()); |
---|
5135 | #endif |
---|
5136 | CFListIterator j; |
---|
5137 | CFMatrix C; |
---|
5138 | CFArray buf; |
---|
5139 | #ifdef HAVE_FLINT |
---|
5140 | long rank; |
---|
5141 | nmod_mat_t FLINTC, FLINTK, null; |
---|
5142 | #else |
---|
5143 | mat_zz_p* NTLC, NTLK; |
---|
5144 | #endif |
---|
5145 | CanonicalForm bufF, truncF; |
---|
5146 | Variable y= F.mvar(); |
---|
5147 | while (l <= liftBound) |
---|
5148 | { |
---|
5149 | bufFactors.insert (LCF); |
---|
5150 | henselLiftResume12 (F, bufFactors, oldL, l, Pi, diophant, M); |
---|
5151 | j= bufFactors; |
---|
5152 | truncF= mod (F, power (y, l)); |
---|
5153 | if (useOldQs) |
---|
5154 | { |
---|
5155 | for (int i= 0; i < bufFactors.length(); i++, j++) |
---|
5156 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
5157 | bufQ[i]); |
---|
5158 | } |
---|
5159 | else |
---|
5160 | { |
---|
5161 | for (int i= 0; i < bufFactors.length(); i++, j++) |
---|
5162 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
5163 | } |
---|
5164 | for (int i= 0; i < d; i++) |
---|
5165 | { |
---|
5166 | if (bounds [i] + 1 <= l/2) |
---|
5167 | { |
---|
5168 | int k= tmin (bounds [i] + 1, l/2); |
---|
5169 | C= CFMatrix (l - k, bufFactors.length()); |
---|
5170 | for (int ii= 0; ii < bufFactors.length(); ii++) |
---|
5171 | { |
---|
5172 | if (A[ii].size() - 1 >= i) |
---|
5173 | { |
---|
5174 | buf= getCoeffs (A[ii] [i], k); |
---|
5175 | writeInMatrix (C, buf, ii + 1, 0); |
---|
5176 | } |
---|
5177 | } |
---|
5178 | #ifdef HAVE_FLINT |
---|
5179 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
5180 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
5181 | getCharacteristic()); |
---|
5182 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
5183 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
5184 | getCharacteristic()); |
---|
5185 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
5186 | nmod_mat_clear (FLINTK); |
---|
5187 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
5188 | nmod_mat_clear (FLINTC); |
---|
5189 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
5190 | nmod_mat_clear (FLINTN); |
---|
5191 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
5192 | getCharacteristic()); |
---|
5193 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
5194 | |
---|
5195 | nmod_mat_clear (FLINTC); |
---|
5196 | nmod_mat_window_clear (FLINTK); |
---|
5197 | nmod_mat_clear (null); |
---|
5198 | #else |
---|
5199 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
5200 | NTLK= (*NTLC)*NTLN; |
---|
5201 | transpose (NTLK, NTLK); |
---|
5202 | kernel (NTLK, NTLK); |
---|
5203 | transpose (NTLK, NTLK); |
---|
5204 | NTLN *= NTLK; |
---|
5205 | delete NTLC; |
---|
5206 | #endif |
---|
5207 | #ifdef HAVE_FLINT |
---|
5208 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
5209 | #else |
---|
5210 | if (NTLN.NumCols() == 1) |
---|
5211 | #endif |
---|
5212 | { |
---|
5213 | irreducible= true; |
---|
5214 | break; |
---|
5215 | } |
---|
5216 | } |
---|
5217 | } |
---|
5218 | |
---|
5219 | #ifdef HAVE_FLINT |
---|
5220 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
5221 | #else |
---|
5222 | if (NTLN.NumCols() == 1) |
---|
5223 | #endif |
---|
5224 | { |
---|
5225 | irreducible= true; |
---|
5226 | break; |
---|
5227 | } |
---|
5228 | |
---|
5229 | #ifdef HAVE_FLINT |
---|
5230 | int * zeroOneVecs= extractZeroOneVecs (FLINTN); |
---|
5231 | #else |
---|
5232 | int * zeroOneVecs= extractZeroOneVecs (NTLN); |
---|
5233 | #endif |
---|
5234 | bufF= F; |
---|
5235 | bufBufFactors= bufFactors; |
---|
5236 | #ifdef HAVE_FLINT |
---|
5237 | result= reconstruction (bufF, bufFactors, zeroOneVecs, l, FLINTN, eval); |
---|
5238 | #else |
---|
5239 | result= reconstruction (bufF, bufFactors, zeroOneVecs, l, NTLN, eval); |
---|
5240 | #endif |
---|
5241 | delete [] zeroOneVecs; |
---|
5242 | if (result.length() > 0 && degree (bufF) + 1 + degree (LC (bufF, 1)) <= l) |
---|
5243 | { |
---|
5244 | F= bufF; |
---|
5245 | factors= bufFactors; |
---|
5246 | delete [] A; |
---|
5247 | return result; |
---|
5248 | } |
---|
5249 | else |
---|
5250 | { |
---|
5251 | bufF= F; |
---|
5252 | bufFactors= bufBufFactors; |
---|
5253 | } |
---|
5254 | |
---|
5255 | #ifdef HAVE_FLINT |
---|
5256 | if (isReduced (FLINTN)) |
---|
5257 | #else |
---|
5258 | if (isReduced (NTLN)) |
---|
5259 | #endif |
---|
5260 | { |
---|
5261 | int factorsFound= 0; |
---|
5262 | bufF= F; |
---|
5263 | #ifdef HAVE_FLINT |
---|
5264 | int* factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)]; |
---|
5265 | for (long i= 0; i < nmod_mat_ncols (FLINTN); i++) |
---|
5266 | #else |
---|
5267 | int* factorsFoundIndex= new int [NTLN.NumCols()]; |
---|
5268 | for (long i= 0; i < NTLN.NumCols(); i++) |
---|
5269 | #endif |
---|
5270 | factorsFoundIndex[i]= 0; |
---|
5271 | #ifdef HAVE_FLINT |
---|
5272 | if (l < liftBound) |
---|
5273 | reconstructionTry (result, bufF, bufFactors, l, factorsFound, |
---|
5274 | factorsFoundIndex, FLINTN, eval, false |
---|
5275 | ); |
---|
5276 | else |
---|
5277 | reconstructionTry (result, bufF, bufFactors, degree (bufF) + 1 + |
---|
5278 | degree (LCF), factorsFound, factorsFoundIndex, |
---|
5279 | FLINTN, eval, false |
---|
5280 | ); |
---|
5281 | |
---|
5282 | if (nmod_mat_ncols (FLINTN) == result.length()) |
---|
5283 | #else |
---|
5284 | if (l < liftBound) |
---|
5285 | reconstructionTry (result, bufF, bufFactors, l, factorsFound, |
---|
5286 | factorsFoundIndex, NTLN, eval, false |
---|
5287 | ); |
---|
5288 | else |
---|
5289 | reconstructionTry (result, bufF, bufFactors, degree (bufF) + 1 + |
---|
5290 | degree (LCF), factorsFound, factorsFoundIndex, |
---|
5291 | NTLN, eval, false |
---|
5292 | ); |
---|
5293 | |
---|
5294 | if (NTLN.NumCols() == result.length()) |
---|
5295 | #endif |
---|
5296 | { |
---|
5297 | delete [] A; |
---|
5298 | delete [] factorsFoundIndex; |
---|
5299 | return result; |
---|
5300 | } |
---|
5301 | delete [] factorsFoundIndex; |
---|
5302 | } |
---|
5303 | result= CFList(); |
---|
5304 | oldL= l; |
---|
5305 | stepSize *= 2; |
---|
5306 | l += stepSize; |
---|
5307 | if (l > liftBound) |
---|
5308 | { |
---|
5309 | if (!hitBound) |
---|
5310 | { |
---|
5311 | l= liftBound; |
---|
5312 | hitBound= true; |
---|
5313 | } |
---|
5314 | else |
---|
5315 | break; |
---|
5316 | } |
---|
5317 | } |
---|
5318 | if (irreducible) |
---|
5319 | { |
---|
5320 | delete [] A; |
---|
5321 | return CFList (F (y-eval,y)); |
---|
5322 | } |
---|
5323 | delete [] A; |
---|
5324 | factors= bufFactors; |
---|
5325 | return CFList(); |
---|
5326 | } |
---|
5327 | |
---|
5328 | //Fq |
---|
5329 | CFList |
---|
5330 | furtherLiftingAndIncreasePrecision (CanonicalForm& F, CFList& |
---|
5331 | factors, int l, int liftBound, int d, int* |
---|
5332 | bounds, mat_zz_pE& NTLN, CFList& diophant, |
---|
5333 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, |
---|
5334 | const CanonicalForm& eval |
---|
5335 | ) |
---|
5336 | { |
---|
5337 | CanonicalForm LCF= LC (F, 1); |
---|
5338 | CFList result; |
---|
5339 | bool irreducible= false; |
---|
5340 | CFList bufFactors= factors; |
---|
5341 | CFList bufBufFactors; |
---|
5342 | CFArray *A = new CFArray [bufFactors.length()]; |
---|
5343 | bool useOldQs= false; |
---|
5344 | bool hitBound= false; |
---|
5345 | int oldL= l; |
---|
5346 | int stepSize= 8; //TODO choose better step size? |
---|
5347 | l += tmax (tmin (8, degree (F) + 1 + degree (LC (F, 1))-l), 2); |
---|
5348 | if (NTLN.NumRows() != factors.length()) //refined factors |
---|
5349 | ident (NTLN, factors.length()); |
---|
5350 | CFListIterator j; |
---|
5351 | CFArray buf; |
---|
5352 | mat_zz_pE* NTLC, NTLK; |
---|
5353 | CanonicalForm bufF, truncF; |
---|
5354 | Variable y= F.mvar(); |
---|
5355 | while (l <= liftBound) |
---|
5356 | { |
---|
5357 | bufFactors.insert (LCF); |
---|
5358 | henselLiftResume12 (F, bufFactors, oldL, l, Pi, diophant, M); |
---|
5359 | j= bufFactors; |
---|
5360 | truncF= mod (F, power (y, l)); |
---|
5361 | if (useOldQs) |
---|
5362 | { |
---|
5363 | for (int i= 0; i < bufFactors.length(); i++, j++) |
---|
5364 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
5365 | bufQ[i]); |
---|
5366 | } |
---|
5367 | else |
---|
5368 | { |
---|
5369 | for (int i= 0; i < bufFactors.length(); i++, j++) |
---|
5370 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
5371 | } |
---|
5372 | for (int i= 0; i < d; i++) |
---|
5373 | { |
---|
5374 | if (bounds [i] + 1 <= l/2) |
---|
5375 | { |
---|
5376 | int k= tmin (bounds [i] + 1, l/2); |
---|
5377 | CFMatrix C= CFMatrix (l - k, bufFactors.length()); |
---|
5378 | for (int ii= 0; ii < bufFactors.length(); ii++) |
---|
5379 | { |
---|
5380 | if (A[ii].size() - 1 >= i) |
---|
5381 | { |
---|
5382 | buf= getCoeffs (A[ii] [i], k); |
---|
5383 | writeInMatrix (C, buf, ii + 1, 0); |
---|
5384 | } |
---|
5385 | } |
---|
5386 | NTLC= convertFacCFMatrix2NTLmat_zz_pE(C); |
---|
5387 | NTLK= (*NTLC)*NTLN; |
---|
5388 | transpose (NTLK, NTLK); |
---|
5389 | kernel (NTLK, NTLK); |
---|
5390 | transpose (NTLK, NTLK); |
---|
5391 | NTLN *= NTLK; |
---|
5392 | delete NTLC; |
---|
5393 | if (NTLN.NumCols() == 1) |
---|
5394 | { |
---|
5395 | irreducible= true; |
---|
5396 | break; |
---|
5397 | } |
---|
5398 | } |
---|
5399 | } |
---|
5400 | if (NTLN.NumCols() == 1) |
---|
5401 | { |
---|
5402 | irreducible= true; |
---|
5403 | break; |
---|
5404 | } |
---|
5405 | |
---|
5406 | int * zeroOneVecs= extractZeroOneVecs (NTLN); |
---|
5407 | bufF= F; |
---|
5408 | bufBufFactors= bufFactors; |
---|
5409 | result= reconstruction (bufF, bufFactors, zeroOneVecs, l, NTLN, eval); |
---|
5410 | delete [] zeroOneVecs; |
---|
5411 | if (result.length() > 0 && degree (bufF) + 1 + degree (LC (bufF, 1)) <= l) |
---|
5412 | { |
---|
5413 | F= bufF; |
---|
5414 | factors= bufFactors; |
---|
5415 | delete [] A; |
---|
5416 | return result; |
---|
5417 | } |
---|
5418 | else |
---|
5419 | { |
---|
5420 | bufF= F; |
---|
5421 | bufFactors= bufBufFactors; |
---|
5422 | } |
---|
5423 | |
---|
5424 | if (isReduced (NTLN)) |
---|
5425 | { |
---|
5426 | int factorsFound= 0; |
---|
5427 | bufF= F; |
---|
5428 | int* factorsFoundIndex= new int [NTLN.NumCols()]; |
---|
5429 | for (long i= 0; i < NTLN.NumCols(); i++) |
---|
5430 | factorsFoundIndex[i]= 0; |
---|
5431 | if (l < liftBound) |
---|
5432 | reconstructionTry (result, bufF, bufFactors, l, factorsFound, |
---|
5433 | factorsFoundIndex, NTLN, eval, false |
---|
5434 | ); |
---|
5435 | else |
---|
5436 | reconstructionTry (result, bufF, bufFactors, degree (bufF) + 1 + |
---|
5437 | degree (LCF), factorsFound, factorsFoundIndex, |
---|
5438 | NTLN, eval, false |
---|
5439 | ); |
---|
5440 | if (NTLN.NumCols() == result.length()) |
---|
5441 | { |
---|
5442 | delete [] A; |
---|
5443 | delete [] factorsFoundIndex; |
---|
5444 | return result; |
---|
5445 | } |
---|
5446 | delete [] factorsFoundIndex; |
---|
5447 | } |
---|
5448 | result= CFList(); |
---|
5449 | oldL= l; |
---|
5450 | stepSize *= 2; |
---|
5451 | l += stepSize; |
---|
5452 | if (l > liftBound) |
---|
5453 | { |
---|
5454 | if (!hitBound) |
---|
5455 | { |
---|
5456 | l= liftBound; |
---|
5457 | hitBound= true; |
---|
5458 | } |
---|
5459 | else |
---|
5460 | break; |
---|
5461 | } |
---|
5462 | } |
---|
5463 | if (irreducible) |
---|
5464 | { |
---|
5465 | delete [] A; |
---|
5466 | return CFList (F (y-eval,y)); |
---|
5467 | } |
---|
5468 | delete [] A; |
---|
5469 | factors= bufFactors; |
---|
5470 | return CFList(); |
---|
5471 | } |
---|
5472 | |
---|
5473 | //over field extension |
---|
5474 | #ifdef HAVE_FLINT |
---|
5475 | CFList |
---|
5476 | extFurtherLiftingAndIncreasePrecision (CanonicalForm& F, CFList& factors, int l, |
---|
5477 | int liftBound, int d, int* bounds, |
---|
5478 | nmod_mat_t FLINTN, CFList& diophant, |
---|
5479 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, |
---|
5480 | const CanonicalForm& evaluation, const |
---|
5481 | ExtensionInfo& info, CFList& source, |
---|
5482 | CFList& dest |
---|
5483 | ) |
---|
5484 | #else |
---|
5485 | CFList |
---|
5486 | extFurtherLiftingAndIncreasePrecision (CanonicalForm& F, CFList& factors, int l, |
---|
5487 | int liftBound, int d, int* bounds, |
---|
5488 | mat_zz_p& NTLN, CFList& diophant, |
---|
5489 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, |
---|
5490 | const CanonicalForm& evaluation, const |
---|
5491 | ExtensionInfo& info, CFList& source, |
---|
5492 | CFList& dest |
---|
5493 | ) |
---|
5494 | #endif |
---|
5495 | { |
---|
5496 | CanonicalForm LCF= LC (F, 1); |
---|
5497 | CFList result; |
---|
5498 | bool irreducible= false; |
---|
5499 | CFList bufFactors= factors; |
---|
5500 | CFList bufBufFactors; |
---|
5501 | CFArray *A = new CFArray [bufFactors.length()]; |
---|
5502 | bool useOldQs= false; |
---|
5503 | bool hitBound= false; |
---|
5504 | bool GF= (CFFactory::gettype()==GaloisFieldDomain); |
---|
5505 | int degMipo= degree (getMipo (info.getAlpha())); |
---|
5506 | Variable alpha= info.getAlpha(); |
---|
5507 | int oldL= l; //be careful |
---|
5508 | int stepSize= 8; |
---|
5509 | l += tmax (tmin (8, degree (F) + 1 + degree (LC (F, 1))-l),2); |
---|
5510 | Variable gamma= info.getBeta(); |
---|
5511 | CanonicalForm primElemAlpha= info.getGamma(); |
---|
5512 | CanonicalForm imPrimElemAlpha= info.getDelta(); |
---|
5513 | #ifdef HAVE_FLINT |
---|
5514 | nmod_mat_clear (FLINTN); |
---|
5515 | nmod_mat_init (FLINTN,factors.length(),factors.length(), getCharacteristic()); |
---|
5516 | for (long i=factors.length()-1; i >= 0; i--) |
---|
5517 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
5518 | #else |
---|
5519 | if (NTLN.NumRows() != factors.length()) //refined factors |
---|
5520 | ident (NTLN, factors.length()); |
---|
5521 | #endif |
---|
5522 | Variable y= F.mvar(); |
---|
5523 | CanonicalForm powX, imBasis, bufF, truncF; |
---|
5524 | CFMatrix Mat, C; |
---|
5525 | CFIterator iter; |
---|
5526 | #ifdef HAVE_FLINT |
---|
5527 | long rank; |
---|
5528 | nmod_mat_t FLINTMat, FLINTMatInv, FLINTC, FLINTK, null; |
---|
5529 | #else |
---|
5530 | mat_zz_p* NTLMat,*NTLC, NTLK; |
---|
5531 | #endif |
---|
5532 | CFListIterator j; |
---|
5533 | CFArray buf; |
---|
5534 | while (l <= liftBound) |
---|
5535 | { |
---|
5536 | bufFactors.insert (LCF); |
---|
5537 | henselLiftResume12 (F, bufFactors, oldL, l, Pi, diophant, M); |
---|
5538 | |
---|
5539 | if (GF) |
---|
5540 | setCharacteristic (getCharacteristic()); |
---|
5541 | |
---|
5542 | powX= power (y-gamma, l); |
---|
5543 | Mat= CFMatrix (l*degMipo, l*degMipo); |
---|
5544 | for (int i= 0; i < l*degMipo; i++) |
---|
5545 | { |
---|
5546 | |
---|
5547 | imBasis= mod (power (y, i), powX); |
---|
5548 | imBasis= imBasis (power (y, degMipo), y); |
---|
5549 | imBasis= imBasis (y, gamma); |
---|
5550 | iter= imBasis; |
---|
5551 | for (; iter.hasTerms(); iter++) |
---|
5552 | Mat (iter.exp()+ 1, i+1)= iter.coeff(); |
---|
5553 | } |
---|
5554 | |
---|
5555 | #ifdef HAVE_FLINT |
---|
5556 | convertFacCFMatrix2nmod_mat_t (FLINTMat, Mat); |
---|
5557 | nmod_mat_init (FLINTMatInv, nmod_mat_nrows (FLINTMat), |
---|
5558 | nmod_mat_nrows (FLINTMat), getCharacteristic()); |
---|
5559 | nmod_mat_inv (FLINTMatInv, FLINTMat); |
---|
5560 | #else |
---|
5561 | NTLMat= convertFacCFMatrix2NTLmat_zz_p (Mat); |
---|
5562 | *NTLMat= inv (*NTLMat); |
---|
5563 | #endif |
---|
5564 | |
---|
5565 | if (GF) |
---|
5566 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
5567 | |
---|
5568 | j= bufFactors; |
---|
5569 | truncF= mod (F, power (y, l)); |
---|
5570 | if (useOldQs) |
---|
5571 | { |
---|
5572 | for (int i= 0; i < bufFactors.length(); i++, j++) |
---|
5573 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
5574 | bufQ[i]); |
---|
5575 | } |
---|
5576 | else |
---|
5577 | { |
---|
5578 | for (int i= 0; i < bufFactors.length(); i++, j++) |
---|
5579 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
5580 | } |
---|
5581 | for (int i= 0; i < d; i++) |
---|
5582 | { |
---|
5583 | if (bounds [i] + 1 <= l/2) |
---|
5584 | { |
---|
5585 | int k= tmin (bounds [i] + 1, l/2); |
---|
5586 | C= CFMatrix (l*degMipo - k, bufFactors.length()); |
---|
5587 | for (int ii= 0; ii < bufFactors.length(); ii++) |
---|
5588 | { |
---|
5589 | if (A[ii].size() - 1 >= i) |
---|
5590 | { |
---|
5591 | if (GF) |
---|
5592 | { |
---|
5593 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
5594 | setCharacteristic (getCharacteristic()); |
---|
5595 | A[ii] [i]= GF2FalphaRep (A[ii] [i], alpha); |
---|
5596 | if (alpha != gamma) |
---|
5597 | A [ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
5598 | gamma, source, dest |
---|
5599 | ); |
---|
5600 | #ifdef HAVE_FLINT |
---|
5601 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, FLINTMatInv); |
---|
5602 | #else |
---|
5603 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, *NTLMat); |
---|
5604 | #endif |
---|
5605 | } |
---|
5606 | else |
---|
5607 | { |
---|
5608 | A [ii] [i]= A [ii] [i] (y-evaluation, y); |
---|
5609 | if (alpha != gamma) |
---|
5610 | A[ii] [i]= mapDown (A[ii] [i], imPrimElemAlpha, primElemAlpha, |
---|
5611 | gamma, source, dest |
---|
5612 | ); |
---|
5613 | #ifdef HAVE_FLINT |
---|
5614 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, FLINTMatInv); |
---|
5615 | #else |
---|
5616 | buf= getCoeffs (A[ii] [i], k, l, degMipo, gamma, 0, *NTLMat); |
---|
5617 | #endif |
---|
5618 | } |
---|
5619 | writeInMatrix (C, buf, ii + 1, 0); |
---|
5620 | } |
---|
5621 | if (GF) |
---|
5622 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
5623 | } |
---|
5624 | |
---|
5625 | if (GF) |
---|
5626 | setCharacteristic(getCharacteristic()); |
---|
5627 | |
---|
5628 | #ifdef HAVE_FLINT |
---|
5629 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
5630 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
5631 | getCharacteristic()); |
---|
5632 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
5633 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
5634 | getCharacteristic()); |
---|
5635 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
5636 | nmod_mat_clear (FLINTK); |
---|
5637 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
5638 | nmod_mat_clear (FLINTC); |
---|
5639 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
5640 | nmod_mat_clear (FLINTN); |
---|
5641 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
5642 | getCharacteristic()); |
---|
5643 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
5644 | |
---|
5645 | nmod_mat_clear (FLINTC); |
---|
5646 | nmod_mat_window_clear (FLINTK); |
---|
5647 | nmod_mat_clear (null); |
---|
5648 | #else |
---|
5649 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
5650 | NTLK= (*NTLC)*NTLN; |
---|
5651 | transpose (NTLK, NTLK); |
---|
5652 | kernel (NTLK, NTLK); |
---|
5653 | transpose (NTLK, NTLK); |
---|
5654 | NTLN *= NTLK; |
---|
5655 | delete NTLC; |
---|
5656 | #endif |
---|
5657 | |
---|
5658 | if (GF) |
---|
5659 | setCharacteristic (getCharacteristic(), degMipo, info.getGFName()); |
---|
5660 | |
---|
5661 | #ifdef HAVE_FLINT |
---|
5662 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
5663 | #else |
---|
5664 | if (NTLN.NumCols() == 1) |
---|
5665 | #endif |
---|
5666 | { |
---|
5667 | irreducible= true; |
---|
5668 | break; |
---|
5669 | } |
---|
5670 | } |
---|
5671 | } |
---|
5672 | |
---|
5673 | #ifdef HAVE_FLINT |
---|
5674 | nmod_mat_clear (FLINTMat); |
---|
5675 | nmod_mat_clear (FLINTMatInv); |
---|
5676 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
5677 | #else |
---|
5678 | delete NTLMat; |
---|
5679 | if (NTLN.NumCols() == 1) |
---|
5680 | #endif |
---|
5681 | { |
---|
5682 | irreducible= true; |
---|
5683 | break; |
---|
5684 | } |
---|
5685 | |
---|
5686 | bufF= F; |
---|
5687 | bufBufFactors= bufFactors; |
---|
5688 | #ifdef HAVE_FLINT |
---|
5689 | int * zeroOneVecs= extractZeroOneVecs (FLINTN); |
---|
5690 | result= extReconstruction (bufF, bufFactors, zeroOneVecs, l, FLINTN, info, |
---|
5691 | evaluation |
---|
5692 | ); |
---|
5693 | #else |
---|
5694 | int * zeroOneVecs= extractZeroOneVecs (NTLN); |
---|
5695 | result= extReconstruction (bufF, bufFactors, zeroOneVecs, l, NTLN, info, |
---|
5696 | evaluation |
---|
5697 | ); |
---|
5698 | #endif |
---|
5699 | delete [] zeroOneVecs; |
---|
5700 | if (result.length() > 0 && degree (bufF) + 1 + degree (LC (bufF, 1)) <= l) |
---|
5701 | { |
---|
5702 | F= bufF; |
---|
5703 | factors= bufFactors; |
---|
5704 | delete [] A; |
---|
5705 | return result; |
---|
5706 | } |
---|
5707 | else |
---|
5708 | { |
---|
5709 | bufF= F; |
---|
5710 | bufFactors= bufBufFactors; |
---|
5711 | } |
---|
5712 | |
---|
5713 | #ifdef HAVE_FLINT |
---|
5714 | if (isReduced (FLINTN)) |
---|
5715 | #else |
---|
5716 | if (isReduced (NTLN)) |
---|
5717 | #endif |
---|
5718 | { |
---|
5719 | int factorsFound= 0; |
---|
5720 | bufF= F; |
---|
5721 | #ifdef HAVE_FLINT |
---|
5722 | int* factorsFoundIndex= new int [nmod_mat_ncols (FLINTN)]; |
---|
5723 | for (long i= 0; i < nmod_mat_ncols (FLINTN); i++) |
---|
5724 | #else |
---|
5725 | int* factorsFoundIndex= new int [NTLN.NumCols()]; |
---|
5726 | for (long i= 0; i < NTLN.NumCols(); i++) |
---|
5727 | #endif |
---|
5728 | factorsFoundIndex[i]= 0; |
---|
5729 | #ifdef HAVE_FLINT |
---|
5730 | if (l < degree (bufF) + 1 + degree (LCF)) |
---|
5731 | extReconstructionTry (result, bufF, bufFactors, l, factorsFound, |
---|
5732 | factorsFoundIndex, FLINTN, false, info, evaluation |
---|
5733 | ); |
---|
5734 | else |
---|
5735 | extReconstructionTry (result, bufF, bufFactors, degree (bufF) + 1 + |
---|
5736 | degree (LCF), factorsFound, factorsFoundIndex, |
---|
5737 | FLINTN, false, info, evaluation |
---|
5738 | ); |
---|
5739 | if (nmod_mat_ncols (FLINTN) == result.length()) |
---|
5740 | #else |
---|
5741 | if (l < degree (bufF) + 1 + degree (LCF)) |
---|
5742 | extReconstructionTry (result, bufF, bufFactors, l, factorsFound, |
---|
5743 | factorsFoundIndex, NTLN, false, info, evaluation |
---|
5744 | ); |
---|
5745 | else |
---|
5746 | extReconstructionTry (result, bufF, bufFactors, degree (bufF) + 1 + |
---|
5747 | degree (LCF), factorsFound, factorsFoundIndex, |
---|
5748 | NTLN, false, info, evaluation |
---|
5749 | ); |
---|
5750 | if (NTLN.NumCols() == result.length()) |
---|
5751 | #endif |
---|
5752 | { |
---|
5753 | delete [] A; |
---|
5754 | delete [] factorsFoundIndex; |
---|
5755 | return result; |
---|
5756 | } |
---|
5757 | delete [] factorsFoundIndex; |
---|
5758 | } |
---|
5759 | result= CFList(); |
---|
5760 | oldL= l; |
---|
5761 | stepSize *= 2; |
---|
5762 | l += stepSize; |
---|
5763 | if (l > liftBound) |
---|
5764 | { |
---|
5765 | if (!hitBound) |
---|
5766 | { |
---|
5767 | l= liftBound; |
---|
5768 | hitBound= true; |
---|
5769 | } |
---|
5770 | else |
---|
5771 | break; |
---|
5772 | } |
---|
5773 | } |
---|
5774 | if (irreducible) |
---|
5775 | { |
---|
5776 | delete [] A; |
---|
5777 | Variable y= Variable (2); |
---|
5778 | CanonicalForm tmp= F (y - evaluation, y); |
---|
5779 | CFList source, dest; |
---|
5780 | tmp= mapDown (tmp, info, source, dest); |
---|
5781 | return CFList (tmp); |
---|
5782 | } |
---|
5783 | delete [] A; |
---|
5784 | factors= bufFactors; |
---|
5785 | return CFList(); |
---|
5786 | } |
---|
5787 | |
---|
5788 | #ifdef HAVE_FLINT |
---|
5789 | CFList |
---|
5790 | furtherLiftingAndIncreasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int |
---|
5791 | l, int liftBound, int d, int* bounds, |
---|
5792 | nmod_mat_t FLINTN, CFList& diophant, |
---|
5793 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, |
---|
5794 | const Variable& alpha, |
---|
5795 | const CanonicalForm& eval |
---|
5796 | ) |
---|
5797 | #else |
---|
5798 | CFList |
---|
5799 | furtherLiftingAndIncreasePrecisionFq2Fp (CanonicalForm& F, CFList& factors, int |
---|
5800 | l, int liftBound, int d, int* bounds, |
---|
5801 | mat_zz_p& NTLN, CFList& diophant, |
---|
5802 | CFMatrix& M, CFArray& Pi, CFArray& bufQ, |
---|
5803 | const Variable& alpha, |
---|
5804 | const CanonicalForm& eval |
---|
5805 | ) |
---|
5806 | #endif |
---|
5807 | { |
---|
5808 | CanonicalForm LCF= LC (F, 1); |
---|
5809 | CFList result; |
---|
5810 | bool irreducible= false; |
---|
5811 | CFList bufFactors= factors; |
---|
5812 | CFList bufBufFactors; |
---|
5813 | CFArray *A = new CFArray [bufFactors.length()]; |
---|
5814 | bool useOldQs= false; |
---|
5815 | int extensionDeg= degree (getMipo (alpha)); |
---|
5816 | bool hitBound= false; |
---|
5817 | int oldL= l; |
---|
5818 | int stepSize= 8; //TODO choose better step size? |
---|
5819 | l += tmax (tmin (8, degree (F) + 1 + degree (LC (F, 1))-l), 2); |
---|
5820 | #ifdef HAVE_FLINT |
---|
5821 | if (nmod_mat_nrows (FLINTN) != factors.length()) //refined factors |
---|
5822 | { |
---|
5823 | nmod_mat_clear (FLINTN); |
---|
5824 | nmod_mat_init(FLINTN,factors.length(),factors.length(),getCharacteristic()); |
---|
5825 | for (long i=factors.length()-1; i >= 0; i--) |
---|
5826 | nmod_mat_entry (FLINTN, i, i)= 1; |
---|
5827 | } |
---|
5828 | #else |
---|
5829 | if (NTLN.NumRows() != factors.length()) //refined factors |
---|
5830 | ident (NTLN, factors.length()); |
---|
5831 | #endif |
---|
5832 | CFListIterator j; |
---|
5833 | CFMatrix C; |
---|
5834 | #ifdef HAVE_FLINT |
---|
5835 | long rank; |
---|
5836 | nmod_mat_t FLINTC, FLINTK, null; |
---|
5837 | #else |
---|
5838 | mat_zz_p* NTLC, NTLK; |
---|
5839 | #endif |
---|
5840 | CanonicalForm bufF, truncF; |
---|
5841 | Variable y= F.mvar(); |
---|
5842 | while (l <= liftBound) |
---|
5843 | { |
---|
5844 | bufFactors.insert (LCF); |
---|
5845 | henselLiftResume12 (F, bufFactors, oldL, l, Pi, diophant, M); |
---|
5846 | j= bufFactors; |
---|
5847 | truncF= mod (F, power (y, l)); |
---|
5848 | if (useOldQs) |
---|
5849 | { |
---|
5850 | for (int i= 0; i < bufFactors.length(); i++, j++) |
---|
5851 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, oldL, bufQ[i], |
---|
5852 | bufQ[i]); |
---|
5853 | } |
---|
5854 | else |
---|
5855 | { |
---|
5856 | for (int i= 0; i < bufFactors.length(); i++, j++) |
---|
5857 | A[i]= logarithmicDerivative (truncF, j.getItem(), l, bufQ [i]); |
---|
5858 | } |
---|
5859 | for (int i= 0; i < d; i++) |
---|
5860 | { |
---|
5861 | if (bounds [i] + 1 <= l/2) |
---|
5862 | { |
---|
5863 | int k= tmin (bounds [i] + 1, l/2); |
---|
5864 | C= CFMatrix ((l - k)*extensionDeg, bufFactors.length()); |
---|
5865 | for (int ii= 0; ii < bufFactors.length(); ii++) |
---|
5866 | { |
---|
5867 | CFArray buf; |
---|
5868 | if (A[ii].size() - 1 >= i) |
---|
5869 | { |
---|
5870 | buf= getCoeffs (A[ii] [i], k, alpha); |
---|
5871 | writeInMatrix (C, buf, ii + 1, 0); |
---|
5872 | } |
---|
5873 | } |
---|
5874 | #ifdef HAVE_FLINT |
---|
5875 | convertFacCFMatrix2nmod_mat_t (FLINTC, C); |
---|
5876 | nmod_mat_init (FLINTK, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTN), |
---|
5877 | getCharacteristic()); |
---|
5878 | nmod_mat_mul (FLINTK, FLINTC, FLINTN); |
---|
5879 | nmod_mat_init (null, nmod_mat_ncols (FLINTK), nmod_mat_ncols (FLINTK), |
---|
5880 | getCharacteristic()); |
---|
5881 | rank= nmod_mat_nullspace (null, FLINTK); |
---|
5882 | nmod_mat_clear (FLINTK); |
---|
5883 | nmod_mat_window_init (FLINTK, null, 0, 0, nmod_mat_nrows(null), rank); |
---|
5884 | nmod_mat_clear (FLINTC); |
---|
5885 | nmod_mat_init_set (FLINTC, FLINTN); |
---|
5886 | nmod_mat_clear (FLINTN); |
---|
5887 | nmod_mat_init (FLINTN, nmod_mat_nrows (FLINTC), nmod_mat_ncols (FLINTK), |
---|
5888 | getCharacteristic()); |
---|
5889 | nmod_mat_mul (FLINTN, FLINTC, FLINTK); //no aliasing allowed!! |
---|
5890 | |
---|
5891 | nmod_mat_clear (FLINTC); |
---|
5892 | nmod_mat_window_clear (FLINTK); |
---|
5893 | nmod_mat_clear (null); |
---|
5894 | #else |
---|
5895 | NTLC= convertFacCFMatrix2NTLmat_zz_p(C); |
---|
5896 | NTLK= (*NTLC)*NTLN; |
---|
5897 | transpose (NTLK, NTLK); |
---|
5898 | kernel (NTLK, NTLK); |
---|
5899 | transpose (NTLK, NTLK); |
---|
5900 | NTLN *= NTLK; |
---|
5901 | delete NTLC; |
---|
5902 | #endif |
---|
5903 | #ifdef HAVE_FLINT |
---|
5904 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
5905 | #else |
---|
5906 | if (NTLN.NumCols() == 1) |
---|
5907 | #endif |
---|
5908 | { |
---|
5909 | irreducible= true; |
---|
5910 | break; |
---|
5911 | } |
---|
5912 | } |
---|
5913 | } |
---|
5914 | #ifdef HAVE_FLINT |
---|
5915 | if (nmod_mat_ncols (FLINTN) == 1) |
---|
5916 | #else |
---|
5917 | if (NTLN.NumCols() == 1) |
---|
5918 | #endif |
---|
5919 | { |
---|
5920 | irreducible= true; |
---|
5921 | break; |
---|
5922 | } |
---|
5923 | |
---|
5924 | #ifdef HAVE_FLINT |
---|
5925 | int * zeroOneVecs= extractZeroOneVecs (FLINTN); |
---|
5926 | #else |
---|
5927 | int * zeroOneVecs= extractZeroOneVecs (NTLN); |
---|
5928 | #endif |
---|
5929 | CanonicalForm bufF= F; |
---|
5930 | bufBufFactors= bufFactors; |
---|
5931 | #ifdef HAVE_FLINT |
---|
5932 | result= reconstruction (bufF, bufFactors, zeroOneVecs, l, FLINTN, eval); |
---|
5933 | #else |
---|
5934 | result= reconstruction (bufF, bufFactors, zeroOneVecs, l, NTLN, eval); |
---|
5935 | #endif |
---|
5936 | delete [] zeroOneVecs; |
---|
5937 | if (result.length() > 0 && degree (bufF) + 1 + degree (LC (bufF, 1)) <= l) |
---|
5938 | { |
---|
5939 | F= bufF; |
---|
5940 | factors= bufFactors; |
---|
5941 | delete [] A; |
---|
5942 | return result; |
---|
5943 | } |
---|
5944 | else |
---|
5945 | { |
---|
5946 | bufF= F; |
---|
5947 | bufFactors= bufBufFactors; |
---|
5948 | } |
---|
5949 | |
---|
5950 | #ifdef H |
---|