source: git/factory/fac_sqrfree.cc @ b1dfaf

fieker-DuValspielwiese
Last change on this file since b1dfaf was d4932a, checked in by Hans Schoenemann <hannes@…>, 14 years ago
fix log(int) -> ilog2 git-svn-id: file:///usr/local/Singular/svn/trunk@12924 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id$ */
3
4#include <config.h>
5
6#include "assert.h"
7
8#include "cf_defs.h"
9#include "canonicalform.h"
10
11static int divexp = 1;
12
13static void divexpfunc ( CanonicalForm &, int & e )
14{
15    e /= divexp;
16}
17
18static int
19compareFactors( const CFFactor & f, const CFFactor & g )
20{
21    return f.exp() > g.exp();
22}
23
24CFFList
25sortCFFList( CFFList & F )
26{
27    F.sort( compareFactors );
28
29    int exp;
30    CanonicalForm f;
31    CFFListIterator I = F;
32    CFFList result;
33
34    // join elements with the same degree
35    while ( I.hasItem() ) {
36        f = I.getItem().factor();
37        exp = I.getItem().exp();
38        I++;
39        while ( I.hasItem() && I.getItem().exp() == exp ) {
40            f *= I.getItem().factor();
41            I++;
42        }
43        result.append( CFFactor( f, exp ) );
44    }
45
46    return result;
47}
48
49CFFList sqrFreeFp ( const CanonicalForm & f )
50{
51    CanonicalForm t0 = f, t, v, w, h;
52    CanonicalForm leadcf = t0.lc();
53    Variable x = f.mvar();
54    CFFList F;
55    int p = getCharacteristic();
56    int k, e = 1;
57
58    if ( ! leadcf.isOne() )
59        t0 /= leadcf;
60
61    divexp = p;
62    while ( t0.degree(x) > 0 )
63    {
64        t = gcd( t0, t0.deriv() );
65        v = t0 / t;
66        k = 0;
67        while ( v.degree(x) > 0 )
68        {
69            k = k+1;
70            if ( k % p == 0 )
71            {
72                t /= v;
73                k = k+1;
74            }
75            w = gcd( t, v );
76            h = v / w;
77            v = w;
78            t /= v;
79            if ( h.degree(x) > 0 )
80                F.append( CFFactor( h/h.lc(), e*k ) );
81        }
82        t0 = apply( t, divexpfunc );
83        e = p * e;
84    }
85    if ( ! leadcf.isOne() )
86    {
87        if ( !F.isEmpty() && (F.getFirst().exp() == 1) )
88        {
89            leadcf = F.getFirst().factor() * leadcf;
90            F.removeFirst();
91        }
92        F.insert( CFFactor( leadcf, 1 ) );
93    }
94    return F;
95}
96
97bool isSqrFreeFp( const CanonicalForm & f )
98{
99  CFFList F = sqrFreeFp( f );
100  return ( F.length() == 1 && F.getFirst().exp() == 1 );
101}
102
103bool isSqrFreeZ ( const CanonicalForm & f )
104{
105    return gcd( f, f.deriv() ).degree() == 0;
106}
107
108/*
109
110CFFList sqrFreeZ ( const CanonicalForm & a )
111{
112    CanonicalForm b = a.deriv(), c = gcd( a, b );
113    CanonicalForm y, z, w = a / c;
114    int i = 1;
115    CFFList F;
116
117    while ( ! c.degree() == 0 )
118    {
119        y = gcd( w, c ); z = w / y;
120        if ( degree( z ) > 0 )
121            if ( lc( z ).sign() < 0 )
122                F.append( CFFactor( -z, i ) );
123            else
124                F.append( CFFactor( z, i ) );
125        i++;
126        w = y; c = c / y;
127    }
128    if ( degree( w ) > 0 )
129        if ( lc( w ).sign() < 0 )
130            F.append( CFFactor( -w, i ) );
131        else
132            F.append( CFFactor( w, i ) );
133    return F;
134}
135*/
136
137CFFList sqrFreeZ ( const CanonicalForm & a )
138{
139    if ( a.inCoeffDomain() )
140        return CFFactor( a, 1 );
141    CanonicalForm cont = content( a );
142    CanonicalForm aa = a / cont;
143    CanonicalForm b = aa.deriv(), c = gcd( aa, b );
144    CanonicalForm y, z, w = aa / c;
145    int i = 1;
146    CFFList F;
147    Variable v = aa.mvar();
148    while ( ! c.degree(v) == 0 )
149    {
150        y = gcd( w, c ); z = w / y;
151        if ( degree( z, v ) > 0 )
152            if ( lc( z ).sign() < 0 )
153                F.append( CFFactor( -z, i ) );
154            else
155                F.append( CFFactor( z, i ) );
156        i++;
157        w = y; c = c / y;
158    }
159    if ( degree( w,v ) > 0 )
160        if ( lc( w ).sign() < 0 )
161            F.append( CFFactor( -w, i ) );
162        else
163            F.append( CFFactor( w, i ) );
164    if ( ! cont.isOne() )
165        F = Union( F, sqrFreeZ( cont ) );
166    if ( lc( a ).sign() < 0 )
167    {
168        if ( F.getFirst().exp() == 1 )
169        {
170            CanonicalForm f = F.getFirst().factor();
171            CFFListIterator(F).getItem() = CFFactor( -f, 1 );
172        }
173        else
174            F.insert( CFFactor( -1, 1 ) );
175    }
176    return F;
177}
Note: See TracBrowser for help on using the repository browser.