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