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 | |
---|
16 | // #include "config.h" |
---|
17 | |
---|
18 | #include "cf_assert.h" |
---|
19 | #include "timing.h" |
---|
20 | |
---|
21 | #include "facFqBivarUtil.h" |
---|
22 | #include "DegreePattern.h" |
---|
23 | #include "cf_util.h" |
---|
24 | #include "facFqSquarefree.h" |
---|
25 | #include "cf_map.h" |
---|
26 | #include "cfNewtonPolygon.h" |
---|
27 | #include "fac_util.h" |
---|
28 | |
---|
29 | TIMING_DEFINE_PRINT(fac_bi_sqrf) |
---|
30 | TIMING_DEFINE_PRINT(fac_bi_factor_sqrf) |
---|
31 | |
---|
32 | /// @return @a biFactorize returns a list of factors of F. If F is not monic |
---|
33 | /// its leading coefficient is not outputted. |
---|
34 | CFList |
---|
35 | biFactorize (const CanonicalForm& F, ///< [in] a bivariate poly |
---|
36 | const Variable& v ///< [in] some algebraic variable |
---|
37 | ); |
---|
38 | |
---|
39 | /// factorize a squarefree bivariate polynomial over \f$ Q(\alpha) \f$. |
---|
40 | /// |
---|
41 | /// @ return @a ratBiSqrfFactorize returns a list of monic factors, the first |
---|
42 | /// element is the leading coefficient. |
---|
43 | #ifdef HAVE_NTL |
---|
44 | inline |
---|
45 | CFList |
---|
46 | ratBiSqrfFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
47 | const Variable& v= Variable (1) ///< [in] algebraic variable |
---|
48 | ) |
---|
49 | { |
---|
50 | CFMap N; |
---|
51 | CanonicalForm F= compress (G, N); |
---|
52 | CanonicalForm contentX= content (F, 1); //erwarte hier primitiven input: primitiv ÃŒber Z bzw. Z[a] |
---|
53 | CanonicalForm contentY= content (F, 2); |
---|
54 | F /= (contentX*contentY); |
---|
55 | CFFList contentXFactors, contentYFactors; |
---|
56 | if (v.level() != 1) |
---|
57 | { |
---|
58 | contentXFactors= factorize (contentX, v); |
---|
59 | contentYFactors= factorize (contentY, v); |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | contentXFactors= factorize (contentX); |
---|
64 | contentYFactors= factorize (contentY); |
---|
65 | } |
---|
66 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
67 | contentXFactors.removeFirst(); |
---|
68 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
69 | contentYFactors.removeFirst(); |
---|
70 | if (F.inCoeffDomain()) |
---|
71 | { |
---|
72 | CFList result; |
---|
73 | for (CFFListIterator i= contentXFactors; i.hasItem(); i++) |
---|
74 | result.append (N (i.getItem().factor())); |
---|
75 | for (CFFListIterator i= contentYFactors; i.hasItem(); i++) |
---|
76 | result.append (N (i.getItem().factor())); |
---|
77 | if (isOn (SW_RATIONAL)) |
---|
78 | { |
---|
79 | normalize (result); |
---|
80 | result.insert (Lc (G)); |
---|
81 | } |
---|
82 | return result; |
---|
83 | } |
---|
84 | |
---|
85 | mpz_t * M=new mpz_t [4]; |
---|
86 | mpz_init (M[0]); |
---|
87 | mpz_init (M[1]); |
---|
88 | mpz_init (M[2]); |
---|
89 | mpz_init (M[3]); |
---|
90 | |
---|
91 | mpz_t * S=new mpz_t [2]; |
---|
92 | mpz_init (S[0]); |
---|
93 | mpz_init (S[1]); |
---|
94 | |
---|
95 | F= compress (F, M, S); |
---|
96 | CFList result= biFactorize (F, v); |
---|
97 | for (CFListIterator i= result; i.hasItem(); i++) |
---|
98 | i.getItem()= N (decompress (i.getItem(), M, S)); |
---|
99 | for (CFFListIterator i= contentXFactors; i.hasItem(); i++) |
---|
100 | result.append (N(i.getItem().factor())); |
---|
101 | for (CFFListIterator i= contentYFactors; i.hasItem(); i++) |
---|
102 | result.append (N (i.getItem().factor())); |
---|
103 | if (isOn (SW_RATIONAL)) |
---|
104 | { |
---|
105 | normalize (result); |
---|
106 | result.insert (Lc (G)); |
---|
107 | } |
---|
108 | |
---|
109 | mpz_clear (M[0]); |
---|
110 | mpz_clear (M[1]); |
---|
111 | mpz_clear (M[2]); |
---|
112 | mpz_clear (M[3]); |
---|
113 | delete [] M; |
---|
114 | |
---|
115 | mpz_clear (S[0]); |
---|
116 | mpz_clear (S[1]); |
---|
117 | delete [] S; |
---|
118 | |
---|
119 | return result; |
---|
120 | } |
---|
121 | |
---|
122 | /// factorize a bivariate polynomial over \f$ Q(\alpha) \f$ |
---|
123 | /// |
---|
124 | /// @return @a ratBiFactorize returns a list of monic factors with |
---|
125 | /// multiplicity, the first element is the leading coefficient. |
---|
126 | inline |
---|
127 | CFFList |
---|
128 | ratBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly |
---|
129 | const Variable& v= Variable (1), ///< [in] algebraic variable |
---|
130 | bool substCheck= true ///< [in] enables substitute check |
---|
131 | ) |
---|
132 | { |
---|
133 | CFMap N; |
---|
134 | CanonicalForm F= compress (G, N); |
---|
135 | |
---|
136 | if (substCheck) |
---|
137 | { |
---|
138 | bool foundOne= false; |
---|
139 | int * substDegree= new int [F.level()]; |
---|
140 | for (int i= 1; i <= F.level(); i++) |
---|
141 | { |
---|
142 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
143 | if (substDegree [i-1] > 1) |
---|
144 | { |
---|
145 | foundOne= true; |
---|
146 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
147 | } |
---|
148 | } |
---|
149 | if (foundOne) |
---|
150 | { |
---|
151 | CFFList result= ratBiFactorize (F, v, false); |
---|
152 | CFFList newResult, tmp; |
---|
153 | CanonicalForm tmp2; |
---|
154 | newResult.insert (result.getFirst()); |
---|
155 | result.removeFirst(); |
---|
156 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
157 | { |
---|
158 | tmp2= i.getItem().factor(); |
---|
159 | for (int j= 1; j <= F.level(); j++) |
---|
160 | { |
---|
161 | if (substDegree[j-1] > 1) |
---|
162 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
163 | } |
---|
164 | tmp= ratBiFactorize (tmp2, v, false); |
---|
165 | tmp.removeFirst(); |
---|
166 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
167 | newResult.append (CFFactor (j.getItem().factor(), |
---|
168 | j.getItem().exp()*i.getItem().exp())); |
---|
169 | } |
---|
170 | decompress (newResult, N); |
---|
171 | delete [] substDegree; |
---|
172 | return newResult; |
---|
173 | } |
---|
174 | delete [] substDegree; |
---|
175 | } |
---|
176 | |
---|
177 | CanonicalForm LcF= Lc (F); |
---|
178 | CanonicalForm contentX= content (F, 1); |
---|
179 | CanonicalForm contentY= content (F, 2); |
---|
180 | F /= (contentX*contentY); |
---|
181 | CFFList contentXFactors, contentYFactors; |
---|
182 | if (v.level() != 1) |
---|
183 | { |
---|
184 | contentXFactors= factorize (contentX, v); |
---|
185 | contentYFactors= factorize (contentY, v); |
---|
186 | } |
---|
187 | else |
---|
188 | { |
---|
189 | contentXFactors= factorize (contentX); |
---|
190 | contentYFactors= factorize (contentY); |
---|
191 | } |
---|
192 | if (contentXFactors.getFirst().factor().inCoeffDomain()) |
---|
193 | contentXFactors.removeFirst(); |
---|
194 | if (contentYFactors.getFirst().factor().inCoeffDomain()) |
---|
195 | contentYFactors.removeFirst(); |
---|
196 | decompress (contentXFactors, N); |
---|
197 | decompress (contentYFactors, N); |
---|
198 | CFFList result, resultRoot; |
---|
199 | if (F.inCoeffDomain()) |
---|
200 | { |
---|
201 | result= Union (contentXFactors, contentYFactors); |
---|
202 | if (isOn (SW_RATIONAL)) |
---|
203 | { |
---|
204 | normalize (result); |
---|
205 | if (v.level() == 1) |
---|
206 | { |
---|
207 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
208 | { |
---|
209 | LcF /= power (bCommonDen (i.getItem().factor()), i.getItem().exp()); |
---|
210 | i.getItem()= CFFactor (i.getItem().factor()* |
---|
211 | bCommonDen(i.getItem().factor()), i.getItem().exp()); |
---|
212 | } |
---|
213 | } |
---|
214 | result.insert (CFFactor (LcF, 1)); |
---|
215 | } |
---|
216 | return result; |
---|
217 | } |
---|
218 | |
---|
219 | mpz_t * M=new mpz_t [4]; |
---|
220 | mpz_init (M[0]); |
---|
221 | mpz_init (M[1]); |
---|
222 | mpz_init (M[2]); |
---|
223 | mpz_init (M[3]); |
---|
224 | |
---|
225 | mpz_t * S=new mpz_t [2]; |
---|
226 | mpz_init (S[0]); |
---|
227 | mpz_init (S[1]); |
---|
228 | |
---|
229 | F= compress (F, M, S); |
---|
230 | TIMING_START (fac_bi_sqrf); |
---|
231 | CFFList sqrfFactors= sqrFree (F); |
---|
232 | TIMING_END_AND_PRINT (fac_bi_sqrf, |
---|
233 | "time for bivariate sqrf factors over Q: "); |
---|
234 | for (CFFListIterator i= sqrfFactors; i.hasItem(); i++) |
---|
235 | { |
---|
236 | TIMING_START (fac_bi_factor_sqrf); |
---|
237 | CFList tmp= ratBiSqrfFactorize (i.getItem().factor(), v); |
---|
238 | TIMING_END_AND_PRINT (fac_bi_factor_sqrf, |
---|
239 | "time to factor bivariate sqrf factors over Q: "); |
---|
240 | for (CFListIterator j= tmp; j.hasItem(); j++) |
---|
241 | { |
---|
242 | if (j.getItem().inCoeffDomain()) continue; |
---|
243 | result.append (CFFactor (N (decompress (j.getItem(), M, S)), |
---|
244 | i.getItem().exp())); |
---|
245 | } |
---|
246 | } |
---|
247 | result= Union (result, contentXFactors); |
---|
248 | result= Union (result, contentYFactors); |
---|
249 | if (isOn (SW_RATIONAL)) |
---|
250 | { |
---|
251 | normalize (result); |
---|
252 | if (v.level() == 1) |
---|
253 | { |
---|
254 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
255 | { |
---|
256 | LcF /= power (bCommonDen (i.getItem().factor()), i.getItem().exp()); |
---|
257 | i.getItem()= CFFactor (i.getItem().factor()* |
---|
258 | bCommonDen(i.getItem().factor()), i.getItem().exp()); |
---|
259 | } |
---|
260 | } |
---|
261 | result.insert (CFFactor (LcF, 1)); |
---|
262 | } |
---|
263 | |
---|
264 | mpz_clear (M[0]); |
---|
265 | mpz_clear (M[1]); |
---|
266 | mpz_clear (M[2]); |
---|
267 | mpz_clear (M[3]); |
---|
268 | delete [] M; |
---|
269 | |
---|
270 | mpz_clear (S[0]); |
---|
271 | mpz_clear (S[1]); |
---|
272 | delete [] S; |
---|
273 | |
---|
274 | return result; |
---|
275 | } |
---|
276 | |
---|
277 | #endif |
---|
278 | |
---|
279 | /// convert a CFFList to a CFList by dropping the multiplicity |
---|
280 | CFList conv (const CFFList& L ///< [in] a CFFList |
---|
281 | ); |
---|
282 | |
---|
283 | modpk |
---|
284 | coeffBound ( const CanonicalForm & f, int p, const CanonicalForm& mipo ); |
---|
285 | |
---|
286 | void findGoodPrime(const CanonicalForm &f, int &start); |
---|
287 | |
---|
288 | modpk |
---|
289 | coeffBound ( const CanonicalForm & f, int p ); |
---|
290 | |
---|
291 | #endif |
---|
292 | |
---|