source: git/factory/cf_factor.cc @ fbbb08

spielwiese
Last change on this file since fbbb08 was fbbb08, checked in by Hans Schoenemann <hannes@…>, 13 years ago
singular_homog_flag moved to factory git-svn-id: file:///usr/local/Singular/svn/trunk@13610 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.8 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id$ */
3
4//{{{ docu
5//
6// cf_factor.cc - factorization and square free algorithms.
7//
8// Used by: fac_multivar.cc, fac_univar.cc, cf_irred.cc
9//
10// Header file: cf_algorithm.h
11//
12//}}}
13
14#include <config.h>
15
16#include "cf_gmp.h"
17
18#include "assert.h"
19
20#include "cf_defs.h"
21#include "canonicalform.h"
22#include "cf_iter.h"
23#include "fac_berlekamp.h"
24#include "fac_cantzass.h"
25#include "fac_univar.h"
26#include "fac_multivar.h"
27#include "fac_sqrfree.h"
28#include "cf_algorithm.h"
29#include "facFqFactorize.h"
30#include "cf_map.h"
31#include "algext.h"
32#include "facAlgExt.h"
33
34#include "int_int.h"
35#ifdef HAVE_NTL
36#include "NTLconvert.h"
37#endif
38
39#ifdef SINGULAR
40#include "singext.h"
41#endif
42
43int getExp(); /* cf_char.cc */
44
45//static bool isUnivariateBaseDomain( const CanonicalForm & f )
46//{
47//    CFIterator i = f;
48//    bool ok = i.coeff().inBaseDomain();
49//    i++;
50//    while ( i.hasTerms() && ( ok = ok && i.coeff().inBaseDomain() ) ) i++;
51//    return ok;
52//}
53
54void find_exp(const CanonicalForm & f, int * exp_f)
55{
56  if ( ! f.inCoeffDomain() )
57  {
58    int e=f.level();
59    CFIterator i = f;
60    if (e>=0)
61    {
62      if (i.exp() > exp_f[e]) exp_f[e]=i.exp();
63    }
64    for (; i.hasTerms(); i++ )
65    {
66      find_exp(i.coeff(), exp_f);
67    }
68  }
69}
70
71int find_mvar(const CanonicalForm & f)
72{
73  int mv=f.level();
74  int *exp_f=new int[mv+1];
75  int i;
76  for(i=mv;i>0;i--) exp_f[i]=0;
77  find_exp(f,exp_f);
78  for(i=mv;i>0;i--)
79  {
80    if ((exp_f[i]>0) && (exp_f[i]<exp_f[mv]))
81    {
82      mv=i;
83    }
84  }
85  delete[] exp_f;
86  return mv;
87}
88
89#if 0
90//#ifndef NOSTREAMIO
91void out_cf(const char *s1,const CanonicalForm &f,const char *s2)
92{
93  printf("%s",s1);
94  if (f.isZero()) printf("+0");
95  //else if (! f.inCoeffDomain() )
96  else if (! f.inBaseDomain() )
97  {
98    int l = f.level();
99    for ( CFIterator i = f; i.hasTerms(); i++ )
100    {
101      int e=i.exp();
102      if (i.coeff().isOne())
103      {
104        printf("+");
105        if (e==0) printf("1");
106        else
107        {
108          printf("v(%d)",l);
109          if (e!=1) printf("^%d",e);
110        }
111      }
112      else
113      {
114        out_cf("+(",i.coeff(),")");
115        if (e!=0)
116        {
117          printf("*v(%d)",l);
118          if (e!=1) printf("^%d",e);
119        }
120      }
121    }
122  }
123  else
124  {
125    if ( f.isImm() )
126    {
127      printf("+%d",f.intval());
128    }
129    else
130    {
131    #ifdef NOSTREAMIO
132      if (f.inZ())
133      {
134        mpz_t m;
135        gmp_numerator(f,m);
136        char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
137        str = mpz_get_str( str, 10, m );
138        printf("%s",str);
139        delete[] str;
140        mpz_clear(m);
141      }
142      else if (f.inQ())
143      {
144        mpz_t m;
145        gmp_numerator(f,m);
146        char * str = new char[mpz_sizeinbase( m, 10 ) + 2];
147        str = mpz_get_str( str, 10, m );
148        printf("%s/",str);
149        delete[] str;
150        mpz_clear(m);
151        gmp_denominator(f,m);
152        str = new char[mpz_sizeinbase( m, 10 ) + 2];
153        str = mpz_get_str( str, 10, m );
154        printf("%s",str);
155        delete[] str;
156        mpz_clear(m);
157      }
158    #else
159       std::cout << f;
160    #endif
161    }
162    //if (f.inZ()) printf("(Z)");
163    //else if (f.inQ()) printf("(Q)");
164    //else if (f.inFF()) printf("(FF)");
165    //else if (f.inPP()) printf("(PP)");
166    //else if (f.inGF()) printf("(PP)");
167    //else
168    if (f.inExtension()) printf("E(%d)",f.level());
169  }
170  printf("%s",s2);
171}
172void out_cff(CFFList &L)
173{
174  //int n = L.length();
175  CFFListIterator J=L;
176  int j=0;
177  for ( ; J.hasItem(); J++, j++ )
178  {
179    printf("F%d",j);out_cf(":",J.getItem().factor()," ^ ");
180    printf("%d\n", J.getItem().exp());
181  }
182}
183void test_cff(CFFList &L,const CanonicalForm & f)
184{
185  //int n = L.length();
186  CFFListIterator J=L;
187  CanonicalForm t=1;
188  int j=0;
189  if (!(L.getFirst().factor().inCoeffDomain()))
190    printf("first entry is not const\n");
191  for ( ; J.hasItem(); J++, j++ )
192  {
193    CanonicalForm tt=J.getItem().factor();
194    if (tt.inCoeffDomain() && (j!=0))
195      printf("other entry is const\n");
196    j=J.getItem().exp();
197    while(j>0) { t*=tt; j--; }
198  }
199  if (!(f-t).isZero()) { printf("problem:\n");out_cf("factor:",f," has problems\n");}
200}
201//#endif
202#endif
203
204bool isPurePoly_m(const CanonicalForm & f)
205{
206  if (f.inBaseDomain()) return true;
207  if (f.level()<0) return false;
208  for (CFIterator i=f;i.hasTerms();i++)
209  {
210    if (!isPurePoly_m(i.coeff())) return false;
211  }
212  return true;
213}
214bool isPurePoly(const CanonicalForm & f)
215{
216  if (f.level()<=0) return false;
217  for (CFIterator i=f;i.hasTerms();i++)
218  {
219    if (!(i.coeff().inBaseDomain())) return false;
220  }
221  return true;
222}
223
224
225///////////////////////////////////////////////////////////////
226// get_max_degree_Variable returns Variable with             //
227// highest degree. We assume f is *not* a constant!          //
228///////////////////////////////////////////////////////////////
229Variable
230get_max_degree_Variable(const CanonicalForm & f)
231{
232  ASSERT( ( ! f.inCoeffDomain() ), "no constants" );
233  int max=0, maxlevel=0, n=level(f);
234  for ( int i=1; i<=n; i++ )
235  {
236    if (degree(f,Variable(i)) >= max)
237    {
238      max= degree(f,Variable(i)); maxlevel= i;
239    }
240  }
241  return Variable(maxlevel);
242}
243
244///////////////////////////////////////////////////////////////
245// get_Terms: Split the polynomial in the containing terms.  //
246// getTerms: the real work is done here.                     //
247///////////////////////////////////////////////////////////////
248void
249getTerms( const CanonicalForm & f, const CanonicalForm & t, CFList & result )
250{
251  if ( getNumVars(f) == 0 ) result.append(f*t);
252  else{
253    Variable x(level(f));
254    for ( CFIterator i=f; i.hasTerms(); i++ )
255      getTerms( i.coeff(), t*power(x,i.exp()), result);
256  }
257}
258CFList
259get_Terms( const CanonicalForm & f ){
260  CFList result,dummy,dummy2;
261  CFIterator i;
262  CFListIterator j;
263
264  if ( getNumVars(f) == 0 ) result.append(f);
265  else{
266    Variable _x(level(f));
267    for ( i=f; i.hasTerms(); i++ ){
268      getTerms(i.coeff(), 1, dummy);
269      for ( j=dummy; j.hasItem(); j++ )
270        result.append(j.getItem() * power(_x, i.exp()));
271
272      dummy= dummy2; // have to initalize new
273    }
274  }
275  return result;
276}
277
278
279///////////////////////////////////////////////////////////////
280// homogenize homogenizes f with Variable x                  //
281///////////////////////////////////////////////////////////////
282
283CanonicalForm
284homogenize( const CanonicalForm & f, const Variable & x)
285{
286#if 0
287  int maxdeg=totaldegree(f), deg;
288  CFIterator i;
289  CanonicalForm elem, result(0);
290
291  for (i=f; i.hasTerms(); i++)
292  {
293    elem= i.coeff()*power(f.mvar(),i.exp());
294    deg = totaldegree(elem);
295    if ( deg < maxdeg )
296      result += elem * power(x,maxdeg-deg);
297    else
298      result+=elem;
299  }
300  return result;
301#else
302  CFList Newlist, Termlist= get_Terms(f);
303  int maxdeg=totaldegree(f), deg;
304  CFListIterator i;
305  CanonicalForm elem, result(0);
306
307  for (i=Termlist; i.hasItem(); i++)
308  {
309    elem= i.getItem();
310    deg = totaldegree(elem);
311    if ( deg < maxdeg )
312      Newlist.append(elem * power(x,maxdeg-deg));
313    else
314      Newlist.append(elem);
315  }
316  for (i=Newlist; i.hasItem(); i++) // rebuild
317    result += i.getItem();
318
319  return result;
320#endif
321}
322
323CanonicalForm
324homogenize( const CanonicalForm & f, const Variable & x, const Variable & v1, const Variable & v2)
325{
326#if 0
327  int maxdeg=totaldegree(f), deg;
328  CFIterator i;
329  CanonicalForm elem, result(0);
330
331  for (i=f; i.hasTerms(); i++)
332  {
333    elem= i.coeff()*power(f.mvar(),i.exp());
334    deg = totaldegree(elem);
335    if ( deg < maxdeg )
336      result += elem * power(x,maxdeg-deg);
337    else
338      result+=elem;
339  }
340  return result;
341#else
342  CFList Newlist, Termlist= get_Terms(f);
343  int maxdeg=totaldegree(f), deg;
344  CFListIterator i;
345  CanonicalForm elem, result(0);
346
347  for (i=Termlist; i.hasItem(); i++)
348  {
349    elem= i.getItem();
350    deg = totaldegree(elem,v1,v2);
351    if ( deg < maxdeg )
352      Newlist.append(elem * power(x,maxdeg-deg));
353    else
354      Newlist.append(elem);
355  }
356  for (i=Newlist; i.hasItem(); i++) // rebuild
357    result += i.getItem();
358
359  return result;
360#endif
361}
362
363int singular_homog_flag=1;
364
365int cmpCF( const CFFactor & f, const CFFactor & g )
366{
367  if (f.exp() > g.exp()) return 1;
368  if (f.exp() < g.exp()) return 0;
369  if (f.factor() > g.factor()) return 1;
370  return 0;
371}
372
373CFFList factorize ( const CanonicalForm & f, bool issqrfree )
374{
375  if ( f.inCoeffDomain() )
376        return CFFList( f );
377  int mv=f.level();
378  int org_v=mv;
379  //out_cf("factorize:",f,"==================================\n");
380  if (! f.isUnivariate() )
381  {
382    if ( singular_homog_flag && f.isHomogeneous())
383    {
384      Variable xn = get_max_degree_Variable(f);
385      int d_xn = degree(f,xn);
386      CFMap n;
387      CanonicalForm F = compress(f(1,xn),n);
388      CFFList Intermediatelist;
389      Intermediatelist = factorize(F);
390      CFFList Homoglist;
391      CFFListIterator j;
392      for ( j=Intermediatelist; j.hasItem(); j++ )
393      {
394        Homoglist.append(
395            CFFactor( n(j.getItem().factor()), j.getItem().exp()) );
396      }
397      CFFList Unhomoglist;
398      CanonicalForm unhomogelem;
399      for ( j=Homoglist; j.hasItem(); j++ )
400      {
401        unhomogelem= homogenize(j.getItem().factor(),xn);
402        Unhomoglist.append(CFFactor(unhomogelem,j.getItem().exp()));
403        d_xn -= (degree(unhomogelem,xn)*j.getItem().exp());
404      }
405      if ( d_xn != 0 ) // have to append xn^(d_xn)
406        Unhomoglist.append(CFFactor(CanonicalForm(xn),d_xn));
407      if(isOn(SW_USE_NTL_SORT)) Unhomoglist.sort(cmpCF);
408      return Unhomoglist;
409    }
410    mv=find_mvar(f);
411    if ( getCharacteristic() == 0 )
412    {
413      if (mv!=f.level())
414      {
415        swapvar(f,Variable(mv),f.mvar());
416      }
417    }
418    else
419    {
420      if (mv!=1)
421      {
422        swapvar(f,Variable(mv),Variable(1));
423        org_v=1;
424      }
425    }
426  }
427  CFFList F;
428  if ( getCharacteristic() > 0 )
429  {
430    if (f.isUnivariate())
431    {
432      #ifdef HAVE_NTL
433      if (isOn(SW_USE_NTL) && (isPurePoly(f)))
434      {
435        // USE NTL
436        if (getCharacteristic()!=2)
437        {
438          if (fac_NTL_char!=getCharacteristic())
439          {
440            fac_NTL_char=getCharacteristic();
441            #ifndef NTL_ZZ
442            if (fac_NTL_char >NTL_SP_BOUND)
443            {
444              ZZ r;
445              r=getCharacteristic();
446              ZZ_pContext ccc(r);
447              ccc.restore();
448              ZZ_p::init(r);
449            }
450            else
451            #endif
452            {
453              #ifdef NTL_ZZ
454              ZZ r;
455              r=getCharacteristic();
456              ZZ_pContext ccc(r);
457              #else
458              zz_pContext ccc(getCharacteristic());
459              #endif
460              ccc.restore();
461              #ifdef NTL_ZZ
462              ZZ_p::init(r);
463              #else
464              zz_p::init(getCharacteristic());
465              #endif
466            }
467          }
468        #ifndef NTL_ZZ
469        if (fac_NTL_char >NTL_SP_BOUND)
470        {
471            // convert to NTL
472            ZZ_pX f1=convertFacCF2NTLZZpX(f);
473            ZZ_p leadcoeff = LeadCoeff(f1);
474            //make monic
475            f1=f1 / LeadCoeff(f1);
476            // factorize
477            vec_pair_ZZ_pX_long factors;
478            CanZass(factors,f1);
479            // convert back to factory
480            F=convertNTLvec_pair_ZZpX_long2FacCFFList(factors,leadcoeff,f.mvar());
481          }
482          else
483          #endif
484          {
485            // convert to NTL
486            #ifdef NTL_ZZ
487            ZZ_pX f1=convertFacCF2NTLZZpX(f);
488            ZZ_p leadcoeff = LeadCoeff(f1);
489            #else
490            zz_pX f1=convertFacCF2NTLzzpX(f);
491            zz_p leadcoeff = LeadCoeff(f1);
492            #endif
493            //make monic
494            f1=f1 / LeadCoeff(f1);
495            // factorize
496            #ifdef NTL_ZZ
497            vec_pair_ZZ_pX_long factors;
498            #else
499            vec_pair_zz_pX_long factors;
500            #endif
501            CanZass(factors,f1);
502            // convert back to factory
503            #ifdef NTL_ZZ
504            F=convertNTLvec_pair_ZZpX_long2FacCFFList(factors,leadcoeff,f.mvar());
505            #else
506            F=convertNTLvec_pair_zzpX_long2FacCFFList(factors,leadcoeff,f.mvar());
507            #endif
508          }
509          //test_cff(F,f);
510        }
511        else
512        {
513          // Specialcase characteristic==2
514          if (fac_NTL_char!=2)
515          {
516            fac_NTL_char=2;
517            zz_p::init(2);
518          }
519          // convert to NTL using the faster conversion routine for characteristic 2
520          GF2X f1=convertFacCF2NTLGF2X(f);
521          // no make monic necessary in GF2
522          //factorize
523          vec_pair_GF2X_long factors;
524          CanZass(factors,f1);
525
526          // convert back to factory again using the faster conversion routine for vectors over GF2X
527          F=convertNTLvec_pair_GF2X_long2FacCFFList(factors,LeadCoeff(f1),f.mvar());
528        }
529      }
530      else
531      #endif
532      {  // Use Factory without NTL
533        if ( isOn( SW_BERLEKAMP ) )
534          F=FpFactorizeUnivariateB( f, issqrfree );
535        else
536          F=FpFactorizeUnivariateCZ( f, issqrfree, 0, Variable(), Variable() );
537      }
538    }
539    else
540    {
541      #ifdef HAVE_NTL
542      if (issqrfree)
543      {
544        CFList factors;
545        Variable alpha;
546        if (CFFactory::gettype() == GaloisFieldDomain)
547          factors= GFSqrfFactorize (f);
548        else if (hasFirstAlgVar (f, alpha))
549          factors= FqSqrfFactorize (f, alpha);
550        else
551          factors= FpSqrfFactorize (f);
552        for (CFListIterator i= factors; i.hasItem(); i++)
553          F.append (CFFactor (i.getItem(), 1));
554      }
555      else
556      {
557        Variable alpha;
558        if (CFFactory::gettype() == GaloisFieldDomain)
559          F= GFFactorize (f);
560        else if (hasFirstAlgVar (f, alpha))
561          F= FqFactorize (f, alpha);
562        else
563          F= FpFactorize (f);
564      }
565      #else
566      ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
567      #endif
568    }
569  }
570  else
571  {
572    bool on_rational = isOn(SW_RATIONAL);
573    On(SW_RATIONAL);
574    CanonicalForm cd = bCommonDen( f );
575    CanonicalForm fz = f * cd;
576    Off(SW_RATIONAL);
577    if ( f.isUnivariate() )
578    {
579      #ifdef HAVE_NTL
580      if ((isOn(SW_USE_NTL)) && (isPurePoly(f)))
581      {
582        //USE NTL
583        CanonicalForm ic=icontent(fz);
584        fz/=ic;
585        ZZ c;
586        vec_pair_ZZX_long factors;
587        //factorize the converted polynomial
588        factor(c,factors,convertFacCF2NTLZZX(fz));
589
590        //convert the result back to Factory
591        F=convertNTLvec_pair_ZZX_long2FacCFFList(factors,c,fz.mvar());
592        if ( ! ic.isOne() )
593        {
594          if ( F.getFirst().factor().inCoeffDomain() )
595          {
596            CFFactor new_first( F.getFirst().factor() * ic );
597            F.removeFirst();
598            F.insert( new_first );
599          }
600          else
601            F.insert( CFFactor( ic ) );
602        }
603        else
604        {
605          if ( !F.getFirst().factor().inCoeffDomain() )
606          {
607            CFFactor new_first( 1 );
608            F.insert( new_first );
609          }
610        }
611        //if ( F.getFirst().factor().isOne() )
612        //{
613        //  F.removeFirst();
614        //}
615        //printf("NTL:\n");out_cff(F);
616        //F=ZFactorizeUnivariate( fz, issqrfree );
617        //printf("fac.:\n");out_cff(F);
618      }
619      else
620      #endif
621      {
622        //Use Factory without NTL
623        F = ZFactorizeUnivariate( fz, issqrfree );
624      }
625    }
626    else
627    {
628      F = ZFactorizeMultivariate( fz, issqrfree );
629    }
630
631    if ( on_rational )
632      On(SW_RATIONAL);
633    if ( ! cd.isOne() )
634    {
635      if ( F.getFirst().factor().inCoeffDomain() )
636      {
637        CFFactor new_first( F.getFirst().factor() / cd );
638        F.removeFirst();
639        F.insert( new_first );
640      }
641      else
642      {
643        F.insert( CFFactor( 1/cd ) );
644      }
645    }
646  }
647
648  if ((mv!=org_v) && (! f.isUnivariate() ))
649  {
650    CFFListIterator J=F;
651    for ( ; J.hasItem(); J++)
652    {
653      swapvar(J.getItem().factor(),Variable(mv),Variable(org_v));
654    }
655    swapvar(f,Variable(mv),Variable(org_v));
656  }
657  //out_cff(F);
658  if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
659  return F;
660}
661
662#ifdef HAVE_NTL
663CanonicalForm fntl ( const CanonicalForm & f, int j )
664{
665  ZZX f1=convertFacCF2NTLZZX(f);
666  return convertZZ2CF(coeff(f1,j));
667}
668#endif
669
670CFFList factorize ( const CanonicalForm & f, const Variable & alpha )
671{
672  //out_cf("factorize:",f,"==================================\n");
673  //out_cf("mipo:",getMipo(alpha),"\n");
674  CFFList F;
675  ASSERT( alpha.level() < 0, "not an algebraic extension" );
676  int ch=getCharacteristic();
677  if (f.isUnivariate()&& (ch>0))
678  {
679    #ifdef HAVE_NTL
680    if  (isOn(SW_USE_NTL))
681    {
682      //USE NTL
683      if (ch>2)
684      {
685        // First all cases with characteristic !=2
686        // set remainder
687        if (fac_NTL_char!=getCharacteristic())
688        {
689          fac_NTL_char=getCharacteristic();
690          #ifdef NTL_ZZ
691          ZZ r;
692          r=getCharacteristic();
693          ZZ_pContext ccc(r);
694          #else
695          zz_pContext ccc(getCharacteristic());
696          #endif
697          ccc.restore();
698          #ifdef NTL_ZZ
699          ZZ_p::init(r);
700          #else
701          zz_p::init(getCharacteristic());
702          #endif
703        }
704
705        // set minimal polynomial in NTL
706        #ifdef NTL_ZZ
707        ZZ_pX minPo=convertFacCF2NTLZZpX(getMipo(alpha));
708        ZZ_pEContext c(minPo);
709        #else
710        zz_pX minPo=convertFacCF2NTLzzpX(getMipo(alpha));
711        zz_pEContext c(minPo);
712        #endif
713
714        c.restore();
715
716        // convert to NTL
717        #ifdef NTL_ZZ
718        ZZ_pEX f1=convertFacCF2NTLZZ_pEX(f,minPo);
719        ZZ_pE leadcoeff= LeadCoeff(f1);
720        #else
721        zz_pEX f1=convertFacCF2NTLzz_pEX(f,minPo);
722        zz_pE leadcoeff= LeadCoeff(f1);
723        #endif
724
725        //make monic
726        f1=f1 / leadcoeff;
727
728        // factorize using NTL
729        #ifdef NTL_ZZ
730        vec_pair_ZZ_pEX_long factors;
731        #else
732        vec_pair_zz_pEX_long factors;
733        #endif
734        CanZass(factors,f1);
735
736        // return converted result
737        F=convertNTLvec_pair_zzpEX_long2FacCFFList(factors,leadcoeff,f.mvar(),alpha);
738      }
739      else if (/*getCharacteristic()*/ch==2)
740      {
741        // special case : GF2
742
743        // remainder is two ==> nothing to do
744        // set remainder
745        ZZ r;
746        r=getCharacteristic();
747        ZZ_pContext ccc(r);
748        ccc.restore();
749
750        // set minimal polynomial in NTL using the optimized conversion routines for characteristic 2
751        GF2X minPo=convertFacCF2NTLGF2X(getMipo(alpha,f.mvar()));
752        GF2EContext c(minPo);
753        c.restore();
754
755        // convert to NTL again using the faster conversion routines
756        GF2EX f1;
757        if (isPurePoly(f))
758        {
759          GF2X f_tmp=convertFacCF2NTLGF2X(f);
760          f1=to_GF2EX(f_tmp);
761        }
762        else
763        {
764          f1=convertFacCF2NTLGF2EX(f,minPo);
765        }
766
767        // make monic (in Z/2(a))
768        GF2E f1_coef=LeadCoeff(f1);
769        MakeMonic(f1);
770
771        // factorize using NTL
772        vec_pair_GF2EX_long factors;
773        CanZass(factors,f1);
774
775        // return converted result
776        F=convertNTLvec_pair_GF2EX_long2FacCFFList(factors,f1_coef,f.mvar(),alpha);
777      }
778      else
779      {
780      }
781    }
782    else
783    #endif
784    {
785      F=FpFactorizeUnivariateCZ( f, false, 1, alpha, Variable() );
786    }
787  }
788  else if (ch>0)
789  {
790    #ifdef HAVE_NTL
791    F= FqFactorize (f, alpha);
792    #else
793    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
794    #endif
795
796  }
797  else if (f.isUnivariate() && ch == 0) // Q(a)[x]
798  {
799    F= AlgExtFactorize (f, alpha);
800  }
801  else //Q(a)[x1,...,xn]
802  {
803  #ifdef SINGULAR
804      WerrorS("not implemented");
805  #else
806      abort();
807  #endif
808  }
809  return F;
810}
811
812CFFList sqrFree ( const CanonicalForm & f )
813{
814//    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
815    CFFList result;
816
817    if ( getCharacteristic() == 0 )
818        result = sqrFreeZ( f );
819    else
820        result = sqrFreeFp( f );
821
822    //return ( sort ? sortCFFList( result ) : result );
823    return result;
824}
825
826bool isSqrFree ( const CanonicalForm & f )
827{
828//    ASSERT( f.isUnivariate(), "multivariate factorization not implemented" );
829    if ( getCharacteristic() == 0 )
830        return isSqrFreeZ( f );
831    else
832        return isSqrFreeFp( f );
833}
834
Note: See TracBrowser for help on using the repository browser.