1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | /**************************************** |
---|
3 | * Computer Algebra System SINGULAR * |
---|
4 | ****************************************/ |
---|
5 | // $Id: clapsing.cc,v 1.10 1997-07-04 13:46:43 Singular Exp $ |
---|
6 | /* |
---|
7 | * ABSTRACT: interface between Singular and factory |
---|
8 | */ |
---|
9 | |
---|
10 | |
---|
11 | #include "mod2.h" |
---|
12 | #ifdef HAVE_FACTORY |
---|
13 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
14 | #include "tok.h" |
---|
15 | #include "clapsing.h" |
---|
16 | #include "ipid.h" |
---|
17 | #include "numbers.h" |
---|
18 | #include "subexpr.h" |
---|
19 | #include "ipshell.h" |
---|
20 | #include <factory.h> |
---|
21 | #include "clapconv.h" |
---|
22 | #ifdef HAVE_LIBFAC_P |
---|
23 | #include <factor.h> |
---|
24 | #endif |
---|
25 | |
---|
26 | poly singclap_gcd ( poly f, poly g ) |
---|
27 | { |
---|
28 | // for now there is only the possibility to handle polynomials over |
---|
29 | // Q and Fp ... |
---|
30 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
31 | { |
---|
32 | setCharacteristic( nGetChar() ); |
---|
33 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
34 | poly res=convClapPSingP( gcd( F, G ) ); |
---|
35 | Off(SW_RATIONAL); |
---|
36 | return res; |
---|
37 | } |
---|
38 | // and over Q(a) / Fp(a) |
---|
39 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
40 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
41 | { |
---|
42 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
43 | else setCharacteristic( -nGetChar() ); |
---|
44 | poly res; |
---|
45 | if (currRing->minpoly!=NULL) |
---|
46 | { |
---|
47 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
48 | Variable a=rootOf(mipo); |
---|
49 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
50 | res= convClapAPSingAP( gcd( F, G ) ); |
---|
51 | } |
---|
52 | else |
---|
53 | { |
---|
54 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
55 | res= convClapPSingTrP( gcd( F, G ) ); |
---|
56 | } |
---|
57 | Off(SW_RATIONAL); |
---|
58 | return res; |
---|
59 | } |
---|
60 | else |
---|
61 | WerrorS( "not implemented" ); |
---|
62 | return NULL; |
---|
63 | } |
---|
64 | |
---|
65 | //poly singclap_resultant ( poly f, poly g , poly x) |
---|
66 | //{ |
---|
67 | // int i=pIsPurePower(x); |
---|
68 | // if (i==0) |
---|
69 | // { |
---|
70 | // WerrorS("3rd argument must be a ring variable"); |
---|
71 | // return NULL; |
---|
72 | // } |
---|
73 | // Variable X(i); |
---|
74 | // // for now there is only the possibility to handle polynomials over |
---|
75 | // // Q and Fp ... |
---|
76 | // if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
77 | // { |
---|
78 | // setCharacteristic( nGetChar() ); |
---|
79 | // CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
80 | // poly res=convClapPSingP( resultant( F, G, X ) ); |
---|
81 | // Off(SW_RATIONAL); |
---|
82 | // return res; |
---|
83 | // } |
---|
84 | // // and over Q(a) / Fp(a) |
---|
85 | // else if (( nGetChar()==1 ) /* Q(a) */ |
---|
86 | // || (nGetChar() <-1)) /* Fp(a) */ |
---|
87 | // { |
---|
88 | // if (nGetChar()==1) setCharacteristic( 0 ); |
---|
89 | // else setCharacteristic( -nGetChar() ); |
---|
90 | // poly res; |
---|
91 | // if (currRing->minpoly!=NULL) |
---|
92 | // { |
---|
93 | // CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
94 | // Variable a=rootOf(mipo); |
---|
95 | // CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
96 | // res= convClapAPSingAP( resultant( F, G, X ) ); |
---|
97 | // } |
---|
98 | // else |
---|
99 | // { |
---|
100 | // CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
101 | // res= convClapPSingTrP( resultant( F, G, X ) ); |
---|
102 | // } |
---|
103 | // Off(SW_RATIONAL); |
---|
104 | // return res; |
---|
105 | // } |
---|
106 | // else |
---|
107 | // WerrorS( "not implemented" ); |
---|
108 | // return NULL; |
---|
109 | //} |
---|
110 | poly singclap_resultant ( poly f, poly g , poly x) |
---|
111 | { |
---|
112 | int i=pVar(x); |
---|
113 | if (i==0) |
---|
114 | { |
---|
115 | WerrorS("ringvar expected"); |
---|
116 | return NULL; |
---|
117 | } |
---|
118 | ideal I=idInit(1,1); |
---|
119 | |
---|
120 | // get the coeffs von f wrt. x: |
---|
121 | I->m[0]=pCopy(f); |
---|
122 | matrix ffi=mpCoeffs(I,i); |
---|
123 | ffi->rank=1; |
---|
124 | ffi->ncols=ffi->nrows; |
---|
125 | ffi->nrows=1; |
---|
126 | ideal fi=(ideal)ffi; |
---|
127 | |
---|
128 | // get the coeffs von g wrt. x: |
---|
129 | I->m[0]=pCopy(g); |
---|
130 | matrix ggi=mpCoeffs(I,i); |
---|
131 | ggi->rank=1; |
---|
132 | ggi->ncols=ggi->nrows; |
---|
133 | ggi->nrows=1; |
---|
134 | ideal gi=(ideal)ggi; |
---|
135 | |
---|
136 | // contruct the matrix: |
---|
137 | int fn=IDELEMS(fi); //= deg(f,x)+1 |
---|
138 | int gn=IDELEMS(gi); //= deg(g,x)+1 |
---|
139 | matrix m=mpNew(fn+gn-2,fn+gn-2); |
---|
140 | if(m==NULL) |
---|
141 | { |
---|
142 | return NULL; |
---|
143 | } |
---|
144 | |
---|
145 | // enter the coeffs into m: |
---|
146 | int j; |
---|
147 | for(i=0;i<gn-1;i++) |
---|
148 | { |
---|
149 | for(j=0;j<fn;j++) |
---|
150 | { |
---|
151 | MATELEM(m,i+1,fn-j+i)=pCopy(fi->m[j]); |
---|
152 | } |
---|
153 | } |
---|
154 | for(i=0;i<fn-1;i++) |
---|
155 | { |
---|
156 | for(j=0;j<gn;j++) |
---|
157 | { |
---|
158 | MATELEM(m,gn+i,gn-j+i)=pCopy(gi->m[j]); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | poly r=mpDet(m); |
---|
163 | |
---|
164 | idDelete(&fi); |
---|
165 | idDelete(&gi); |
---|
166 | idDelete((ideal *)&m); |
---|
167 | return r; |
---|
168 | } |
---|
169 | |
---|
170 | lists singclap_extgcd ( poly f, poly g ) |
---|
171 | { |
---|
172 | // for now there is only the possibility to handle univariate |
---|
173 | // polynomials over |
---|
174 | // Q and Fp ... |
---|
175 | poly res=NULL,pa=NULL,pb=NULL; |
---|
176 | On(SW_SYMMETRIC_FF); |
---|
177 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
178 | { |
---|
179 | setCharacteristic( nGetChar() ); |
---|
180 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
181 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
182 | { |
---|
183 | Off(SW_RATIONAL); |
---|
184 | WerrorS("not univariate"); |
---|
185 | return NULL; |
---|
186 | } |
---|
187 | CanonicalForm Fa,Gb; |
---|
188 | res=convClapPSingP( extgcd( F, G, Fa, Gb ) ); |
---|
189 | pa=convClapPSingP(Fa); |
---|
190 | pb=convClapPSingP(Gb); |
---|
191 | Off(SW_RATIONAL); |
---|
192 | } |
---|
193 | // and over Q(a) / Fp(a) |
---|
194 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
195 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
196 | { |
---|
197 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
198 | else setCharacteristic( -nGetChar() ); |
---|
199 | CanonicalForm Fa,Gb; |
---|
200 | if (currRing->minpoly!=NULL) |
---|
201 | { |
---|
202 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
203 | Variable a=rootOf(mipo); |
---|
204 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
205 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
206 | { |
---|
207 | WerrorS("not univariate"); |
---|
208 | return NULL; |
---|
209 | } |
---|
210 | res= convClapAPSingAP( extgcd( F, G, Fa, Gb ) ); |
---|
211 | pa=convClapAPSingAP(Fa); |
---|
212 | pb=convClapAPSingAP(Gb); |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
217 | if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar()) |
---|
218 | { |
---|
219 | Off(SW_RATIONAL); |
---|
220 | WerrorS("not univariate"); |
---|
221 | return NULL; |
---|
222 | } |
---|
223 | res= convClapPSingTrP( extgcd( F, G, Fa, Gb ) ); |
---|
224 | pa=convClapPSingTrP(Fa); |
---|
225 | pb=convClapPSingTrP(Gb); |
---|
226 | } |
---|
227 | Off(SW_RATIONAL); |
---|
228 | } |
---|
229 | else |
---|
230 | { |
---|
231 | WerrorS( "not implemented" ); |
---|
232 | return NULL; |
---|
233 | } |
---|
234 | lists L=(lists)Alloc(sizeof(slists)); |
---|
235 | L->Init(3); |
---|
236 | L->m[0].rtyp=POLY_CMD; |
---|
237 | L->m[0].data=(void *)res; |
---|
238 | L->m[1].rtyp=POLY_CMD; |
---|
239 | L->m[1].data=(void *)pa; |
---|
240 | L->m[2].rtyp=POLY_CMD; |
---|
241 | L->m[2].data=(void *)pb; |
---|
242 | return L; |
---|
243 | } |
---|
244 | |
---|
245 | poly singclap_pdivide ( poly f, poly g ) |
---|
246 | { |
---|
247 | // for now there is only the possibility to handle polynomials over |
---|
248 | // Q and Fp ... |
---|
249 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
250 | { |
---|
251 | setCharacteristic( nGetChar() ); |
---|
252 | CanonicalForm F( convSingPClapP( f ) ), G( convSingPClapP( g ) ); |
---|
253 | return convClapPSingP( F / G ); |
---|
254 | } |
---|
255 | // and over Q(a) / Fp(a) |
---|
256 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
257 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
258 | { |
---|
259 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
260 | else setCharacteristic( -nGetChar() ); |
---|
261 | poly res; |
---|
262 | if (currRing->minpoly!=NULL) |
---|
263 | { |
---|
264 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
265 | Variable a=rootOf(mipo); |
---|
266 | CanonicalForm F( convSingAPClapAP( f,a ) ), G( convSingAPClapAP( g,a ) ); |
---|
267 | res= convClapAPSingAP( F / G ); |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | CanonicalForm F( convSingTrPClapP( f ) ), G( convSingTrPClapP( g ) ); |
---|
272 | res= convClapPSingTrP( F / G ); |
---|
273 | } |
---|
274 | Off(SW_RATIONAL); |
---|
275 | return res; |
---|
276 | } |
---|
277 | else |
---|
278 | WerrorS( "not implemented" ); |
---|
279 | return NULL; |
---|
280 | } |
---|
281 | |
---|
282 | void singclap_divide_content ( poly f ) |
---|
283 | { |
---|
284 | if ( nGetChar() == 1 ) |
---|
285 | setCharacteristic( 0 ); |
---|
286 | else if ( nGetChar() == -1 ) |
---|
287 | return; /* not implemented for R */ |
---|
288 | else if ( nGetChar() < 0 ) |
---|
289 | setCharacteristic( -nGetChar() ); |
---|
290 | else |
---|
291 | setCharacteristic( nGetChar() ); |
---|
292 | if ( f==NULL ) |
---|
293 | { |
---|
294 | return; |
---|
295 | } |
---|
296 | else if ( pNext( f ) == NULL ) |
---|
297 | { |
---|
298 | pSetCoeff( f, nInit( 1 ) ); |
---|
299 | pTest(f); |
---|
300 | return; |
---|
301 | } |
---|
302 | else |
---|
303 | { |
---|
304 | CFList L; |
---|
305 | CanonicalForm g, h; |
---|
306 | poly p = pNext(f); |
---|
307 | g = convSingTrClapP( ((lnumber)pGetCoeff(f))->z ); |
---|
308 | L.append( g ); |
---|
309 | while ( p && (g != 1) ) |
---|
310 | { |
---|
311 | h = convSingTrClapP( ((lnumber)pGetCoeff(p))->z ); |
---|
312 | p = pNext( p ); |
---|
313 | g = gcd( g, h ); |
---|
314 | L.append( h ); |
---|
315 | } |
---|
316 | if ( g == 1 ) |
---|
317 | { |
---|
318 | pTest(f); |
---|
319 | return; |
---|
320 | } |
---|
321 | else |
---|
322 | { |
---|
323 | CFListIterator i; |
---|
324 | for ( i = L, p = f; i.hasItem(); i++, p=pNext(p) ) |
---|
325 | { |
---|
326 | lnumber c=(lnumber)pGetCoeff(p); |
---|
327 | napDelete(&c->z); |
---|
328 | c->z=convClapPSingTr( i.getItem() / g ); |
---|
329 | } |
---|
330 | } |
---|
331 | pTest(f); |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | ideal singclap_factorize ( poly f, intvec ** v , int with_exps) |
---|
336 | { |
---|
337 | // with_exps: 1 return only true factors |
---|
338 | // 2 return true factors and exponents |
---|
339 | // 0 return factors and exponents |
---|
340 | |
---|
341 | ideal res=NULL; |
---|
342 | if (f==NULL) |
---|
343 | { |
---|
344 | res=idInit(1,1); |
---|
345 | if (with_exps!=1) |
---|
346 | { |
---|
347 | (*v)=new intvec(1); |
---|
348 | } |
---|
349 | return res; |
---|
350 | } |
---|
351 | Off(SW_RATIONAL); |
---|
352 | On(SW_SYMMETRIC_FF); |
---|
353 | CFFList L; |
---|
354 | number N=NULL; |
---|
355 | |
---|
356 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
357 | { |
---|
358 | setCharacteristic( nGetChar() ); |
---|
359 | if (nGetChar()==0) /* Q */ |
---|
360 | { |
---|
361 | if (f!=NULL) |
---|
362 | { |
---|
363 | if (with_exps==0) |
---|
364 | N=nCopy(pGetCoeff(f)); |
---|
365 | pCleardenom(f); |
---|
366 | if (with_exps==0) |
---|
367 | { |
---|
368 | number nn=nDiv(N,pGetCoeff(f)); |
---|
369 | nDelete(&N); |
---|
370 | N=nn; |
---|
371 | } |
---|
372 | } |
---|
373 | } |
---|
374 | CanonicalForm F( convSingPClapP( f ) ); |
---|
375 | if (nGetChar()==0) /* Q */ |
---|
376 | { |
---|
377 | L = factorize( F ); |
---|
378 | } |
---|
379 | else /* Fp */ |
---|
380 | { |
---|
381 | #ifdef HAVE_LIBFAC_P |
---|
382 | L = Factorize( F ); |
---|
383 | #else |
---|
384 | return NULL; |
---|
385 | #endif |
---|
386 | } |
---|
387 | } |
---|
388 | // and over Q(a) / Fp(a) |
---|
389 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
390 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
391 | { |
---|
392 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
393 | else setCharacteristic( -nGetChar() ); |
---|
394 | if (currRing->minpoly!=NULL) |
---|
395 | { |
---|
396 | //if (nGetChar()==1) |
---|
397 | //{ |
---|
398 | // WerrorS("not implemented"); |
---|
399 | // return NULL; |
---|
400 | //} |
---|
401 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
402 | Variable a=rootOf(mipo); |
---|
403 | CanonicalForm F( convSingAPClapAP( f,a ) ); |
---|
404 | L = factorize( F, a ); |
---|
405 | } |
---|
406 | else |
---|
407 | { |
---|
408 | CanonicalForm F( convSingTrPClapP( f ) ); |
---|
409 | if (nGetChar()==1) /* Q(a) */ |
---|
410 | { |
---|
411 | L = factorize( F ); |
---|
412 | } |
---|
413 | else /* Fp(a) */ |
---|
414 | { |
---|
415 | #ifdef HAVE_LIBFAC_P |
---|
416 | L = Factorize( F ); |
---|
417 | #else |
---|
418 | return NULL; |
---|
419 | #endif |
---|
420 | } |
---|
421 | } |
---|
422 | } |
---|
423 | else |
---|
424 | { |
---|
425 | WerrorS( "not implemented" ); |
---|
426 | goto end; |
---|
427 | } |
---|
428 | { |
---|
429 | // the first factor should be a constant |
---|
430 | if ( getNumVars(L.getFirst().factor()) != 0 ) |
---|
431 | L.insert(CFFactor(1,1)); |
---|
432 | // convert into ideal |
---|
433 | int n = L.length(); |
---|
434 | CFFListIterator J=L; |
---|
435 | int j=0; |
---|
436 | if (with_exps!=1) |
---|
437 | { |
---|
438 | if ((with_exps==2)&&(n>1)) |
---|
439 | { |
---|
440 | n--; |
---|
441 | J++; |
---|
442 | } |
---|
443 | *v = new intvec( n ); |
---|
444 | } |
---|
445 | res = idInit( n ,1); |
---|
446 | for ( ; J.hasItem(); J++, j++ ) |
---|
447 | { |
---|
448 | if (with_exps!=1) (**v)[j] = J.getItem().exp(); |
---|
449 | if ((nGetChar()==0)||(nGetChar()>1)) /* Q, Fp */ |
---|
450 | res->m[j] = convClapPSingP( J.getItem().factor() ); |
---|
451 | else if ((nGetChar()==1)||(nGetChar()<-1)) /* Q(a), Fp(a) */ |
---|
452 | { |
---|
453 | if (currRing->minpoly==NULL) |
---|
454 | res->m[j] = convClapPSingTrP( J.getItem().factor() ); |
---|
455 | else |
---|
456 | res->m[j] = convClapAPSingAP( J.getItem().factor() ); |
---|
457 | } |
---|
458 | } |
---|
459 | if (N!=NULL) |
---|
460 | { |
---|
461 | pMultN(res->m[0],N); |
---|
462 | nDelete(&N); |
---|
463 | } |
---|
464 | // delete constants |
---|
465 | if ((with_exps!=0) && (res!=NULL)) |
---|
466 | { |
---|
467 | int i=IDELEMS(res)-1; |
---|
468 | for(;i>=0;i--) |
---|
469 | { |
---|
470 | if (pIsConstant(res->m[i])) |
---|
471 | pDelete(&(res->m[i])); |
---|
472 | } |
---|
473 | idSkipZeroes(res); |
---|
474 | if (res->m[0]==NULL) |
---|
475 | { |
---|
476 | res->m[0]=pOne(); |
---|
477 | } |
---|
478 | } |
---|
479 | } |
---|
480 | end: |
---|
481 | return res; |
---|
482 | } |
---|
483 | |
---|
484 | matrix singclap_irrCharSeries ( ideal I) |
---|
485 | { |
---|
486 | #ifdef HAVE_LIBFAC_P |
---|
487 | // for now there is only the possibility to handle polynomials over |
---|
488 | // Q and Fp ... |
---|
489 | matrix res=NULL; |
---|
490 | int i; |
---|
491 | Off(SW_RATIONAL); |
---|
492 | On(SW_SYMMETRIC_FF); |
---|
493 | CFList L; |
---|
494 | ListCFList LL; |
---|
495 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
496 | { |
---|
497 | setCharacteristic( nGetChar() ); |
---|
498 | for(i=0;i<IDELEMS(I);i++) |
---|
499 | { |
---|
500 | L.append(convSingPClapP(I->m[i])); |
---|
501 | } |
---|
502 | } |
---|
503 | // and over Q(a) / Fp(a) |
---|
504 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
505 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
506 | { |
---|
507 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
508 | else setCharacteristic( -nGetChar() ); |
---|
509 | for(i=0;i<IDELEMS(I);i++) |
---|
510 | { |
---|
511 | L.append(convSingTrPClapP(I->m[i])); |
---|
512 | } |
---|
513 | } |
---|
514 | else |
---|
515 | { |
---|
516 | WerrorS("not implemented"); |
---|
517 | return res; |
---|
518 | } |
---|
519 | |
---|
520 | LL=IrrCharSeries(L); |
---|
521 | int m= LL.length(); // Anzahl Zeilen |
---|
522 | int n=0; |
---|
523 | ListIterator<CFList> LLi; |
---|
524 | CFListIterator Li; |
---|
525 | for ( LLi = LL; LLi.hasItem(); LLi++ ) |
---|
526 | { |
---|
527 | n = max(LLi.getItem().length(),n); |
---|
528 | } |
---|
529 | res=mpNew(m,n); |
---|
530 | if ((m==0) || (n==0)) |
---|
531 | { |
---|
532 | Warn("char_series returns %d x %d matrix from %d input polys (%d)\n",m,n,IDELEMS(I)+1,LL.length()); |
---|
533 | iiWriteMatrix((matrix)I,"I",2,0); |
---|
534 | } |
---|
535 | for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ ) |
---|
536 | { |
---|
537 | for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++) |
---|
538 | { |
---|
539 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
540 | MATELEM(res,m,n)=convClapPSingP(Li.getItem()); |
---|
541 | else |
---|
542 | MATELEM(res,m,n)=convClapPSingTrP(Li.getItem()); |
---|
543 | } |
---|
544 | } |
---|
545 | Off(SW_RATIONAL); |
---|
546 | return res; |
---|
547 | #else |
---|
548 | return NULL; |
---|
549 | #endif |
---|
550 | } |
---|
551 | |
---|
552 | char* singclap_neworder ( ideal I) |
---|
553 | { |
---|
554 | #ifdef HAVE_LIBFAC_P |
---|
555 | int i; |
---|
556 | Off(SW_RATIONAL); |
---|
557 | On(SW_SYMMETRIC_FF); |
---|
558 | CFList L; |
---|
559 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
560 | { |
---|
561 | setCharacteristic( nGetChar() ); |
---|
562 | for(i=0;i<IDELEMS(I);i++) |
---|
563 | { |
---|
564 | L.append(convSingPClapP(I->m[i])); |
---|
565 | } |
---|
566 | } |
---|
567 | // and over Q(a) / Fp(a) |
---|
568 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
569 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
570 | { |
---|
571 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
572 | else setCharacteristic( -nGetChar() ); |
---|
573 | for(i=0;i<IDELEMS(I);i++) |
---|
574 | { |
---|
575 | L.append(convSingTrPClapP(I->m[i])); |
---|
576 | } |
---|
577 | } |
---|
578 | else |
---|
579 | { |
---|
580 | WerrorS("not implemented"); |
---|
581 | return NULL; |
---|
582 | } |
---|
583 | |
---|
584 | List<int> IL=neworderint(L); |
---|
585 | ListIterator<int> Li; |
---|
586 | StringSet(""); |
---|
587 | Li = IL; |
---|
588 | int* mark=(int*)Alloc0(pVariables*sizeof(int)); |
---|
589 | int cnt=pVariables; |
---|
590 | loop |
---|
591 | { |
---|
592 | i=Li.getItem()-1; |
---|
593 | mark[i]=1; |
---|
594 | StringAppend(currRing->names[i]); |
---|
595 | Li++; |
---|
596 | cnt--; |
---|
597 | if(cnt==0) break; |
---|
598 | StringAppend(","); |
---|
599 | if(! Li.hasItem()) break; |
---|
600 | } |
---|
601 | for(i=0;i<pVariables;i++) |
---|
602 | { |
---|
603 | if(mark[i]==0) |
---|
604 | { |
---|
605 | StringAppend(currRing->names[i]); |
---|
606 | cnt--; |
---|
607 | if(cnt==0) break; |
---|
608 | StringAppend(","); |
---|
609 | } |
---|
610 | } |
---|
611 | return mstrdup(StringAppend("")); |
---|
612 | #else |
---|
613 | return NULL; |
---|
614 | #endif |
---|
615 | } |
---|
616 | |
---|
617 | BOOLEAN singclap_isSqrFree(poly f) |
---|
618 | { |
---|
619 | BOOLEAN b=FALSE; |
---|
620 | Off(SW_RATIONAL); |
---|
621 | // Q / Fp |
---|
622 | if ( (nGetChar() == 0) || (nGetChar() > 1) ) |
---|
623 | { |
---|
624 | setCharacteristic( nGetChar() ); |
---|
625 | CanonicalForm F( convSingPClapP( f ) ); |
---|
626 | if((nGetChar()>1)&&(!F.isUnivariate())) |
---|
627 | goto err; |
---|
628 | b=(BOOLEAN)isSqrFree(F); |
---|
629 | } |
---|
630 | // and over Q(a) / Fp(a) |
---|
631 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
632 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
633 | { |
---|
634 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
635 | else setCharacteristic( -nGetChar() ); |
---|
636 | //if (currRing->minpoly!=NULL) |
---|
637 | //{ |
---|
638 | // CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
639 | // Variable a=rootOf(mipo); |
---|
640 | // CanonicalForm F( convSingAPClapAP( f,a ) ); |
---|
641 | // ... |
---|
642 | //} |
---|
643 | //else |
---|
644 | { |
---|
645 | CanonicalForm F( convSingTrPClapP( f ) ); |
---|
646 | b=(BOOLEAN)isSqrFree(F); |
---|
647 | } |
---|
648 | Off(SW_RATIONAL); |
---|
649 | } |
---|
650 | else |
---|
651 | { |
---|
652 | err: |
---|
653 | WerrorS( "not implemented" ); |
---|
654 | } |
---|
655 | return b; |
---|
656 | } |
---|
657 | |
---|
658 | poly singclap_det( const matrix m ) |
---|
659 | { |
---|
660 | int r=m->rows(); |
---|
661 | if (r!=m->cols()) |
---|
662 | { |
---|
663 | Werror("det of %d x %d matrix",r,m->cols()); |
---|
664 | return NULL; |
---|
665 | } |
---|
666 | poly res=NULL; |
---|
667 | if ( nGetChar() == 0 || nGetChar() > 1 ) |
---|
668 | { |
---|
669 | setCharacteristic( nGetChar() ); |
---|
670 | CFMatrix M(r,r); |
---|
671 | int i,j; |
---|
672 | for(i=1;i<=r;i++) |
---|
673 | { |
---|
674 | for(j=1;j<=r;j++) |
---|
675 | { |
---|
676 | M(i,j)=convSingPClapP(MATELEM(m,i,j)); |
---|
677 | } |
---|
678 | } |
---|
679 | res= convClapPSingP( determinant(M,r) ) ; |
---|
680 | } |
---|
681 | // and over Q(a) / Fp(a) |
---|
682 | else if (( nGetChar()==1 ) /* Q(a) */ |
---|
683 | || (nGetChar() <-1)) /* Fp(a) */ |
---|
684 | { |
---|
685 | if (nGetChar()==1) setCharacteristic( 0 ); |
---|
686 | else setCharacteristic( -nGetChar() ); |
---|
687 | CFMatrix M(r,r); |
---|
688 | poly res; |
---|
689 | if (currRing->minpoly!=NULL) |
---|
690 | { |
---|
691 | CanonicalForm mipo=convSingTrClapP(((lnumber)currRing->minpoly)->z); |
---|
692 | Variable a=rootOf(mipo); |
---|
693 | int i,j; |
---|
694 | for(i=1;i<=r;i++) |
---|
695 | { |
---|
696 | for(j=1;j<=r;j++) |
---|
697 | { |
---|
698 | M(i,j)=convSingAPClapAP(MATELEM(m,i,j),a); |
---|
699 | } |
---|
700 | } |
---|
701 | res= convClapAPSingAP( determinant(M,r) ) ; |
---|
702 | } |
---|
703 | else |
---|
704 | { |
---|
705 | int i,j; |
---|
706 | for(i=1;i<=r;i++) |
---|
707 | { |
---|
708 | for(j=1;j<=r;j++) |
---|
709 | { |
---|
710 | M(i,j)=convSingTrPClapP(MATELEM(m,i,j)); |
---|
711 | } |
---|
712 | } |
---|
713 | res= convClapPSingTrP( determinant(M,r) ); |
---|
714 | } |
---|
715 | } |
---|
716 | else |
---|
717 | WerrorS( "not implemented" ); |
---|
718 | Off(SW_RATIONAL); |
---|
719 | return res; |
---|
720 | } |
---|
721 | |
---|
722 | int singclap_det_i( intvec * m ) |
---|
723 | { |
---|
724 | setCharacteristic( 0 ); |
---|
725 | CFMatrix M(m->rows(),m->cols()); |
---|
726 | int i,j; |
---|
727 | for(i=1;i<=m->rows();i++) |
---|
728 | { |
---|
729 | for(j=1;j<=m->cols();j++) |
---|
730 | { |
---|
731 | M(i,j)=IMATELEM(*m,i,j); |
---|
732 | } |
---|
733 | } |
---|
734 | int res= convClapISingI( determinant(M,m->rows())) ; |
---|
735 | Off(SW_RATIONAL); |
---|
736 | return res; |
---|
737 | } |
---|
738 | /*==============================================================*/ |
---|
739 | /* interpreter interface : */ |
---|
740 | BOOLEAN jjGCD_P(leftv res, leftv u, leftv v) |
---|
741 | { |
---|
742 | res->data=(void *)singclap_gcd((poly)(u->Data()),((poly)v->Data())); |
---|
743 | return FALSE; |
---|
744 | } |
---|
745 | |
---|
746 | BOOLEAN jjFAC_P(leftv res, leftv u) |
---|
747 | { |
---|
748 | intvec *v=NULL; |
---|
749 | ideal f=singclap_factorize((poly)(u->Data()), &v, 0); |
---|
750 | #ifndef HAVE_LIBFAC_P |
---|
751 | if (f==NULL) return TRUE; |
---|
752 | #endif |
---|
753 | lists l=(lists)Alloc(sizeof(slists)); |
---|
754 | l->Init(2); |
---|
755 | l->m[0].rtyp=IDEAL_CMD; |
---|
756 | l->m[0].data=(void *)f; |
---|
757 | l->m[1].rtyp=INTVEC_CMD; |
---|
758 | l->m[1].data=(void *)v; |
---|
759 | res->data=(void *)l; |
---|
760 | return FALSE; |
---|
761 | } |
---|
762 | |
---|
763 | BOOLEAN jjSQR_FREE_DEC(leftv res, leftv u,leftv dummy) |
---|
764 | { |
---|
765 | intvec *v=NULL; |
---|
766 | int sw=(int)dummy->Data(); |
---|
767 | ideal f=singclap_factorize((poly)(u->Data()), &v, sw); |
---|
768 | switch(sw) |
---|
769 | { |
---|
770 | case 0: |
---|
771 | case 2: |
---|
772 | { |
---|
773 | lists l=(lists)Alloc(sizeof(slists)); |
---|
774 | l->Init(2); |
---|
775 | l->m[0].rtyp=IDEAL_CMD; |
---|
776 | l->m[0].data=(void *)f; |
---|
777 | l->m[1].rtyp=INTVEC_CMD; |
---|
778 | l->m[1].data=(void *)v; |
---|
779 | res->data=(void *)l; |
---|
780 | res->rtyp=LIST_CMD; |
---|
781 | return FALSE; |
---|
782 | } |
---|
783 | case 1: |
---|
784 | res->data=(void *)f; |
---|
785 | return f==NULL; |
---|
786 | } |
---|
787 | WerrorS("invalid switch"); |
---|
788 | return TRUE; |
---|
789 | } |
---|
790 | |
---|
791 | #if 0 |
---|
792 | BOOLEAN jjIS_SQR_FREE(leftv res, leftv u) |
---|
793 | { |
---|
794 | BOOLEAN b=singclap_factorize((poly)(u->Data()), &v, 0); |
---|
795 | res->data=(void *)b; |
---|
796 | } |
---|
797 | #endif |
---|
798 | |
---|
799 | BOOLEAN jjEXTGCD_P(leftv res, leftv u, leftv v) |
---|
800 | { |
---|
801 | res->data=singclap_extgcd((poly)u->Data(),(poly)v->Data()); |
---|
802 | return (res->data==NULL); |
---|
803 | } |
---|
804 | BOOLEAN jjRESULTANT(leftv res, leftv u, leftv v, leftv w) |
---|
805 | { |
---|
806 | res->data=singclap_resultant((poly)u->Data(),(poly)v->Data(), (poly)w->Data()); |
---|
807 | return (res->data==NULL); |
---|
808 | } |
---|
809 | BOOLEAN jjCHARSERIES(leftv res, leftv u) |
---|
810 | { |
---|
811 | res->data=singclap_irrCharSeries((ideal)u->Data()); |
---|
812 | return (res->data==NULL); |
---|
813 | } |
---|
814 | #endif |
---|