source: git/factory/facAlgExt.cc @ 85bcd6

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