199{
202
204
209
210
211 if (F.isUnivariate())
212 {
216 else
218 if (
result.getFirst().inCoeffDomain())
221 }
222
223
225 {
227 if (
buf.getFirst().inCoeffDomain())
230 }
231
234
235
241
242
244 if (
A.inCoeffDomain())
245 {
247 {
248 if (
i.getItem().inCoeffDomain())
249 continue;
250 else
251 {
252 lcmCont /=
i.getItem();
253 contentAFactors=
256 break;
257 }
258 }
262 return contentAFactors;
263 }
264
265
269
270
272 if (
A.isUnivariate ())
273 {
276 else
278 append (factors, contentAFactors);
280 return factors;
281 }
282
285 int factorNums= 2;
286
287
288
289
290
291
292
293 CFList biFactors, bufBiFactors;
295 int lift, bufLift, lengthAeval2=
A.level()-2;
298 int counter;
299 int differentSecondVar= 0;
302 "time to preprocess poly and extract content over Q: ");
303
304
307 for (
int i= 0;
i < factorNums;
i++)
308 {
309 counter= 0;
315 "time to find evaluation point over Q: ");
317 evalPoly= 0;
318
322 "time to eval wrt diff second vars over Q: ");
323
324 for (
int j= 0;
j < lengthAeval2;
j++)
325 {
326 if (!bufAeval2[
j].isEmpty())
327 counter++;
328 }
329
331
335 "time for bivariate factorization: ");
337
338 if (bufBiFactors.
length() == 1)
339 {
344 delete [] bufAeval2;
345 delete [] Aeval2;
346 return factors;
347 }
348
350 {
353 biFactors= bufBiFactors;
355 for (
int j= 0;
j < lengthAeval2;
j++)
356 Aeval2 [
j]= bufAeval2 [
j];
357 differentSecondVar= counter;
358 }
359 else
360 {
363 counter > differentSecondVar)
364 {
367 biFactors= bufBiFactors;
369 for (
int j= 0;
j < lengthAeval2;
j++)
370 Aeval2 [
j]= bufAeval2 [
j];
371 differentSecondVar= counter;
372 }
373 }
376 evalPoly +=
j.getItem()*
power (
x,
k);
378 }
379
380 delete [] bufAeval2;
381
383
389 "time for bivariate factorization wrt diff second vars over Q: ");
390
392 "total time for eval and bivar factors over Q: ");
394 {
399 delete [] Aeval2;
400 return factors;
401 }
402
408
410
412
414
416 {
421 delete [] Aeval2;
422 return factors;
423 }
424
425 if (differentSecondVar == lengthAeval2)
426 {
427 bool zeroOccured= false;
429 {
431 {
432 zeroOccured= true;
433 break;
434 }
435 }
436 if (!zeroOccured)
437 {
441 {
444 delete [] Aeval2;
445 return factors;
446 }
447 else
449
450 }
451 }
452
454 for (
int i= 0;
i < lengthAeval2;
i++)
455 oldAeval[
i]= Aeval2[
i];
456
458
461 biFactorsLCs.
append (
LC (
i.getItem(), 1));
462
467
471
473 CFList oldBiFactors= biFactors;
474
478
479 if (!LCmultiplierIsConst)
481
482
486
488 CFList bufLeadingCoeffs2= leadingCoeffs2[lengthAeval2-1];
489 bufBiFactors= biFactors;
492 if (!LCmultiplierIsConst)
493 {
495 for (
int i= 0;
i < lengthAeval2;
i++)
496 {
497 if (!oldAeval[
i].isEmpty())
499 }
500 }
502 "time to precompute LC over Q: ");
503
506 bool LCheuristic= false;
508 factors))
509 {
512 CFList oldFactors= factors;
514
516 {
518 {
521 }
522
526 delete [] Aeval2;
528 "time for successful LucksWang over Q: ");
529 return factors;
530 }
531 else if (factors.
length() > 0)
532 {
533 int oneCount= 0;
536 {
538 {
540 for (
int j=1;
j <=
i-oneCount;
j++)
543 for (
int j= 0;
j < lengthAeval2;
j++)
544 {
545 l= leadingCoeffs2[
j];
547 for (
int k=1;
k <=
i-oneCount;
k++)
551 }
552 oneCount++;
553 }
554 }
555 bufFactors= factors;
557 }
558 else if (!LCmultiplierIsConst && factors.
length() == 0)
559 {
560 LCheuristic= true;
561 factors= oldFactors;
563 bool foundTrueMultiplier= false;
564 LCHeuristic2 (LCmultiplier, factors, leadingCoeffs2[lengthAeval2-1],
565 contents, LCs, foundTrueMultiplier);
566 if (foundTrueMultiplier)
567 {
569 leadingCoeffs= leadingCoeffs2[lengthAeval2-1];
570 for (
int i= lengthAeval2-1;
i > -1;
i--)
574 }
575 else
576 {
577 bool foundMultiplier= false;
578 LCHeuristic3 (LCmultiplier, factors, oldBiFactors, contents, oldAeval,
579 A, leadingCoeffs2, lengthAeval2, foundMultiplier);
580
581 if (foundMultiplier)
582 {
583 foundMultiplier= false;
584 LCHeuristic4 (oldBiFactors, oldAeval, contents, factors, testVars,
585 lengthAeval2, leadingCoeffs2,
A, LCmultiplier,
586 foundMultiplier);
587 }
588 else
589 {
591 leadingCoeffs2[lengthAeval2-1], foundMultiplier);
593 {
594 LCHeuristic (
A, LCmultiplier, biFactors, leadingCoeffs2, oldAeval,
596 }
597 }
598
599
600 leadingCoeffs= leadingCoeffs2[lengthAeval2-1];
601 for (
int i= lengthAeval2-1;
i > -1;
i--)
605 }
607 if (!
fdivides (
LC (oldA,1),
prod (leadingCoeffs2[lengthAeval2-1])))
608 {
609 LCheuristic= false;
611 biFactors= bufBiFactors;
612 leadingCoeffs2[lengthAeval2-1]= bufLeadingCoeffs2;
613 LCmultiplier= bufLCmultiplier;
614 }
615 }
616 else
619 }
621
623 if (!LCheuristic && !LCmultiplierIsConst && bufFactors.
isEmpty()
625 {
626 LCheuristic= true;
627 LCHeuristic (
A, LCmultiplier, biFactors, leadingCoeffs2, oldAeval,
629
630 leadingCoeffs= leadingCoeffs2[lengthAeval2-1];
631 for (
int i= lengthAeval2-1;
i > -1;
i--)
635
636 if (!
fdivides (
LC (oldA,1),
prod (leadingCoeffs2[lengthAeval2-1])))
637 {
638 LCheuristic= false;
640 biFactors= bufBiFactors;
641 leadingCoeffs2[lengthAeval2-1]= bufLeadingCoeffs2;
642 LCmultiplier= bufLCmultiplier;
643 }
644 }
646
647tryAgainWithoutHeu:
648
654
657
658 for (
int i= 0;
i < lengthAeval2-1;
i++)
661 {
663 for (
int i=
A.level() - 4;
i > -1;
i--)
664 {
665 if (
i + 1 == lengthAeval2-1)
667 else
669 }
670 }
672 "time to shift evaluation point to zero: ");
673
676 int* liftBounds=
new int [
A.level() - 1];
677 int liftBoundsLength=
A.level() - 1;
678 for (
int i= 0;
i < liftBoundsLength;
i++)
680
682 bool noOneToOne= false;
683
685 CFList commonDenominators;
690 for (
int i= 0;
i < lengthAeval2;
i++)
691 {
692 iter2= commonDenominators;
694 {
699 }
700 }
703 {
708 }
710 multiplier= tmp3/
tmp1;
711 iter2= commonDenominators;
714
717
718 for (
int i= 0;
i < lengthAeval2;
i++)
719 {
720 iter2= commonDenominators;
723 }
725
728 Pi, liftBounds, liftBoundsLength, noOneToOne);
730 "time for non monic hensel lifting over Q: ");
731
732 if (!noOneToOne)
733 {
739 "time to recover factors over Q: ");
741 noOneToOne= true;
742 else
743 factors=
Union (factors, bufFactors);
744 }
745 if (noOneToOne)
746 {
747 if (!LCmultiplierIsConst && LCheuristic)
748 {
750 biFactors= bufBiFactors;
751 leadingCoeffs2[lengthAeval2-1]= bufLeadingCoeffs2;
752 delete [] liftBounds;
753 LCheuristic= false;
754 goto tryAgainWithoutHeu;
755
756 }
757
759 biFactors= oldBiFactors;
767
768 for (;
i.hasItem();
i++)
770
772
776 for (;
i.hasItem();
i++)
777 {
778 LCA=
LC (
i.getItem(), 1);
779 extgcd (LCA, yToLift, LCA, dummy);
780 i.getItem()=
mod (
i.getItem()*LCA, yToLift);
781 }
782
783 liftBoundsLength= F.
level() - 1;
785
787 bool earlySuccess;
793 (
A, MOD, liftBounds, earlySuccess, earlyFactors,
796
800 "time for factor recombination: ");
801
802 if (earlySuccess)
803 factors=
Union (factors, earlyFactors);
804
806 {
809 {
810 if (
i.getItem().level() < kk)
811 continue;
812 i.getItem()=
i.getItem() (
Variable (kk) -
j.getItem(), kk);
813 }
814 }
815 }
816
818 {
821 }
822
823 append (factors, contentAFactors);
827
828 delete [] leadingCoeffs2;
829 delete [] oldAeval;
830 delete [] Aeval2;
831 delete[] liftBounds;
832
833 return factors;
834}
const CanonicalForm CFMap CFMap & N
int myCompress(const CanonicalForm &F, const CanonicalForm &G, CFMap &M, CFMap &N, bool topLevel)
compressing two polynomials F and G, M is used for compressing, N to reverse the compression
CanonicalForm decompress(const CanonicalForm &F, const mpz_t *inverseM, const mpz_t *A)
decompress a bivariate poly
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
bool fdivides(const CanonicalForm &f, const CanonicalForm &g)
bool fdivides ( const CanonicalForm & f, const CanonicalForm & g )
CFFList FACTORY_PUBLIC factorize(const CanonicalForm &f, bool issqrfree=false)
factorization over or
static const int SW_RATIONAL
set to 1 for computations over Q
ExtensionInfo contains information about extension.
void remove(int moveright)
class to generate random evaluation points
factory's class for variables
const CanonicalForm int const CFList & evaluation
const CanonicalForm int const CFList const Variable & y
CFFList append(const CFFList &Inputlist, const CFFactor &TheFactor)
CFList conv(const CFFList &L)
convert a CFFList to a CFList by dropping the multiplicity
CFList ratBiSqrfFactorize(const CanonicalForm &G, const Variable &v=Variable(1))
factorize a squarefree bivariate polynomial over .
const Variable & v
< [in] a sqrfree bivariate poly
CFList multiFactorize(const CanonicalForm &F, const Variable &v)
Factorization over Q (a)
void factorizationWRTDifferentSecondVars(const CanonicalForm &A, CFList *&Aeval, int &minFactorsLength, bool &irred, const Variable &w)
CFList int & minFactorsLength
[in,out] minimal length of bivariate factors
CFList *& Aeval
<[in] poly
CFList int bool & irred
[in,out] Is A irreducible?
void appendSwapDecompress(CFList &factors1, const CFList &factors2, const CFList &factors3, const bool swap1, const bool swap2, const CFMap &N)
first swap Variables in factors1 if necessary, then append factors2 and factors3 on factors1 and fina...
CFList henselLiftAndEarly(CanonicalForm &A, bool &earlySuccess, CFList &earlyFactors, DegreePattern °s, int &liftBound, const CFList &uniFactors, const ExtensionInfo &info, const CanonicalForm &eval, modpk &b, CanonicalForm &den)
hensel Lifting and early factor detection
CFList factorRecombination(CFList &factors, CanonicalForm &F, const CanonicalForm &N, DegreePattern °s, const CanonicalForm &eval, int s, int thres, const modpk &b, const CanonicalForm &den)
naive factor recombination as decribed in "Factoring multivariate polynomials over a finite field" by...
CFList recoverFactors(const CanonicalForm &F, const CFList &factors)
divides factors by their content wrt. Variable(1) and checks if these polys divide F
CanonicalForm shift2Zero(const CanonicalForm &F, CFList &Feval, const CFList &evaluation, int l)
shift evaluation point to zero
int * liftingBounds(const CanonicalForm &A, const int &bivarLiftBound)
compute lifting bounds
CFList precomputeLeadingCoeff(const CanonicalForm &LCF, const CFList &LCFFactors, const Variable &alpha, const CFList &evaluation, CFList *&differentSecondVarLCs, int lSecondVarLCs, Variable &y)
computes a list l of length length(LCFFactors)+1 of polynomials such that prod (l)=LCF,...
void LCHeuristicCheck(const CFList &LCs, const CFList &contents, CanonicalForm &A, const CanonicalForm &oldA, CFList &leadingCoeffs, bool &foundTrueMultiplier)
checks if prod(LCs)==LC (oldA,1) and if so divides elements of leadingCoeffs by elements in contents,...
void distributeLCmultiplier(CanonicalForm &A, CFList &leadingCoeffs, CFList &biFactors, const CFList &evaluation, const CanonicalForm &LCmultipler)
distributes a divisor LCmultiplier of LC(A,1) on the bivariate factors and the precomputed leading co...
void evaluationWRTDifferentSecondVars(CFList *&Aeval, const CFList &evaluation, const CanonicalForm &A)
evaluate a poly A with main variable at level 1 at an evaluation point in K^(n-1) wrt different secon...
void prepareLeadingCoeffs(CFList *&LCs, CanonicalForm &A, CFList &Aeval, int n, const CFList &leadingCoeffs, const CFList &biFactors, const CFList &evaluation)
normalize precomputed leading coefficients such that leading coefficients evaluated at evaluation in ...
void LCHeuristic4(const CFList &oldBiFactors, const CFList *oldAeval, const CFList &contents, const CFList &factors, const CanonicalForm &testVars, int lengthAeval, CFList *&leadingCoeffs, CanonicalForm &A, CanonicalForm &LCmultiplier, bool &foundMultiplier)
heuristic to remove factors of LCmultiplier from factors. More precisely checks if elements of conten...
void changeSecondVariable(CanonicalForm &A, CFList &biFactors, CFList &evaluation, CFList *&oldAeval, int lengthAeval2, const CFList &uniFactors, const Variable &w)
changes the second variable to be w and updates all relevant data
void sortByUniFactors(CFList *&Aeval, int AevalLength, CFList &uniFactors, CFList &biFactors, const CFList &evaluation)
sort bivariate factors in Aeval such that their corresponding univariate factors coincide with uniFac...
CanonicalForm lcmContent(const CanonicalForm &A, CFList &contentAi)
compute the LCM of the contents of A wrt to each variable occuring in A.
void getLeadingCoeffs(const CanonicalForm &A, CFList *&Aeval)
extract leading coefficients wrt Variable(1) from bivariate factors obtained from factorizations of A...
void LCHeuristic3(const CanonicalForm &LCmultiplier, const CFList &factors, const CFList &oldBiFactors, const CFList &contents, const CFList *oldAeval, CanonicalForm &A, CFList *&leadingCoeffs, int lengthAeval, bool &foundMultiplier)
heuristic to remove LCmultiplier from a factor based on the contents of factors. factors are assumed ...
void LCHeuristic(CanonicalForm &A, const CanonicalForm &LCmultiplier, CFList &biFactors, CFList *&leadingCoeffs, const CFList *oldAeval, int lengthAeval, const CFList &evaluation, const CFList &oldBiFactors)
heuristic to distribute LCmultiplier onto factors based on the variables that occur in LCmultiplier a...
void refineBiFactors(const CanonicalForm &A, CFList &biFactors, CFList *const &Aeval, const CFList &evaluation, int minFactorsLength)
refine a bivariate factorization of A with l factors to one with minFactorsLength if possible
void LCHeuristic2(const CanonicalForm &LCmultiplier, const CFList &factors, CFList &leadingCoeffs, CFList &contents, CFList &LCs, bool &foundTrueMultiplier)
heuristic to distribute LCmultiplier onto factors based on the contents of factors....
CFList buildUniFactors(const CFList &biFactors, const CanonicalForm &evalPoint, const Variable &y)
plug in evalPoint for y in a list of polys
CFList evalPoints(const CanonicalForm &F, CFList &eval, const Variable &alpha, CFList &list, const bool &GF, bool &fail)
evaluation point search for multivariate factorization, looks for a (F.level() - 1)-tuple such that t...
CFList nonMonicHenselLift(const CFList &F, const CFList &factors, const CFList &LCs, CFList &diophant, CFArray &Pi, CFMatrix &M, int lOld, int &lNew, const CFList &MOD, bool &noOneToOne)
void sortList(CFList &list, const Variable &x)
sort a list of polynomials by their degree in x.
int LucksWangSparseHeuristic(const CanonicalForm &F, const CFList &factors, int level, const CFList &leadingCoeffs, CFList &result)
sparse heuristic lifting by Wang and Lucks
CFList sparseHeuristic(const CanonicalForm &A, const CFList &biFactors, CFList *&moreBiFactors, const CFList &evaluation, int minFactorsLength)
sparse heuristic which patches together bivariate factors of A wrt. different second variables by the...
template CanonicalForm tmax(const CanonicalForm &, const CanonicalForm &)
template CanonicalForm tmin(const CanonicalForm &, const CanonicalForm &)
template List< Variable > Union(const List< Variable > &, const List< Variable > &)
ideal lift(const ideal J, const ring r, const ideal inI, const ring s)
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
static int index(p_Length length, p_Ord ord)
int status int void * buf
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
#define TIMING_END_AND_PRINT(t, msg)