source: git/factory/fac_distrib.cc @ 72dd6e

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