source: git/factory/fac_distrib.cc @ e0fbbeb

fieker-DuValspielwiese
Last change on this file since e0fbbeb was 16f511, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Fixed the usage of "config.h" (if defined HAVE_CONFIG_H)
  • Property mode set to 100644
File size: 5.6 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#ifdef HAVE_CONFIG_H
4#include "config.h"
5#endif /* HAVE_CONFIG_H */
6
7#include "cf_assert.h"
8#include "debug.h"
9
10#include "cf_defs.h"
11#include "canonicalform.h"
12#include "cf_algorithm.h"
13#include "cf_iter.h"
14#include "fac_util.h"
15
16bool
17nonDivisors ( CanonicalForm omega, CanonicalForm delta, const CFArray & F, CFArray & d )
18{
19    DEBINCLEVEL( cerr, "nonDivisors" );
20    CanonicalForm q, r;
21    int k = F.size();
22    d = CFArray( 0, k );
23    d[0] = delta * omega;
24    for ( int i = 1; i <= k; i++ )
25    {
26        q = abs(F[i]);
27        for ( int j = i-1; j >= 0; j-- )
28        {
29            r = d[j];
30            do
31            {
32                r = gcd( r, q );
33                q = q / r;
34            } while ( !r.isOne() );
35            if ( q == 1 )
36            {
37                DEBDECLEVEL( cerr, "nonDivisors" );
38                return false;
39            }
40        }
41        d[i] = q;
42    }
43    DEBDECLEVEL( cerr, "nonDivisors" );
44    return true;
45}
46
47bool
48checkEvaluation ( const CanonicalForm & U, const CanonicalForm & lcU, const CanonicalForm & omega, const CFFList & F, const Evaluation & A, CanonicalForm & delta )
49{
50    CanonicalForm Vn, U0 = A( U );
51    CFFListIterator I;
52    int j;
53    CFArray FF = CFArray( 1, F.length() );
54    CFArray D;
55    Vn = A( lcU );
56    if ( Vn.isZero() )
57        return false;
58    delta = content( U0 );
59    for ( I = F, j = 1; I.hasItem(); I++, j++ )
60        FF[j] = A( I.getItem().factor() );
61    return nonDivisors( omega, delta, FF, D );
62}
63
64bool
65distributeLeadingCoeffs ( CanonicalForm & U, CFArray & G, CFArray & lcG, const CFFList & F, const CFArray & D, CanonicalForm & delta, CanonicalForm & omega, const Evaluation & A, int r )
66{
67    DEBINCLEVEL( cerr, "distributeLeadingCoeffs" );
68    CanonicalForm ut, gt, d, ft;
69    CanonicalForm dd, quot;
70    CFFListIterator I;
71    int m, j, i;
72    lcG = CFArray( 1, r );
73    for ( j = 1; j <= r; j ++ )
74        lcG[j] = 1;
75
76    for ( I = F, i = 1; I.hasItem(); I++, i++ )
77    {
78        ft = I.getItem().factor();
79        m = I.getItem().exp();
80        DEBOUTLN( cerr, "trying to distribute " << ft );
81        DEBOUTLN( cerr, "which is tested with " << D[i] );
82        DEBOUTLN( cerr, "and contained to the power of " << m );
83        j = 1;
84        while ( m > 0 && j <= r )
85        {
86            ut = lc( G[j] );
87            DEBOUTLN( cerr, "checking with " << ut );
88            while ( m > 0 && fdivides( D[i], ut, quot ) )
89            {
90                DEBOUTLN( cerr, "match found" );
91                m--; ut= quot;
92                lcG[j] *= ft;
93            }
94            j++;
95        }
96        if (m != 0)
97        {
98            DEBDECLEVEL( cerr, "distributeLeadingCoeffs" );
99            return false;
100        }
101    }
102    DEBOUTLN( cerr, "the leading coeffs before omega and delta correction: " << lcG );
103    if ( !omega.isOne() )
104    {
105        for ( j = 1; j <= r; j++ )
106        {
107//            G[j] *= omega;
108            lcG[j] *= omega;
109            if(lc( G[j] ).isZero()) return false;
110            G[j] = G[j] * ( A( lcG[j] ) / lc( G[j] ) );
111        }
112        U *= power( omega, r-1 );
113    }
114    if ( !delta.isOne() )
115    {
116        for ( j = 1; j <= r; j++ )
117        {
118            lcG[j] *= delta;
119            if(lc( G[j] ).isZero()) return false;
120            G[j] = G[j] * ( A( lcG[j] ) / lc( G[j] ) );
121        }
122        U *= power( delta, r );
123    }
124    DEBDECLEVEL( cerr, "distributeLeadingCoeffs" );
125    return true;
126}
127
128
129static void
130gfbAdjoin ( const CanonicalForm & F, CFList & L )
131{
132    if ( F.isOne() )
133        return;
134    if ( L.isEmpty() )
135    {
136        L.append( F );
137        return;
138    }
139    CanonicalForm h, quot, f = F;
140    CFListIterator i, j;
141    for ( i = L; i.hasItem() && ! f.isOne(); )
142    {
143        h = gcd( f, i.getItem() );
144        if ( h.isOne() )
145        {
146            i++;
147            continue;
148        }
149        while ( fdivides( h, f, quot ) )
150            f= quot;
151        CFList D( h );
152        gfbAdjoin( i.getItem() / h, D );
153        for ( j = D; j.hasItem(); j++ )
154            i.append( j.getItem() );
155        i.remove( true );
156    }
157    if ( ! f.isOne() )
158        L.append( f );
159}
160
161
162CFList
163gcdFreeBasis ( const CFList L )
164{
165    CFListIterator i;
166    CFList R;
167    for ( i = L; i.hasItem(); i++ )
168        gfbAdjoin( i.getItem(), R );
169    return R;
170}
171
172bool
173Univar2Bivar(const CanonicalForm & U, CFArray & G, const Evaluation & A, const modpk & bound, const Variable & x )
174{
175    CanonicalForm l = LC( U, Variable(1) );
176    int n = G.size();
177    CFArray lcG(1,n);
178    for ( int i = 1; i <= n; i++ )
179    {
180        G[i] *= A(l)/lc(G[i]);
181        lcG[i] = l;
182    }
183    return Hensel( U * power( l, n-1 ), G, lcG, A, bound, x );
184}
185
186bool
187Hensel2 ( const CanonicalForm & U, CFArray & G, const Evaluation & A, const modpk & bound, const Variable & x )
188{
189    int i,n = G.size(); // n is number of factors of U
190    CFArray TrueLcs(1, n);
191    for (i=1; i <= n; i++)
192        TrueLcs[i] = 1;
193    Variable y;
194    CanonicalForm lcU = LC ( U, Variable(1) );
195    while (! lcU.inCoeffDomain())
196    {
197        y = lcU.mvar(); // should make a more intelligent choice
198        CanonicalForm BivariateU = A ( U, 2, y.level() - 1 );
199        CFArray BivariateFactors = G;
200        CFArray lcFactors(1,n);
201        Univar2Bivar(BivariateU, BivariateFactors, A, bound, y);
202        for (i = 1; i <= n; i++)
203        {
204            BivariateFactors[i] /= content(BivariateFactors[i]);
205            lcFactors[i] = LC(BivariateFactors[i],Variable(1));
206        }
207//        GFB = GcdFreeBasis(lcFactors); // this is not right... should probably make everything squarefree
208//        Hensel2(lcU, GFB, A, bound, y);
209    }
210    for (i = 1; i <= n; i++)
211        G[i] *= A(TrueLcs[i])/lc(G[i]);
212    return Hensel(U, G, TrueLcs, A, bound, x);
213}
Note: See TracBrowser for help on using the repository browser.