source: git/factory/fac_sqrfree.cc @ 36652d8

spielwiese
Last change on this file since 36652d8 was 36652d8, checked in by Rüdiger Stobbe <stobbe@…>, 27 years ago
"sqrFreeZ: Now handles the sign of the argument right. " git-svn-id: file:///usr/local/Singular/svn/trunk@29 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.2 KB
Line 
1// emacs edit mode for this file is -*- C++ -*-
2// $Id: fac_sqrfree.cc,v 1.2 1996-06-26 13:15:28 stobbe Exp $
3
4#include "assert.h"
5#include "cf_defs.h"
6#include "canonicalform.h"
7
8/*
9$Log: not supported by cvs2svn $
10Revision 1.1  1996/05/20 13:39:48  stobbe
11"sqrFree: Now the product of all factors found by sqrFree is equal to the
12         parameter of sqrFree. The bug resulted from an incorrect handling
13         of the leading coefficient of the argument of sqrFree.
14"
15
16// Revision 1.0  1996/05/17  10:59:45  stobbe
17// Initial revision
18//
19*/
20
21static int divexp = 1;
22
23static void divexpfunc ( CanonicalForm &, int & e )
24{
25    e /= divexp;
26}
27
28CFFList sqrFreeFp ( const CanonicalForm & f )
29{
30    CanonicalForm t0 = f, t, v, w, h;
31    CanonicalForm leadcf = t0.lc();
32    Variable x = f.mvar();
33    CFFList F;
34    int p = getCharacteristic();
35    int k, e = 1;
36
37    if ( ! leadcf.isOne() )
38        t0 /= leadcf;
39
40    divexp = p;
41    while ( t0.degree(x) > 0 ) {
42        t = gcd( t0, t0.deriv() );
43        v = t0 / t;
44        k = 0;
45        while ( v.degree(x) > 0 ) {
46            k = k+1;
47            if ( k % p == 0 ) {
48                t /= v;
49                k = k+1;
50            }
51            w = gcd( t, v );
52            h = v / w;
53            v = w;
54            t /= v;
55            if ( h.degree(x) > 0 )
56                F.append( CFFactor( h/h.lc(), e*k ) );
57        }
58        t0 = apply( t, divexpfunc );
59        e = p * e;
60    }
61    if ( ! leadcf.isOne() ) {
62        if ( F.getFirst().exp() == 1 ) {
63            leadcf = F.getFirst().factor() * leadcf;
64            F.removeFirst();
65        }
66        F.insert( CFFactor( leadcf, 1 ) );
67    }
68    return F;
69}
70
71bool isSqrFreeFp( const CanonicalForm & f )
72{
73  CFFList F = sqrFreeFp( f );
74  return ( F.length() == 1 && F.getFirst().exp() == 1 );
75}
76
77int isSqrFreeZ ( const CanonicalForm & f )
78{
79    return gcd( f, f.deriv() ).degree() == 0;
80}
81
82/*
83
84CFFList sqrFreeZ ( const CanonicalForm & a )
85{
86    CanonicalForm b = a.deriv(), c = gcd( a, b );
87    CanonicalForm y, z, w = a / c;
88    int i = 1;
89    CFFList F;
90
91    while ( ! c.degree() == 0 ) {
92        y = gcd( w, c ); z = w / y;
93        if ( degree( z ) > 0 )
94            if ( lc( z ).sign() < 0 )
95                F.append( CFFactor( -z, i ) );
96            else
97                F.append( CFFactor( z, i ) );
98        i++;
99        w = y; c = c / y;
100    }
101    if ( degree( w ) > 0 )
102        if ( lc( w ).sign() < 0 )
103            F.append( CFFactor( -w, i ) );
104        else
105            F.append( CFFactor( w, i ) );
106    return F;
107}
108*/
109
110CFFList sqrFreeZ ( const CanonicalForm & a )
111{
112    if ( a.inCoeffDomain() )
113        return CFFactor( a, 1 );
114    CanonicalForm cont = content( a );
115    CanonicalForm aa = a / cont;
116    CanonicalForm b = aa.deriv(), c = gcd( aa, b );
117    CanonicalForm y, z, w = aa / c;
118    int i = 1;
119    CFFList F;
120    Variable v = aa.mvar();
121    while ( ! c.degree(v) == 0 ) {
122        y = gcd( w, c ); z = w / y;
123        if ( degree( z, v ) > 0 )
124            if ( lc( z ).sign() < 0 )
125                F.append( CFFactor( -z, i ) );
126            else
127                F.append( CFFactor( z, i ) );
128        i++;
129        w = y; c = c / y;
130    }
131    if ( degree( w,v ) > 0 )
132        if ( lc( w ).sign() < 0 )
133            F.append( CFFactor( -w, i ) );
134        else
135            F.append( CFFactor( w, i ) );
136    if ( ! cont.isOne() && ! cont.inCoeffDomain() )
137        F = Union( F, sqrFreeZ( cont ) );
138    if ( lc( a ).sign() < 0 ) {
139        if ( F.getFirst().exp() == 1 ) {
140            CanonicalForm f = F.getFirst().factor();
141            CFFListIterator(F).getItem() = CFFactor( -f, 1 );
142        }
143        else
144            F.insert( CFFactor( -1, 1 ) );
145    }
146    return F;
147}
Note: See TracBrowser for help on using the repository browser.