My Project  debian-1:4.1.2-p1+ds-2
clapsing.cc
Go to the documentation of this file.
1 // emacs edit mode for this file is -*- C++ -*-
2 /****************************************
3 * Computer Algebra System SINGULAR *
4 ****************************************/
5 /*
6 * ABSTRACT: interface between Singular and factory
7 */
8 
9 //#define FACTORIZE2_DEBUG
10 
11 #include "misc/auxiliary.h"
12 #include "clapsing.h"
13 
14 #include "factory/factory.h"
15 
16 #include "coeffs/numbers.h"
17 #include "coeffs/coeffs.h"
18 #include "coeffs/bigintmat.h"
19 
20 #include "monomials/ring.h"
21 #include "simpleideals.h"
22 
23 
24 //#include "polys.h"
25 #define TRANSEXT_PRIVATES
26 
27 #include "ext_fields/transext.h"
28 
29 
30 #include "clapconv.h"
31 
33 #include "polys/monomials/ring.h"
34 #include "polys/simpleideals.h"
35 #include "misc/intvec.h"
36 #include "polys/matpol.h"
37 #include "coeffs/bigintmat.h"
38 
39 
40 void out_cf(const char *s1,const CanonicalForm &f,const char *s2);
41 
42 poly singclap_gcd_r ( poly f, poly g, const ring r )
43 {
44  poly res=NULL;
45 
46  assume(f!=NULL);
47  assume(g!=NULL);
48 
49  if(pNext(f)==NULL)
50  {
51  return p_GcdMon(f,g,r);
52  }
53  else if(pNext(g)==NULL)
54  {
55  return p_GcdMon(g,f,r);
56  }
57 
59  if (rField_is_Q(r) || rField_is_Zp(r) || rField_is_Z(r)
60  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
61  {
64  res=convFactoryPSingP( gcd( F, G ) , r);
65  }
66  // and over Q(a) / Fp(a)
67  else if ( r->cf->extRing!=NULL )
68  {
69  if ( rField_is_Q_a(r)) setCharacteristic( 0 );
70  else setCharacteristic( rChar(r) );
71  if (r->cf->extRing->qideal!=NULL)
72  {
73  bool b1=isOn(SW_USE_QGCD);
74  if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
75  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
76  r->cf->extRing);
77  Variable a=rootOf(mipo);
79  G( convSingAPFactoryAP( g,a,r ) );
80  res= convFactoryAPSingAP( gcd( F, G ),r );
81  prune (a);
82  if (!b1) Off(SW_USE_QGCD);
83  }
84  else
85  {
86  convSingTrP(f,r);
87  convSingTrP(g,r);
89  res= convFactoryPSingTrP( gcd( F, G ),r );
90  }
91  }
92  else if (r->cf->convSingNFactoryN==ndConvSingNFactoryN)
94  else
95  { // handle user type coeffs:
98  res=convFactoryPSingP( gcd( F, G ) , r);
99  }
100  Off(SW_RATIONAL);
101  return res;
102 }
103 
104 poly singclap_gcd_and_divide ( poly& f, poly& g, const ring r)
105 {
106  poly res=NULL;
107 
108  if (g == NULL)
109  {
110  res= f;
111  f=p_One (r);
112  return res;
113  }
114  if (f==NULL)
115  {
116  res= g;
117  g=p_One (r);
118  return res;
119  }
120  if (pNext(g)==NULL)
121  {
122  poly G=p_GcdMon(g,f,r);
123  if (!n_IsOne(pGetCoeff(G),r->cf)
124  || (!p_IsConstant(G,r)))
125  {
126  f=p_Div_mm(f,G,r);
127  g=p_Div_mm(g,G,r);
128  }
129  return G;
130  }
131  else if (pNext(f)==NULL)
132  {
133  poly G=p_GcdMon(f,g,r);
134  if (!n_IsOne(pGetCoeff(G),r->cf)
135  || (!p_IsConstant(G,r)))
136  {
137  f=p_Div_mm(f,G,r);
138  g=p_Div_mm(g,G,r);
139  }
140  return G;
141  }
142 
143  Off(SW_RATIONAL);
144  CanonicalForm F,G,GCD;
145  if (rField_is_Q(r) || (rField_is_Zp(r))
146  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
147  {
148  bool b1=isOn(SW_USE_EZGCD_P);
149  setCharacteristic( rChar(r) );
150  F=convSingPFactoryP( f,r );
151  G=convSingPFactoryP( g,r );
152  GCD=gcd(F,G);
153  if (!GCD.isOne())
154  {
155  p_Delete(&f,r);
156  p_Delete(&g,r);
157  if (getCharacteristic() == 0)
158  On (SW_RATIONAL);
159  F /= GCD;
160  G /= GCD;
161  if (getCharacteristic() == 0)
162  {
163  CanonicalForm denF= bCommonDen (F);
164  CanonicalForm denG= bCommonDen (G);
165  G *= denG;
166  F *= denF;
167  Off (SW_RATIONAL);
168  CanonicalForm gcddenFdenG= gcd (denG, denF);
169  denG /= gcddenFdenG;
170  denF /= gcddenFdenG;
171  On (SW_RATIONAL);
172  G *= denF;
173  F *= denG;
174  }
175  f=convFactoryPSingP( F, r);
176  g=convFactoryPSingP( G, r);
177  }
178  res=convFactoryPSingP( GCD , r);
179  if (!b1) Off (SW_USE_EZGCD_P);
180  }
181  // and over Q(a) / Fp(a)
182  else if ( r->cf->extRing )
183  {
184  if ( rField_is_Q_a(r)) setCharacteristic( 0 );
185  else setCharacteristic( rChar(r) );
186  if (r->cf->extRing->qideal!=NULL)
187  {
188  bool b1=isOn(SW_USE_QGCD);
189  if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
190  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
191  r->cf->extRing);
192  Variable a=rootOf(mipo);
193  F=( convSingAPFactoryAP( f,a,r ) );
194  G=( convSingAPFactoryAP( g,a,r ) );
195  GCD=gcd(F,G);
196  if (!GCD.isOne())
197  {
198  p_Delete(&f,r);
199  p_Delete(&g,r);
200  if (getCharacteristic() == 0)
201  On (SW_RATIONAL);
202  F /= GCD;
203  G /= GCD;
204  if (getCharacteristic() == 0)
205  {
206  CanonicalForm denF= bCommonDen (F);
207  CanonicalForm denG= bCommonDen (G);
208  G *= denG;
209  F *= denF;
210  Off (SW_RATIONAL);
211  CanonicalForm gcddenFdenG= gcd (denG, denF);
212  denG /= gcddenFdenG;
213  denF /= gcddenFdenG;
214  On (SW_RATIONAL);
215  G *= denF;
216  F *= denG;
217  }
218  f= convFactoryAPSingAP( F,r );
219  g= convFactoryAPSingAP( G,r );
220  }
221  res= convFactoryAPSingAP( GCD,r );
222  prune (a);
223  if (!b1) Off(SW_USE_QGCD);
224  }
225  else
226  {
227  F=( convSingTrPFactoryP( f,r ) );
228  G=( convSingTrPFactoryP( g,r ) );
229  GCD=gcd(F,G);
230  if (!GCD.isOne())
231  {
232  p_Delete(&f,r);
233  p_Delete(&g,r);
234  if (getCharacteristic() == 0)
235  On (SW_RATIONAL);
236  F /= GCD;
237  G /= GCD;
238  if (getCharacteristic() == 0)
239  {
240  CanonicalForm denF= bCommonDen (F);
241  CanonicalForm denG= bCommonDen (G);
242  G *= denG;
243  F *= denF;
244  Off (SW_RATIONAL);
245  CanonicalForm gcddenFdenG= gcd (denG, denF);
246  denG /= gcddenFdenG;
247  denF /= gcddenFdenG;
248  On (SW_RATIONAL);
249  G *= denF;
250  F *= denG;
251  }
252  f= convFactoryPSingTrP( F,r );
253  g= convFactoryPSingTrP( G,r );
254  }
255  res= convFactoryPSingTrP( GCD,r );
256  }
257  }
258  else
260  Off(SW_RATIONAL);
261  return res;
262 }
263 
264 /*2 find the maximal exponent of var(i) in poly p*/
265 int pGetExp_Var(poly p, int i, const ring r)
266 {
267  int m=0;
268  int mm;
269  while (p!=NULL)
270  {
271  mm=p_GetExp(p,i,r);
272  if (mm>m) m=mm;
273  pIter(p);
274  }
275  return m;
276 }
277 
278 // destroys f,g,x
279 poly singclap_resultant ( poly f, poly g , poly x, const ring r)
280 {
281  poly res=NULL;
282  int i=p_IsPurePower(x, r);
283  if (i==0)
284  {
285  WerrorS("3rd argument must be a ring variable");
286  goto resultant_returns_res;
287  }
288  if ((f==NULL) || (g==NULL))
289  goto resultant_returns_res;
290  // for now there is only the possibility to handle polynomials over
291  // Q and Fp ...
292  if (rField_is_Zp(r) || rField_is_Q(r)
293  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
294  {
295  Variable X(i);
296  setCharacteristic( rChar(r) );
298  res=convFactoryPSingP( resultant( F, G, X),r );
299  Off(SW_RATIONAL);
300  goto resultant_returns_res;
301  }
302  // and over Q(a) / Fp(a)
303  else if (r->cf->extRing!=NULL)
304  {
305  if (rField_is_Q_a(r)) setCharacteristic( 0 );
306  else setCharacteristic( rChar(r) );
307  Variable X(i+rPar(r));
308  if (r->cf->extRing->qideal!=NULL)
309  {
310  //Variable X(i);
311  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
312  r->cf->extRing);
313  Variable a=rootOf(mipo);
314  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
315  G( convSingAPFactoryAP( g,a,r ) );
316  res= convFactoryAPSingAP( resultant( F, G, X ),r );
317  prune (a);
318  }
319  else
320  {
321  //Variable X(i+rPar(currRing));
322  number nf,ng;
324  int ef,eg;
325  ef=pGetExp_Var(f,i,r);
326  eg=pGetExp_Var(g,i,r);
328  res= convFactoryPSingTrP( resultant( F, G, X ),r );
329  if ((nf!=NULL)&&(!n_IsOne(nf,r->cf)))
330  {
331  number n=n_Invers(nf,r->cf);
332  while(eg>0)
333  {
334  res=__p_Mult_nn(res,n,r);
335  eg--;
336  }
337  n_Delete(&n,r->cf);
338  }
339  n_Delete(&nf,r->cf);
340  if ((ng!=NULL)&&(!n_IsOne(ng,r->cf)))
341  {
342  number n=n_Invers(ng,r->cf);
343  while(ef>0)
344  {
345  res=__p_Mult_nn(res,n,r);
346  ef--;
347  }
348  n_Delete(&n,r->cf);
349  }
350  n_Delete(&ng,r->cf);
351  }
352  Off(SW_RATIONAL);
353  goto resultant_returns_res;
354  }
355  else
357 resultant_returns_res:
358  p_Delete(&f,r);
359  p_Delete(&g,r);
360  p_Delete(&x,r);
361  return res;
362 }
363 //poly singclap_resultant ( poly f, poly g , poly x)
364 //{
365 // int i=pVar(x);
366 // if (i==0)
367 // {
368 // WerrorS("ringvar expected");
369 // return NULL;
370 // }
371 // ideal I=idInit(1,1);
372 //
373 // // get the coeffs von f wrt. x:
374 // I->m[0]=pCopy(f);
375 // matrix ffi=mpCoeffs(I,i);
376 // ffi->rank=1;
377 // ffi->ncols=ffi->nrows;
378 // ffi->nrows=1;
379 // ideal fi=(ideal)ffi;
380 //
381 // // get the coeffs von g wrt. x:
382 // I->m[0]=pCopy(g);
383 // matrix ggi=mpCoeffs(I,i);
384 // ggi->rank=1;
385 // ggi->ncols=ggi->nrows;
386 // ggi->nrows=1;
387 // ideal gi=(ideal)ggi;
388 //
389 // // contruct the matrix:
390 // int fn=IDELEMS(fi); //= deg(f,x)+1
391 // int gn=IDELEMS(gi); //= deg(g,x)+1
392 // matrix m=mpNew(fn+gn-2,fn+gn-2);
393 // if(m==NULL)
394 // {
395 // return NULL;
396 // }
397 //
398 // // enter the coeffs into m:
399 // int j;
400 // for(i=0;i<gn-1;i++)
401 // {
402 // for(j=0;j<fn;j++)
403 // {
404 // MATELEM(m,i+1,fn-j+i)=pCopy(fi->m[j]);
405 // }
406 // }
407 // for(i=0;i<fn-1;i++)
408 // {
409 // for(j=0;j<gn;j++)
410 // {
411 // MATELEM(m,gn+i,gn-j+i)=pCopy(gi->m[j]);
412 // }
413 // }
414 //
415 // poly r=mpDet(m);
416 //
417 // idDelete(&fi);
418 // idDelete(&gi);
419 // idDelete((ideal *)&m);
420 // return r;
421 //}
422 
423 BOOLEAN singclap_extgcd ( poly f, poly g, poly &res, poly &pa, poly &pb , const ring r)
424 {
425  // for now there is only the possibility to handle univariate
426  // polynomials over
427  // Q and Fp ...
428  res=NULL;pa=NULL;pb=NULL;
430  if ( rField_is_Q(r) || rField_is_Zp(r)
431  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
432  {
433  setCharacteristic( rChar(r) );
435  CanonicalForm FpG=F+G;
436  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
437  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
438  {
439  Off(SW_RATIONAL);
440  WerrorS("not univariate");
441  return TRUE;
442  }
443  CanonicalForm Fa,Gb;
444  On(SW_RATIONAL);
445  res=convFactoryPSingP( extgcd( F, G, Fa, Gb ),r );
446  pa=convFactoryPSingP(Fa,r);
447  pb=convFactoryPSingP(Gb,r);
448  Off(SW_RATIONAL);
449  }
450  // and over Q(a) / Fp(a)
451  else if ( r->cf->extRing!=NULL )
452  {
453  if (rField_is_Q_a(r)) setCharacteristic( 0 );
454  else setCharacteristic( rChar(r) );
455  CanonicalForm Fa,Gb;
456  if (r->cf->extRing->qideal!=NULL)
457  {
458  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
459  r->cf->extRing);
460  Variable a=rootOf(mipo);
461  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
462  G( convSingAPFactoryAP( g,a,r ) );
463  CanonicalForm FpG=F+G;
464  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
465  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
466  {
467  WerrorS("not univariate");
468  return TRUE;
469  }
470  res= convFactoryAPSingAP( extgcd( F, G, Fa, Gb ),r );
471  pa=convFactoryAPSingAP(Fa,r);
472  pb=convFactoryAPSingAP(Gb,r);
473  prune (a);
474  }
475  else
476  {
478  CanonicalForm FpG=F+G;
479  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
480  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
481  {
482  Off(SW_RATIONAL);
483  WerrorS("not univariate");
484  return TRUE;
485  }
486  res= convFactoryPSingTrP( extgcd( F, G, Fa, Gb ), r );
487  pa=convFactoryPSingTrP(Fa, r);
488  pb=convFactoryPSingTrP(Gb, r);
489  }
490  Off(SW_RATIONAL);
491  }
492  else
493  {
495  return TRUE;
496  }
497 #ifndef SING_NDEBUG
498  // checking the result of extgcd:
499  poly dummy;
500  dummy=p_Sub(p_Add_q(pp_Mult_qq(f,pa,r),pp_Mult_qq(g,pb,r),r),p_Copy(res,r),r);
501  if (dummy!=NULL)
502  {
503  PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
504  PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
505  p_Delete(&dummy,r);
506  }
507 #endif
508  return FALSE;
509 }
510 
511 poly singclap_pmult ( poly f, poly g, const ring r )
512 {
513  poly res=NULL;
514  On(SW_RATIONAL);
515  if (rField_is_Zp(r) || rField_is_Q(r) || rField_is_Z(r)
516  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
517  {
518  if (rField_is_Z(r)) Off(SW_RATIONAL);
519  setCharacteristic( rChar(r) );
521  res = convFactoryPSingP( F * G,r );
522  }
523  else if (r->cf->extRing!=NULL)
524  {
525  if (rField_is_Q_a(r)) setCharacteristic( 0 );
526  else setCharacteristic( rChar(r) );
527  if (r->cf->extRing->qideal!=NULL)
528  {
529  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
530  r->cf->extRing);
531  Variable a=rootOf(mipo);
532  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
533  G( convSingAPFactoryAP( g,a,r ) );
534  res= convFactoryAPSingAP( F * G, r );
535  prune (a);
536  }
537  else
538  {
540  res= convFactoryPSingTrP( F * G,r );
541  }
542  }
543 #if 0 // not yet working
544  else if (rField_is_GF())
545  {
546  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
547  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
548  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
549  res = convFactoryGFSingGF( F * G );
550  }
551 #endif
552  else
554  Off(SW_RATIONAL);
555  return res;
556 }
557 
558 poly singclap_pdivide ( poly f, poly g, const ring r )
559 {
560  poly res=NULL;
561  On(SW_RATIONAL);
562  if (rField_is_Zp(r) || rField_is_Q(r)
563  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
564  {
565  setCharacteristic( rChar(r) );
567  res = convFactoryPSingP( F / G,r );
568  }
569  // div is not implemented for ZZ coeffs in factory
570  else if (r->cf->extRing!=NULL)
571  {
572  if (rField_is_Q_a(r)) setCharacteristic( 0 );
573  else setCharacteristic( rChar(r) );
574  if (r->cf->extRing->qideal!=NULL)
575  {
576  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
577  r->cf->extRing);
578  Variable a=rootOf(mipo);
579  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
580  G( convSingAPFactoryAP( g,a,r ) );
581  res= convFactoryAPSingAP( F / G, r );
582  prune (a);
583  }
584  else
585  {
587  res= convFactoryPSingTrP( F / G,r );
588  }
589  }
590 #if 0 // not yet working
591  else if (rField_is_GF())
592  {
593  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
594  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
595  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
596  res = convFactoryGFSingGF( F / G );
597  }
598 #endif
599  else
601  Off(SW_RATIONAL);
602  return res;
603 }
604 
605 poly singclap_pmod ( poly f, poly g, const ring r )
606 {
607  poly res=NULL;
608  On(SW_RATIONAL);
609  if (rField_is_Zp(r) || rField_is_Q(r)
610  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
611  {
612  setCharacteristic( rChar(r) );
614  res = convFactoryPSingP( F-(F/G)*G,r );
615  }
616  // mod is not implemented for ZZ coeffs in factory
617  else if (r->cf->extRing!=NULL)
618  {
619  if (rField_is_Q_a(r)) setCharacteristic( 0 );
620  else setCharacteristic( rChar(r) );
621  if (r->cf->extRing->qideal!=NULL)
622  {
623  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
624  r->cf->extRing);
625  Variable a=rootOf(mipo);
626  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
627  G( convSingAPFactoryAP( g,a,r ) );
628  res= convFactoryAPSingAP( F-(F/G)*G, r );
629  prune (a);
630  }
631  else
632  {
634  res= convFactoryPSingTrP( F-(F/G)*G,r );
635  }
636  }
637 #if 0 // not yet working
638  else if (rField_is_GF())
639  {
640  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
641  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
642  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
643  res = convFactoryGFSingGF( F / G );
644  }
645 #endif
646  else
648  Off(SW_RATIONAL);
649  return res;
650 }
651 
652 #if 0
653 // unused
654 void singclap_divide_content ( poly f, const ring r )
655 {
656  if ( f==NULL )
657  {
658  return;
659  }
660  else if ( pNext( f ) == NULL )
661  {
662  p_SetCoeff( f, n_Init( 1, r->cf ), r );
663  return;
664  }
665  else
666  {
667  if ( rField_is_Q_a(r) )
668  setCharacteristic( 0 );
669  else if ( rField_is_Zp_a(r) )
670  setCharacteristic( -rChar(r) );
671  else
672  return; /* not implemented*/
673 
674  CFList L;
675  CanonicalForm g, h;
676  poly p = pNext(f);
677 
678  // first attemp: find 2 smallest g:
679 
680  number g1=pGetCoeff(f);
681  number g2=pGetCoeff(p); // p==pNext(f);
682  pIter(p);
683  int sz1=n_Size(g1, r->cf);
684  int sz2=n_Size(g2, r->cf);
685  if (sz1>sz2)
686  {
687  number gg=g1;
688  g1=g2; g2=gg;
689  int sz=sz1;
690  sz1=sz2; sz2=sz;
691  }
692  while (p!=NULL)
693  {
694  int n_sz=n_Size(pGetCoeff(p),r->cf);
695  if (n_sz<sz1)
696  {
697  sz2=sz1;
698  g2=g1;
699  g1=pGetCoeff(p);
700  sz1=n_sz;
701  if (sz1<=3) break;
702  }
703  else if(n_sz<sz2)
704  {
705  sz2=n_sz;
706  g2=pGetCoeff(p);
707  sz2=n_sz;
708  }
709  pIter(p);
710  }
711  g = convSingPFactoryP( NUM(((fraction)g1)), r->cf->extRing );
712  g = gcd( g, convSingPFactoryP( NUM(((fraction)g2)) , r->cf->extRing));
713 
714  // second run: gcd's
715 
716  p = f;
717  while ( (p != NULL) && (g != 1) && ( g != 0))
718  {
719  h = convSingPFactoryP( NUM(((fraction)pGetCoeff(p))), r->cf->extRing );
720  pIter( p );
721 
722  g = gcd( g, h );
723 
724  L.append( h );
725  }
726  if (( g == 1 ) || (g == 0))
727  {
728  // pTest(f);
729  return;
730  }
731  else
732  {
734  for ( i = L, p = f; i.hasItem(); i++, p=pNext(p) )
735  {
736  fraction c=(fraction)pGetCoeff(p);
737  p_Delete(&(NUM(c)),r->cf->extRing); // 2nd arg used to be nacRing
738  NUM(c)=convFactoryPSingP( i.getItem() / g, r->cf->extRing );
739  //nTest((number)c);
740  //#ifdef LDEBUG
741  //number cn=(number)c;
742  //StringSetS(""); nWrite(nt); StringAppend(" ==> ");
743  //nWrite(cn);PrintS(StringEndS("\n")); // NOTE/TODO: use StringAppendS("\n"); omFree(s);
744  //#endif
745  }
746  }
747  // pTest(f);
748  }
749 }
750 #endif
751 
752 BOOLEAN count_Factors(ideal I, intvec *v,int j, poly &f, poly fac, const ring r)
753 {
754  p_Test(f,r);
755  p_Test(fac,r);
756  int e=0;
757  if (!p_IsConstantPoly(fac,r))
758  {
759 #ifdef FACTORIZE2_DEBUG
760  printf("start count_Factors(%d), Fdeg=%d, factor deg=%d\n",j,p_Totaldegree(f,r),p_Totaldegree(fac,r));
761  p_wrp(fac,r);PrintLn();
762 #endif
763  On(SW_RATIONAL);
764  CanonicalForm F, FAC,Q,R;
765  Variable a;
766  if (rField_is_Zp(r) || rField_is_Q(r)
767  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
768  {
769  F=convSingPFactoryP( f,r );
770  FAC=convSingPFactoryP( fac,r );
771  }
772  else if (r->cf->extRing!=NULL)
773  {
774  if (r->cf->extRing->qideal!=NULL)
775  {
776  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
777  r->cf->extRing);
778  a=rootOf(mipo);
779  F=convSingAPFactoryAP( f,a,r );
780  FAC=convSingAPFactoryAP( fac,a,r );
781  }
782  else
783  {
784  F=convSingTrPFactoryP( f,r );
785  FAC=convSingTrPFactoryP( fac,r );
786  }
787  }
788  else
790 
791  poly q;
792  loop
793  {
794  Q=F;
795  Q/=FAC;
796  R=Q;
797  R*=FAC;
798  R-=F;
799  if (R.isZero())
800  {
801  if (rField_is_Zp(r) || rField_is_Q(r)
802  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
803  {
804  q = convFactoryPSingP( Q,r );
805  }
806  else if (r->cf->extRing!=NULL)
807  {
808  if (r->cf->extRing->qideal!=NULL)
809  {
810  q= convFactoryAPSingAP( Q,r );
811  }
812  else
813  {
814  q= convFactoryPSingTrP( Q,r );
815  }
816  }
817  e++; p_Delete(&f,r); f=q; q=NULL; F=Q;
818  }
819  else
820  {
821  break;
822  }
823  }
824  if (r->cf->extRing!=NULL)
825  if (r->cf->extRing->qideal!=NULL)
826  prune (a);
827  if (e==0)
828  {
829  Off(SW_RATIONAL);
830  return FALSE;
831  }
832  }
833  else e=1;
834  I->m[j]=fac;
835  if (v!=NULL) (*v)[j]=e;
836  Off(SW_RATIONAL);
837  return TRUE;
838 }
839 
841 
842 ideal singclap_factorize ( poly f, intvec ** v , int with_exps, const ring r)
843 /* destroys f, sets *v */
844 {
845  p_Test(f,r);
846 #ifdef FACTORIZE2_DEBUG
847  printf("singclap_factorize, degree %ld\n",p_Totaldegree(f,r));
848 #endif
849  // with_exps: 3,1 return only true factors, no exponents
850  // 2 return true factors and exponents
851  // 0 return coeff, factors and exponents
852  BOOLEAN save_errorreported=errorreported;
853 
854  ideal res=NULL;
855 
856  // handle factorize(0) =========================================
857  if (f==NULL)
858  {
859  res=idInit(1,1);
860  if (with_exps!=1)
861  {
862  (*v)=new intvec(1);
863  (**v)[0]=1;
864  }
865  return res;
866  }
867  // handle factorize(mon) =========================================
868  if (pNext(f)==NULL)
869  {
870  int i=0;
871  int n=0;
872  int e;
873  for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
874  if (with_exps==0) n++; // with coeff
875  res=idInit(si_max(n,1),1);
876  switch(with_exps)
877  {
878  case 0: // with coef & exp.
879  res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
880  // no break
881  case 2: // with exp.
882  (*v)=new intvec(si_max(1,n));
883  (**v)[0]=1;
884  // no break
885  case 1: ;
886 #ifdef TEST
887  default: ;
888 #endif
889  }
890  if (n==0)
891  {
892  if (res->m[0]==NULL) res->m[0]=p_One(r);
893  // (**v)[0]=1; is already done
894  }
895  else
896  {
897  for(i=rVar(r);i>0;i--)
898  {
899  e=p_GetExp(f,i,r);
900  if(e!=0)
901  {
902  n--;
903  poly p=p_One(r);
904  p_SetExp(p,i,1,r);
905  p_Setm(p,r);
906  res->m[n]=p;
907  if (with_exps!=1) (**v)[n]=e;
908  }
909  }
910  }
911  p_Delete(&f,r);
912  return res;
913  }
914  //PrintS("S:");p_Write(f,r);PrintLn();
915  // use factory/libfac in general ==============================
916  Variable dummy(-1); prune(dummy); // remove all (tmp.) extensions
917  Off(SW_RATIONAL);
919  CFFList L;
920  number N=NULL;
921  number NN=NULL;
922  number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
923 
924  Variable a;
925  if (!rField_is_Zp(r) && !rField_is_Zp_a(r) && !rField_is_Z(r)
926  && !(rField_is_Zn(r) && (r->cf->convSingNFactoryN!=ndConvSingNFactoryN))) /* Q, Q(a) */
927  {
928  //if (f!=NULL) // already tested at start of routine
929  {
930  number n0=n_Copy(pGetCoeff(f),r->cf);
931  if (with_exps==0)
932  N=n_Copy(n0,r->cf);
933  p_Cleardenom(f, r);
934  //after here f should not have a denominator!!
935  //PrintS("S:");p_Write(f,r);PrintLn();
936  NN=n_Div(n0,pGetCoeff(f),r->cf);
937  n_Delete(&n0,r->cf);
938  if (with_exps==0)
939  {
940  n_Delete(&N,r->cf);
941  N=n_Copy(NN,r->cf);
942  }
943  }
944  }
945  else if (rField_is_Zp_a(r))
946  {
947  //if (f!=NULL) // already tested at start of routine
949  {
950  number n0=n_Copy(pGetCoeff(f),r->cf);
951  if (with_exps==0)
952  N=n_Copy(n0,r->cf);
953  p_Norm(f,r);
954  p_Cleardenom(f, r);
955  NN=n_Div(n0,pGetCoeff(f),r->cf);
956  n_Delete(&n0,r->cf);
957  if (with_exps==0)
958  {
959  n_Delete(&N,r->cf);
960  N=n_Copy(NN,r->cf);
961  }
962  }
963  }
964  if ((rField_is_Q(r) || rField_is_Zp(r) || (rField_is_Z(r)))
965  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
966  {
967  setCharacteristic( rChar(r) );
969  L = factorize( F );
970  }
971  // and over Q(a) / Fp(a)
972  else if ((r->cf->extRing!=NULL)
973  &&(r->cf->extRing->cf->convSingNFactoryN!=ndConvSingNFactoryN))
974  {
975  if (rField_is_Q_a (r)) setCharacteristic (0);
976  else setCharacteristic( rChar(r) );
977  if (r->cf->extRing->qideal!=NULL)
978  {
979  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
980  r->cf->extRing);
981  a=rootOf(mipo);
982  CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
983  if (rField_is_Zp_a(r))
984  {
985  L = factorize( F, a );
986  }
987  else
988  {
989  // over Q(a)
990  L= factorize (F, a);
991  }
992  prune(a);
993  }
994  else
995  {
997  L = factorize( F );
998  }
999  }
1000  else
1001  {
1002  goto notImpl;
1003  }
1004  {
1005  poly ff=p_Copy(f,r); // a copy for the retry stuff
1006  // the first factor should be a constant
1007  if ( ! L.getFirst().factor().inCoeffDomain() )
1008  L.insert(CFFactor(1,1));
1009  // convert into ideal
1010  int n = L.length();
1011  if (n==0) n=1;
1012  CFFListIterator J=L;
1013  int j=0;
1014  if (with_exps!=1)
1015  {
1016  if ((with_exps==2)&&(n>1))
1017  {
1018  n--;
1019  J++;
1020  }
1021  *v = new intvec( n );
1022  }
1023  res = idInit( n ,1);
1024  for ( ; J.hasItem(); J++, j++ )
1025  {
1026  if (with_exps!=1) (**v)[j] = J.getItem().exp();
1027  if (rField_is_Zp(r) || rField_is_Q(r)|| rField_is_Z(r)
1028  || (rField_is_Zn(r) && r->cf->convSingNFactoryN!=ndConvSingNFactoryN)) /* Q, Fp, Z */
1029  {
1030  //count_Factors(res,*v,f, j, convFactoryPSingP( J.getItem().factor() );
1031  res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1032  }
1033 #if 0
1034  else if (rField_is_GF())
1035  res->m[j] = convFactoryGFSingGF( J.getItem().factor() );
1036 #endif
1037  else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1038  {
1039 #ifndef SING_NDEBUG
1040  intvec *w=NULL;
1041  if (v!=NULL) w=*v;
1042 #endif
1043  if (r->cf->extRing->qideal==NULL)
1044  {
1045 #ifdef SING_NDEBUG
1046  res->m[j]= convFactoryPSingTrP( J.getItem().factor(),r );
1047 #else
1048  if(!count_Factors(res,w,j,ff,convFactoryPSingTrP( J.getItem().factor(),r ),r))
1049  {
1050  if (w!=NULL)
1051  (*w)[j]=1;
1052  res->m[j]=p_One(r);
1053  }
1054 #endif
1055  }
1056  else
1057  {
1058 #ifdef SING_NDEBUG
1059  res->m[j]= convFactoryAPSingAP( J.getItem().factor(),r );
1060 #else
1061  if (!count_Factors(res,w,j,ff,convFactoryAPSingAP( J.getItem().factor(),r ),r))
1062  {
1063  if (w!=NULL)
1064  (*w)[j]=1;
1065  res->m[j]=p_One(r);
1066  }
1067 #endif
1068  }
1069  }
1070  }
1071  if (r->cf->extRing!=NULL)
1072  if (r->cf->extRing->qideal!=NULL)
1073  prune (a);
1074 #ifndef SING_NDEBUG
1075  if ((r->cf->extRing!=NULL) && (!p_IsConstantPoly(ff,r)))
1076  {
1079  {
1080  int jj;
1081 #ifdef FACTORIZE2_DEBUG
1082  printf("factorize_retry\n");
1083 #endif
1084  intvec *ww=NULL;
1085  id_Test(res,r);
1086  ideal h=singclap_factorize ( ff, &ww , with_exps, r );
1087  id_Test(h,r);
1088  int l=(*v)->length();
1089  (*v)->resize(l+ww->length());
1090  for(jj=0;jj<ww->length();jj++)
1091  (**v)[jj+l]=(*ww)[jj];
1092  delete ww;
1093  ideal hh=idInit(IDELEMS(res)+IDELEMS(h),1);
1094  for(jj=IDELEMS(res)-1;jj>=0;jj--)
1095  {
1096  hh->m[jj]=res->m[jj];
1097  res->m[jj]=NULL;
1098  }
1099  for(jj=IDELEMS(h)-1;jj>=0;jj--)
1100  {
1101  hh->m[jj+IDELEMS(res)]=h->m[jj];
1102  h->m[jj]=NULL;
1103  }
1104  id_Delete(&res,r);
1105  id_Delete(&h,r);
1106  res=hh;
1107  id_Test(res,r);
1108  ff=NULL;
1109  }
1110  else
1111  {
1112  WarnS("problem with factorize");
1113 #if 0
1114  pWrite(ff);
1115  idShow(res);
1116 #endif
1117  id_Delete(&res,r);
1118  res=idInit(2,1);
1119  res->m[0]=p_One(r);
1120  res->m[1]=ff; ff=NULL;
1121  }
1122  }
1123 #endif
1124  p_Delete(&ff,r);
1125  if (N!=NULL)
1126  {
1127  __p_Mult_nn(res->m[0],N,r);
1128  n_Delete(&N,r->cf);
1129  N=NULL;
1130  }
1131  // delete constants
1132  if (res!=NULL)
1133  {
1134  int i=IDELEMS(res)-1;
1135  int j=0;
1136  for(;i>=0;i--)
1137  {
1138  if ((res->m[i]!=NULL)
1139  && (pNext(res->m[i])==NULL)
1140  && (p_IsConstant(res->m[i],r)))
1141  {
1142  if (with_exps!=0)
1143  {
1144  p_Delete(&(res->m[i]),r);
1145  if ((v!=NULL) && ((*v)!=NULL))
1146  (**v)[i]=0;
1147  j++;
1148  }
1149  else if (i!=0)
1150  {
1151  while ((v!=NULL) && ((*v)!=NULL) && ((**v)[i]>1))
1152  {
1153  res->m[0]=p_Mult_q(res->m[0],p_Copy(res->m[i],r),r);
1154  (**v)[i]--;
1155  }
1156  res->m[0]=p_Mult_q(res->m[0],res->m[i],r);
1157  res->m[i]=NULL;
1158  if ((v!=NULL) && ((*v)!=NULL))
1159  (**v)[i]=1;
1160  j++;
1161  }
1162  }
1163  }
1164  if (j>0)
1165  {
1166  idSkipZeroes(res);
1167  if ((v!=NULL) && ((*v)!=NULL))
1168  {
1169  intvec *w=*v;
1170  int len=IDELEMS(res);
1171  *v = new intvec( len );
1172  for (i=0,j=0;i<si_min(w->length(),len);i++)
1173  {
1174  if((*w)[i]!=0)
1175  {
1176  (**v)[j]=(*w)[i]; j++;
1177  }
1178  }
1179  delete w;
1180  }
1181  }
1182  if (res->m[0]==NULL)
1183  {
1184  res->m[0]=p_One(r);
1185  }
1186  }
1187  }
1188  if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1189  {
1190  int i=IDELEMS(res)-1;
1191  int stop=1;
1192  if (with_exps!=0) stop=0;
1193  for(;i>=stop;i--)
1194  {
1195  p_Norm(res->m[i],r);
1196  }
1197  if (with_exps==0) p_SetCoeff(res->m[0],old_lead_coeff,r);
1198  else n_Delete(&old_lead_coeff,r->cf);
1199  }
1200  else
1201  n_Delete(&old_lead_coeff,r->cf);
1202  errorreported=save_errorreported;
1203 notImpl:
1204  prune(a);
1205  if (res==NULL)
1207  if (NN!=NULL)
1208  {
1209  n_Delete(&NN,r->cf);
1210  }
1211  if (N!=NULL)
1212  {
1213  n_Delete(&N,r->cf);
1214  }
1215  if (f!=NULL) p_Delete(&f,r);
1216  //PrintS("......S\n");
1217  return res;
1218 }
1220 ideal singclap_sqrfree ( poly f, intvec ** v , int with_exps, const ring r)
1221 {
1222  p_Test(f,r);
1223 #ifdef FACTORIZE2_DEBUG
1224  printf("singclap_sqrfree, degree %d\n",pTotaldegree(f));
1225 #endif
1226  // with_exps: 3,1 return only true factors, no exponents
1227  // 2 return true factors and exponents
1228  // 0 return coeff, factors and exponents
1229  BOOLEAN save_errorreported=errorreported;
1230 
1231  ideal res=NULL;
1232 
1233  // handle factorize(0) =========================================
1234  if (f==NULL)
1235  {
1236  res=idInit(1,1);
1237  if (with_exps!=1 && with_exps!=3)
1238  {
1239  (*v)=new intvec(1);
1240  (**v)[0]=1;
1241  }
1242  return res;
1243  }
1244  // handle factorize(mon) =========================================
1245  if (pNext(f)==NULL)
1246  {
1247  int i=0;
1248  int n=0;
1249  int e;
1250  for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
1251  if (with_exps==0 || with_exps==3) n++; // with coeff
1252  res=idInit(si_max(n,1),1);
1253  if(with_exps!=1)
1254  {
1255  (*v)=new intvec(si_max(1,n));
1256  (**v)[0]=1;
1257  }
1258  res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
1259  if (n==0)
1260  {
1261  res->m[0]=p_One(r);
1262  // (**v)[0]=1; is already done
1263  }
1264  else
1265  {
1266  for(i=rVar(r);i>0;i--)
1267  {
1268  e=p_GetExp(f,i,r);
1269  if(e!=0)
1270  {
1271  n--;
1272  poly p=p_One(r);
1273  p_SetExp(p,i,1,r);
1274  p_Setm(p,r);
1275  res->m[n]=p;
1276  if (with_exps!=1) (**v)[n]=e;
1277  }
1278  }
1279  }
1280  p_Delete(&f,r);
1281  return res;
1282  }
1283  //PrintS("S:");pWrite(f);PrintLn();
1284  // use factory/libfac in general ==============================
1285  Off(SW_RATIONAL);
1287  CFFList L;
1288  number N=NULL;
1289  number NN=NULL;
1290  number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
1291  Variable a;
1292 
1293  if (!rField_is_Zp(r) && !rField_is_Zp_a(r)) /* Q, Q(a) */
1294  {
1295  //if (f!=NULL) // already tested at start of routine
1296  number n0=n_Copy(pGetCoeff(f),r->cf);
1297  if (with_exps==0 || with_exps==3)
1298  N=n_Copy(n0,r->cf);
1299  p_Cleardenom(f, r);
1300  //after here f should not have a denominator!!
1301  //PrintS("S:");p_Write(f,r);PrintLn();
1302  NN=n_Div(n0,pGetCoeff(f),r->cf);
1303  n_Delete(&n0,r->cf);
1304  if (with_exps==0 || with_exps==3)
1305  {
1306  n_Delete(&N,r->cf);
1307  N=n_Copy(NN,r->cf);
1308  }
1309  }
1310  else if (rField_is_Zp_a(r))
1311  {
1312  //if (f!=NULL) // already tested at start of routine
1313  if (singclap_factorize_retry==0)
1314  {
1315  number n0=n_Copy(pGetCoeff(f),r->cf);
1316  if (with_exps==0 || with_exps==3)
1317  N=n_Copy(n0,r->cf);
1318  p_Norm(f,r);
1319  p_Cleardenom(f, r);
1320  NN=n_Div(n0,pGetCoeff(f),r->cf);
1321  n_Delete(&n0,r->cf);
1322  if (with_exps==0 || with_exps==3)
1323  {
1324  n_Delete(&N,r->cf);
1325  N=n_Copy(NN,r->cf);
1326  }
1327  }
1328  }
1329  if (rField_is_Q(r) || rField_is_Zp(r)
1330  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1331  {
1332  setCharacteristic( rChar(r) );
1333  CanonicalForm F( convSingPFactoryP( f,r ) );
1334  L = sqrFree( F );
1335  }
1336  else if (r->cf->extRing!=NULL)
1337  {
1338  if (rField_is_Q_a (r)) setCharacteristic (0);
1339  else setCharacteristic( rChar(r) );
1340  if (r->cf->extRing->qideal!=NULL)
1341  {
1342  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
1343  r->cf->extRing);
1344  a=rootOf(mipo);
1345  CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
1346  L= sqrFree (F);
1347  }
1348  else
1349  {
1351  L = sqrFree( F );
1352  }
1353  }
1354  #if 0
1355  else if (rField_is_GF())
1356  {
1357  int c=rChar(r);
1358  setCharacteristic( c, primepower(c) );
1359  CanonicalForm F( convSingGFFactoryGF( f ) );
1360  if (F.isUnivariate())
1361  {
1362  L = factorize( F );
1363  }
1364  else
1365  {
1366  goto notImpl;
1367  }
1368  }
1369  #endif
1370  else
1371  {
1372  goto notImpl;
1373  }
1374  {
1375  // convert into ideal
1376  int n = L.length();
1377  if (n==0) n=1;
1378  CFFListIterator J=L;
1379  int j=0;
1380  if (with_exps!=1)
1381  {
1382  if ((with_exps==2)&&(n>1))
1383  {
1384  n--;
1385  J++;
1386  }
1387  *v = new intvec( n );
1388  }
1389  else if (L.getFirst().factor().inCoeffDomain() && with_exps!=3)
1390  {
1391  n--;
1392  J++;
1393  }
1394  res = idInit( n ,1);
1395  for ( ; J.hasItem(); J++, j++ )
1396  {
1397  if (with_exps!=1 && with_exps!=3) (**v)[j] = J.getItem().exp();
1398  if (rField_is_Zp(r) || rField_is_Q(r)
1399  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1400  res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1401  else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1402  {
1403  if (r->cf->extRing->qideal==NULL)
1404  res->m[j]=convFactoryPSingTrP( J.getItem().factor(),r );
1405  else
1406  res->m[j]=convFactoryAPSingAP( J.getItem().factor(),r );
1407  }
1408  }
1409  if (res->m[0]==NULL)
1410  {
1411  res->m[0]=p_One(r);
1412  }
1413  if (N!=NULL)
1414  {
1415  __p_Mult_nn(res->m[0],N,r);
1416  n_Delete(&N,r->cf);
1417  N=NULL;
1418  }
1419  }
1420  if (r->cf->extRing!=NULL)
1421  if (r->cf->extRing->qideal!=NULL)
1422  prune (a);
1423  if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1424  {
1425  int i=IDELEMS(res)-1;
1426  int stop=1;
1427  if (with_exps!=0 || with_exps==3) stop=0;
1428  for(;i>=stop;i--)
1429  {
1430  p_Norm(res->m[i],r);
1431  }
1432  if (with_exps==0 || with_exps==3) p_SetCoeff(res->m[0],old_lead_coeff,r);
1433  else n_Delete(&old_lead_coeff,r->cf);
1434  }
1435  else
1436  n_Delete(&old_lead_coeff,r->cf);
1437  p_Delete(&f,r);
1438  errorreported=save_errorreported;
1439 notImpl:
1440  if (res==NULL)
1442  if (NN!=NULL)
1443  {
1444  n_Delete(&NN,r->cf);
1445  }
1446  if (N!=NULL)
1447  {
1448  n_Delete(&N,r->cf);
1449  }
1450  return res;
1451 }
1453 matrix singclap_irrCharSeries ( ideal I, const ring r)
1454 {
1455  if (idIs0(I)) return mpNew(1,1);
1456 
1457  // for now there is only the possibility to handle polynomials over
1458  // Q and Fp ...
1459  matrix res=NULL;
1460  int i;
1461  Off(SW_RATIONAL);
1463  CFList L;
1464  ListCFList LL;
1465  if (rField_is_Q(r) || rField_is_Zp(r)
1466  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1467  {
1468  setCharacteristic( rChar(r) );
1469  for(i=0;i<IDELEMS(I);i++)
1470  {
1471  poly p=I->m[i];
1472  if (p!=NULL)
1473  {
1474  p=p_Copy(p,r);
1475  p_Cleardenom(p, r);
1476  L.append(convSingPFactoryP(p,r));
1477  p_Delete(&p,r);
1478  }
1479  }
1480  }
1481  // and over Q(a) / Fp(a)
1482  else if (nCoeff_is_transExt (r->cf))
1483  {
1484  setCharacteristic( rChar(r) );
1485  for(i=0;i<IDELEMS(I);i++)
1486  {
1487  poly p=I->m[i];
1488  if (p!=NULL)
1489  {
1490  p=p_Copy(p,r);
1491  p_Cleardenom(p, r);
1493  p_Delete(&p,r);
1494  }
1495  }
1496  }
1497  else
1498  {
1500  return res;
1501  }
1502 
1503  // a very bad work-around --- FIX IT in libfac
1504  // should be fixed as of 2001/6/27
1505  int tries=0;
1506  int m,n;
1508  loop
1509  {
1510  LL=irrCharSeries(L);
1511  m= LL.length(); // Anzahl Zeilen
1512  n=0;
1513  for ( LLi = LL; LLi.hasItem(); LLi++ )
1514  {
1515  n = si_max(LLi.getItem().length(),n);
1516  }
1517  if ((m!=0) && (n!=0)) break;
1518  tries++;
1519  if (tries>=5) break;
1520  }
1521  if ((m==0) || (n==0))
1522  {
1523  Warn("char_series returns %d x %d matrix from %d input polys (%d)",
1524  m,n,IDELEMS(I)+1,LL.length());
1525  iiWriteMatrix((matrix)I,"I",2,r,0);
1526  m=si_max(m,1);
1527  n=si_max(n,1);
1528  }
1529  res=mpNew(m,n);
1530  CFListIterator Li;
1531  for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ )
1532  {
1533  for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++)
1534  {
1535  if (rField_is_Q(r) || rField_is_Zp(r)
1536  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1537  MATELEM(res,m,n)=convFactoryPSingP(Li.getItem(),r);
1538  else
1540  }
1541  }
1542  Off(SW_RATIONAL);
1543  return res;
1544 }
1546 char* singclap_neworder ( ideal I, const ring r)
1547 {
1548  int i;
1549  Off(SW_RATIONAL);
1551  CFList L;
1552  if (rField_is_Q(r) || rField_is_Zp(r)
1553  || (rField_is_Zn(r)&&(r->cf->convSingNFactoryN!=ndConvSingNFactoryN)))
1554  {
1555  setCharacteristic( rChar(r) );
1556  for(i=0;i<IDELEMS(I);i++)
1557  {
1558  poly p=I->m[i];
1559  if (p!=NULL)
1560  {
1561  p=p_Copy(p,r);
1562  p_Cleardenom(p, r);
1563  L.append(convSingPFactoryP(p,r));
1564  }
1565  }
1566  }
1567  // and over Q(a) / Fp(a)
1568  else if (nCoeff_is_transExt (r->cf))
1569  {
1570  setCharacteristic( rChar(r) );
1571  for(i=0;i<IDELEMS(I);i++)
1572  {
1573  poly p=I->m[i];
1574  if (p!=NULL)
1575  {
1576  p=p_Copy(p,r);
1577  p_Cleardenom(p, r);
1579  }
1580  }
1581  }
1582  else
1583  {
1585  return NULL;
1586  }
1587 
1588  List<int> IL=neworderint(L);
1589  ListIterator<int> Li;
1590  StringSetS("");
1591  Li = IL;
1592  int offs=rPar(r);
1593  int* mark=(int*)omAlloc0((rVar(r)+offs)*sizeof(int));
1594  int cnt=rVar(r)+offs;
1595  loop
1596  {
1597  if(! Li.hasItem()) break;
1598  BOOLEAN done=TRUE;
1599  i=Li.getItem()-1;
1600  mark[i]=1;
1601  if (i<offs)
1602  {
1603  done=FALSE;
1604  //StringAppendS(r->parameter[i]);
1605  }
1606  else
1607  {
1608  StringAppendS(r->names[i-offs]);
1609  }
1610  Li++;
1611  cnt--;
1612  if(cnt==0) break;
1613  if (done) StringAppendS(",");
1614  }
1615  for(i=0;i<rVar(r)+offs;i++)
1616  {
1617  BOOLEAN done=TRUE;
1618  if(mark[i]==0)
1619  {
1620  if (i<offs)
1621  {
1622  done=FALSE;
1623  //StringAppendS(r->parameter[i]);
1624  }
1625  else
1626  {
1627  StringAppendS(r->names[i-offs]);
1628  }
1629  cnt--;
1630  if(cnt==0) break;
1631  if (done) StringAppendS(",");
1632  }
1633  }
1634  char * s=StringEndS();
1635  if (s[strlen(s)-1]==',') s[strlen(s)-1]='\0';
1636  return s;
1637 }
1639 poly singclap_det( const matrix m, const ring s )
1640 {
1641  int r=m->rows();
1642  if (r!=m->cols())
1643  {
1644  Werror("det of %d x %d matrix",r,m->cols());
1645  return NULL;
1646  }
1647  poly res=NULL;
1648  CFMatrix M(r,r);
1649  int i,j;
1650  for(i=r;i>0;i--)
1651  {
1652  for(j=r;j>0;j--)
1653  {
1655  }
1656  }
1658  Off(SW_RATIONAL);
1659  return res;
1660 }
1662 int singclap_det_i( intvec * m, const ring /*r*/)
1663 {
1664 // assume( r == currRing ); // Anything else is not guaranted to work!
1665 
1666  setCharacteristic( 0 ); // ?
1667  CFMatrix M(m->rows(),m->cols());
1668  int i,j;
1669  for(i=m->rows();i>0;i--)
1670  {
1671  for(j=m->cols();j>0;j--)
1672  {
1673  M(i,j)=IMATELEM(*m,i,j);
1674  }
1675  }
1676  int res= convFactoryISingI( determinant(M,m->rows()) ) ;
1677  return res;
1678 }
1680 number singclap_det_bi( bigintmat * m, const coeffs cf)
1681 {
1682  assume(m->basecoeffs()==cf);
1683  CFMatrix M(m->rows(),m->cols());
1684  int i,j;
1685  BOOLEAN setchar=TRUE;
1686  for(i=m->rows();i>0;i--)
1687  {
1688  for(j=m->cols();j>0;j--)
1689  {
1690  M(i,j)=n_convSingNFactoryN(BIMATELEM(*m,i,j),setchar,cf);
1691  setchar=FALSE;
1692  }
1693  }
1694  number res=n_convFactoryNSingN( determinant(M,m->rows()),cf ) ;
1695  return res;
1696 }
1697 
1698 #ifdef HAVE_NTL
1699 matrix singntl_HNF(matrix m, const ring s )
1700 {
1701  int r=m->rows();
1702  if (r!=m->cols())
1703  {
1704  Werror("HNF of %d x %d matrix",r,m->cols());
1705  return NULL;
1706  }
1707 
1708  matrix res=mpNew(r,r);
1709 
1710  if (rField_is_Q(s))
1711  {
1712 
1713  CFMatrix M(r,r);
1714  int i,j;
1715  for(i=r;i>0;i--)
1716  {
1717  for(j=r;j>0;j--)
1718  {
1719  M(i,j)=convSingPFactoryP(MATELEM(m,i,j),s );
1720  }
1721  }
1722  CFMatrix *MM=cf_HNF(M);
1723  for(i=r;i>0;i--)
1724  {
1725  for(j=r;j>0;j--)
1726  {
1727  MATELEM(res,i,j)=convFactoryPSingP((*MM)(i,j),s);
1728  }
1729  }
1730  delete MM;
1731  }
1732  return res;
1733 }
1736 {
1737  int r=m->rows();
1738  if (r!=m->cols())
1739  {
1740  Werror("HNF of %d x %d matrix",r,m->cols());
1741  return NULL;
1742  }
1743  setCharacteristic( 0 );
1744  CFMatrix M(r,r);
1745  int i,j;
1746  for(i=r;i>0;i--)
1747  {
1748  for(j=r;j>0;j--)
1749  {
1750  M(i,j)=IMATELEM(*m,i,j);
1751  }
1752  }
1753  CFMatrix *MM=cf_HNF(M);
1754  intvec *mm=ivCopy(m);
1755  for(i=r;i>0;i--)
1756  {
1757  for(j=r;j>0;j--)
1758  {
1759  IMATELEM(*mm,i,j)=convFactoryISingI((*MM)(i,j));
1760  }
1761  }
1762  delete MM;
1763  return mm;
1764 }
1767 {
1768  int r=b->rows();
1769  if (r!=b->cols())
1770  {
1771  Werror("HNF of %d x %d matrix",r,b->cols());
1772  return NULL;
1773  }
1774  setCharacteristic( 0 );
1775  CFMatrix M(r,r);
1776  int i,j;
1777  for(i=r;i>0;i--)
1778  {
1779  for(j=r;j>0;j--)
1780  {
1781  M(i,j)=n_convSingNFactoryN(BIMATELEM(*b,i,j),FALSE,b->basecoeffs());
1782  }
1783  }
1784  CFMatrix *MM=cf_HNF(M);
1785  bigintmat *mm=bimCopy(b);
1786  for(i=r;i>0;i--)
1787  {
1788  for(j=r;j>0;j--)
1789  {
1790  BIMATELEM(*mm,i,j)=n_convFactoryNSingN((*MM)(i,j),b->basecoeffs());
1791  }
1792  }
1793  delete MM;
1794  return mm;
1795 }
1797 matrix singntl_LLL(matrix m, const ring s )
1798 {
1799  int r=m->rows();
1800  int c=m->cols();
1801  matrix res=mpNew(r,c);
1802  if (rField_is_Q(s))
1803  {
1804  CFMatrix M(r,c);
1805  int i,j;
1806  for(i=r;i>0;i--)
1807  {
1808  for(j=c;j>0;j--)
1809  {
1811  }
1812  }
1813  CFMatrix *MM=cf_LLL(M);
1814  for(i=r;i>0;i--)
1815  {
1816  for(j=c;j>0;j--)
1817  {
1818  MATELEM(res,i,j)=convFactoryPSingP((*MM)(i,j),s);
1819  }
1820  }
1821  delete MM;
1822  }
1823  return res;
1824 }
1827 {
1828  int r=m->rows();
1829  int c=m->cols();
1830  setCharacteristic( 0 );
1831  CFMatrix M(r,c);
1832  int i,j;
1833  for(i=r;i>0;i--)
1834  {
1835  for(j=c;j>0;j--)
1836  {
1837  M(i,j)=IMATELEM(*m,i,j);
1838  }
1839  }
1840  CFMatrix *MM=cf_LLL(M);
1841  intvec *mm=ivCopy(m);
1842  for(i=r;i>0;i--)
1843  {
1844  for(j=c;j>0;j--)
1845  {
1846  IMATELEM(*mm,i,j)=convFactoryISingI((*MM)(i,j));
1847  }
1848  }
1849  delete MM;
1850  return mm;
1851 }
1853 ideal singclap_absFactorize ( poly f, ideal & mipos, intvec ** exps, int & numFactors, const ring r)
1854 {
1855  p_Test(f, r);
1856 
1857  ideal res=NULL;
1858 
1859  int offs = rPar(r);
1860  if (f==NULL)
1861  {
1862  res= idInit (1, 1);
1863  mipos= idInit (1, 1);
1864  mipos->m[0]= convFactoryPSingTrP (Variable (offs), r); //overkill
1865  (*exps)=new intvec (1);
1866  (**exps)[0]= 1;
1867  numFactors= 0;
1868  return res;
1869  }
1871 
1872  bool isRat= isOn (SW_RATIONAL);
1873  if (!isRat)
1874  On (SW_RATIONAL);
1875 
1876  CFAFList absFactors= absFactorize (F);
1877 
1878  int n= absFactors.length();
1879  *exps=new intvec (n);
1880 
1881  res= idInit (n, 1);
1882 
1883  mipos= idInit (n, 1);
1884 
1885  Variable x= Variable (offs);
1886  Variable alpha;
1887  int i= 0;
1888  numFactors= 0;
1889  int count;
1890  CFAFListIterator iter= absFactors;
1891  CanonicalForm lead= iter.getItem().factor();
1892  if (iter.getItem().factor().inCoeffDomain())
1893  {
1894  i++;
1895  iter++;
1896  }
1897  for (; iter.hasItem(); iter++, i++)
1898  {
1899  (**exps)[i]= iter.getItem().exp();
1900  alpha= iter.getItem().minpoly().mvar();
1901  if (iter.getItem().minpoly().isOne())
1902  lead /= power (bCommonDen (iter.getItem().factor()), iter.getItem().exp());
1903  else
1904  lead /= power (power (bCommonDen (iter.getItem().factor()), degree (iter.getItem().minpoly())), iter.getItem().exp());
1905  res->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().factor()*bCommonDen (iter.getItem().factor()), alpha, x), r);
1906  if (iter.getItem().minpoly().isOne())
1907  {
1908  count= iter.getItem().exp();
1909  mipos->m[i]= convFactoryPSingTrP (x,r);
1910  }
1911  else
1912  {
1913  count= iter.getItem().exp()*degree (iter.getItem().minpoly());
1914  mipos->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().minpoly(), alpha, x), r);
1915  }
1916  if (!iter.getItem().minpoly().isOne())
1917  prune (alpha);
1918  numFactors += count;
1919  }
1920  if (!isRat)
1921  Off (SW_RATIONAL);
1922 
1923  (**exps)[0]= 1;
1924  res->m[0]= convFactoryPSingTrP (lead, r);
1925  mipos->m[0]= convFactoryPSingTrP (x, r);
1926  return res;
1927 }
1928 
1929 #else
1930 matrix singntl_HNF(matrix m, const ring s )
1931 {
1932  WerrorS("NTL missing");
1933  return NULL;
1934 }
1935 
1937 {
1938  WerrorS("NTL missing");
1939  return NULL;
1940 }
1941 
1942 matrix singntl_LLL(matrix m, const ring s )
1943 {
1944  WerrorS("NTL missing");
1945  return NULL;
1946 }
1947 
1949 {
1950  WerrorS("NTL missing");
1951  return NULL;
1952 }
1953 
1954 ideal singclap_absFactorize ( poly f, ideal & mipos, intvec ** exps, int & numFactors, const ring r)
1955 {
1956  WerrorS("NTL missing");
1957  return NULL;
1958 }
1959 
1960 #endif /* HAVE_NTL */
1961 
Matrix
Definition: ftmpl_matrix.h:20
si_min
static int si_min(const int a, const int b)
Definition: auxiliary.h:141
FALSE
#define FALSE
Definition: auxiliary.h:96
rField_is_Zn
static BOOLEAN rField_is_Zn(const ring r)
Definition: ring.h:506
SW_RATIONAL
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:29
ip_smatrix
Definition: matpol.h:13
singclap_factorize_retry
VAR int singclap_factorize_retry
Definition: clapsing.cc:839
StringAppendS
void StringAppendS(const char *st)
Definition: reporter.cc:106
isOn
bool isOn(int sw)
switches
Definition: canonicalform.cc:1912
p_GetExp
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:456
j
int j
Definition: facHensel.cc:105
f
FILE * f
Definition: checklibs.c:9
cf_HNF
CFMatrix * cf_HNF(CFMatrix &A)
The input matrix A is an n x m matrix of rank m (so n >= m), and D is a multiple of the determinant o...
Definition: cf_hnf.cc:38
p_Write0
void p_Write0(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:331
x
Variable x
Definition: cfModGcd.cc:4023
MATELEM
#define MATELEM(mat, i, j)
1-based access to matrix
Definition: matpol.h:29
bigintmat
Definition: bigintmat.h:49
h
STATIC_VAR Poly * h
Definition: janet.cc:971
singclap_det
poly singclap_det(const matrix m, const ring s)
Definition: clapsing.cc:1638
singclap_factorize
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:841
cf
CanonicalForm cf
Definition: cfModGcd.cc:4024
simpleideals.h
absFactorize
CFAFList absFactorize(const CanonicalForm &G)
absolute factorization of a multivariate poly over Q
Definition: facAbsFact.cc:267
power
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
Definition: canonicalform.cc:1837
singclap_pdivide
poly singclap_pdivide(poly f, poly g, const ring r)
Definition: clapsing.cc:557
g
g
Definition: cfModGcd.cc:4031
bimCopy
bigintmat * bimCopy(const bigintmat *b)
same as copy constructor - apart from it being able to accept NULL as input
Definition: bigintmat.cc:405
n_Delete
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:454
convFactoryAPSingAP
poly convFactoryAPSingAP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:150
p_Test
#define p_Test(p, r)
Definition: p_polys.h:154
rootOf
Variable rootOf(const CanonicalForm &, char name='@')
returns a symbolic root of polynomial with name name Use it to define algebraic variables
Definition: variable.cc:162
p_wrp
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:372
clapconv.h
auxiliary.h
N
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:48
rField_is_Zp_a
static BOOLEAN rField_is_Zp_a(const ring r)
Definition: ring.h:523
StringEndS
char * StringEndS()
Definition: reporter.cc:150
iter
CFFListIterator iter
Definition: facAbsBiFact.cc:54
n_IsOne
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:467
idIs0
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
Definition: simpleideals.cc:776
loop
#define loop
Definition: structs.h:79
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
getCharacteristic
int getCharacteristic()
Definition: cf_char.cc:51
b
CanonicalForm b
Definition: cfModGcd.cc:4044
__p_Mult_nn
#define __p_Mult_nn(p, n, r)
Definition: p_polys.h:915
bigintmat.h
convSingAPFactoryAP
CanonicalForm convSingAPFactoryAP(poly p, const Variable &a, const ring r)
Definition: clapconv.cc:115
extgcd
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
Definition: cfUnivarGcd.cc:173
iiWriteMatrix
void iiWriteMatrix(matrix im, const char *n, int dim, const ring r, int spaces)
set spaces to zero by default
Definition: matpol.cc:833
pTotaldegree
static long pTotaldegree(poly p)
Definition: polys.h:266
pb
BOOLEAN pb(leftv res, leftv args)
Definition: cohomo.cc:4373
nf
Definition: gnumpfl.cc:25
CanonicalForm
factory's main class
Definition: canonicalform.h:77
p_SetExp
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:475
singclap_resultant
poly singclap_resultant(poly f, poly g, poly x, const ring r)
Definition: clapsing.cc:278
p_Copy
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:796
CanonicalForm::isOne
CF_NO_INLINE bool isOne() const
CF_INLINE bool CanonicalForm::isOne, isZero () const.
Definition: cf_inline.cc:354
rVar
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:586
TRUE
#define TRUE
Definition: auxiliary.h:100
i
int i
Definition: cfEzgcd.cc:125
rChar
int rChar(ring r)
Definition: ring.cc:712
ivCopy
intvec * ivCopy(const intvec *o)
Definition: intvec.h:134
id_Delete
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
Definition: simpleideals.cc:122
p_Sub
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1962
res
CanonicalForm res
Definition: facAbsFact.cc:64
out_cf
void out_cf(const char *s1, const CanonicalForm &f, const char *s2)
Definition: cf_factor.cc:90
matpol.h
rField_is_Q_a
static BOOLEAN rField_is_Q_a(const ring r)
Definition: ring.h:533
idShow
void idShow(const ideal id, const ring lmRing, const ring tailRing, const int debugPrint)
Definition: simpleideals.cc:56
M
#define M
Definition: sirandom.c:25
n_convFactoryNSingN
number n_convFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: numbers.cc:621
PrintS
void PrintS(const char *s)
Definition: reporter.cc:283
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:87
alpha
Variable alpha
Definition: facAbsBiFact.cc:52
clapsing.h
idSkipZeroes
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
Definition: simpleideals.cc:180
convSingTrPFactoryP
CanonicalForm convSingTrPFactoryP(poly p, const ring r)
Definition: clapconv.cc:283
VAR
#define VAR
Definition: globaldefs.h:5
convFactoryISingI
int convFactoryISingI(const CanonicalForm &f)
Definition: clapconv.cc:109
G
STATIC_VAR TreeM * G
Definition: janet.cc:31
setCharacteristic
void setCharacteristic(int c)
Definition: cf_char.cc:23
singclap_det_i
int singclap_det_i(intvec *m, const ring)
Definition: clapsing.cc:1661
count_Factors
BOOLEAN count_Factors(ideal I, intvec *v, int j, poly &f, poly fac, const ring r)
Definition: clapsing.cc:751
coeffs
singclap_irrCharSeries
matrix singclap_irrCharSeries(ideal I, const ring r)
Definition: clapsing.cc:1452
pp_Mult_qq
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1075
p_Div_mm
poly p_Div_mm(poly p, const poly m, const ring r)
divide polynomial by monomial
Definition: p_polys.cc:1517
prune
void prune(Variable &alpha)
Definition: variable.cc:261
p_Write
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:341
intvec
Definition: intvec.h:18
Q
STATIC_VAR jList * Q
Definition: janet.cc:30
pIter
#define pIter(p)
Definition: monomials.h:34
p_Cleardenom
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2788
p_polys.h
singntl_HNF
matrix singntl_HNF(matrix m, const ring s)
Definition: clapsing.cc:1698
determinant
CanonicalForm determinant(const CFMatrix &M, int n)
Definition: cf_linsys.cc:222
rPar
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:593
n_Init
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:537
factorize
CFFList factorize(const CanonicalForm &f, bool issqrfree=false)
factorization over or
Definition: cf_factor.cc:390
p_GcdMon
poly p_GcdMon(poly f, poly g, const ring r)
polynomial gcd for f=mon
Definition: p_polys.cc:4846
intvec.h
nCoeff_is_transExt
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:939
ListIterator::hasItem
int hasItem()
Definition: ftmpl_list.cc:439
mpNew
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:36
n_convSingNFactoryN
CanonicalForm n_convSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: numbers.cc:626
Off
void Off(int sw)
switches
Definition: canonicalform.cc:1905
singclap_pmult
poly singclap_pmult(poly f, poly g, const ring r)
Definition: clapsing.cc:510
List::getFirst
T getFirst() const
Definition: ftmpl_list.cc:279
convSingPFactoryP
CanonicalForm convSingPFactoryP(poly p, const ring r)
Definition: clapconv.cc:84
Factor
Definition: ftmpl_factor.h:18
nfMinPoly
STATIC_VAR int nfMinPoly[16]
Definition: ffields.cc:548
p_IsPurePower
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition: p_polys.cc:1213
IMATELEM
#define IMATELEM(M, I, J)
Definition: intvec.h:85
ring.h
bCommonDen
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
Definition: cf_algorithm.cc:293
transext.h
CanonicalForm::inCoeffDomain
bool inCoeffDomain() const
Definition: canonicalform.cc:119
p_Delete
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:845
p_Add_q
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:880
singclap_det_bi
number singclap_det_bi(bigintmat *m, const coeffs cf)
Definition: clapsing.cc:1679
p_One
poly p_One(const ring r)
Definition: p_polys.cc:1300
rField_is_GF
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:515
singclap_extgcd
BOOLEAN singclap_extgcd(poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
Definition: clapsing.cc:422
List::length
int length() const
Definition: ftmpl_list.cc:273
n_Invers
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of 'a'; raise an error if 'a' is not invertible
Definition: coeffs.h:563
StringSetS
void StringSetS(const char *st)
Definition: reporter.cc:127
Variable
factory's class for variables
Definition: factory.h:117
ListIterator::getItem
T & getItem() const
Definition: ftmpl_list.cc:431
si_max
static int si_max(const int a, const int b)
Definition: auxiliary.h:140
SW_USE_EZGCD_P
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
Definition: cf_defs.h:35
pGetExp_Var
int pGetExp_Var(poly p, int i, const ring r)
Definition: clapsing.cc:264
singclap_pmod
poly singclap_pmod(poly f, poly g, const ring r)
Definition: clapsing.cc:604
p_NSet
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1452
Werror
void Werror(const char *fmt,...)
Definition: reporter.cc:188
singclap_gcd_r
poly singclap_gcd_r(poly f, poly g, const ring r)
Definition: clapsing.cc:41
convSingTrP
BOOLEAN convSingTrP(poly p, const ring r)
Definition: clapconv.cc:319
idInit
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:34
p_SetCoeff
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:399
n_Copy
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:450
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
resultant
CanonicalForm resultant(const CanonicalForm &f, const CanonicalForm &g, const Variable &x)
CanonicalForm resultant ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x )
Definition: cf_resultant.cc:173
m
int m
Definition: cfEzgcd.cc:121
singntl_LLL
matrix singntl_LLL(matrix m, const ring s)
Definition: clapsing.cc:1796
WarnS
#define WarnS
Definition: emacs.cc:77
SW_SYMMETRIC_FF
static const int SW_SYMMETRIC_FF
set to 1 for symmetric representation over F_q
Definition: cf_defs.h:31
assume
#define assume(x)
Definition: mod2.h:384
sqrFree
CFFList sqrFree(const CanonicalForm &f, bool sort=false)
squarefree factorization
Definition: cf_factor.cc:757
NULL
#define NULL
Definition: omList.c:11
BIMATELEM
#define BIMATELEM(M, I, J)
Definition: bigintmat.h:132
l
int l
Definition: cfEzgcd.cc:93
neworderint
IntList neworderint(const CFList &PolyList)
Definition: cfCharSets.cc:88
feNotImplemented
const char feNotImplemented[]
Definition: reporter.cc:53
errorreported
VAR short errorreported
Definition: feFopen.cc:23
mark
std::pair< int, int > mark
Definition: ppinitialReduction.h:7
R
#define R
Definition: sirandom.c:27
CanonicalForm::isUnivariate
bool isUnivariate() const
Definition: canonicalform.cc:152
p_Setm
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:223
pa
BOOLEAN pa(leftv res, leftv args)
Definition: cohomo.cc:4346
gcd
int gcd(int a, int b)
Definition: walkSupport.cc:836
convFactoryPSingTrP
poly convFactoryPSingTrP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:333
Warn
#define Warn
Definition: emacs.cc:76
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
p_Totaldegree
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1428
p
int p
Definition: cfModGcd.cc:4019
mipo
CanonicalForm mipo
Definition: facAlgExt.cc:57
p_IsConstantPoly
static BOOLEAN p_IsConstantPoly(const poly p, const ring r)
Definition: p_polys.h:1923
List< CanonicalForm >
p_IsConstant
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:1909
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
replacevar
CanonicalForm replacevar(const CanonicalForm &, const Variable &, const Variable &)
CanonicalForm replacevar ( const CanonicalForm & f, const Variable & x1, const Variable & x2 )
Definition: cf_ops.cc:271
ndConvSingNFactoryN
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition: numbers.cc:272
count
int status int void size_t count
Definition: si_signals.h:58
n_Div
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:614
IDELEMS
#define IDELEMS(i)
Definition: simpleideals.h:23
SW_USE_QGCD
static const int SW_USE_QGCD
set to 1 to use Encarnacion GCD over Q(a)
Definition: cf_defs.h:41
p_Norm
void p_Norm(poly p1, const ring r)
Definition: p_polys.cc:3676
p_Mult_q
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1038
pGetCoeff
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:41
PrintLn
void PrintLn()
Definition: reporter.cc:309
n_Size
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
Definition: coeffs.h:569
rField_is_Z
static BOOLEAN rField_is_Z(const ring r)
Definition: ring.h:503
intvec::length
int length() const
Definition: intvec.h:94
id_Test
#define id_Test(A, lR)
Definition: simpleideals.h:78
irrCharSeries
ListCFList irrCharSeries(const CFList &PS)
irreducible characteristic series
Definition: cfCharSets.cc:568
rField_is_Zp
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:494
List::append
void append(const T &)
Definition: ftmpl_list.cc:256
cf_LLL
CFMatrix * cf_LLL(CFMatrix &A)
performs LLL reduction.
Definition: cf_hnf.cc:48
singclap_sqrfree
ideal singclap_sqrfree(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:1219
numbers.h
pNext
#define pNext(p)
Definition: monomials.h:33
degree
int degree(const CanonicalForm &f)
Definition: canonicalform.h:309
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:209
List::insert
void insert(const T &)
Definition: ftmpl_list.cc:193
singclap_absFactorize
ideal singclap_absFactorize(poly f, ideal &mipos, intvec **exps, int &numFactors, const ring r)
Definition: clapsing.cc:1852
convFactoryPSingP
poly convFactoryPSingP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:39
On
void On(int sw)
switches
Definition: canonicalform.cc:1898
singclap_gcd_and_divide
poly singclap_gcd_and_divide(poly &f, poly &g, const ring r)
clears denominators of f and g, divides by gcd(f,g)
Definition: clapsing.cc:103
ListIterator
Definition: ftmpl_list.h:17
coeffs.h
singclap_neworder
char * singclap_neworder(ideal I, const ring r)
Definition: clapsing.cc:1545
rField_is_Q
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:500
pWrite
void pWrite(poly p)
Definition: polys.h:292
p_Cleardenom_n
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2897