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