1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: cf_factor.cc,v 1.6 1997-09-01 08:50:56 schmidt Exp $ */ |
---|
3 | |
---|
4 | //{{{ docu |
---|
5 | // |
---|
6 | // cf_factor.cc - factorization and square free algorithms. |
---|
7 | // |
---|
8 | // Used by: fac_multivar.cc, fac_univar.cc, cf_irred.cc |
---|
9 | // |
---|
10 | // Header file: cf_algorithm.h |
---|
11 | // |
---|
12 | //}}} |
---|
13 | |
---|
14 | #include <config.h> |
---|
15 | |
---|
16 | #include "cf_gmp.h" |
---|
17 | |
---|
18 | #include "assert.h" |
---|
19 | |
---|
20 | #include "cf_defs.h" |
---|
21 | #include "cf_globals.h" |
---|
22 | #include "canonicalform.h" |
---|
23 | #include "cf_iter.h" |
---|
24 | #include "fac_berlekamp.h" |
---|
25 | #include "fac_cantzass.h" |
---|
26 | #include "fac_univar.h" |
---|
27 | #include "fac_multivar.h" |
---|
28 | #include "fac_sqrfree.h" |
---|
29 | |
---|
30 | static bool isUnivariateBaseDomain( const CanonicalForm & f ) |
---|
31 | { |
---|
32 | CFIterator i = f; |
---|
33 | bool ok = i.coeff().inBaseDomain(); |
---|
34 | i++; |
---|
35 | while ( i.hasTerms() && ( ok = ok && i.coeff().inBaseDomain() ) ) i++; |
---|
36 | return ok; |
---|
37 | } |
---|
38 | |
---|
39 | CFFList factorize ( const CanonicalForm & f, bool issqrfree ) |
---|
40 | { |
---|
41 | if ( f.inCoeffDomain() ) |
---|
42 | return CFFList( f ); |
---|
43 | if ( getCharacteristic() > 0 ) { |
---|
44 | ASSERT( f.isUnivariate(), "multivariate factorization not implemented" ); |
---|
45 | if ( cf_glob_switches.isOn( SW_BERLEKAMP ) ) |
---|
46 | return FpFactorizeUnivariateB( f, issqrfree ); |
---|
47 | else |
---|
48 | return FpFactorizeUnivariateCZ( f, issqrfree ); |
---|
49 | } |
---|
50 | else { |
---|
51 | if ( f.isUnivariate() ) |
---|
52 | return ZFactorizeUnivariate( f, issqrfree ); |
---|
53 | else |
---|
54 | return ZFactorizeMultivariate( f, issqrfree ); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | CFFList factorize ( const CanonicalForm & f, const Variable & alpha ) |
---|
59 | { |
---|
60 | ASSERT( alpha.level() < 0, "not an algebraic extension" ); |
---|
61 | ASSERT( f.isUnivariate(), "multivariate factorization not implemented" ); |
---|
62 | ASSERT( getCharacteristic() > 0, "char 0 factorization not implemented" ); |
---|
63 | return FpFactorizeUnivariateCZ( f, false, 1, alpha ); |
---|
64 | } |
---|
65 | |
---|
66 | CFFList sqrFree ( const CanonicalForm & f, bool sort ) |
---|
67 | { |
---|
68 | // ASSERT( f.isUnivariate(), "multivariate factorization not implemented" ); |
---|
69 | CFFList result; |
---|
70 | |
---|
71 | if ( getCharacteristic() == 0 ) |
---|
72 | result = sqrFreeZ( f ); |
---|
73 | else |
---|
74 | result = sqrFreeFp( f ); |
---|
75 | |
---|
76 | return ( sort ? sortCFFList( result ) : result ); |
---|
77 | } |
---|
78 | |
---|
79 | bool isSqrFree ( const CanonicalForm & f ) |
---|
80 | { |
---|
81 | // ASSERT( f.isUnivariate(), "multivariate factorization not implemented" ); |
---|
82 | if ( getCharacteristic() == 0 ) |
---|
83 | return isSqrFreeZ( f ); |
---|
84 | else |
---|
85 | return isSqrFreeFp( f ); |
---|
86 | } |
---|