source: git/factory/fac_sqrfree.cc @ 0d500e

spielwiese
Last change on this file since 0d500e was 0d500e, checked in by Jens Schmidt <schmidt@…>, 27 years ago
o new functions sortCFFList() and compareFactors() added to sort a CFFList. used by sqrFree(). git-svn-id: file:///usr/local/Singular/svn/trunk@180 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.0 KB
Line 
1// emacs edit mode for this file is -*- C++ -*-
2// $Id: fac_sqrfree.cc,v 1.5 1997-04-18 16:02:55 schmidt Exp $
3
4#include <config.h>
5
6#include "assert.h"
7
8#include "cf_defs.h"
9#include "canonicalform.h"
10
11/*
12$Log: not supported by cvs2svn $
13Revision 1.4  1997/04/08 10:32:03  schmidt
14#include <config.h> added
15
16Revision 1.3  1996/12/05 18:24:55  schmidt
17``Unconditional'' check-in.
18Now it is my turn to develop factory.
19
20Revision 1.2  1996/06/26 13:15:28  stobbe
21"sqrFreeZ: Now handles the sign of the argument right.
22"
23
24Revision 1.1  1996/05/20 13:39:48  stobbe
25"sqrFree: Now the product of all factors found by sqrFree is equal to the
26         parameter of sqrFree. The bug resulted from an incorrect handling
27         of the leading coefficient of the argument of sqrFree.
28"
29
30// Revision 1.0  1996/05/17  10:59:45  stobbe
31// Initial revision
32//
33*/
34
35static int divexp = 1;
36
37static void divexpfunc ( CanonicalForm &, int & e )
38{
39    e /= divexp;
40}
41
42static int
43compareFactors( const CFFactor & f, const CFFactor & g )
44{
45    return f.exp() > g.exp();
46}
47
48CFFList
49sortCFFList( CFFList & F )
50{
51    F.sort( compareFactors );
52
53    int exp;
54    CanonicalForm f;
55    CFFListIterator I = F;
56    CFFList result;
57
58    // join elements with the same degree
59    while ( I.hasItem() ) {
60        f = I.getItem().factor();
61        exp = I.getItem().exp();
62        I++;
63        while ( I.hasItem() && I.getItem().exp() == exp ) {
64            f *= I.getItem().factor();
65            I++;
66        }
67        result.append( CFFactor( f, exp ) );
68    }
69
70    return result;
71}
72
73CFFList sqrFreeFp ( const CanonicalForm & f )
74{
75    CanonicalForm t0 = f, t, v, w, h;
76    CanonicalForm leadcf = t0.lc();
77    Variable x = f.mvar();
78    CFFList F;
79    int p = getCharacteristic();
80    int k, e = 1;
81
82    if ( ! leadcf.isOne() )
83        t0 /= leadcf;
84
85    divexp = p;
86    while ( t0.degree(x) > 0 ) {
87        t = gcd( t0, t0.deriv() );
88        v = t0 / t;
89        k = 0;
90        while ( v.degree(x) > 0 ) {
91            k = k+1;
92            if ( k % p == 0 ) {
93                t /= v;
94                k = k+1;
95            }
96            w = gcd( t, v );
97            h = v / w;
98            v = w;
99            t /= v;
100            if ( h.degree(x) > 0 )
101                F.append( CFFactor( h/h.lc(), e*k ) );
102        }
103        t0 = apply( t, divexpfunc );
104        e = p * e;
105    }
106    if ( ! leadcf.isOne() ) {
107        if ( F.getFirst().exp() == 1 ) {
108            leadcf = F.getFirst().factor() * leadcf;
109            F.removeFirst();
110        }
111        F.insert( CFFactor( leadcf, 1 ) );
112    }
113    return F;
114}
115
116bool isSqrFreeFp( const CanonicalForm & f )
117{
118  CFFList F = sqrFreeFp( f );
119  return ( F.length() == 1 && F.getFirst().exp() == 1 );
120}
121
122int isSqrFreeZ ( const CanonicalForm & f )
123{
124    return gcd( f, f.deriv() ).degree() == 0;
125}
126
127/*
128
129CFFList sqrFreeZ ( const CanonicalForm & a )
130{
131    CanonicalForm b = a.deriv(), c = gcd( a, b );
132    CanonicalForm y, z, w = a / c;
133    int i = 1;
134    CFFList F;
135
136    while ( ! c.degree() == 0 ) {
137        y = gcd( w, c ); z = w / y;
138        if ( degree( z ) > 0 )
139            if ( lc( z ).sign() < 0 )
140                F.append( CFFactor( -z, i ) );
141            else
142                F.append( CFFactor( z, i ) );
143        i++;
144        w = y; c = c / y;
145    }
146    if ( degree( w ) > 0 )
147        if ( lc( w ).sign() < 0 )
148            F.append( CFFactor( -w, i ) );
149        else
150            F.append( CFFactor( w, i ) );
151    return F;
152}
153*/
154
155CFFList sqrFreeZ ( const CanonicalForm & a )
156{
157    if ( a.inCoeffDomain() )
158        return CFFactor( a, 1 );
159    CanonicalForm cont = content( a );
160    CanonicalForm aa = a / cont;
161    CanonicalForm b = aa.deriv(), c = gcd( aa, b );
162    CanonicalForm y, z, w = aa / c;
163    int i = 1;
164    CFFList F;
165    Variable v = aa.mvar();
166    while ( ! c.degree(v) == 0 ) {
167        y = gcd( w, c ); z = w / y;
168        if ( degree( z, v ) > 0 )
169            if ( lc( z ).sign() < 0 )
170                F.append( CFFactor( -z, i ) );
171            else
172                F.append( CFFactor( z, i ) );
173        i++;
174        w = y; c = c / y;
175    }
176    if ( degree( w,v ) > 0 )
177        if ( lc( w ).sign() < 0 )
178            F.append( CFFactor( -w, i ) );
179        else
180            F.append( CFFactor( w, i ) );
181    if ( ! cont.isOne() )
182        F = Union( F, sqrFreeZ( cont ) );
183    if ( lc( a ).sign() < 0 ) {
184        if ( F.getFirst().exp() == 1 ) {
185            CanonicalForm f = F.getFirst().factor();
186            CFFListIterator(F).getItem() = CFFactor( -f, 1 );
187        }
188        else
189            F.insert( CFFactor( -1, 1 ) );
190    }
191    return F;
192}
Note: See TracBrowser for help on using the repository browser.