source: git/factory/facAlgExt.cc @ 4e35a89

spielwiese
Last change on this file since 4e35a89 was 35eb6c, checked in by Martin Lee <martinlee84@…>, 13 years ago
compute norm now modular changed handling of On (SW_RATIONAL) changed NTL zz_p initalizations in cfModResultant.cc git-svn-id: file:///usr/local/Singular/svn/trunk@14289 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100755
File size: 4.1 KB
Line 
1// -*- c++ -*-
2//*****************************************************************************
3/** @file facAlgExt.cc
4 *
5 * @author Martin Lee
6 * @date
7 *
8 * Univariate factorization over algebraic extension of Q using Trager's
9 * algorithm
10 *
11 * @par Copyright:
12 *   (c) by The SINGULAR Team, see LICENSE file
13 *
14 * @internal
15 * @version \$Id$
16 *
17**/
18//*****************************************************************************
19
20#include <config.h>
21
22#include "assert.h"
23#include "debug.h"
24#include "timing.h"
25
26#include "canonicalform.h"
27#include "cf_random.h"
28#include "cf_algorithm.h"
29#include "facFqBivarUtil.h"
30#include "facAlgExt.h"
31#include "cfModResultant.h"
32
33// squarefree part of F
34CanonicalForm
35uniSqrfPart (const CanonicalForm& F)
36{
37  ASSERT (F.isUnivariate(), "univariate input expected");
38  ASSERT (getCharacteristic() == 0, "characteristic 0 expected");
39  CanonicalForm G= deriv (F, F.mvar());
40  G= gcd (F, G);
41  return F/G;
42}
43
44// i is an integer such that Norm (F (x-i*alpha)) is squarefree
45CanonicalForm sqrfNorm (const CanonicalForm& F, const Variable& alpha, int& i)
46{
47  Variable x= Variable (F.level() + 1);
48  Variable y= F.mvar();
49  CanonicalForm g= F (x, alpha);
50  CanonicalForm mipo= getMipo (alpha);
51  mipo= mipo (x, alpha);
52
53  int degg= degree (g);
54  int degmipo= degree (mipo);
55  CanonicalForm norm;
56  if (degg >= 8 || degmipo >= 8)
57    norm= resultantZ (g, mipo, x);
58  else
59    norm= resultant (g, mipo, x);
60
61  i= 0;
62  int k;
63  if (degree (gcd (deriv (norm, y), norm)) <= 0)
64    return norm;
65  i= 1;
66  do
67  {
68    k= 1;
69    while (k < 3)
70    {
71      if (k == 1)
72      {
73        g= F (y - i*alpha, y);
74        if (degg >= 8 || degmipo >= 8)
75          norm= resultantZ (g (x, alpha), mipo, x);
76        else
77          norm= resultant (g (x, alpha), mipo, x);
78      }
79      else
80      {
81        g= F (y + i*alpha, y);
82        if (degg >= 8 || degmipo >= 8)
83          norm= resultantZ (g (x, alpha), mipo, x);
84        else
85          norm= resultant (g (x, alpha), mipo, x);
86      }
87      if (degree (gcd (deriv (norm, y), norm)) <= 0)
88      {
89        if (k == 2)
90          i= -i;
91        return norm;
92      }
93      k++;
94    }
95    i++;
96  } while (1);
97}
98
99CFList
100AlgExtSqrfFactorize (const CanonicalForm& F, const Variable& alpha)
101{
102  ASSERT (F.isUnivariate(), "univariate input expected");
103  ASSERT (getCharacteristic() == 0, "characteristic 0 expected");
104
105  if (!isOn (SW_RATIONAL))
106    On (SW_RATIONAL);
107  CanonicalForm f= F*bCommonDen (F);
108  int shift;
109  CanonicalForm norm= sqrfNorm (f, alpha, shift);
110  ASSERT (degree (norm, alpha) <= 0, "wrong norm computed");
111  CFFList normFactors= factorize (norm); //maybe compute norm (not necessarily squarefree), split f and procede recursively
112  CFList factors;
113  if (normFactors.length() <= 2)
114    return CFList (F);
115
116  normFactors.removeFirst();
117  CanonicalForm buf;
118  if (shift != 0)
119    buf= f (f.mvar() - shift*alpha, f.mvar());
120  else
121    buf= f;
122  CanonicalForm factor;
123  for (CFFListIterator i= normFactors; i.hasItem(); i++)
124  {
125    ASSERT (i.getItem().exp() == 1, "norm not squarefree");
126    factor= gcd (buf, i.getItem().factor());
127    buf /= factor;
128    if (shift != 0)
129      factor= factor (f.mvar() + shift*alpha, f.mvar());
130    factors.append (factor);
131  }
132  ASSERT (degree (buf) <= 0, "incomplete factorization");
133  return factors;
134}
135
136CFFList
137AlgExtFactorize (const CanonicalForm& F, const Variable& alpha)
138{
139  ASSERT (F.isUnivariate(), "univariate input expected");
140  ASSERT (getCharacteristic() == 0, "characteristic 0 expected");
141
142
143  if (F.inCoeffDomain())
144    return CFFList (CFFactor (F, 1));
145
146  CanonicalForm sqrf= uniSqrfPart (F);
147  CFList sqrfFactors= AlgExtSqrfFactorize (sqrf, alpha);
148
149  if (!isOn (SW_RATIONAL))
150    On (SW_RATIONAL);
151  CanonicalForm buf= F/Lc (F);
152  CFFList factors;
153  int multi;
154  for (CFListIterator i= sqrfFactors; i.hasItem(); i++)
155  {
156    multi= 0;
157    i.getItem() /= Lc (i.getItem()); //make factors monic
158    while (fdivides (i.getItem(), buf))
159    {
160      buf /= i.getItem();
161      multi++;
162    }
163    factors.append (CFFactor (i.getItem(), multi));
164  }
165  factors.insert (CFFactor (Lc(F), 1));
166  ASSERT (degree (buf) <= 0, "bug in AlgExtFactorize");
167  return factors;
168}
169
Note: See TracBrowser for help on using the repository browser.