[6c44098] | 1 | /*****************************************************************************\ |
---|
| 2 | * Computer Algebra System SINGULAR |
---|
| 3 | \*****************************************************************************/ |
---|
| 4 | /** @file facBivar.h |
---|
| 5 | * |
---|
| 6 | * bivariate factorization over Q(a) |
---|
| 7 | * |
---|
| 8 | * @author Martin Lee |
---|
| 9 | * |
---|
| 10 | **/ |
---|
| 11 | /*****************************************************************************/ |
---|
| 12 | |
---|
| 13 | #ifndef FAC_BIVAR_H |
---|
| 14 | #define FAC_BIVAR_H |
---|
| 15 | |
---|
[d990001] | 16 | #include <config.h> |
---|
[6c44098] | 17 | |
---|
| 18 | #include "assert.h" |
---|
| 19 | |
---|
| 20 | #include "facFqBivarUtil.h" |
---|
| 21 | #include "DegreePattern.h" |
---|
| 22 | #include "cf_util.h" |
---|
| 23 | #include "facFqSquarefree.h" |
---|
| 24 | #include "cf_map.h" |
---|
| 25 | #include "cfNewtonPolygon.h" |
---|
| 26 | #include "algext.h" |
---|
[015711] | 27 | #include "fac_util.h" |
---|
[6c44098] | 28 | |
---|
| 29 | /// @return @a biFactorize returns a list of factors of F. If F is not monic |
---|
| 30 | /// its leading coefficient is not outputted. |
---|
| 31 | CFList |
---|
| 32 | biFactorize (const CanonicalForm& F, ///< [in] a bivariate poly |
---|
| 33 | const Variable& v ///< [in] some algebraic variable |
---|
| 34 | ); |
---|
| 35 | |
---|
| 36 | /// factorize a squarefree bivariate polynomial over \f$ Q(\alpha) \f$. |
---|
| 37 | /// |
---|
| 38 | /// @ return @a ratBiSqrfFactorize returns a list of monic factors, the first |
---|
| 39 | /// element is the leading coefficient. |
---|
[d990001] | 40 | #ifdef HAVE_NTL |
---|
[6c44098] | 41 | inline |
---|
[f9b796e] | 42 | CFList |
---|
[530295] | 43 | ratBiSqrfFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
| 44 | const Variable& v= Variable (1) ///< [in] algebraic variable |
---|
[f9b796e] | 45 | ) |
---|
[6c44098] | 46 | { |
---|
| 47 | CFMap N; |
---|
| 48 | CanonicalForm F= compress (G, N); |
---|
| 49 | CanonicalForm contentX= content (F, 1); |
---|
| 50 | CanonicalForm contentY= content (F, 2); |
---|
| 51 | F /= (contentX*contentY); |
---|
| 52 | CFFList contentXFactors, contentYFactors; |
---|
[530295] | 53 | if (v.level() != 1) |
---|
| 54 | { |
---|
| 55 | contentXFactors= factorize (contentX, v); |
---|
| 56 | contentYFactors= factorize (contentY, v); |
---|
| 57 | } |
---|
| 58 | else |
---|
| 59 | { |
---|
| 60 | contentXFactors= factorize (contentX); |
---|
| 61 | contentYFactors= factorize (contentY); |
---|
| 62 | } |
---|
[6c44098] | 63 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
| 64 | contentXFactors.removeFirst(); |
---|
| 65 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
| 66 | contentYFactors.removeFirst(); |
---|
| 67 | if (F.inCoeffDomain()) |
---|
| 68 | { |
---|
| 69 | CFList result; |
---|
| 70 | for (CFFListIterator i= contentXFactors; i.hasItem(); i++) |
---|
| 71 | result.append (N (i.getItem().factor())); |
---|
| 72 | for (CFFListIterator i= contentYFactors; i.hasItem(); i++) |
---|
| 73 | result.append (N (i.getItem().factor())); |
---|
| 74 | if (isOn (SW_RATIONAL)) |
---|
| 75 | { |
---|
| 76 | normalize (result); |
---|
| 77 | result.insert (Lc (G)); |
---|
| 78 | } |
---|
| 79 | return result; |
---|
| 80 | } |
---|
| 81 | mat_ZZ M; |
---|
| 82 | vec_ZZ S; |
---|
| 83 | F= compress (F, M, S); |
---|
[f9da5e] | 84 | CFList result= biFactorize (F, v); |
---|
| 85 | for (CFListIterator i= result; i.hasItem(); i++) |
---|
| 86 | i.getItem()= N (decompress (i.getItem(), M, S)); |
---|
[6c44098] | 87 | for (CFFListIterator i= contentXFactors; i.hasItem(); i++) |
---|
| 88 | result.append (N(i.getItem().factor())); |
---|
| 89 | for (CFFListIterator i= contentYFactors; i.hasItem(); i++) |
---|
| 90 | result.append (N (i.getItem().factor())); |
---|
| 91 | if (isOn (SW_RATIONAL)) |
---|
| 92 | { |
---|
| 93 | normalize (result); |
---|
| 94 | result.insert (Lc (G)); |
---|
| 95 | } |
---|
| 96 | return result; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /// factorize a bivariate polynomial over \f$ Q(\alpha) \f$ |
---|
| 100 | /// |
---|
| 101 | /// @return @a ratBiFactorize returns a list of monic factors with |
---|
| 102 | /// multiplicity, the first element is the leading coefficient. |
---|
| 103 | inline |
---|
[f9b796e] | 104 | CFFList |
---|
[530295] | 105 | ratBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
| 106 | const Variable& v= Variable (1), ///< [in] algebraic variable |
---|
| 107 | bool substCheck= true ///< [in] enables substitute check |
---|
[f9b796e] | 108 | ) |
---|
[6c44098] | 109 | { |
---|
| 110 | CFMap N; |
---|
| 111 | CanonicalForm F= compress (G, N); |
---|
[f9b796e] | 112 | |
---|
| 113 | if (substCheck) |
---|
| 114 | { |
---|
| 115 | bool foundOne= false; |
---|
| 116 | int * substDegree= new int [F.level()]; |
---|
| 117 | for (int i= 1; i <= F.level(); i++) |
---|
| 118 | { |
---|
| 119 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
| 120 | if (substDegree [i-1] > 1) |
---|
| 121 | { |
---|
| 122 | foundOne= true; |
---|
| 123 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | if (foundOne) |
---|
| 127 | { |
---|
| 128 | CFFList result= ratBiFactorize (F, v, false); |
---|
| 129 | CFFList newResult, tmp; |
---|
| 130 | CanonicalForm tmp2; |
---|
| 131 | newResult.insert (result.getFirst()); |
---|
| 132 | result.removeFirst(); |
---|
| 133 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 134 | { |
---|
| 135 | tmp2= i.getItem().factor(); |
---|
| 136 | for (int j= 1; j <= F.level(); j++) |
---|
| 137 | { |
---|
| 138 | if (substDegree[j-1] > 1) |
---|
| 139 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
| 140 | } |
---|
| 141 | tmp= ratBiFactorize (tmp2, v, false); |
---|
| 142 | tmp.removeFirst(); |
---|
| 143 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
| 144 | newResult.append (CFFactor (j.getItem().factor(), |
---|
| 145 | j.getItem().exp()*i.getItem().exp())); |
---|
| 146 | } |
---|
| 147 | decompress (newResult, N); |
---|
| 148 | delete [] substDegree; |
---|
| 149 | return newResult; |
---|
| 150 | } |
---|
| 151 | delete [] substDegree; |
---|
| 152 | } |
---|
| 153 | |
---|
[6c44098] | 154 | CanonicalForm LcF= Lc (F); |
---|
| 155 | CanonicalForm contentX= content (F, 1); |
---|
| 156 | CanonicalForm contentY= content (F, 2); |
---|
| 157 | F /= (contentX*contentY); |
---|
| 158 | CFFList contentXFactors, contentYFactors; |
---|
[530295] | 159 | if (v.level() != 1) |
---|
| 160 | { |
---|
| 161 | contentXFactors= factorize (contentX, v); |
---|
| 162 | contentYFactors= factorize (contentY, v); |
---|
| 163 | } |
---|
| 164 | else |
---|
| 165 | { |
---|
| 166 | contentXFactors= factorize (contentX); |
---|
| 167 | contentYFactors= factorize (contentY); |
---|
| 168 | } |
---|
[6c44098] | 169 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
| 170 | contentXFactors.removeFirst(); |
---|
| 171 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
| 172 | contentYFactors.removeFirst(); |
---|
| 173 | decompress (contentXFactors, N); |
---|
| 174 | decompress (contentYFactors, N); |
---|
| 175 | CFFList result, resultRoot; |
---|
| 176 | if (F.inCoeffDomain()) |
---|
| 177 | { |
---|
| 178 | result= Union (contentXFactors, contentYFactors); |
---|
| 179 | if (isOn (SW_RATIONAL)) |
---|
| 180 | { |
---|
| 181 | normalize (result); |
---|
[a8a93f] | 182 | if (v.level() == 1) |
---|
| 183 | { |
---|
| 184 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 185 | { |
---|
[ed66770] | 186 | LcF /= power (bCommonDen (i.getItem().factor()), i.getItem().exp()); |
---|
[a8a93f] | 187 | i.getItem()= CFFactor (i.getItem().factor()* |
---|
| 188 | bCommonDen(i.getItem().factor()), i.getItem().exp()); |
---|
| 189 | } |
---|
| 190 | } |
---|
[6c44098] | 191 | result.insert (CFFactor (LcF, 1)); |
---|
| 192 | } |
---|
| 193 | return result; |
---|
| 194 | } |
---|
| 195 | mat_ZZ M; |
---|
| 196 | vec_ZZ S; |
---|
| 197 | F= compress (F, M, S); |
---|
[5f9b47] | 198 | CFFList sqrfFactors= sqrFree (F); |
---|
| 199 | for (CFFListIterator i= sqrfFactors; i.hasItem(); i++) |
---|
| 200 | { |
---|
[f9da5e] | 201 | CFList tmp= ratBiSqrfFactorize (i.getItem().factor(), v); |
---|
| 202 | for (CFListIterator j= tmp; j.hasItem(); j++) |
---|
[5f9b47] | 203 | { |
---|
[f9da5e] | 204 | if (j.getItem().inCoeffDomain()) continue; |
---|
| 205 | result.append (CFFactor (N (decompress (j.getItem(), M, S)), |
---|
| 206 | i.getItem().exp())); |
---|
[5f9b47] | 207 | } |
---|
| 208 | } |
---|
[6c44098] | 209 | result= Union (result, contentXFactors); |
---|
| 210 | result= Union (result, contentYFactors); |
---|
| 211 | if (isOn (SW_RATIONAL)) |
---|
| 212 | { |
---|
| 213 | normalize (result); |
---|
[a8a93f] | 214 | if (v.level() == 1) |
---|
| 215 | { |
---|
| 216 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
| 217 | { |
---|
[ed66770] | 218 | LcF /= power (bCommonDen (i.getItem().factor()), i.getItem().exp()); |
---|
[a8a93f] | 219 | i.getItem()= CFFactor (i.getItem().factor()* |
---|
| 220 | bCommonDen(i.getItem().factor()), i.getItem().exp()); |
---|
| 221 | } |
---|
| 222 | } |
---|
[6c44098] | 223 | result.insert (CFFactor (LcF, 1)); |
---|
| 224 | } |
---|
| 225 | return result; |
---|
| 226 | } |
---|
| 227 | |
---|
[d990001] | 228 | #endif |
---|
| 229 | |
---|
[6c44098] | 230 | /// convert a CFFList to a CFList by dropping the multiplicity |
---|
| 231 | CFList conv (const CFFList& L ///< [in] a CFFList |
---|
| 232 | ); |
---|
| 233 | |
---|
[5f92d8] | 234 | modpk |
---|
| 235 | coeffBound ( const CanonicalForm & f, int p, const CanonicalForm& mipo ); |
---|
| 236 | |
---|
| 237 | void findGoodPrime(const CanonicalForm &f, int &start); |
---|
| 238 | |
---|
| 239 | modpk |
---|
| 240 | coeffBound ( const CanonicalForm & f, int p ); |
---|
| 241 | |
---|
[6c44098] | 242 | #endif |
---|
| 243 | |
---|