source: git/factory/cf_factor.cc @ 194f5e5

spielwiese
Last change on this file since 194f5e5 was 8d4aea, checked in by Jens Schmidt <schmidt@…>, 26 years ago
* cf_algorithm.cc (cden, common_den): renamed to `internalBCommonDen()' and `bCommonDen()', resp. Declarations adapted. All references changed. git-svn-id: file:///usr/local/Singular/svn/trunk@1217 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: cf_factor.cc,v 1.10 1998-03-12 10:27:41 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 "canonicalform.h"
22#include "cf_iter.h"
23#include "fac_berlekamp.h"
24#include "fac_cantzass.h"
25#include "fac_univar.h"
26#include "fac_multivar.h"
27#include "fac_sqrfree.h"
28#include "cf_algorithm.h"
29
30static 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
39CFFList 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 ( isOn( SW_BERLEKAMP ) )
46            return FpFactorizeUnivariateB( f, issqrfree );
47        else
48            return FpFactorizeUnivariateCZ( f, issqrfree, 0, Variable(), Variable() );
49    }
50    else {
51        CanonicalForm cd = bCommonDen( f );
52        CanonicalForm fz = f * cd;
53        CFFList F;
54        bool on_rational = isOn(SW_RATIONAL);
55        Off(SW_RATIONAL);
56        if ( f.isUnivariate() )
57            F = ZFactorizeUnivariate( fz, issqrfree );
58        else
59            F = ZFactorizeMultivariate( fz, issqrfree );
60        if ( on_rational )
61            On(SW_RATIONAL);
62        if ( ! cd.isOne() ) {
63            if ( F.getFirst().factor().inCoeffDomain() ) {
64                CFFactor new_first( F.getFirst().factor() / cd );
65                F.removeFirst();
66                F.insert( new_first );
67            }
68            else {
69                F.insert( CFFactor( 1/cd ) );
70            }
71        }
72        return F;
73    }
74}
75
76CFFList factorize ( const CanonicalForm & f, const Variable & alpha )
77{
78    ASSERT( alpha.level() < 0, "not an algebraic extension" );
79    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
80    ASSERT( getCharacteristic() > 0, "char 0 factorization not implemented" );
81    return FpFactorizeUnivariateCZ( f, false, 1, alpha, Variable() );
82}
83
84CFFList sqrFree ( const CanonicalForm & f, bool sort )
85{
86//    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
87    CFFList result;
88
89    if ( getCharacteristic() == 0 )
90        result = sqrFreeZ( f );
91    else
92        result = sqrFreeFp( f );
93
94    return ( sort ? sortCFFList( result ) : result );
95}
96
97bool isSqrFree ( const CanonicalForm & f )
98{
99//    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
100    if ( getCharacteristic() == 0 )
101        return isSqrFreeZ( f );
102    else
103        return isSqrFreeFp( f );
104}
Note: See TracBrowser for help on using the repository browser.