source: git/factory/fac_distrib.cc @ ebc602

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