source: git/factory/facFqSquarefree.cc @ 3426de2

spielwiese
Last change on this file since 3426de2 was 0349c20, checked in by Martin Lee <martinlee84@…>, 13 years ago
deleted unused cf_gcd_charp.cc, cfGEval.*, ffreval.* deleted factorization over Fp from fac_multivar.cc deleted some unused parameters git-svn-id: file:///usr/local/Singular/svn/trunk@14377 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR
3\*****************************************************************************/
4/** @file facFqSquarefree.cc
5 *
6 * This file provides functions for squarefrees factorizing over
7 * \f$ F_{p} \f$ , \f$ F_{p}(\alpha ) \f$ or GF, as decribed in "Factoring
8 * multivariate polynomials over a finite field" by L. Bernardin
9 *
10 * @author Martin Lee
11 *
12 * @internal @version \$Id$
13 *
14 **/
15/*****************************************************************************/
16
17#include <config.h>
18
19#include "canonicalform.h"
20
21#include "cf_gcd_smallp.h"
22#include "cf_iter.h"
23#include "cf_map.h"
24#include "cf_util.h"
25#include "cf_factory.h"
26#include "facFqSquarefree.h"
27
28static inline
29CanonicalForm
30pthRoot (const CanonicalForm & F, const int & q)
31{
32  CanonicalForm A= F;
33  int p= getCharacteristic ();
34  if (A.inCoeffDomain())
35  {
36    A= power (A, q/p);
37    return A;
38  }
39  else
40  {
41    CanonicalForm buf= 0;
42    for (CFIterator i= A; i.hasTerms(); i++)
43      buf= buf + power(A.mvar(), i.exp()/p)*pthRoot (i.coeff(), q);
44    return buf;
45  }
46}
47
48CanonicalForm
49maxpthRoot (const CanonicalForm & F, const int & q, int& l)
50{
51  CanonicalForm result= F;
52  bool derivZero= true;
53  l= 0;
54  while (derivZero)
55  {
56    for (int i= 1; i <= result.level(); i++)
57    {
58      if (!deriv (result, Variable (i)).isZero())
59      {
60        derivZero= false;
61        break;
62      }
63    }
64    if (!derivZero)
65      break;
66    result= pthRoot (result, q);
67    l++;
68  }
69  return result;
70}
71
72static inline
73CFFList
74sqrfPosDer (const CanonicalForm & F, const Variable & x,
75            CanonicalForm & c)
76{
77  CanonicalForm b= deriv (F, x);
78  c= gcd (F, b);
79  CanonicalForm w= F/c;
80  CanonicalForm v= b/c;
81  CanonicalForm u= v - deriv (w, x);
82  int j= 1;
83  int p= getCharacteristic();
84  CanonicalForm g;
85  CFFList result;
86  while (j < p - 1 && degree(u) >= 0)
87  {
88    g= gcd (w, u);
89    if (degree(g) > 0)
90      result.append (CFFactor (g, j));
91    w= w/g;
92    c= c/w;
93    v= u/g;
94    u= v - deriv (w, x);
95    j++;
96  }
97  if (degree(w) > 0)
98    result.append (CFFactor (w, j));
99  return result;
100}
101
102CFFList
103squarefreeFactorization (const CanonicalForm & F, const Variable & alpha)
104{
105  int p= getCharacteristic();
106  CanonicalForm A= F;
107  CFMap M;
108  A= compress (A, M);
109  Variable x= A.mvar();
110  int l= x.level();
111  int k;
112  bool GF= false;
113  if (CFFactory::gettype() == GaloisFieldDomain)
114  {
115    k= getGFDegree();
116    GF= true;
117  }
118  if (alpha.level() != 1)
119    k= degree (getMipo (alpha));
120  else
121    k= 1;
122  Variable buf, buf2;
123  CanonicalForm tmp;
124
125  CFFList tmp1, tmp2;
126  bool found;
127  for (int i= l; i > 0; i--)
128  {
129    buf= Variable (i);
130    if (degree (deriv (A, buf)) >= 0)
131    {
132      tmp1= sqrfPosDer (A, buf, tmp);
133      A= tmp;
134      for (CFFListIterator j= tmp1; j.hasItem(); j++)
135      {
136        found= false;
137        CFFListIterator k= tmp2;
138        if (!k.hasItem()) tmp2.append (j.getItem());
139        else
140        {
141          for (; k.hasItem(); k++)
142          {
143            if (k.getItem().exp() == j.getItem().exp())
144            {
145              k.getItem()= CFFactor (k.getItem().factor()*j.getItem().factor(),
146                                     j.getItem().exp());
147              found= true;
148            }
149          }
150          if (found == false)
151            tmp2.append(j.getItem());
152        }
153      }
154    }
155  }
156
157  bool degcheck= false;;
158  for (int i= l; i > 0; i--)
159  if (degree (A, Variable(i)) >= p)
160    degcheck= true;
161
162  if (degcheck == false && tmp1.isEmpty() && tmp2.isEmpty())
163    return CFFList (CFFactor (F/Lc(F), 1));
164
165  CanonicalForm buffer= pthRoot (A, ipower (p, k));
166
167  tmp1= squarefreeFactorization (buffer, alpha);
168
169  CFFList result;
170  buf= alpha;
171  for (CFFListIterator i= tmp2; i.hasItem(); i++)
172  {
173    for (CFFListIterator j= tmp1; j.hasItem(); j++)
174    {
175      tmp= gcd (i.getItem().factor(), j.getItem().factor());
176      i.getItem()= CFFactor (i.getItem().factor()/tmp, i.getItem().exp());
177      j.getItem()= CFFactor (j.getItem().factor()/tmp, j.getItem().exp());
178      if (degree (tmp) > 0 && tmp.level() > 0)
179        result.append (CFFactor (M (tmp),
180                       j.getItem().exp()*p + i.getItem().exp()));
181    }
182  }
183  for (CFFListIterator i= tmp2; i.hasItem(); i++)
184    if (degree (i.getItem().factor()) > 0 && i.getItem().factor().level() >= 0)
185      result.append (CFFactor (M (i.getItem().factor()), i.getItem().exp()));
186  for (CFFListIterator j= tmp1; j.hasItem(); j++)
187    if (degree (j.getItem().factor()) > 0 && j.getItem().factor().level() >= 0)
188      result.append (CFFactor (M (j.getItem().factor()), j.getItem().exp()*p));
189  return result;
190}
191
192CanonicalForm
193sqrfPart (const CanonicalForm& F, CanonicalForm& pthPower,
194          const Variable& alpha)
195{
196  if (F.inCoeffDomain())
197  {
198    pthPower= 1;
199    return F;
200  }
201  CFMap M;
202  CanonicalForm A= compress (F, M);
203  Variable vBuf= alpha;
204  CanonicalForm w, v, b;
205  pthPower= 1;
206  CanonicalForm result;
207  int i= 1;
208  bool allZero= true;
209  for (; i <= A.level(); i++)
210  {
211    if (!deriv (A, Variable (i)).isZero())
212    {
213      allZero= false;
214      break;
215    }
216  }
217  if (allZero)
218  {
219    pthPower= F;
220    return 1;
221  }
222  w= gcd (A, deriv (A, Variable (i)));
223
224  b= A/w;
225  result= b;
226  if (degree (w) < 1)
227    return M (result);
228  i++;
229  for (; i <= A.level(); i++)
230  {
231    if (!deriv (w, Variable (i)).isZero())
232    {
233      b= w;
234      w= gcd (w, deriv (w, Variable (i)));
235      b /= w;
236      if (degree (b) < 1)
237        break;
238      CanonicalForm g;
239      g= gcd (b, result);
240      if (degree (g) > 0)
241        result *= b/g;
242      if (degree (g) <= 0)
243        result *= b;
244    }
245  }
246  result= M (result);
247  return result;
248}
249
Note: See TracBrowser for help on using the repository browser.