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