[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 | * |
---|
[806c18] | 14 | * @internal |
---|
[59a7ca1] | 15 | * @version \$Id$ |
---|
| 16 | * |
---|
| 17 | **/ |
---|
| 18 | //***************************************************************************** |
---|
| 19 | |
---|
[e4fe2b] | 20 | #include "config.h" |
---|
[59a7ca1] | 21 | |
---|
[650f2d8] | 22 | #include "cf_assert.h" |
---|
[59a7ca1] | 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" |
---|
[35eb6c] | 31 | #include "cfModResultant.h" |
---|
[b2929e7] | 32 | #include "fac_sqrfree.h" |
---|
[59a7ca1] | 33 | |
---|
[1b38e5d] | 34 | // squarefree part of F |
---|
[59a7ca1] | 35 | CanonicalForm |
---|
[35eb6c] | 36 | uniSqrfPart (const CanonicalForm& F) |
---|
[59a7ca1] | 37 | { |
---|
| 38 | ASSERT (F.isUnivariate(), "univariate input expected"); |
---|
| 39 | ASSERT (getCharacteristic() == 0, "characteristic 0 expected"); |
---|
| 40 | CanonicalForm G= deriv (F, F.mvar()); |
---|
| 41 | G= gcd (F, G); |
---|
[806c18] | 42 | return F/G; |
---|
[59a7ca1] | 43 | } |
---|
| 44 | |
---|
[1b38e5d] | 45 | // i is an integer such that Norm (F (x-i*alpha)) is squarefree |
---|
[59a7ca1] | 46 | CanonicalForm sqrfNorm (const CanonicalForm& F, const Variable& alpha, int& i) |
---|
| 47 | { |
---|
| 48 | Variable x= Variable (F.level() + 1); |
---|
| 49 | Variable y= F.mvar(); |
---|
| 50 | CanonicalForm g= F (x, alpha); |
---|
| 51 | CanonicalForm mipo= getMipo (alpha); |
---|
| 52 | mipo= mipo (x, alpha); |
---|
[50a2aa9] | 53 | mipo *= bCommonDen (mipo); |
---|
[806c18] | 54 | |
---|
[35eb6c] | 55 | int degg= degree (g); |
---|
| 56 | int degmipo= degree (mipo); |
---|
| 57 | CanonicalForm norm; |
---|
| 58 | if (degg >= 8 || degmipo >= 8) |
---|
| 59 | norm= resultantZ (g, mipo, x); |
---|
| 60 | else |
---|
| 61 | norm= resultant (g, mipo, x); |
---|
| 62 | |
---|
[59a7ca1] | 63 | i= 0; |
---|
| 64 | int k; |
---|
| 65 | if (degree (gcd (deriv (norm, y), norm)) <= 0) |
---|
| 66 | return norm; |
---|
| 67 | i= 1; |
---|
| 68 | do |
---|
| 69 | { |
---|
| 70 | k= 1; |
---|
| 71 | while (k < 3) |
---|
| 72 | { |
---|
| 73 | if (k == 1) |
---|
| 74 | { |
---|
| 75 | g= F (y - i*alpha, y); |
---|
[50a2aa9] | 76 | g *= bCommonDen (g); |
---|
[35eb6c] | 77 | if (degg >= 8 || degmipo >= 8) |
---|
| 78 | norm= resultantZ (g (x, alpha), mipo, x); |
---|
| 79 | else |
---|
| 80 | norm= resultant (g (x, alpha), mipo, x); |
---|
[59a7ca1] | 81 | } |
---|
| 82 | else |
---|
| 83 | { |
---|
| 84 | g= F (y + i*alpha, y); |
---|
[50a2aa9] | 85 | g *= bCommonDen (g); |
---|
[35eb6c] | 86 | if (degg >= 8 || degmipo >= 8) |
---|
| 87 | norm= resultantZ (g (x, alpha), mipo, x); |
---|
| 88 | else |
---|
| 89 | norm= resultant (g (x, alpha), mipo, x); |
---|
[59a7ca1] | 90 | } |
---|
| 91 | if (degree (gcd (deriv (norm, y), norm)) <= 0) |
---|
| 92 | { |
---|
| 93 | if (k == 2) |
---|
| 94 | i= -i; |
---|
| 95 | return norm; |
---|
| 96 | } |
---|
| 97 | k++; |
---|
| 98 | } |
---|
| 99 | i++; |
---|
| 100 | } while (1); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | CFList |
---|
| 104 | AlgExtSqrfFactorize (const CanonicalForm& F, const Variable& alpha) |
---|
| 105 | { |
---|
| 106 | ASSERT (F.isUnivariate(), "univariate input expected"); |
---|
| 107 | ASSERT (getCharacteristic() == 0, "characteristic 0 expected"); |
---|
[806c18] | 108 | |
---|
[9fd0b1] | 109 | bool save_rat=!isOn (SW_RATIONAL); |
---|
| 110 | On (SW_RATIONAL); |
---|
[35eb6c] | 111 | CanonicalForm f= F*bCommonDen (F); |
---|
[59a7ca1] | 112 | int shift; |
---|
| 113 | CanonicalForm norm= sqrfNorm (f, alpha, shift); |
---|
| 114 | ASSERT (degree (norm, alpha) <= 0, "wrong norm computed"); |
---|
[50a2aa9] | 115 | CFFList normFactors= factorize (norm); |
---|
[59a7ca1] | 116 | CFList factors; |
---|
| 117 | if (normFactors.length() <= 2) |
---|
[9fd0b1] | 118 | { |
---|
| 119 | if (save_rat) Off(SW_RATIONAL); |
---|
[35eb6c] | 120 | return CFList (F); |
---|
[9fd0b1] | 121 | } |
---|
[806c18] | 122 | |
---|
[59a7ca1] | 123 | normFactors.removeFirst(); |
---|
| 124 | CanonicalForm buf; |
---|
[062583] | 125 | buf= f; |
---|
[59a7ca1] | 126 | CanonicalForm factor; |
---|
| 127 | for (CFFListIterator i= normFactors; i.hasItem(); i++) |
---|
| 128 | { |
---|
| 129 | ASSERT (i.getItem().exp() == 1, "norm not squarefree"); |
---|
[062583] | 130 | if (shift == 0) |
---|
| 131 | factor= gcd (buf, i.getItem().factor()); |
---|
| 132 | else |
---|
| 133 | factor= gcd (buf, i.getItem().factor() (f.mvar() + shift*alpha, f.mvar())); |
---|
[59a7ca1] | 134 | buf /= factor; |
---|
| 135 | factors.append (factor); |
---|
[806c18] | 136 | } |
---|
[59a7ca1] | 137 | ASSERT (degree (buf) <= 0, "incomplete factorization"); |
---|
[9fd0b1] | 138 | if (save_rat) Off(SW_RATIONAL); |
---|
[59a7ca1] | 139 | return factors; |
---|
| 140 | } |
---|
| 141 | |
---|
[806c18] | 142 | CFFList |
---|
[59a7ca1] | 143 | AlgExtFactorize (const CanonicalForm& F, const Variable& alpha) |
---|
| 144 | { |
---|
| 145 | ASSERT (F.isUnivariate(), "univariate input expected"); |
---|
| 146 | ASSERT (getCharacteristic() == 0, "characteristic 0 expected"); |
---|
[806c18] | 147 | |
---|
[35eb6c] | 148 | |
---|
[59a7ca1] | 149 | if (F.inCoeffDomain()) |
---|
| 150 | return CFFList (CFFactor (F, 1)); |
---|
| 151 | |
---|
[50a2aa9] | 152 | bool save_rat=!isOn (SW_RATIONAL); |
---|
| 153 | On (SW_RATIONAL); |
---|
[5f9b47] | 154 | CFFList sqrf= sqrFreeZ (F); |
---|
| 155 | CFList factorsSqrf; |
---|
[59a7ca1] | 156 | CFFList factors; |
---|
[5f9b47] | 157 | CFListIterator j; |
---|
| 158 | |
---|
| 159 | for (CFFListIterator i= sqrf; i.hasItem(); i++) |
---|
[59a7ca1] | 160 | { |
---|
[5f9b47] | 161 | if (i.getItem().factor().inCoeffDomain()) continue; |
---|
| 162 | factorsSqrf= AlgExtSqrfFactorize (i.getItem().factor(), alpha); |
---|
| 163 | for (j= factorsSqrf; j.hasItem(); j++) |
---|
| 164 | factors.append (CFFactor (j.getItem()/Lc (j.getItem()), i.getItem().exp())); |
---|
[806c18] | 165 | } |
---|
[5f9b47] | 166 | |
---|
[59a7ca1] | 167 | factors.insert (CFFactor (Lc(F), 1)); |
---|
[50a2aa9] | 168 | if (save_rat) Off(SW_RATIONAL); |
---|
[806c18] | 169 | return factors; |
---|
[59a7ca1] | 170 | } |
---|
| 171 | |
---|