source: git/factory/facAlgExt.cc @ 202df9

fieker-DuValspielwiese
Last change on this file since 202df9 was 806c18, checked in by Hans Schoenemann <hannes@…>, 14 years ago
format git-svn-id: file:///usr/local/Singular/svn/trunk@13655 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100755
File size: 3.7 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
32// squarefree part of F
33CanonicalForm
34sqrfPart (const CanonicalForm& F)
35{
36  ASSERT (F.isUnivariate(), "univariate input expected");
37  ASSERT (getCharacteristic() == 0, "characteristic 0 expected");
38  CanonicalForm G= deriv (F, F.mvar());
39  G= gcd (F, G);
40  return F/G;
41}
42
43// i is an integer such that Norm (F (x-i*alpha)) is squarefree
44CanonicalForm sqrfNorm (const CanonicalForm& F, const Variable& alpha, int& i)
45{
46  Variable x= Variable (F.level() + 1);
47  Variable y= F.mvar();
48  CanonicalForm g= F (x, alpha);
49  CanonicalForm mipo= getMipo (alpha);
50  mipo= mipo (x, alpha);
51
52  CanonicalForm norm= resultant (g, mipo, x);
53  i= 0;
54  int k;
55  if (degree (gcd (deriv (norm, y), norm)) <= 0)
56    return norm;
57  i= 1;
58  do
59  {
60    k= 1;
61    while (k < 3)
62    {
63      if (k == 1)
64      {
65        g= F (y - i*alpha, y);
66        norm= resultant (g (x, alpha), mipo, x);
67      }
68      else
69      {
70        g= F (y + i*alpha, y);
71        norm= resultant (g (x, alpha), mipo, x);
72      }
73      if (degree (gcd (deriv (norm, y), norm)) <= 0)
74      {
75        if (k == 2)
76          i= -i;
77        return norm;
78      }
79      k++;
80    }
81    i++;
82  } while (1);
83}
84
85CFList
86AlgExtSqrfFactorize (const CanonicalForm& F, const Variable& alpha)
87{
88  ASSERT (F.isUnivariate(), "univariate input expected");
89  ASSERT (getCharacteristic() == 0, "characteristic 0 expected");
90
91  On (SW_RATIONAL);
92  CanonicalForm f= F;
93  int shift;
94  CanonicalForm norm= sqrfNorm (f, alpha, shift);
95  ASSERT (degree (norm, alpha) <= 0, "wrong norm computed");
96  CFFList normFactors= factorize (norm); //maybe compute norm (not necessarily squarefree), split f and procede recursively
97  CFList factors;
98  if (normFactors.length() <= 2)
99    return CFList (f);
100
101  normFactors.removeFirst();
102  CanonicalForm buf;
103  if (shift != 0)
104    buf= f (f.mvar() - shift*alpha, f.mvar());
105  else
106    buf= f;
107  CanonicalForm factor;
108  for (CFFListIterator i= normFactors; i.hasItem(); i++)
109  {
110    ASSERT (i.getItem().exp() == 1, "norm not squarefree");
111    factor= gcd (buf, i.getItem().factor());
112    buf /= factor;
113    if (shift != 0)
114      factor= factor (f.mvar() + shift*alpha, f.mvar());
115    factors.append (factor);
116  }
117  ASSERT (degree (buf) <= 0, "incomplete factorization");
118  Off (SW_RATIONAL);
119  return factors;
120}
121
122CFFList
123AlgExtFactorize (const CanonicalForm& F, const Variable& alpha)
124{
125  ASSERT (F.isUnivariate(), "univariate input expected");
126  ASSERT (getCharacteristic() == 0, "characteristic 0 expected");
127
128  if (F.inCoeffDomain())
129    return CFFList (CFFactor (F, 1));
130
131  CanonicalForm sqrf= sqrfPart (F);
132  CFList sqrfFactors= AlgExtSqrfFactorize (sqrf, alpha);
133
134  On (SW_RATIONAL);
135  CanonicalForm buf= F/Lc (F);
136  CFFList factors;
137  int multi;
138  for (CFListIterator i= sqrfFactors; i.hasItem(); i++)
139  {
140    multi= 0;
141    i.getItem() /= Lc (i.getItem()); //make factors monic
142    while (fdivides (i.getItem(), buf))
143    {
144      buf /= i.getItem();
145      multi++;
146    }
147    factors.append (CFFactor (i.getItem(), multi));
148  }
149  Off (SW_RATIONAL);
150  factors.insert (CFFactor (Lc(F), 1));
151  ASSERT (degree (buf) <= 0, "bug in AlgExtFactorize");
152  return factors;
153}
154
Note: See TracBrowser for help on using the repository browser.