My Project  debian-1:4.1.1-p2+ds-4build2
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_Ring_Z(r))
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  {
87  res= convFactoryPSingTrP( gcd( F, G ),r );
88  }
89  }
90  else
93  return res;
94 }
95 
96 poly singclap_gcd_and_divide ( poly& f, poly& g, const ring r)
97 {
98  poly res=NULL;
99 
100  if (g == NULL)
101  {
102  res= f;
103  f=p_One (r);
104  return res;
105  }
106  if (f==NULL)
107  {
108  res= g;
109  g=p_One (r);
110  return res;
111  }
112  if (pNext(g)==NULL)
113  {
114  poly G=p_GcdMon(g,f,r);
115  if (!n_IsOne(pGetCoeff(G),r->cf)
116  || (!p_IsConstant(G,r)))
117  {
118  f=p_Div_mm(f,G,r);
119  g=p_Div_mm(g,G,r);
120  }
121  return G;
122  }
123  else if (pNext(f)==NULL)
124  {
125  poly G=p_GcdMon(f,g,r);
126  if (!n_IsOne(pGetCoeff(G),r->cf)
127  || (!p_IsConstant(G,r)))
128  {
129  f=p_Div_mm(f,G,r);
130  g=p_Div_mm(g,G,r);
131  }
132  return G;
133  }
134 
135  Off(SW_RATIONAL);
136  CanonicalForm F,G,GCD;
137  if (rField_is_Q(r) || (rField_is_Zp(r)))
138  {
139  bool b1=isOn(SW_USE_EZGCD_P);
140  setCharacteristic( rChar(r) );
141  F=convSingPFactoryP( f,r );
142  G=convSingPFactoryP( g,r );
143  GCD=gcd(F,G);
144  if (!GCD.isOne())
145  {
146  p_Delete(&f,r);
147  p_Delete(&g,r);
148  if (getCharacteristic() == 0)
149  On (SW_RATIONAL);
150  F /= GCD;
151  G /= GCD;
152  if (getCharacteristic() == 0)
153  {
154  CanonicalForm denF= bCommonDen (F);
155  CanonicalForm denG= bCommonDen (G);
156  G *= denG;
157  F *= denF;
158  Off (SW_RATIONAL);
159  CanonicalForm gcddenFdenG= gcd (denG, denF);
160  denG /= gcddenFdenG;
161  denF /= gcddenFdenG;
162  On (SW_RATIONAL);
163  G *= denF;
164  F *= denG;
165  }
166  f=convFactoryPSingP( F, r);
167  g=convFactoryPSingP( G, r);
168  }
169  res=convFactoryPSingP( GCD , r);
170  if (!b1) Off (SW_USE_EZGCD_P);
171  }
172  // and over Q(a) / Fp(a)
173  else if ( r->cf->extRing )
174  {
175  if ( rField_is_Q_a(r)) setCharacteristic( 0 );
176  else setCharacteristic( rChar(r) );
177  if (r->cf->extRing->qideal!=NULL)
178  {
179  bool b1=isOn(SW_USE_QGCD);
180  if ( rField_is_Q_a(r) ) On(SW_USE_QGCD);
181  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
182  r->cf->extRing);
183  Variable a=rootOf(mipo);
184  F=( convSingAPFactoryAP( f,a,r ) );
185  G=( convSingAPFactoryAP( g,a,r ) );
186  GCD=gcd(F,G);
187  if (!GCD.isOne())
188  {
189  p_Delete(&f,r);
190  p_Delete(&g,r);
191  if (getCharacteristic() == 0)
192  On (SW_RATIONAL);
193  F /= GCD;
194  G /= GCD;
195  if (getCharacteristic() == 0)
196  {
197  CanonicalForm denF= bCommonDen (F);
198  CanonicalForm denG= bCommonDen (G);
199  G *= denG;
200  F *= denF;
201  Off (SW_RATIONAL);
202  CanonicalForm gcddenFdenG= gcd (denG, denF);
203  denG /= gcddenFdenG;
204  denF /= gcddenFdenG;
205  On (SW_RATIONAL);
206  G *= denF;
207  F *= denG;
208  }
209  f= convFactoryAPSingAP( F,r );
210  g= convFactoryAPSingAP( G,r );
211  }
212  res= convFactoryAPSingAP( GCD,r );
213  prune (a);
214  if (!b1) Off(SW_USE_QGCD);
215  }
216  else
217  {
218  F=( convSingTrPFactoryP( f,r ) );
219  G=( convSingTrPFactoryP( g,r ) );
220  GCD=gcd(F,G);
221  if (!GCD.isOne())
222  {
223  p_Delete(&f,r);
224  p_Delete(&g,r);
225  if (getCharacteristic() == 0)
226  On (SW_RATIONAL);
227  F /= GCD;
228  G /= GCD;
229  if (getCharacteristic() == 0)
230  {
231  CanonicalForm denF= bCommonDen (F);
232  CanonicalForm denG= bCommonDen (G);
233  G *= denG;
234  F *= denF;
235  Off (SW_RATIONAL);
236  CanonicalForm gcddenFdenG= gcd (denG, denF);
237  denG /= gcddenFdenG;
238  denF /= gcddenFdenG;
239  On (SW_RATIONAL);
240  G *= denF;
241  F *= denG;
242  }
243  f= convFactoryPSingTrP( F,r );
244  g= convFactoryPSingTrP( G,r );
245  }
246  res= convFactoryPSingTrP( GCD,r );
247  }
248  }
249  else
251  Off(SW_RATIONAL);
252  return res;
253 }
254 
255 poly singclap_gcd ( poly f, poly g, const ring r)
256 {
257  poly res=NULL;
258 
259  if (f!=NULL)
260  {
261  //if (r->cf->has_simple_Inverse) p_Norm(f,r);
262  if (rField_is_Zp(r)) p_Norm(f,r);
263  else p_Cleardenom(f, r);
264  }
265  if (g!=NULL)
266  {
267  //if (r->cf->has_simple_Inverse) p_Norm(g,r);
268  if (rField_is_Zp(r)) p_Norm(g,r);
269  else p_Cleardenom(g, r);
270  }
271  else return f; // g==0 => gcd=f (but do a p_Cleardenom/pNorm)
272  if (f==NULL) return g; // f==0 => gcd=g (but do a p_Cleardenom/pNorm)
273 
274  res=singclap_gcd_r(f,g,r);
275  p_Delete(&f, r);
276  p_Delete(&g, r);
277  return res;
278 }
279 
280 /*2 find the maximal exponent of var(i) in poly p*/
281 int pGetExp_Var(poly p, int i, const ring r)
282 {
283  int m=0;
284  int mm;
285  while (p!=NULL)
286  {
287  mm=p_GetExp(p,i,r);
288  if (mm>m) m=mm;
289  pIter(p);
290  }
291  return m;
292 }
293 
294 // destroys f,g,x
295 poly singclap_resultant ( poly f, poly g , poly x, const ring r)
296 {
297  poly res=NULL;
298  int i=p_IsPurePower(x, r);
299  if (i==0)
300  {
301  WerrorS("3rd argument must be a ring variable");
302  goto resultant_returns_res;
303  }
304  if ((f==NULL) || (g==NULL))
305  goto resultant_returns_res;
306  // for now there is only the possibility to handle polynomials over
307  // Q and Fp ...
308  if (rField_is_Zp(r) || rField_is_Q(r))
309  {
310  Variable X(i);
311  setCharacteristic( rChar(r) );
313  res=convFactoryPSingP( resultant( F, G, X),r );
314  Off(SW_RATIONAL);
315  goto resultant_returns_res;
316  }
317  // and over Q(a) / Fp(a)
318  else if (r->cf->extRing!=NULL)
319  {
320  if (rField_is_Q_a(r)) setCharacteristic( 0 );
321  else setCharacteristic( rChar(r) );
322  Variable X(i+rPar(r));
323  if (r->cf->extRing->qideal!=NULL)
324  {
325  //Variable X(i);
326  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
327  r->cf->extRing);
328  Variable a=rootOf(mipo);
329  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
330  G( convSingAPFactoryAP( g,a,r ) );
331  res= convFactoryAPSingAP( resultant( F, G, X ),r );
332  prune (a);
333  }
334  else
335  {
336  //Variable X(i+rPar(currRing));
337  number nf,ng;
339  int ef,eg;
340  ef=pGetExp_Var(f,i,r);
341  eg=pGetExp_Var(g,i,r);
343  res= convFactoryPSingTrP( resultant( F, G, X ),r );
344  if ((nf!=NULL)&&(!n_IsOne(nf,r->cf)))
345  {
346  number n=n_Invers(nf,r->cf);
347  while(eg>0)
348  {
349  res=__p_Mult_nn(res,n,r);
350  eg--;
351  }
352  n_Delete(&n,r->cf);
353  }
354  n_Delete(&nf,r->cf);
355  if ((ng!=NULL)&&(!n_IsOne(ng,r->cf)))
356  {
357  number n=n_Invers(ng,r->cf);
358  while(ef>0)
359  {
360  res=__p_Mult_nn(res,n,r);
361  ef--;
362  }
363  n_Delete(&n,r->cf);
364  }
365  n_Delete(&ng,r->cf);
366  }
367  Off(SW_RATIONAL);
368  goto resultant_returns_res;
369  }
370  else
372 resultant_returns_res:
373  p_Delete(&f,r);
374  p_Delete(&g,r);
375  p_Delete(&x,r);
376  return res;
377 }
378 //poly singclap_resultant ( poly f, poly g , poly x)
379 //{
380 // int i=pVar(x);
381 // if (i==0)
382 // {
383 // WerrorS("ringvar expected");
384 // return NULL;
385 // }
386 // ideal I=idInit(1,1);
387 //
388 // // get the coeffs von f wrt. x:
389 // I->m[0]=pCopy(f);
390 // matrix ffi=mpCoeffs(I,i);
391 // ffi->rank=1;
392 // ffi->ncols=ffi->nrows;
393 // ffi->nrows=1;
394 // ideal fi=(ideal)ffi;
395 //
396 // // get the coeffs von g wrt. x:
397 // I->m[0]=pCopy(g);
398 // matrix ggi=mpCoeffs(I,i);
399 // ggi->rank=1;
400 // ggi->ncols=ggi->nrows;
401 // ggi->nrows=1;
402 // ideal gi=(ideal)ggi;
403 //
404 // // contruct the matrix:
405 // int fn=IDELEMS(fi); //= deg(f,x)+1
406 // int gn=IDELEMS(gi); //= deg(g,x)+1
407 // matrix m=mpNew(fn+gn-2,fn+gn-2);
408 // if(m==NULL)
409 // {
410 // return NULL;
411 // }
412 //
413 // // enter the coeffs into m:
414 // int j;
415 // for(i=0;i<gn-1;i++)
416 // {
417 // for(j=0;j<fn;j++)
418 // {
419 // MATELEM(m,i+1,fn-j+i)=pCopy(fi->m[j]);
420 // }
421 // }
422 // for(i=0;i<fn-1;i++)
423 // {
424 // for(j=0;j<gn;j++)
425 // {
426 // MATELEM(m,gn+i,gn-j+i)=pCopy(gi->m[j]);
427 // }
428 // }
429 //
430 // poly r=mpDet(m);
431 //
432 // idDelete(&fi);
433 // idDelete(&gi);
434 // idDelete((ideal *)&m);
435 // return r;
436 //}
437 
438 BOOLEAN singclap_extgcd ( poly f, poly g, poly &res, poly &pa, poly &pb , const ring r)
439 {
440  // for now there is only the possibility to handle univariate
441  // polynomials over
442  // Q and Fp ...
443  res=NULL;pa=NULL;pb=NULL;
445  if ( rField_is_Q(r) || rField_is_Zp(r) )
446  {
447  setCharacteristic( rChar(r) );
449  CanonicalForm FpG=F+G;
450  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
451  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
452  {
453  Off(SW_RATIONAL);
454  WerrorS("not univariate");
455  return TRUE;
456  }
457  CanonicalForm Fa,Gb;
458  On(SW_RATIONAL);
459  res=convFactoryPSingP( extgcd( F, G, Fa, Gb ),r );
460  pa=convFactoryPSingP(Fa,r);
461  pb=convFactoryPSingP(Gb,r);
462  Off(SW_RATIONAL);
463  }
464  // and over Q(a) / Fp(a)
465  else if ( r->cf->extRing!=NULL )
466  {
467  if (rField_is_Q_a(r)) setCharacteristic( 0 );
468  else setCharacteristic( rChar(r) );
469  CanonicalForm Fa,Gb;
470  if (r->cf->extRing->qideal!=NULL)
471  {
472  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
473  r->cf->extRing);
474  Variable a=rootOf(mipo);
475  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
476  G( convSingAPFactoryAP( g,a,r ) );
477  CanonicalForm FpG=F+G;
478  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
479  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
480  {
481  WerrorS("not univariate");
482  return TRUE;
483  }
484  res= convFactoryAPSingAP( extgcd( F, G, Fa, Gb ),r );
485  pa=convFactoryAPSingAP(Fa,r);
486  pb=convFactoryAPSingAP(Gb,r);
487  prune (a);
488  }
489  else
490  {
492  CanonicalForm FpG=F+G;
493  if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
494  //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
495  {
496  Off(SW_RATIONAL);
497  WerrorS("not univariate");
498  return TRUE;
499  }
500  res= convFactoryPSingTrP( extgcd( F, G, Fa, Gb ), r );
501  pa=convFactoryPSingTrP(Fa, r);
502  pb=convFactoryPSingTrP(Gb, r);
503  }
504  Off(SW_RATIONAL);
505  }
506  else
507  {
509  return TRUE;
510  }
511 #ifndef SING_NDEBUG
512  // checking the result of extgcd:
513  poly dummy;
514  dummy=p_Sub(p_Add_q(pp_Mult_qq(f,pa,r),pp_Mult_qq(g,pb,r),r),p_Copy(res,r),r);
515  if (dummy!=NULL)
516  {
517  PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
518  PrintS("extgcd( ");p_Write(f,r);p_Write0(g,r);PrintS(" )\n");
519  p_Delete(&dummy,r);
520  }
521 #endif
522  return FALSE;
523 }
524 
525 poly singclap_pmult ( poly f, poly g, const ring r )
526 {
527  poly res=NULL;
528  On(SW_RATIONAL);
529  if (rField_is_Zp(r) || rField_is_Q(r))
530  {
531  setCharacteristic( rChar(r) );
533  res = convFactoryPSingP( F * G,r );
534  }
535  else if (rField_is_Ring_Z(r))
536  {
537  Off(SW_RATIONAL);
538  setCharacteristic( rChar(r) );
540  res = convFactoryPSingP( F * G,r );
541  }
542  else if (r->cf->extRing!=NULL)
543  {
544  if (rField_is_Q_a(r)) setCharacteristic( 0 );
545  else setCharacteristic( rChar(r) );
546  if (r->cf->extRing->qideal!=NULL)
547  {
548  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
549  r->cf->extRing);
550  Variable a=rootOf(mipo);
551  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
552  G( convSingAPFactoryAP( g,a,r ) );
553  res= convFactoryAPSingAP( F * G, r );
554  prune (a);
555  }
556  else
557  {
559  res= convFactoryPSingTrP( F * G,r );
560  }
561  }
562 #if 0 // not yet working
563  else if (rField_is_GF())
564  {
565  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
566  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
567  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
568  res = convFactoryGFSingGF( F * G );
569  }
570 #endif
571  else
573  Off(SW_RATIONAL);
574  return res;
575 }
576 
577 poly singclap_pdivide ( poly f, poly g, const ring r )
578 {
579  poly res=NULL;
580  On(SW_RATIONAL);
581  if (rField_is_Zp(r) || rField_is_Q(r))
582  {
583  setCharacteristic( rChar(r) );
585  res = convFactoryPSingP( F / G,r );
586  }
587  // div is not implemented for ZZ coeffs in factory
588  else if (r->cf->extRing!=NULL)
589  {
590  if (rField_is_Q_a(r)) setCharacteristic( 0 );
591  else setCharacteristic( rChar(r) );
592  if (r->cf->extRing->qideal!=NULL)
593  {
594  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
595  r->cf->extRing);
596  Variable a=rootOf(mipo);
597  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
598  G( convSingAPFactoryAP( g,a,r ) );
599  res= convFactoryAPSingAP( F / G, r );
600  prune (a);
601  }
602  else
603  {
605  res= convFactoryPSingTrP( F / G,r );
606  }
607  }
608 #if 0 // not yet working
609  else if (rField_is_GF())
610  {
611  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
612  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
613  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
614  res = convFactoryGFSingGF( F / G );
615  }
616 #endif
617  else
619  Off(SW_RATIONAL);
620  return res;
621 }
622 
623 poly singclap_pmod ( poly f, poly g, const ring r )
624 {
625  poly res=NULL;
626  On(SW_RATIONAL);
627  if (rField_is_Zp(r) || rField_is_Q(r))
628  {
629  setCharacteristic( rChar(r) );
631  res = convFactoryPSingP( F % G,r );
632  }
633  // mod is not implemented for ZZ coeffs in factory
634  else if (r->cf->extRing!=NULL)
635  {
636  if (rField_is_Q_a(r)) setCharacteristic( 0 );
637  else setCharacteristic( rChar(r) );
638  if (r->cf->extRing->qideal!=NULL)
639  {
640  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
641  r->cf->extRing);
642  Variable a=rootOf(mipo);
643  CanonicalForm F( convSingAPFactoryAP( f,a,r ) ),
644  G( convSingAPFactoryAP( g,a,r ) );
645  res= convFactoryAPSingAP( F % G, r );
646  prune (a);
647  }
648  else
649  {
651  res= convFactoryPSingTrP( F % G,r );
652  }
653  }
654 #if 0 // not yet working
655  else if (rField_is_GF())
656  {
657  //Print("GF(%d^%d)\n",nfCharP,nfMinPoly[0]);
658  setCharacteristic( nfCharP,nfMinPoly[0], currRing->parameter[0][0] );
659  CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
660  res = convFactoryGFSingGF( F / G );
661  }
662 #endif
663  else
665  Off(SW_RATIONAL);
666  return res;
667 }
668 
669 void singclap_divide_content ( poly f, const ring r )
670 {
671  if ( f==NULL )
672  {
673  return;
674  }
675  else if ( pNext( f ) == NULL )
676  {
677  p_SetCoeff( f, n_Init( 1, r->cf ), r );
678  return;
679  }
680  else
681  {
682  if ( rField_is_Q_a(r) )
683  setCharacteristic( 0 );
684  else if ( rField_is_Zp_a(r) )
685  setCharacteristic( -rChar(r) );
686  else
687  return; /* not implemented*/
688 
689  CFList L;
690  CanonicalForm g, h;
691  poly p = pNext(f);
692 
693  // first attemp: find 2 smallest g:
694 
695  number g1=pGetCoeff(f);
696  number g2=pGetCoeff(p); // p==pNext(f);
697  pIter(p);
698  int sz1=n_Size(g1, r->cf);
699  int sz2=n_Size(g2, r->cf);
700  if (sz1>sz2)
701  {
702  number gg=g1;
703  g1=g2; g2=gg;
704  int sz=sz1;
705  sz1=sz2; sz2=sz;
706  }
707  while (p!=NULL)
708  {
709  int n_sz=n_Size(pGetCoeff(p),r->cf);
710  if (n_sz<sz1)
711  {
712  sz2=sz1;
713  g2=g1;
714  g1=pGetCoeff(p);
715  sz1=n_sz;
716  if (sz1<=3) break;
717  }
718  else if(n_sz<sz2)
719  {
720  sz2=n_sz;
721  g2=pGetCoeff(p);
722  sz2=n_sz;
723  }
724  pIter(p);
725  }
726  g = convSingPFactoryP( NUM(((fraction)g1)), r->cf->extRing );
727  g = gcd( g, convSingPFactoryP( NUM(((fraction)g2)) , r->cf->extRing));
728 
729  // second run: gcd's
730 
731  p = f;
732  while ( (p != NULL) && (g != 1) && ( g != 0))
733  {
734  h = convSingPFactoryP( NUM(((fraction)pGetCoeff(p))), r->cf->extRing );
735  pIter( p );
736 
737  g = gcd( g, h );
738 
739  L.append( h );
740  }
741  if (( g == 1 ) || (g == 0))
742  {
743  // pTest(f);
744  return;
745  }
746  else
747  {
749  for ( i = L, p = f; i.hasItem(); i++, p=pNext(p) )
750  {
751  fraction c=(fraction)pGetCoeff(p);
752  p_Delete(&(NUM(c)),r->cf->extRing); // 2nd arg used to be nacRing
753  NUM(c)=convFactoryPSingP( i.getItem() / g, r->cf->extRing );
754  //nTest((number)c);
755  //#ifdef LDEBUG
756  //number cn=(number)c;
757  //StringSetS(""); nWrite(nt); StringAppend(" ==> ");
758  //nWrite(cn);PrintS(StringEndS("\n")); // NOTE/TODO: use StringAppendS("\n"); omFree(s);
759  //#endif
760  }
761  }
762  // pTest(f);
763  }
764 }
765 
766 BOOLEAN count_Factors(ideal I, intvec *v,int j, poly &f, poly fac, const ring r)
767 {
768  p_Test(f,r);
769  p_Test(fac,r);
770  int e=0;
771  if (!p_IsConstantPoly(fac,r))
772  {
773 #ifdef FACTORIZE2_DEBUG
774  printf("start count_Factors(%d), Fdeg=%d, factor deg=%d\n",j,p_Totaldegree(f,r),p_Totaldegree(fac,r));
775  p_wrp(fac,r);PrintLn();
776 #endif
777  On(SW_RATIONAL);
778  CanonicalForm F, FAC,Q,R;
779  Variable a;
780  if (rField_is_Zp(r) || rField_is_Q(r))
781  {
782  F=convSingPFactoryP( f,r );
783  FAC=convSingPFactoryP( fac,r );
784  }
785  else if (r->cf->extRing!=NULL)
786  {
787  if (r->cf->extRing->qideal!=NULL)
788  {
789  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
790  r->cf->extRing);
791  a=rootOf(mipo);
792  F=convSingAPFactoryAP( f,a,r );
793  FAC=convSingAPFactoryAP( fac,a,r );
794  }
795  else
796  {
797  F=convSingTrPFactoryP( f,r );
798  FAC=convSingTrPFactoryP( fac,r );
799  }
800  }
801  else
803 
804  poly q;
805  loop
806  {
807  Q=F;
808  Q/=FAC;
809  R=Q;
810  R*=FAC;
811  R-=F;
812  if (R.isZero())
813  {
814  if (rField_is_Zp(r) || rField_is_Q(r))
815  {
816  q = convFactoryPSingP( Q,r );
817  }
818  else if (r->cf->extRing!=NULL)
819  {
820  if (r->cf->extRing->qideal!=NULL)
821  {
822  q= convFactoryAPSingAP( Q,r );
823  }
824  else
825  {
826  q= convFactoryPSingTrP( Q,r );
827  }
828  }
829  e++; p_Delete(&f,r); f=q; q=NULL; F=Q;
830  }
831  else
832  {
833  break;
834  }
835  }
836  if (r->cf->extRing!=NULL)
837  if (r->cf->extRing->qideal!=NULL)
838  prune (a);
839  if (e==0)
840  {
841  Off(SW_RATIONAL);
842  return FALSE;
843  }
844  }
845  else e=1;
846  I->m[j]=fac;
847  if (v!=NULL) (*v)[j]=e;
848  Off(SW_RATIONAL);
849  return TRUE;
850 }
851 
853 
854 ideal singclap_factorize ( poly f, intvec ** v , int with_exps, const ring r)
855 /* destroys f, sets *v */
856 {
857  p_Test(f,r);
858 #ifdef FACTORIZE2_DEBUG
859  printf("singclap_factorize, degree %ld\n",p_Totaldegree(f,r));
860 #endif
861  // with_exps: 3,1 return only true factors, no exponents
862  // 2 return true factors and exponents
863  // 0 return coeff, factors and exponents
864  BOOLEAN save_errorreported=errorreported;
865 
866  ideal res=NULL;
867 
868  // handle factorize(0) =========================================
869  if (f==NULL)
870  {
871  res=idInit(1,1);
872  if (with_exps!=1)
873  {
874  (*v)=new intvec(1);
875  (**v)[0]=1;
876  }
877  return res;
878  }
879  // handle factorize(mon) =========================================
880  if (pNext(f)==NULL)
881  {
882  int i=0;
883  int n=0;
884  int e;
885  for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
886  if (with_exps==0) n++; // with coeff
887  res=idInit(si_max(n,1),1);
888  switch(with_exps)
889  {
890  case 0: // with coef & exp.
891  res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
892  // no break
893  case 2: // with exp.
894  (*v)=new intvec(si_max(1,n));
895  (**v)[0]=1;
896  // no break
897  case 1: ;
898 #ifdef TEST
899  default: ;
900 #endif
901  }
902  if (n==0)
903  {
904  res->m[0]=p_One(r);
905  // (**v)[0]=1; is already done
906  }
907  else
908  {
909  for(i=rVar(r);i>0;i--)
910  {
911  e=p_GetExp(f,i,r);
912  if(e!=0)
913  {
914  n--;
915  poly p=p_One(r);
916  p_SetExp(p,i,1,r);
917  p_Setm(p,r);
918  res->m[n]=p;
919  if (with_exps!=1) (**v)[n]=e;
920  }
921  }
922  }
923  p_Delete(&f,r);
924  return res;
925  }
926  //PrintS("S:");p_Write(f,r);PrintLn();
927  // use factory/libfac in general ==============================
928  Off(SW_RATIONAL);
930  CFFList L;
931  number N=NULL;
932  number NN=NULL;
933  number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
934 
935  Variable a;
936  if (!rField_is_Zp(r) && !rField_is_Zp_a(r) && !rField_is_Z(r)) /* Q, Q(a) */
937  {
938  //if (f!=NULL) // already tested at start of routine
939  {
940  number n0=n_Copy(pGetCoeff(f),r->cf);
941  if (with_exps==0)
942  N=n_Copy(n0,r->cf);
943  p_Cleardenom(f, r);
944  //after here f should not have a denominator!!
945  //PrintS("S:");p_Write(f,r);PrintLn();
946  NN=n_Div(n0,pGetCoeff(f),r->cf);
947  n_Delete(&n0,r->cf);
948  if (with_exps==0)
949  {
950  n_Delete(&N,r->cf);
951  N=n_Copy(NN,r->cf);
952  }
953  }
954  }
955  else if (rField_is_Zp_a(r))
956  {
957  //if (f!=NULL) // already tested at start of routine
959  {
960  number n0=n_Copy(pGetCoeff(f),r->cf);
961  if (with_exps==0)
962  N=n_Copy(n0,r->cf);
963  p_Norm(f,r);
964  p_Cleardenom(f, r);
965  NN=n_Div(n0,pGetCoeff(f),r->cf);
966  n_Delete(&n0,r->cf);
967  if (with_exps==0)
968  {
969  n_Delete(&N,r->cf);
970  N=n_Copy(NN,r->cf);
971  }
972  }
973  }
974  if (rField_is_Q(r) || rField_is_Zp(r) || (rField_is_Z(r)))
975  {
976  setCharacteristic( rChar(r) );
978  L = factorize( F );
979  }
980  // and over Q(a) / Fp(a)
981  else if (r->cf->extRing!=NULL)
982  {
983  if (rField_is_Q_a (r)) setCharacteristic (0);
984  else setCharacteristic( rChar(r) );
985  if (r->cf->extRing->qideal!=NULL)
986  {
987  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
988  r->cf->extRing);
989  a=rootOf(mipo);
990  CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
991  if (rField_is_Zp_a(r))
992  {
993  L = factorize( F, a );
994  }
995  else
996  {
997  // over Q(a)
998  L= factorize (F, a);
999  }
1000  }
1001  else
1002  {
1004  L = factorize( F );
1005  }
1006  }
1007  else
1008  {
1009  goto notImpl;
1010  }
1011  {
1012  poly ff=p_Copy(f,r); // a copy for the retry stuff
1013  // the first factor should be a constant
1014  if ( ! L.getFirst().factor().inCoeffDomain() )
1015  L.insert(CFFactor(1,1));
1016  // convert into ideal
1017  int n = L.length();
1018  if (n==0) n=1;
1019  CFFListIterator J=L;
1020  int j=0;
1021  if (with_exps!=1)
1022  {
1023  if ((with_exps==2)&&(n>1))
1024  {
1025  n--;
1026  J++;
1027  }
1028  *v = new intvec( n );
1029  }
1030  res = idInit( n ,1);
1031  for ( ; J.hasItem(); J++, j++ )
1032  {
1033  if (with_exps!=1) (**v)[j] = J.getItem().exp();
1034  if (rField_is_Zp(r) || rField_is_Q(r)|| rField_is_Z(r)) /* Q, Fp, Z */
1035  {
1036  //count_Factors(res,*v,f, j, convFactoryPSingP( J.getItem().factor() );
1037  res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1038  }
1039 #if 0
1040  else if (rField_is_GF())
1041  res->m[j] = convFactoryGFSingGF( J.getItem().factor() );
1042 #endif
1043  else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1044  {
1045 #ifndef SING_NDEBUG
1046  intvec *w=NULL;
1047  if (v!=NULL) w=*v;
1048 #endif
1049  if (r->cf->extRing->qideal==NULL)
1050  {
1051 #ifdef SING_NDEBUG
1052  res->m[j]= convFactoryPSingTrP( J.getItem().factor(),r );
1053 #else
1054  if(!count_Factors(res,w,j,ff,convFactoryPSingTrP( J.getItem().factor(),r ),r))
1055  {
1056  if (w!=NULL)
1057  (*w)[j]=1;
1058  res->m[j]=p_One(r);
1059  }
1060 #endif
1061  }
1062  else
1063  {
1064 #ifdef SING_NDEBUG
1065  res->m[j]= convFactoryAPSingAP( J.getItem().factor(),r );
1066 #else
1067  if (!count_Factors(res,w,j,ff,convFactoryAPSingAP( J.getItem().factor(),r ),r))
1068  {
1069  if (w!=NULL)
1070  (*w)[j]=1;
1071  res->m[j]=p_One(r);
1072  }
1073 #endif
1074  }
1075  }
1076  }
1077  if (r->cf->extRing!=NULL)
1078  if (r->cf->extRing->qideal!=NULL)
1079  prune (a);
1080 #ifndef SING_NDEBUG
1081  if ((r->cf->extRing!=NULL) && (!p_IsConstantPoly(ff,r)))
1082  {
1085  {
1086  int jj;
1087 #ifdef FACTORIZE2_DEBUG
1088  printf("factorize_retry\n");
1089 #endif
1090  intvec *ww=NULL;
1091  id_Test(res,r);
1092  ideal h=singclap_factorize ( ff, &ww , with_exps, r );
1093  id_Test(h,r);
1094  int l=(*v)->length();
1095  (*v)->resize(l+ww->length());
1096  for(jj=0;jj<ww->length();jj++)
1097  (**v)[jj+l]=(*ww)[jj];
1098  delete ww;
1099  ideal hh=idInit(IDELEMS(res)+IDELEMS(h),1);
1100  for(jj=IDELEMS(res)-1;jj>=0;jj--)
1101  {
1102  hh->m[jj]=res->m[jj];
1103  res->m[jj]=NULL;
1104  }
1105  for(jj=IDELEMS(h)-1;jj>=0;jj--)
1106  {
1107  hh->m[jj+IDELEMS(res)]=h->m[jj];
1108  h->m[jj]=NULL;
1109  }
1110  id_Delete(&res,r);
1111  id_Delete(&h,r);
1112  res=hh;
1113  id_Test(res,r);
1114  ff=NULL;
1115  }
1116  else
1117  {
1118  WarnS("problem with factorize");
1119 #if 0
1120  pWrite(ff);
1121  idShow(res);
1122 #endif
1123  id_Delete(&res,r);
1124  res=idInit(2,1);
1125  res->m[0]=p_One(r);
1126  res->m[1]=ff; ff=NULL;
1127  }
1128  }
1129 #endif
1130  p_Delete(&ff,r);
1131  if (N!=NULL)
1132  {
1133  __p_Mult_nn(res->m[0],N,r);
1134  n_Delete(&N,r->cf);
1135  N=NULL;
1136  }
1137  // delete constants
1138  if (res!=NULL)
1139  {
1140  int i=IDELEMS(res)-1;
1141  int j=0;
1142  for(;i>=0;i--)
1143  {
1144  if ((res->m[i]!=NULL)
1145  && (pNext(res->m[i])==NULL)
1146  && (p_IsConstant(res->m[i],r)))
1147  {
1148  if (with_exps!=0)
1149  {
1150  p_Delete(&(res->m[i]),r);
1151  if ((v!=NULL) && ((*v)!=NULL))
1152  (**v)[i]=0;
1153  j++;
1154  }
1155  else if (i!=0)
1156  {
1157  while ((v!=NULL) && ((*v)!=NULL) && ((**v)[i]>1))
1158  {
1159  res->m[0]=p_Mult_q(res->m[0],p_Copy(res->m[i],r),r);
1160  (**v)[i]--;
1161  }
1162  res->m[0]=p_Mult_q(res->m[0],res->m[i],r);
1163  res->m[i]=NULL;
1164  if ((v!=NULL) && ((*v)!=NULL))
1165  (**v)[i]=1;
1166  j++;
1167  }
1168  }
1169  }
1170  if (j>0)
1171  {
1172  idSkipZeroes(res);
1173  if ((v!=NULL) && ((*v)!=NULL))
1174  {
1175  intvec *w=*v;
1176  int len=IDELEMS(res);
1177  *v = new intvec( len );
1178  for (i=0,j=0;i<si_min(w->length(),len);i++)
1179  {
1180  if((*w)[i]!=0)
1181  {
1182  (**v)[j]=(*w)[i]; j++;
1183  }
1184  }
1185  delete w;
1186  }
1187  }
1188  if (res->m[0]==NULL)
1189  {
1190  res->m[0]=p_One(r);
1191  }
1192  }
1193  }
1194  if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1195  {
1196  int i=IDELEMS(res)-1;
1197  int stop=1;
1198  if (with_exps!=0) stop=0;
1199  for(;i>=stop;i--)
1200  {
1201  p_Norm(res->m[i],r);
1202  }
1203  if (with_exps==0) p_SetCoeff(res->m[0],old_lead_coeff,r);
1204  else n_Delete(&old_lead_coeff,r->cf);
1205  }
1206  else
1207  n_Delete(&old_lead_coeff,r->cf);
1208  errorreported=save_errorreported;
1209 notImpl:
1210  if (res==NULL)
1212  if (NN!=NULL)
1213  {
1214  n_Delete(&NN,r->cf);
1215  }
1216  if (N!=NULL)
1217  {
1218  n_Delete(&N,r->cf);
1219  }
1220  if (f!=NULL) p_Delete(&f,r);
1221  //PrintS("......S\n");
1222  return res;
1223 }
1224 
1225 ideal singclap_sqrfree ( poly f, intvec ** v , int with_exps, const ring r)
1226 {
1227  p_Test(f,r);
1228 #ifdef FACTORIZE2_DEBUG
1229  printf("singclap_sqrfree, degree %d\n",pTotaldegree(f));
1230 #endif
1231  // with_exps: 3,1 return only true factors, no exponents
1232  // 2 return true factors and exponents
1233  // 0 return coeff, factors and exponents
1234  BOOLEAN save_errorreported=errorreported;
1235 
1236  ideal res=NULL;
1237 
1238  // handle factorize(0) =========================================
1239  if (f==NULL)
1240  {
1241  res=idInit(1,1);
1242  if (with_exps!=1 && with_exps!=3)
1243  {
1244  (*v)=new intvec(1);
1245  (**v)[0]=1;
1246  }
1247  return res;
1248  }
1249  // handle factorize(mon) =========================================
1250  if (pNext(f)==NULL)
1251  {
1252  int i=0;
1253  int n=0;
1254  int e;
1255  for(i=rVar(r);i>0;i--) if(p_GetExp(f,i,r)!=0) n++;
1256  if (with_exps==0 || with_exps==3) n++; // with coeff
1257  res=idInit(si_max(n,1),1);
1258  if(with_exps!=1)
1259  {
1260  (*v)=new intvec(si_max(1,n));
1261  (**v)[0]=1;
1262  }
1263  res->m[0]=p_NSet(n_Copy(pGetCoeff(f),r->cf),r);
1264  if (n==0)
1265  {
1266  res->m[0]=p_One(r);
1267  // (**v)[0]=1; is already done
1268  }
1269  else
1270  {
1271  for(i=rVar(r);i>0;i--)
1272  {
1273  e=p_GetExp(f,i,r);
1274  if(e!=0)
1275  {
1276  n--;
1277  poly p=p_One(r);
1278  p_SetExp(p,i,1,r);
1279  p_Setm(p,r);
1280  res->m[n]=p;
1281  if (with_exps!=1) (**v)[n]=e;
1282  }
1283  }
1284  }
1285  p_Delete(&f,r);
1286  return res;
1287  }
1288  //PrintS("S:");pWrite(f);PrintLn();
1289  // use factory/libfac in general ==============================
1290  Off(SW_RATIONAL);
1292  CFFList L;
1293  number N=NULL;
1294  number NN=NULL;
1295  number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf);
1296  Variable a;
1297 
1298  if (!rField_is_Zp(r) && !rField_is_Zp_a(r)) /* Q, Q(a) */
1299  {
1300  //if (f!=NULL) // already tested at start of routine
1301  number n0=n_Copy(pGetCoeff(f),r->cf);
1302  if (with_exps==0 || with_exps==3)
1303  N=n_Copy(n0,r->cf);
1304  p_Cleardenom(f, r);
1305  //after here f should not have a denominator!!
1306  //PrintS("S:");p_Write(f,r);PrintLn();
1307  NN=n_Div(n0,pGetCoeff(f),r->cf);
1308  n_Delete(&n0,r->cf);
1309  if (with_exps==0 || with_exps==3)
1310  {
1311  n_Delete(&N,r->cf);
1312  N=n_Copy(NN,r->cf);
1313  }
1314  }
1315  else if (rField_is_Zp_a(r))
1316  {
1317  //if (f!=NULL) // already tested at start of routine
1318  if (singclap_factorize_retry==0)
1319  {
1320  number n0=n_Copy(pGetCoeff(f),r->cf);
1321  if (with_exps==0 || with_exps==3)
1322  N=n_Copy(n0,r->cf);
1323  p_Norm(f,r);
1324  p_Cleardenom(f, r);
1325  NN=n_Div(n0,pGetCoeff(f),r->cf);
1326  n_Delete(&n0,r->cf);
1327  if (with_exps==0 || with_exps==3)
1328  {
1329  n_Delete(&N,r->cf);
1330  N=n_Copy(NN,r->cf);
1331  }
1332  }
1333  }
1334  if (rField_is_Q(r) || rField_is_Zp(r))
1335  {
1336  setCharacteristic( rChar(r) );
1337  CanonicalForm F( convSingPFactoryP( f,r ) );
1338  L = sqrFree( F );
1339  }
1340  else if (r->cf->extRing!=NULL)
1341  {
1342  if (rField_is_Q_a (r)) setCharacteristic (0);
1343  else setCharacteristic( rChar(r) );
1344  if (r->cf->extRing->qideal!=NULL)
1345  {
1346  CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0],
1347  r->cf->extRing);
1348  a=rootOf(mipo);
1349  CanonicalForm F( convSingAPFactoryAP( f, a, r ) );
1350  L= sqrFree (F);
1351  }
1352  else
1353  {
1355  L = sqrFree( F );
1356  }
1357  }
1358  #if 0
1359  else if (rField_is_GF())
1360  {
1361  int c=rChar(r);
1362  setCharacteristic( c, primepower(c) );
1363  CanonicalForm F( convSingGFFactoryGF( f ) );
1364  if (F.isUnivariate())
1365  {
1366  L = factorize( F );
1367  }
1368  else
1369  {
1370  goto notImpl;
1371  }
1372  }
1373  #endif
1374  else
1375  {
1376  goto notImpl;
1377  }
1378  {
1379  // convert into ideal
1380  int n = L.length();
1381  if (n==0) n=1;
1382  CFFListIterator J=L;
1383  int j=0;
1384  if (with_exps!=1)
1385  {
1386  if ((with_exps==2)&&(n>1))
1387  {
1388  n--;
1389  J++;
1390  }
1391  *v = new intvec( n );
1392  }
1393  else if (L.getFirst().factor().inCoeffDomain() && with_exps!=3)
1394  {
1395  n--;
1396  J++;
1397  }
1398  res = idInit( n ,1);
1399  for ( ; J.hasItem(); J++, j++ )
1400  {
1401  if (with_exps!=1 && with_exps!=3) (**v)[j] = J.getItem().exp();
1402  if (rField_is_Zp(r) || rField_is_Q(r))
1403  res->m[j] = convFactoryPSingP( J.getItem().factor(),r );
1404  else if (r->cf->extRing!=NULL) /* Q(a), Fp(a) */
1405  {
1406  if (r->cf->extRing->qideal==NULL)
1407  res->m[j]=convFactoryPSingTrP( J.getItem().factor(),r );
1408  else
1409  res->m[j]=convFactoryAPSingAP( J.getItem().factor(),r );
1410  }
1411  }
1412  if (res->m[0]==NULL)
1413  {
1414  res->m[0]=p_One(r);
1415  }
1416  if (N!=NULL)
1417  {
1418  __p_Mult_nn(res->m[0],N,r);
1419  n_Delete(&N,r->cf);
1420  N=NULL;
1421  }
1422  }
1423  if (r->cf->extRing!=NULL)
1424  if (r->cf->extRing->qideal!=NULL)
1425  prune (a);
1426  if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL))
1427  {
1428  int i=IDELEMS(res)-1;
1429  int stop=1;
1430  if (with_exps!=0 || with_exps==3) stop=0;
1431  for(;i>=stop;i--)
1432  {
1433  p_Norm(res->m[i],r);
1434  }
1435  if (with_exps==0 || with_exps==3) p_SetCoeff(res->m[0],old_lead_coeff,r);
1436  else n_Delete(&old_lead_coeff,r->cf);
1437  }
1438  else
1439  n_Delete(&old_lead_coeff,r->cf);
1440  p_Delete(&f,r);
1441  errorreported=save_errorreported;
1442 notImpl:
1443  if (res==NULL)
1445  if (NN!=NULL)
1446  {
1447  n_Delete(&NN,r->cf);
1448  }
1449  if (N!=NULL)
1450  {
1451  n_Delete(&N,r->cf);
1452  }
1453  return res;
1454 }
1455 
1456 matrix singclap_irrCharSeries ( ideal I, const ring r)
1457 {
1458  if (idIs0(I)) return mpNew(1,1);
1459 
1460  // for now there is only the possibility to handle polynomials over
1461  // Q and Fp ...
1462  matrix res=NULL;
1463  int i;
1464  Off(SW_RATIONAL);
1466  CFList L;
1467  ListCFList LL;
1468  if (rField_is_Q(r) || rField_is_Zp(r))
1469  {
1470  setCharacteristic( rChar(r) );
1471  for(i=0;i<IDELEMS(I);i++)
1472  {
1473  poly p=I->m[i];
1474  if (p!=NULL)
1475  {
1476  p=p_Copy(p,r);
1477  p_Cleardenom(p, r);
1478  L.append(convSingPFactoryP(p,r));
1479  p_Delete(&p,r);
1480  }
1481  }
1482  }
1483  // and over Q(a) / Fp(a)
1484  else if (nCoeff_is_transExt (r->cf))
1485  {
1486  setCharacteristic( rChar(r) );
1487  for(i=0;i<IDELEMS(I);i++)
1488  {
1489  poly p=I->m[i];
1490  if (p!=NULL)
1491  {
1492  p=p_Copy(p,r);
1493  p_Cleardenom(p, r);
1495  p_Delete(&p,r);
1496  }
1497  }
1498  }
1499  else
1500  {
1502  return res;
1503  }
1504 
1505  // a very bad work-around --- FIX IT in libfac
1506  // should be fixed as of 2001/6/27
1507  int tries=0;
1508  int m,n;
1510  loop
1511  {
1512  LL=irrCharSeries(L);
1513  m= LL.length(); // Anzahl Zeilen
1514  n=0;
1515  for ( LLi = LL; LLi.hasItem(); LLi++ )
1516  {
1517  n = si_max(LLi.getItem().length(),n);
1518  }
1519  if ((m!=0) && (n!=0)) break;
1520  tries++;
1521  if (tries>=5) break;
1522  }
1523  if ((m==0) || (n==0))
1524  {
1525  Warn("char_series returns %d x %d matrix from %d input polys (%d)",
1526  m,n,IDELEMS(I)+1,LL.length());
1527  iiWriteMatrix((matrix)I,"I",2,r,0);
1528  m=si_max(m,1);
1529  n=si_max(n,1);
1530  }
1531  res=mpNew(m,n);
1532  CFListIterator Li;
1533  for ( m=1, LLi = LL; LLi.hasItem(); LLi++, m++ )
1534  {
1535  for (n=1, Li = LLi.getItem(); Li.hasItem(); Li++, n++)
1536  {
1537  if (rField_is_Q(r) || rField_is_Zp(r))
1538  MATELEM(res,m,n)=convFactoryPSingP(Li.getItem(),r);
1539  else
1541  }
1542  }
1543  Off(SW_RATIONAL);
1544  return res;
1545 }
1546 
1547 char* singclap_neworder ( ideal I, const ring r)
1548 {
1549  int i;
1550  Off(SW_RATIONAL);
1552  CFList L;
1553  if (rField_is_Q(r) || rField_is_Zp(r))
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 }
1638 
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 }
1661 
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 }
1679 
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=mp_New(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 }
1734 
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 }
1765 
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 }
1796 
1797 matrix singntl_LLL(matrix m, const ring s )
1798 {
1799  int r=m->rows();
1800  int c=m->cols();
1801  matrix res=mp_New(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 }
1825 
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 }
1852 
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:139
FALSE
#define FALSE
Definition: auxiliary.h:94
omalloc.h
SW_RATIONAL
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
ip_smatrix
Definition: matpol.h:14
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:469
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:51
singclap_gcd
poly singclap_gcd(poly f, poly g, const ring r)
destroys f and g
Definition: clapsing.cc:255
singclap_divide_content
void singclap_divide_content(poly f, const ring r)
Definition: clapsing.cc:669
singclap_det
poly singclap_det(const matrix m, const ring s)
Definition: clapsing.cc:1639
singclap_factorize
ideal singclap_factorize(poly f, intvec **v, int with_exps, const ring r)
Definition: clapsing.cc:854
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:577
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:456
convFactoryAPSingAP
poly convFactoryAPSingAP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:153
p_Test
#define p_Test(p, r)
Definition: p_polys.h:163
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:521
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:469
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:927
bigintmat.h
convSingAPFactoryAP
CanonicalForm convSingAPFactoryAP(poly p, const Variable &a, const ring r)
Definition: clapconv.cc:118
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:734
pTotaldegree
static long pTotaldegree(poly p)
Definition: polys.h:268
nf
Definition: gnumpfl.cc:27
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:488
singclap_resultant
poly singclap_resultant(poly f, poly g, poly x, const ring r)
Definition: clapsing.cc:295
p_Copy
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:812
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:583
rField_is_Ring_Z
static BOOLEAN rField_is_Ring_Z(const ring r)
Definition: ring.h:474
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
rChar
int rChar(ring r)
Definition: ring.cc:688
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:531
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:592
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:286
convFactoryISingI
int convFactoryISingI(const CanonicalForm &f)
Definition: clapconv.cc:112
nfMinPoly
static int nfMinPoly[16]
Definition: ffields.cc:562
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:1662
count_Factors
BOOLEAN count_Factors(ideal I, intvec *v, int j, poly &f, poly fac, const ring r)
Definition: clapsing.cc:766
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:1456
pp_Mult_qq
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1093
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:17
pIter
#define pIter(p)
Definition: monomials.h:44
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:1699
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:590
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:539
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:4824
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:932
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:597
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:525
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:857
p_Add_q
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:892
singclap_det_bi
number singclap_det_bi(bigintmat *m, const coeffs cf)
Definition: clapsing.cc:1680
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:513
singclap_extgcd
BOOLEAN singclap_extgcd(poly f, poly g, poly &res, poly &pa, poly &pb, const ring r)
Definition: clapsing.cc:438
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:565
StringSetS
void StringSetS(const char *st)
Definition: reporter.cc:128
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: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:281
singclap_pmod
poly singclap_pmod(poly f, poly g, const ring r)
Definition: clapsing.cc:623
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:412
n_Copy
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:452
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:1797
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:233
gcd
int gcd(int a, int b)
Definition: walkSupport.cc:836
convFactoryPSingTrP
poly convFactoryPSingTrP(const CanonicalForm &f, const ring r)
Definition: clapconv.cc:322
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:1453
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:1937
List< CanonicalForm >
p_IsConstant
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:1923
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
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:616
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:3656
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:1050
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:51
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:571
rField_is_Z
static BOOLEAN rField_is_Z(const ring r)
Definition: ring.h:504
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:495
singclap_factorize_retry
int singclap_factorize_retry
Definition: clapsing.cc:852
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:1225
numbers.h
pNext
#define pNext(p)
Definition: monomials.h:43
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:1853
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:96
ListIterator
Definition: ftmpl_list.h:17
coeffs.h
singclap_neworder
char * singclap_neworder(ideal I, const ring r)
Definition: clapsing.cc:1547
rField_is_Q
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:501
pWrite
void pWrite(poly p)
Definition: polys.h:294
p_Cleardenom_n
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2891