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