1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | /**************************************** |
---|
3 | * Computer Algebra System SINGULAR * |
---|
4 | ****************************************/ |
---|
5 | // $Id: clapsing.cc,v 1.43 1998-12-11 16:41:08 schmidt Exp $ |
---|
6 | /* |
---|
7 | * ABSTRACT: interface between Singular and factory |
---|
8 | */ |
---|
9 | |
---|
10 | #include "mod2.h" |
---|
11 | #ifdef HAVE_FACTORY |
---|
12 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
13 | #include "tok.h" |
---|
14 | #include "clapsing.h" |
---|
15 | #include "ipid.h" |
---|
16 | #include "numbers.h" |
---|
17 | #include "subexpr.h" |
---|
18 | #include "ipshell.h" |
---|
19 | #include "ring.h" |
---|
20 | #include <factory.h> |
---|
21 | #include "clapconv.h" |
---|
22 | #ifdef HAVE_LIBFAC_P |
---|
23 | #include <factor.h> |
---|
24 | #endif |
---|
25 | #include "ring.h" |
---|
26 | |
---|
27 | // |
---|
28 | // FACTORY_GCD_TEST: use new gcd instead of old one. Does not work |
---|
29 | // without new gcd-implementation which is not publicly available. |
---|
30 | // |
---|
31 | // FACTORY_GCD_STAT: print statistics on polynomials. Works only |
---|
32 | // with the file `gcd_stat.cc' and `gcd_stat.h which may be found |
---|
33 | // in the repository, module `factory-devel'. |
---|
34 | // Overall statistics may printed using `system("gcdstat");'. |
---|
35 | // |
---|
36 | // FACTORY_GCD_TIMING: accumulate time used for gcd calculations. |
---|
37 | // Time may be printed (and reset) with `system("gcdtime");'. |
---|
38 | // For this define, `timing.h' from the factory source directory |
---|
39 | // has to be copied to the Singular source directory. |
---|
40 | // Note: for better readability, the macros `TIMING_START()' and |
---|
41 | // `TIMING_END()' are used in any case. However, they expand to |
---|
42 | // nothing if `FACTORY_GCD_TIMING' is off. |
---|
43 | // |
---|
44 | // FACTORY_GCD_DEBOUT: print polynomials involved in gcd calculations. |
---|
45 | // The polynomials are printed by means of the macros |
---|
46 | // `FACTORY_*OUT_POLY' which are defined to be empty if |
---|
47 | // `FACTORY_GCD_DEBOUT' is off. |
---|
48 | // |
---|
49 | // FACTORY_GCD_DEBOUT_PATTERN: print degree patterns of polynomials |
---|
50 | // involved in gcd calculations. |
---|
51 | // The patterns are printed by means of the macros |
---|
52 | // `FACTORY_*OUT_PAT' which are defined to be empty if |
---|
53 | // `FACTORY_GCD_DEBOUT_PATTERN' is off. |
---|
54 | // |
---|
55 | // A degree pattern looks like this: |
---|
56 | // |
---|
57 | // totDeg size deg(v1) deg(v2) ... |
---|
58 | // |
---|
59 | // where "totDeg" means total degree, "size" the number of terms, |
---|
60 | // and "deg(vi)" is the degree with respect to variable i. |
---|
61 | // In univariate case, the "deg(vi)" are missing. For this feature |
---|
62 | // you need the files `gcd_stat.cc' and `gcd_stat.h'. |
---|
63 | // |
---|
64 | // |
---|
65 | // And here is what the functions print if `FACTORY_GCD_DEBOUT' (1), |
---|
66 | // `FACTORY_GCD_STAT' (2), or `FACTORY_GCD_DEBOUT_PATTERN' (3) is on: |
---|
67 | // |
---|
68 | // sinclap_divide_content: |
---|
69 | // (1) G = <firstCoeff> |
---|
70 | // (3) G#= <firstCoeff, pattern> |
---|
71 | // (1) h = <nextCoeff> |
---|
72 | // (3) h#= <nextCoeff, pattern> |
---|
73 | // (2) gcnt: <statistics on gcd as explained above> |
---|
74 | // (1) g = <intermediateResult> |
---|
75 | // (3) g#= <intermediateResult, pattern> |
---|
76 | // (1) h = <nextCoeff> |
---|
77 | // (3) h#= <nextCoeff, pattern> |
---|
78 | // (2) gcnt: <statistics on gcd as explained above> |
---|
79 | // ... |
---|
80 | // (1) h = <lastCoeff> |
---|
81 | // (3) h#= <lastCoeff, pattern> |
---|
82 | // (1) g = <finalResult> |
---|
83 | // (3) g#= <finalResult, pattern> |
---|
84 | // (2) gcnt: <statistics on gcd as explained above> |
---|
85 | // (2) cont: <statistics on content as explained above> |
---|
86 | // |
---|
87 | // singclap_alglcm: |
---|
88 | // (1) f = <inputPolyF> |
---|
89 | // (3) f#= <inputPolyF, pattern> |
---|
90 | // (1) g = <inputPolyG> |
---|
91 | // (3) g#= <inputPolyG, pattern> |
---|
92 | // (1) d = <its gcd> |
---|
93 | // (3) d#= <its gcd, pattern> |
---|
94 | // (2) alcm: <statistics as explained above> |
---|
95 | // |
---|
96 | // singclap_algdividecontent: |
---|
97 | // (1) f = <inputPolyF> |
---|
98 | // (3) f#= <inputPolyF, pattern> |
---|
99 | // (1) g = <inputPolyG> |
---|
100 | // (3) g#= <inputPolyG, pattern> |
---|
101 | // (1) d = <its gcd> |
---|
102 | // (3) d#= <its gcd, pattern> |
---|
103 | // (2) acnt: <statistics as explained above> |
---|
104 | // |
---|
105 | |
---|
106 | #ifdef FACTORY_GCD_STAT |
---|
107 | #include "gcd_stat.h" |
---|
108 | #define FACTORY_GCDSTAT( tag, f, g, d ) \ |
---|
109 | printGcdStat( tag, f, g, d ) |
---|
110 | #define FACTORY_CONTSTAT( tag, f ) \ |
---|
111 | printContStat( tag, f ) |
---|
112 | #else |
---|
113 | #define FACTORY_GCDSTAT( tag, f, g, d ) |
---|
114 | #define FACTORY_CONTSTAT( tag, f ) |
---|
115 | #endif |
---|
116 | |
---|
117 | #ifdef FACTORY_GCD_TIMING |
---|
118 | #define TIMING |
---|
119 | #include "timing.h" |
---|
120 | TIMING_DEFINE_PRINT( contentTimer ); |
---|
121 | TIMING_DEFINE_PRINT( algContentTimer ); |
---|
122 | TIMING_DEFINE_PRINT( algLcmTimer ); |
---|
123 | #else |
---|
124 | #define TIMING_START( timer ) |
---|
125 | #define TIMING_END( timer ) |
---|
126 | #endif |
---|
127 | |
---|
128 | #ifdef FACTORY_GCD_DEBOUT |
---|
129 | #include "longalg.h" |
---|
130 | #include "febase.h" |
---|
131 | // alg f |
---|
132 | #define FACTORY_ALGOUT_POLY( tag, f ) \ |
---|
133 | StringSetS( tag ); \ |
---|
134 | napWrite( f ); \ |
---|
135 | PrintS(StringAppend("\n")); |
---|
136 | // CanonicalForm f, represents transcendent extension |
---|
137 | #define FACTORY_CFTROUT_POLY( tag, f ) \ |
---|
138 | { \ |
---|
139 | alg F=convClapPSingTr( f ); \ |
---|
140 | StringSetS( tag ); \ |
---|
141 | napWrite( F ); \ |
---|
142 | PrintS(StringAppend("\n")); \ |
---|
143 | napDelete( &F ); \ |
---|
144 | } |
---|
145 | // CanonicalForm f, represents algebraic extension |
---|
146 | #define FACTORY_CFAOUT_POLY( tag, f ) \ |
---|
147 | { \ |
---|
148 | alg F=convClapASingA( f ); \ |
---|
149 | StringSetS( tag ); \ |
---|
150 | napWrite( F ); \ |
---|
151 | PrintS(StringAppend("\n")); \ |
---|
152 | napDelete( &F ); \ |
---|
153 | } |
---|
154 | #else /* ! FACTORY_GCD_DEBOUT */ |
---|
155 | #define FACTORY_ALGOUT_POLY( tag, f ) |
---|
156 | #define FACTORY_CFTROUT_POLY( tag, f ) |
---|
157 | #define FACTORY_CFAOUT_POLY( tag, f ) |
---|
158 | #endif /* ! FACTORY_GCD_DEBOUT */ |
---|
159 | |
---|
160 | #ifdef FACTORY_GCD_DEBOUT_PATTERN |
---|
161 | // alg f |
---|
162 | #define FACTORY_ALGOUT_PAT( tag, f ) \ |
---|
163 | if (currRing->minpoly!=NULL) \ |
---|
164 | { \ |
---|
165 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); \ |
---|
166 | Variable a=rootOf(mipo); \ |
---|
167 | printPolyPattern( tag, convSingAClapA( f,a ), rPar( currRing ) ); \ |
---|
168 | } \ |
---|
169 | else \ |
---|
170 | { \ |
---|
171 | printPolyPattern( tag, convSingTrClapP( f ), rPar( currRing ) ); \ |
---|
172 | } |
---|
173 | // CanonicalForm f, represents transcendent extension |
---|
174 | #define FACTORY_CFTROUT_PAT( tag, f ) printPolyPattern( tag, f, rPar( currRing ) ) |
---|
175 | // CanonicalForm f, represents algebraic extension |
---|
176 | #define FACTORY_CFAOUT_PAT( tag, f ) printPolyPattern( tag, f, rPar( currRing ) ) |
---|
177 | #else /* ! FACTORY_GCD_DEBOUT_PATTERN */ |
---|
178 | #define FACTORY_ALGOUT_PAT( tag, f ) |
---|
179 | #define FACTORY_CFTROUT_PAT( tag, f ) |
---|
180 | #define FACTORY_CFAOUT_PAT( tag, f ) |
---|
181 | #endif /* ! FACTORY_GCD_DEBOUT_PATTERN */ |
---|
182 | |
---|
183 | // these macors combine both print macros |
---|
184 | #define FACTORY_ALGOUT( tag, f ) \ |
---|
185 | FACTORY_ALGOUT_POLY( tag " = ", f ); \ |
---|
186 | FACTORY_ALGOUT_PAT( tag "#= ", f ) |
---|
187 | #define FACTORY_CFTROUT( tag, f ) \ |
---|
188 | FACTORY_CFTROUT_POLY( tag " = ", f ); \ |
---|
189 | FACTORY_CFTROUT_PAT( tag "#= ", f ) |
---|
190 | #define FACTORY_CFAOUT( tag, f ) \ |
---|
191 | FACTORY_CFAOUT_POLY( tag " = ", f ); \ |
---|
192 | FACTORY_CFAOUT_PAT( tag "#= ", f ) |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | poly singclap_gcd ( poly f, poly g ) |
---|
199 | { |
---|
200 | poly res=NULL; |
---|
201 | |
---|
202 | if (f!=NULL) pCleardenom(f); |
---|
203 | if (g!=NULL) pCleardenom(g); |
---|
204 | |
---|
205 | // for now there is only the possibility to handle polynomials over |
---|
206 | // Q and Fp ... |
---|
207 | if (( nGetChar() == 0 || nGetChar() > 1 ) |
---|
208 | && (currRing->parameter==NULL)) |
---|
209 | { |
---|
210 | setCharacteristic( nGetChar() ); |
---|
211 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
212 | res=convClapPSingP( gcd( F, G ) ); |
---|
213 | Off(SW_RATIONAL); |
---|
214 | } |
---|
215 | // and over Q(a) / Fp(a) |
---|
216 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
217 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
218 | { |
---|
219 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
220 | else setCharacteristic( -nGetChar() ); |
---|
221 | if (currRing->minpoly!=NULL) |
---|
222 | { |
---|
223 | if ( nGetChar()==1 ) /* Q(a) */ |
---|
224 | { |
---|
225 | WerrorS( feNotImplemented ); |
---|
226 | } |
---|
227 | else |
---|
228 | { |
---|
229 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
230 | Variable a=rootOf(mipo); |
---|
231 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
232 | res= convClapAPSingAP( gcd( F, G ) ); |
---|
233 | } |
---|
234 | } |
---|
235 | else |
---|
236 | { |
---|
237 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
238 | res= convClapPSingTrP( gcd( F, G ) ); |
---|
239 | } |
---|
240 | Off(SW_RATIONAL); |
---|
241 | } |
---|
242 | #if 0 |
---|
243 | else if (( nGetChar()>1 )&&(currRing->parameter!=NULL)) /* GF(q) */ |
---|
244 | { |
---|
245 | int p=rChar(currRing); |
---|
246 | int n=2; |
---|
247 | int t=p*p; |
---|
248 | while (t!=nChar) { t*=p;n++; } |
---|
249 | setCharacteristic(p,n,'a'); |
---|
250 | CanonicalForm F( convSingGFClapGF( f ) ), G( convSingGFClapGF( g ) ); |
---|
251 | res= convClapGFSingGF( gcd( F, G ) ); |
---|
252 | } |
---|
253 | #endif |
---|
254 | else |
---|
255 | WerrorS( feNotImplemented ); |
---|
256 | |
---|
257 | pDelete(&f); |
---|
258 | pDelete(&g); |
---|
259 | return res; |
---|
260 | } |
---|
261 | |
---|
262 | poly singclap_resultant ( poly f, poly g , poly x) |
---|
263 | { |
---|
264 | int i=pIsPurePower(x); |
---|
265 | if (i==0) |
---|
266 | { |
---|
267 | WerrorS("3rd argument must be a ring variable"); |
---|
268 | return NULL; |
---|
269 | } |
---|
270 | // for now there is only the possibility to handle polynomials over |
---|
271 | // Q and Fp ... |
---|
272 | if (( nGetChar() == 0 || nGetChar() > 1 ) |
---|
273 | && (currRing->parameter==NULL)) |
---|
274 | { |
---|
275 | Variable X(i); |
---|
276 | setCharacteristic( nGetChar() ); |
---|
277 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
278 | poly res=convClapPSingP( resultant( F, G, X ) ); |
---|
279 | Off(SW_RATIONAL); |
---|
280 | return res; |
---|
281 | } |
---|
282 | // and over Q(a) / Fp(a) |
---|
283 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
284 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
285 | { |
---|
286 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
287 | else setCharacteristic( -nGetChar() ); |
---|
288 | poly res; |
---|
289 | if (currRing->minpoly!=NULL) |
---|
290 | { |
---|
291 | Variable X(i); |
---|
292 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
293 | Variable a=rootOf(mipo); |
---|
294 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
295 | res= convClapAPSingAP( resultant( F, G, X ) ); |
---|
296 | } |
---|
297 | else |
---|
298 | { |
---|
299 | Variable X(i+rPar(currRing)); |
---|
300 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
301 | res= convClapPSingTrP( resultant( F, G, X ) ); |
---|
302 | } |
---|
303 | Off(SW_RATIONAL); |
---|
304 | return res; |
---|
305 | } |
---|
306 | else |
---|
307 | WerrorS( feNotImplemented ); |
---|
308 | return NULL; |
---|
309 | } |
---|
310 | //poly singclap_resultant ( poly f, poly g , poly x) |
---|
311 | //{ |
---|
312 | // int i=pVar(x); |
---|
313 | // if (i==0) |
---|
314 | // { |
---|
315 | // WerrorS("ringvar expected"); |
---|
316 | // return NULL; |
---|
317 | // } |
---|
318 | // ideal I=idInit(1,1); |
---|
319 | // |
---|
320 | // // get the coeffs von f wrt. x: |
---|
321 | // I->m[0]=pCopy(f); |
---|
322 | // matrix ffi=mpCoeffs(I,i); |
---|
323 | // ffi->rank=1; |
---|
324 | // ffi->ncols=ffi->nrows; |
---|
325 | // ffi->nrows=1; |
---|
326 | // ideal fi=(ideal)ffi; |
---|
327 | // |
---|
328 | // // get the coeffs von g wrt. x: |
---|
329 | // I->m[0]=pCopy(g); |
---|
330 | // matrix ggi=mpCoeffs(I,i); |
---|
331 | // ggi->rank=1; |
---|
332 | // ggi->ncols=ggi->nrows; |
---|
333 | // ggi->nrows=1; |
---|
334 | // ideal gi=(ideal)ggi; |
---|
335 | // |
---|
336 | // // contruct the matrix: |
---|
337 | // int fn=IDELEMS(fi); //= deg(f,x)+1 |
---|
338 | // int gn=IDELEMS(gi); //= deg(g,x)+1 |
---|
339 | // matrix m=mpNew(fn+gn-2,fn+gn-2); |
---|
340 | // if(m==NULL) |
---|
341 | // { |
---|
342 | // return NULL; |
---|
343 | // } |
---|
344 | // |
---|
345 | // // enter the coeffs into m: |
---|
346 | // int j; |
---|
347 | // for(i=0;i<gn-1;i++) |
---|
348 | // { |
---|
349 | // for(j=0;j<fn;j++) |
---|
350 | // { |
---|
351 | // MATELEM(m,i+1,fn-j+i)=pCopy(fi->m[j]); |
---|
352 | // } |
---|
353 | // } |
---|
354 | // for(i=0;i<fn-1;i++) |
---|
355 | // { |
---|
356 | // for(j=0;j<gn;j++) |
---|
357 | // { |
---|
358 | // MATELEM(m,gn+i,gn-j+i)=pCopy(gi->m[j]); |
---|
359 | // } |
---|
360 | // } |
---|
361 | // |
---|
362 | // poly r=mpDet(m); |
---|
363 | // |
---|
364 | // idDelete(&fi); |
---|
365 | // idDelete(&gi); |
---|
366 | // idDelete((ideal *)&m); |
---|
367 | // return r; |
---|
368 | //} |
---|
369 | |
---|
370 | lists singclap_extgcd ( poly f, poly g ) |
---|
371 | { |
---|
372 | // for now there is only the possibility to handle univariate |
---|
373 | // polynomials over |
---|
374 | // Q and Fp ... |
---|
375 | poly res=NULL,pa=NULL,pb=NULL; |
---|
376 | On(SW_SYMMETRIC_FF); |
---|
377 | if (( nGetChar() == 0 || nGetChar() > 1 ) |
---|
378 | && (currRing->parameter==NULL)) |
---|
379 | { |
---|
380 | setCharacteristic( nGetChar() ); |
---|
381 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
382 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
383 | { |
---|
384 | Off(SW_RATIONAL); |
---|
385 | WerrorS("not univariate"); |
---|
386 | return NULL; |
---|
387 | } |
---|
388 | CanonicalForm Fa,Gb; |
---|
389 | On(SW_RATIONAL); |
---|
390 | res=convClapPSingP( extgcd( F, G, Fa, Gb ) ); |
---|
391 | pa=convClapPSingP(Fa); |
---|
392 | pb=convClapPSingP(Gb); |
---|
393 | Off(SW_RATIONAL); |
---|
394 | } |
---|
395 | // and over Q(a) / Fp(a) |
---|
396 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
397 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
398 | { |
---|
399 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
400 | else setCharacteristic( -nGetChar() ); |
---|
401 | CanonicalForm Fa,Gb; |
---|
402 | if (currRing->minpoly!=NULL) |
---|
403 | { |
---|
404 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
405 | Variable a=rootOf(mipo); |
---|
406 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
407 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
408 | { |
---|
409 | WerrorS("not univariate"); |
---|
410 | return NULL; |
---|
411 | } |
---|
412 | res= convClapAPSingAP( extgcd( F, G, Fa, Gb ) ); |
---|
413 | pa=convClapAPSingAP(Fa); |
---|
414 | pb=convClapAPSingAP(Gb); |
---|
415 | } |
---|
416 | else |
---|
417 | { |
---|
418 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
419 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
420 | { |
---|
421 | Off(SW_RATIONAL); |
---|
422 | WerrorS("not univariate"); |
---|
423 | return NULL; |
---|
424 | } |
---|
425 | res= convClapPSingTrP( extgcd( F, G, Fa, Gb ) ); |
---|
426 | pa=convClapPSingTrP(Fa); |
---|
427 | pb=convClapPSingTrP(Gb); |
---|
428 | } |
---|
429 | Off(SW_RATIONAL); |
---|
430 | } |
---|
431 | else |
---|
432 | { |
---|
433 | WerrorS( feNotImplemented ); |
---|
434 | return NULL; |
---|
435 | } |
---|
436 | lists L=(lists)Alloc(sizeof(slists)); |
---|
437 | L->Init(3); |
---|
438 | L->m[0].rtyp=POLY_CMD; |
---|
439 | L->m[0].data=(void *)res; |
---|
440 | L->m[1].rtyp=POLY_CMD; |
---|
441 | L->m[1].data=(void *)pa; |
---|
442 | L->m[2].rtyp=POLY_CMD; |
---|
443 | L->m[2].data=(void *)pb; |
---|
444 | return L; |
---|
445 | } |
---|
446 | |
---|
447 | poly singclap_pdivide ( poly f, poly g ) |
---|
448 | { |
---|
449 | // for now there is only the possibility to handle polynomials over |
---|
450 | // Q and Fp ... |
---|
451 | poly res=NULL; |
---|
452 | On(SW_RATIONAL); |
---|
453 | if (( nGetChar() == 0 || nGetChar() > 1 ) |
---|
454 | && (currRing->parameter==NULL)) |
---|
455 | { |
---|
456 | setCharacteristic( nGetChar() ); |
---|
457 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
458 | res = convClapPSingP( F / G ); |
---|
459 | } |
---|
460 | // and over Q(a) / Fp(a) |
---|
461 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
462 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
463 | { |
---|
464 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
465 | else setCharacteristic( -nGetChar() ); |
---|
466 | if (currRing->minpoly!=NULL) |
---|
467 | { |
---|
468 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
469 | Variable a=rootOf(mipo); |
---|
470 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
471 | res= convClapAPSingAP( F / G ); |
---|
472 | } |
---|
473 | else |
---|
474 | { |
---|
475 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
476 | res= convClapPSingTrP( F / G ); |
---|
477 | } |
---|
478 | } |
---|
479 | else |
---|
480 | WerrorS( feNotImplemented ); |
---|
481 | Off(SW_RATIONAL); |
---|
482 | return res; |
---|
483 | } |
---|
484 | |
---|
485 | void singclap_divide_content ( poly f ) |
---|
486 | { |
---|
487 | if ( nGetChar() == 1 ) |
---|
488 | setCharacteristic( 0 ); |
---|
489 | else if ( nGetChar() == -1 ) |
---|
490 | return; /* not implemented for R */ |
---|
491 | else if ( nGetChar() < 0 ) |
---|
492 | setCharacteristic( -nGetChar() ); |
---|
493 | else if (currRing->parameter==NULL) /* not GF(q) */ |
---|
494 | setCharacteristic( nGetChar() ); |
---|
495 | else |
---|
496 | return; /* not implemented*/ |
---|
497 | if ( f==NULL ) |
---|
498 | { |
---|
499 | return; |
---|
500 | } |
---|
501 | else if ( pNext( f ) == NULL ) |
---|
502 | { |
---|
503 | pSetCoeff( f, nInit( 1 ) ); |
---|
504 | return; |
---|
505 | } |
---|
506 | else |
---|
507 | { |
---|
508 | CFList L; |
---|
509 | CanonicalForm g, h; |
---|
510 | poly p = pNext(f); |
---|
511 | //nTest(pGetCoeff(f)); |
---|
512 | FACTORY_ALGOUT( "G", (((lnumber)pGetCoeff(f))->z) ); |
---|
513 | g = convSingTrClapP( ((lnumber)pGetCoeff(f))->z ); |
---|
514 | L.append( g ); |
---|
515 | TIMING_START( contentTimer ); |
---|
516 | while ( (p != NULL) && (g != 1) ) |
---|
517 | { |
---|
518 | //nTest(pGetCoeff(p)); |
---|
519 | FACTORY_ALGOUT( "h", (((lnumber)pGetCoeff(p))->z) ); |
---|
520 | h = convSingTrClapP( ((lnumber)pGetCoeff(p))->z ); |
---|
521 | p = pNext( p ); |
---|
522 | #ifdef FACTORY_GCD_STAT |
---|
523 | // save g |
---|
524 | CanonicalForm gOld = g; |
---|
525 | #endif |
---|
526 | |
---|
527 | #ifdef FACTORY_GCD_TEST |
---|
528 | g = CFPrimitiveGcdUtil::gcd( g, h ); |
---|
529 | #else |
---|
530 | g = gcd( g, h ); |
---|
531 | #endif |
---|
532 | |
---|
533 | FACTORY_GCDSTAT( "gcnt:", gOld, h, g ); |
---|
534 | FACTORY_CFTROUT( "g", g ); |
---|
535 | L.append( h ); |
---|
536 | } |
---|
537 | TIMING_END( contentTimer ); |
---|
538 | FACTORY_CONTSTAT( "cont:", g ); |
---|
539 | if ( g == 1 ) |
---|
540 | { |
---|
541 | pTest(f); |
---|
542 | return; |
---|
543 | } |
---|
544 | #ifdef LDEBUG |
---|
545 | else if ( g == 0 ) |
---|
546 | { |
---|
547 | pTest(f); |
---|
548 | pWrite(f); |
---|
549 | PrintS("=> gcd 0 in divide_content\n"); |
---|
550 | return; |
---|
551 | } |
---|
552 | #endif |
---|
553 | else |
---|
554 | { |
---|
555 | CFListIterator i; |
---|
556 | for ( i = L, p = f; i.hasItem(); i++, p=pNext(p) ) |
---|
557 | { |
---|
558 | lnumber c=(lnumber)pGetCoeff(p); |
---|
559 | napDelete(&c->z); |
---|
560 | #ifdef LDEBUG |
---|
561 | number nt=(number)Alloc0(sizeof(rnumber)); |
---|
562 | lnumber nnt=(lnumber)nt; |
---|
563 | nnt->z=convClapPSingTr( i.getItem()); |
---|
564 | nTest(nt); |
---|
565 | #endif |
---|
566 | c->z=convClapPSingTr( i.getItem() / g ); |
---|
567 | //nTest((number)c); |
---|
568 | //#ifdef LDEBUG |
---|
569 | //number cn=(number)c; |
---|
570 | //StringSet(""); nWrite(nt); StringAppend(" ==> "); |
---|
571 | //nWrite(cn);PrintS(StringAppend("\n")); |
---|
572 | //#endif |
---|
573 | } |
---|
574 | } |
---|
575 | pTest(f); |
---|
576 | } |
---|
577 | } |
---|
578 | |
---|
579 | ideal singclap_factorize ( poly f, intvec ** v , int with_exps) |
---|
580 | { |
---|
581 | // with_exps: 1 return only true factors |
---|
582 | // 2 return true factors and exponents |
---|
583 | // 0 return factors and exponents |
---|
584 | |
---|
585 | ideal res=NULL; |
---|
586 | if (f==NULL) |
---|
587 | { |
---|
588 | res=idInit(1,1); |
---|
589 | if (with_exps!=1) |
---|
590 | { |
---|
591 | (*v)=new intvec(1); |
---|
592 | (*v)[1]=1; |
---|
593 | } |
---|
594 | return res; |
---|
595 | } |
---|
596 | Off(SW_RATIONAL); |
---|
597 | On(SW_SYMMETRIC_FF); |
---|
598 | CFFList L; |
---|
599 | number N=NULL; |
---|
600 | number NN=NULL; |
---|
601 | |
---|
602 | if (( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
603 | && (currRing->parameter==NULL)) |
---|
604 | { |
---|
605 | setCharacteristic( nGetChar() ); |
---|
606 | if (nGetChar()==0) /* Q */ |
---|
607 | { |
---|
608 | if (f!=NULL) |
---|
609 | { |
---|
610 | number n0=nCopy(pGetCoeff(f)); |
---|
611 | if (with_exps==0) |
---|
612 | N=nCopy(n0); |
---|
613 | pCleardenom(f); |
---|
614 | NN=nDiv(n0,pGetCoeff(f)); |
---|
615 | nDelete(&n0); |
---|
616 | if (with_exps==0) |
---|
617 | { |
---|
618 | nDelete(&N); |
---|
619 | N=nCopy(NN); |
---|
620 | } |
---|
621 | } |
---|
622 | } |
---|
623 | CanonicalForm F( convSingPClapP( f ) ); |
---|
624 | if (nGetChar()==0) /* Q */ |
---|
625 | { |
---|
626 | L = factorize( F ); |
---|
627 | } |
---|
628 | else /* Fp */ |
---|
629 | { |
---|
630 | #ifdef HAVE_LIBFAC_P |
---|
631 | L = Factorize( F ); |
---|
632 | #else |
---|
633 | goto notImpl; |
---|
634 | #endif |
---|
635 | } |
---|
636 | } |
---|
637 | // and over Q(a) / Fp(a) |
---|
638 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
639 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
640 | { |
---|
641 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
642 | else setCharacteristic( -nGetChar() ); |
---|
643 | if ((currRing->minpoly!=NULL) |
---|
644 | && (nGetChar()<(-1))) |
---|
645 | { |
---|
646 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
647 | Variable a=rootOf(mipo); |
---|
648 | CanonicalForm F( convSingAPClapAP( f,a ) ); |
---|
649 | if (F.isUnivariate()) |
---|
650 | { |
---|
651 | L = factorize( F, a ); |
---|
652 | } |
---|
653 | else |
---|
654 | { |
---|
655 | CanonicalForm G( convSingTrPClapP( f ) ); |
---|
656 | L = factorize( G ); |
---|
657 | } |
---|
658 | } |
---|
659 | else |
---|
660 | { |
---|
661 | CanonicalForm F( convSingTrPClapP( f ) ); |
---|
662 | if (nGetChar()==1) /* Q(a) */ |
---|
663 | { |
---|
664 | L = factorize( F ); |
---|
665 | } |
---|
666 | else /* Fp(a) */ |
---|
667 | { |
---|
668 | #ifdef HAVE_LIBFAC_P |
---|
669 | L = Factorize( F ); |
---|
670 | #else |
---|
671 | goto notImpl; |
---|
672 | #endif |
---|
673 | } |
---|
674 | } |
---|
675 | } |
---|
676 | else |
---|
677 | { |
---|
678 | goto notImpl; |
---|
679 | } |
---|
680 | { |
---|
681 | // the first factor should be a constant |
---|
682 | if ( ! L.getFirst().factor().inCoeffDomain() ) |
---|
683 | L.insert(CFFactor(1,1)); |
---|
684 | // convert into ideal |
---|
685 | int n = L.length(); |
---|
686 | CFFListIterator J=L; |
---|
687 | int j=0; |
---|
688 | if (with_exps!=1) |
---|
689 | { |
---|
690 | if ((with_exps==2)&&(n>1)) |
---|
691 | { |
---|
692 | n--; |
---|
693 | J++; |
---|
694 | } |
---|
695 | *v = new intvec( n ); |
---|
696 | } |
---|
697 | res = idInit( n ,1); |
---|
698 | for ( ; J.hasItem(); J++, j++ ) |
---|
699 | { |
---|
700 | if (with_exps!=1) (**v)[j] = J.getItem().exp(); |
---|
701 | if ((nGetChar()==0)||(nGetChar()>1)) /* Q, Fp */ |
---|
702 | res->m[j] = convClapPSingP( J.getItem().factor() ); |
---|
703 | else if ((nGetChar()==1)||(nGetChar()<-1)) /* Q(a), Fp(a) */ |
---|
704 | { |
---|
705 | if (currRing->minpoly==NULL) |
---|
706 | res->m[j] = convClapPSingTrP( J.getItem().factor() ); |
---|
707 | else |
---|
708 | res->m[j] = convClapAPSingAP( J.getItem().factor() ); |
---|
709 | } |
---|
710 | } |
---|
711 | if (N!=NULL) |
---|
712 | { |
---|
713 | pMultN(res->m[0],N); |
---|
714 | nDelete(&N); |
---|
715 | N=NULL; |
---|
716 | } |
---|
717 | // delete constants |
---|
718 | if ((with_exps!=0) && (res!=NULL)) |
---|
719 | { |
---|
720 | int i=IDELEMS(res)-1; |
---|
721 | int j=0; |
---|
722 | for(;i>=0;i--) |
---|
723 | { |
---|
724 | if (pIsConstant(res->m[i])) |
---|
725 | { |
---|
726 | pDelete(&(res->m[i])); |
---|
727 | if ((v!=NULL) && ((*v)!=NULL)) |
---|
728 | (**v)[i]=0; |
---|
729 | j++; |
---|
730 | } |
---|
731 | } |
---|
732 | if (j>0) |
---|
733 | { |
---|
734 | idSkipZeroes(res); |
---|
735 | if ((v!=NULL) && ((*v)!=NULL)) |
---|
736 | { |
---|
737 | intvec *w=*v; |
---|
738 | *v = new intvec( max(n-j,1) ); |
---|
739 | for (i=0,j=0;i<w->length();i++) |
---|
740 | { |
---|
741 | if((*w)[i]!=0) |
---|
742 | { |
---|
743 | (**v)[j]=(*w)[i]; j++; |
---|
744 | } |
---|
745 | } |
---|
746 | delete w; |
---|
747 | } |
---|
748 | } |
---|
749 | if (res->m[0]==NULL) |
---|
750 | { |
---|
751 | res->m[0]=pOne(); |
---|
752 | } |
---|
753 | } |
---|
754 | } |
---|
755 | notImpl: |
---|
756 | if (res==NULL) |
---|
757 | WerrorS( feNotImplemented ); |
---|
758 | if (NN!=NULL) |
---|
759 | { |
---|
760 | pMultN(f,NN); |
---|
761 | nDelete(&NN); |
---|
762 | } |
---|
763 | if (N!=NULL) |
---|
764 | { |
---|
765 | nDelete(&N); |
---|
766 | } |
---|
767 | return res; |
---|
768 | } |
---|
769 | |
---|
770 | matrix singclap_irrCharSeries ( ideal I) |
---|
771 | { |
---|
772 | #ifdef HAVE_LIBFAC_P |
---|
773 | // for now there is only the possibility to handle polynomials over |
---|
774 | // Q and Fp ... |
---|
775 | matrix res=NULL; |
---|
776 | int i; |
---|
777 | Off(SW_RATIONAL); |
---|
778 | On(SW_SYMMETRIC_FF); |
---|
779 | CFList L; |
---|
780 | ListCFList LL; |
---|
781 | if (((nGetChar() == 0) || (nGetChar() > 1) ) |
---|
782 | && (currRing->parameter==NULL)) |
---|
783 | { |
---|
784 | setCharacteristic( nGetChar() ); |
---|
785 | for(i=0;i<IDELEMS(I);i++) |
---|
786 | { |
---|
787 | L.append(convSingPClapP(I->m[i])); |
---|
788 | } |
---|
789 | } |
---|
790 | // and over Q(a) / Fp(a) |
---|
791 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
792 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
793 | { |
---|
794 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
795 | else setCharacteristic( -nGetChar() ); |
---|
796 | for(i=0;i<IDELEMS(I);i++) |
---|
797 | { |
---|
798 | L.append(convSingTrPClapP(I->m[i])); |
---|
799 | } |
---|
800 | } |
---|
801 | else |
---|
802 | { |
---|
803 | WerrorS( feNotImplemented ); |
---|
804 | return res; |
---|
805 | } |
---|
806 | |
---|
807 | LL=IrrCharSeries(L); |
---|
808 | int m= LL.length(); // Anzahl Zeilen |
---|
809 | int n=0; |
---|
810 | ListIterator<CFList> LLi; |
---|
811 | CFListIterator Li; |
---|
812 | for ( LLi = LL; LLi.hasItem(); LLi++ ) |
---|
813 | { |
---|
814 | n = max(LLi.getItem().length(),n); |
---|
815 | } |
---|
816 | res=mpNew(m,n); |
---|
817 | if ((m==0) || (n==0)) |
---|
818 | { |
---|
819 | Warn("char_series returns %d x %d matrix from %d input polys (%d)\n",m,n,IDELEMS(I)+1,LL.length()); |
---|
820 | iiWriteMatrix((matrix)I,"I",2,0); |
---|
821 | } |
---|
822 | for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ ) |
---|
823 | { |
---|
824 | for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++) |
---|
825 | { |
---|
826 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
827 | MATELEM(res,m,n)=convClapPSingP(Li.getItem()); |
---|
828 | else |
---|
829 | MATELEM(res,m,n)=convClapPSingTrP(Li.getItem()); |
---|
830 | } |
---|
831 | } |
---|
832 | Off(SW_RATIONAL); |
---|
833 | return res; |
---|
834 | #else |
---|
835 | return NULL; |
---|
836 | #endif |
---|
837 | } |
---|
838 | |
---|
839 | char* singclap_neworder ( ideal I) |
---|
840 | { |
---|
841 | #ifdef HAVE_LIBFAC_P |
---|
842 | int i; |
---|
843 | Off(SW_RATIONAL); |
---|
844 | On(SW_SYMMETRIC_FF); |
---|
845 | CFList L; |
---|
846 | if (((nGetChar() == 0) || (nGetChar() > 1) ) |
---|
847 | && (currRing->parameter==NULL)) |
---|
848 | { |
---|
849 | setCharacteristic( nGetChar() ); |
---|
850 | for(i=0;i<IDELEMS(I);i++) |
---|
851 | { |
---|
852 | L.append(convSingPClapP(I->m[i])); |
---|
853 | } |
---|
854 | } |
---|
855 | // and over Q(a) / Fp(a) |
---|
856 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
857 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
858 | { |
---|
859 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
860 | else setCharacteristic( -nGetChar() ); |
---|
861 | for(i=0;i<IDELEMS(I);i++) |
---|
862 | { |
---|
863 | L.append(convSingTrPClapP(I->m[i])); |
---|
864 | } |
---|
865 | } |
---|
866 | else |
---|
867 | { |
---|
868 | WerrorS( feNotImplemented ); |
---|
869 | return NULL; |
---|
870 | } |
---|
871 | |
---|
872 | List<int> IL=neworderint(L); |
---|
873 | ListIterator<int> Li; |
---|
874 | StringSet(""); |
---|
875 | Li = IL; |
---|
876 | int offs=rPar(currRing); |
---|
877 | int* mark=(int*)Alloc0((pVariables+offs)*sizeof(int)); |
---|
878 | int cnt=pVariables+offs; |
---|
879 | loop |
---|
880 | { |
---|
881 | i=Li.getItem()-1; |
---|
882 | mark[i]=1; |
---|
883 | if (i<offs) |
---|
884 | { |
---|
885 | StringAppend(currRing->parameter[i]); |
---|
886 | } |
---|
887 | else |
---|
888 | { |
---|
889 | StringAppend(currRing->names[i-offs]); |
---|
890 | } |
---|
891 | Li++; |
---|
892 | cnt--; |
---|
893 | if(cnt==0) break; |
---|
894 | StringAppend(","); |
---|
895 | if(! Li.hasItem()) break; |
---|
896 | } |
---|
897 | for(i=0;i<pVariables+offs;i++) |
---|
898 | { |
---|
899 | if(mark[i]==0) |
---|
900 | { |
---|
901 | if (i<offs) |
---|
902 | { |
---|
903 | StringAppend(currRing->parameter[i]); |
---|
904 | } |
---|
905 | else |
---|
906 | { |
---|
907 | StringAppend(currRing->names[i-offs]); |
---|
908 | } |
---|
909 | cnt--; |
---|
910 | if(cnt==0) break; |
---|
911 | StringAppend(","); |
---|
912 | } |
---|
913 | } |
---|
914 | return mstrdup(StringAppend("")); |
---|
915 | #else |
---|
916 | return NULL; |
---|
917 | #endif |
---|
918 | } |
---|
919 | |
---|
920 | BOOLEAN singclap_isSqrFree(poly f) |
---|
921 | { |
---|
922 | BOOLEAN b=FALSE; |
---|
923 | Off(SW_RATIONAL); |
---|
924 | // Q / Fp |
---|
925 | if (((nGetChar() == 0) || (nGetChar() > 1) ) |
---|
926 | &&(currRing->parameter==NULL)) |
---|
927 | { |
---|
928 | setCharacteristic( nGetChar() ); |
---|
929 | CanonicalForm F( convSingPClapP( f ) ); |
---|
930 | if((nGetChar()>1)&&(!F.isUnivariate())) |
---|
931 | goto err; |
---|
932 | b=(BOOLEAN)isSqrFree(F); |
---|
933 | } |
---|
934 | // and over Q(a) / Fp(a) |
---|
935 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
936 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
937 | { |
---|
938 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
939 | else setCharacteristic( -nGetChar() ); |
---|
940 | //if (currRing->minpoly!=NULL) |
---|
941 | //{ |
---|
942 | // CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
943 | // Variable a=rootOf(mipo); |
---|
944 | // CanonicalForm F( convSingAPClapAP( f,a ) ); |
---|
945 | // ... |
---|
946 | //} |
---|
947 | //else |
---|
948 | { |
---|
949 | CanonicalForm F( convSingTrPClapP( f ) ); |
---|
950 | b=(BOOLEAN)isSqrFree(F); |
---|
951 | } |
---|
952 | Off(SW_RATIONAL); |
---|
953 | } |
---|
954 | else |
---|
955 | { |
---|
956 | err: |
---|
957 | WerrorS( feNotImplemented ); |
---|
958 | } |
---|
959 | return b; |
---|
960 | } |
---|
961 | |
---|
962 | poly singclap_det( const matrix m ) |
---|
963 | { |
---|
964 | int r=m->rows(); |
---|
965 | if (r!=m->cols()) |
---|
966 | { |
---|
967 | Werror("det of %d x %d matrix",r,m->cols()); |
---|
968 | return NULL; |
---|
969 | } |
---|
970 | poly res=NULL; |
---|
971 | if (( nGetChar() == 0 || nGetChar() > 1 ) |
---|
972 | && (currRing->parameter==NULL)) |
---|
973 | { |
---|
974 | setCharacteristic( nGetChar() ); |
---|
975 | CFMatrix M(r,r); |
---|
976 | int i,j; |
---|
977 | for(i=r;i>0;i--) |
---|
978 | { |
---|
979 | for(j=r;j>0;j--) |
---|
980 | { |
---|
981 | M(i,j)=convSingPClapP(MATELEM(m,i,j)); |
---|
982 | } |
---|
983 | } |
---|
984 | res= convClapPSingP( determinant(M,r) ) ; |
---|
985 | } |
---|
986 | // and over Q(a) / Fp(a) |
---|
987 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
988 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
989 | { |
---|
990 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
991 | else setCharacteristic( -nGetChar() ); |
---|
992 | CFMatrix M(r,r); |
---|
993 | poly res; |
---|
994 | if (currRing->minpoly!=NULL) |
---|
995 | { |
---|
996 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
997 | Variable a=rootOf(mipo); |
---|
998 | int i,j; |
---|
999 | for(i=r;i>0;i--) |
---|
1000 | { |
---|
1001 | for(j=r;j>0;j--) |
---|
1002 | { |
---|
1003 | M(i,j)=convSingAPClapAP(MATELEM(m,i,j),a); |
---|
1004 | } |
---|
1005 | } |
---|
1006 | res= convClapAPSingAP( determinant(M,r) ) ; |
---|
1007 | } |
---|
1008 | else |
---|
1009 | { |
---|
1010 | int i,j; |
---|
1011 | for(i=r;i>0;i--) |
---|
1012 | { |
---|
1013 | for(j=r;j>0;j--) |
---|
1014 | { |
---|
1015 | M(i,j)=convSingTrPClapP(MATELEM(m,i,j)); |
---|
1016 | } |
---|
1017 | } |
---|
1018 | res= convClapPSingTrP( determinant(M,r) ); |
---|
1019 | } |
---|
1020 | } |
---|
1021 | else |
---|
1022 | WerrorS( feNotImplemented ); |
---|
1023 | Off(SW_RATIONAL); |
---|
1024 | return res; |
---|
1025 | } |
---|
1026 | |
---|
1027 | int singclap_det_i( intvec * m ) |
---|
1028 | { |
---|
1029 | setCharacteristic( 0 ); |
---|
1030 | CFMatrix M(m->rows(),m->cols()); |
---|
1031 | int i,j; |
---|
1032 | for(i=m->rows();i>0;i--) |
---|
1033 | { |
---|
1034 | for(j=m->cols();j>0;j--) |
---|
1035 | { |
---|
1036 | M(i,j)=IMATELEM(*m,i,j); |
---|
1037 | } |
---|
1038 | } |
---|
1039 | int res= convClapISingI( determinant(M,m->rows())) ; |
---|
1040 | Off(SW_RATIONAL); |
---|
1041 | return res; |
---|
1042 | } |
---|
1043 | /*==============================================================*/ |
---|
1044 | /* interpreter interface : */ |
---|
1045 | BOOLEAN jjGCD_P(leftv res, leftv u, leftv v) |
---|
1046 | { |
---|
1047 | res->data=(void *)singclap_gcd((poly)(u->CopyD()),((poly)v->CopyD())); |
---|
1048 | return FALSE; |
---|
1049 | } |
---|
1050 | |
---|
1051 | BOOLEAN jjFAC_P(leftv res, leftv u) |
---|
1052 | { |
---|
1053 | intvec *v=NULL; |
---|
1054 | ideal f=singclap_factorize((poly)(u->Data()), &v, 0); |
---|
1055 | if (f==NULL) return TRUE; |
---|
1056 | lists l=(lists)Alloc(sizeof(slists)); |
---|
1057 | l->Init(2); |
---|
1058 | l->m[0].rtyp=IDEAL_CMD; |
---|
1059 | l->m[0].data=(void *)f; |
---|
1060 | l->m[1].rtyp=INTVEC_CMD; |
---|
1061 | l->m[1].data=(void *)v; |
---|
1062 | res->data=(void *)l; |
---|
1063 | return FALSE; |
---|
1064 | } |
---|
1065 | |
---|
1066 | BOOLEAN jjSQR_FREE_DEC(leftv res, leftv u,leftv dummy) |
---|
1067 | { |
---|
1068 | intvec *v=NULL; |
---|
1069 | int sw=(int)dummy->Data(); |
---|
1070 | ideal f=singclap_factorize((poly)(u->Data()), &v, sw); |
---|
1071 | if (f==NULL) |
---|
1072 | return TRUE; |
---|
1073 | switch(sw) |
---|
1074 | { |
---|
1075 | case 0: |
---|
1076 | case 2: |
---|
1077 | { |
---|
1078 | lists l=(lists)Alloc(sizeof(slists)); |
---|
1079 | l->Init(2); |
---|
1080 | l->m[0].rtyp=IDEAL_CMD; |
---|
1081 | l->m[0].data=(void *)f; |
---|
1082 | l->m[1].rtyp=INTVEC_CMD; |
---|
1083 | l->m[1].data=(void *)v; |
---|
1084 | res->data=(void *)l; |
---|
1085 | res->rtyp=LIST_CMD; |
---|
1086 | return FALSE; |
---|
1087 | } |
---|
1088 | case 1: |
---|
1089 | res->data=(void *)f; |
---|
1090 | return FALSE; |
---|
1091 | case 3: |
---|
1092 | { |
---|
1093 | poly p=f->m[0]; |
---|
1094 | int i=IDELEMS(f); |
---|
1095 | f->m[0]=NULL; |
---|
1096 | while(i>1) |
---|
1097 | { |
---|
1098 | i--; |
---|
1099 | p=pMult(p,f->m[i]); |
---|
1100 | f->m[i]=NULL; |
---|
1101 | } |
---|
1102 | res->data=(void *)p; |
---|
1103 | res->rtyp=POLY_CMD; |
---|
1104 | } |
---|
1105 | return FALSE; |
---|
1106 | } |
---|
1107 | WerrorS("invalid switch"); |
---|
1108 | return TRUE; |
---|
1109 | } |
---|
1110 | |
---|
1111 | #if 0 |
---|
1112 | BOOLEAN jjIS_SQR_FREE(leftv res, leftv u) |
---|
1113 | { |
---|
1114 | BOOLEAN b=singclap_factorize((poly)(u->Data()), &v, 0); |
---|
1115 | res->data=(void *)b; |
---|
1116 | } |
---|
1117 | #endif |
---|
1118 | |
---|
1119 | BOOLEAN jjEXTGCD_P(leftv res, leftv u, leftv v) |
---|
1120 | { |
---|
1121 | res->data=singclap_extgcd((poly)u->Data(),(poly)v->Data()); |
---|
1122 | return (res->data==NULL); |
---|
1123 | } |
---|
1124 | BOOLEAN jjRESULTANT(leftv res, leftv u, leftv v, leftv w) |
---|
1125 | { |
---|
1126 | res->data=singclap_resultant((poly)u->Data(),(poly)v->Data(), (poly)w->Data()); |
---|
1127 | return errorreported; |
---|
1128 | } |
---|
1129 | BOOLEAN jjCHARSERIES(leftv res, leftv u) |
---|
1130 | { |
---|
1131 | res->data=singclap_irrCharSeries((ideal)u->Data()); |
---|
1132 | return (res->data==NULL); |
---|
1133 | } |
---|
1134 | |
---|
1135 | alg singclap_alglcm ( alg f, alg g ) |
---|
1136 | { |
---|
1137 | FACTORY_ALGOUT( "f", f ); |
---|
1138 | FACTORY_ALGOUT( "g", g ); |
---|
1139 | |
---|
1140 | // over Q(a) / Fp(a) |
---|
1141 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
1142 | else setCharacteristic( -nGetChar() ); |
---|
1143 | alg res; |
---|
1144 | |
---|
1145 | if (currRing->minpoly!=NULL) |
---|
1146 | { |
---|
1147 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
1148 | Variable a=rootOf(mipo); |
---|
1149 | CanonicalForm F( convSingAClapA( f,a ) ), G( convSingAClapA( g,a ) ); |
---|
1150 | CanonicalForm GCD; |
---|
1151 | |
---|
1152 | TIMING_START( algLcmTimer ); |
---|
1153 | // calculate gcd |
---|
1154 | #ifdef FACTORY_GCD_TEST |
---|
1155 | GCD = CFPrimitiveGcdUtil::gcd( F, G ); |
---|
1156 | #else |
---|
1157 | GCD = gcd( F, G ); |
---|
1158 | #endif |
---|
1159 | TIMING_END( algLcmTimer ); |
---|
1160 | |
---|
1161 | FACTORY_CFAOUT( "d", GCD ); |
---|
1162 | FACTORY_GCDSTAT( "alcm:", F, G, GCD ); |
---|
1163 | |
---|
1164 | // calculate lcm |
---|
1165 | res= convClapASingA( (F/GCD)*G ); |
---|
1166 | } |
---|
1167 | else |
---|
1168 | { |
---|
1169 | CanonicalForm F( convSingTrClapP( f ) ), G( convSingTrClapP( g ) ); |
---|
1170 | CanonicalForm GCD; |
---|
1171 | TIMING_START( algLcmTimer ); |
---|
1172 | // calculate gcd |
---|
1173 | #ifdef FACTORY_GCD_TEST |
---|
1174 | GCD = CFPrimitiveGcdUtil::gcd( F, G ); |
---|
1175 | #else |
---|
1176 | GCD = gcd( F, G ); |
---|
1177 | #endif |
---|
1178 | TIMING_END( algLcmTimer ); |
---|
1179 | |
---|
1180 | FACTORY_CFTROUT( "d", GCD ); |
---|
1181 | FACTORY_GCDSTAT( "alcm:", F, G, GCD ); |
---|
1182 | |
---|
1183 | // calculate lcm |
---|
1184 | res= convClapPSingTr( (F/GCD)*G ); |
---|
1185 | } |
---|
1186 | |
---|
1187 | Off(SW_RATIONAL); |
---|
1188 | return res; |
---|
1189 | } |
---|
1190 | |
---|
1191 | void singclap_algdividecontent ( alg f, alg g, alg &ff, alg &gg ) |
---|
1192 | { |
---|
1193 | FACTORY_ALGOUT( "f", f ); |
---|
1194 | FACTORY_ALGOUT( "g", g ); |
---|
1195 | |
---|
1196 | // over Q(a) / Fp(a) |
---|
1197 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
1198 | else setCharacteristic( -nGetChar() ); |
---|
1199 | ff=gg=NULL; |
---|
1200 | |
---|
1201 | if (currRing->minpoly!=NULL) |
---|
1202 | { |
---|
1203 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
1204 | Variable a=rootOf(mipo); |
---|
1205 | CanonicalForm F( convSingAClapA( f,a ) ), G( convSingAClapA( g,a ) ); |
---|
1206 | CanonicalForm GCD; |
---|
1207 | |
---|
1208 | TIMING_START( algContentTimer ); |
---|
1209 | #ifdef FACTORY_GCD_TEST |
---|
1210 | GCD=CFPrimitiveGcdUtil::gcd( F, G ); |
---|
1211 | #else |
---|
1212 | GCD=gcd( F, G ); |
---|
1213 | #endif |
---|
1214 | TIMING_END( algContentTimer ); |
---|
1215 | |
---|
1216 | FACTORY_CFAOUT( "d", GCD ); |
---|
1217 | FACTORY_GCDSTAT( "acnt:", F, G, GCD ); |
---|
1218 | |
---|
1219 | if (GCD!=1) |
---|
1220 | { |
---|
1221 | ff= convClapASingA( F/ GCD ); |
---|
1222 | gg= convClapASingA( G/ GCD ); |
---|
1223 | } |
---|
1224 | } |
---|
1225 | else |
---|
1226 | { |
---|
1227 | CanonicalForm F( convSingTrClapP( f ) ), G( convSingTrClapP( g ) ); |
---|
1228 | CanonicalForm GCD; |
---|
1229 | |
---|
1230 | TIMING_START( algContentTimer ); |
---|
1231 | #ifdef FACTORY_GCD_TEST |
---|
1232 | GCD=CFPrimitiveGcdUtil::gcd( F, G ); |
---|
1233 | #else |
---|
1234 | GCD=gcd( F, G ); |
---|
1235 | #endif |
---|
1236 | TIMING_END( algContentTimer ); |
---|
1237 | |
---|
1238 | FACTORY_CFTROUT( "d", GCD ); |
---|
1239 | FACTORY_GCDSTAT( "acnt:", F, G, GCD ); |
---|
1240 | |
---|
1241 | if (GCD!=1) |
---|
1242 | { |
---|
1243 | ff= convClapPSingTr( F/ GCD ); |
---|
1244 | gg= convClapPSingTr( G/ GCD ); |
---|
1245 | } |
---|
1246 | } |
---|
1247 | |
---|
1248 | Off(SW_RATIONAL); |
---|
1249 | } |
---|
1250 | #endif |
---|