Changeset e89e56 in git for libfac/factor


Ignore:
Timestamp:
Mar 17, 2008, 6:44:17 PM (16 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
85194f264939ff85dd7731d524a483b21f35f5ac
Parents:
ca847b0e390392983ef3461c16980b5defee8e0c
Message:
*hannes: fact.tst


git-svn-id: file:///usr/local/Singular/svn/trunk@10621 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
libfac/factor
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • libfac/factor/Factor.cc

    rca847b re89e56  
    11/* Copyright 1996 Michael Messollen. All rights reserved. */
    22///////////////////////////////////////////////////////////////////////////////
    3 static char * rcsid = "$Id: Factor.cc,v 1.41 2008-02-22 12:16:03 Singular Exp $ ";
     3static char * rcsid = "$Id: Factor.cc,v 1.42 2008-03-17 17:44:16 Singular Exp $ ";
    44static char * errmsg = "\nYou found a bug!\nPlease inform (Michael Messollen) michael@math.uni-sb.de \nPlease include above information and your input (the ideal/polynomial and characteristic) in your bug-report.\nThank you.";
    55///////////////////////////////////////////////////////////////////////////////
     
    190190
    191191  retvalue= mydivremt(num,denum,a,b);
    192   if ( retvalue && b.isZero() ) // num/denum from FFdomain
     192  if ( retvalue && b == num.genZero() ) // num/denum from FFdomain
    193193    return a;
    194194  else // num/denum is rational
     
    257257          numerator= numerator(x*lt,levelF); // x <- x*lt
    258258          denumerator= power(lt,degree(F,levelF)-1); // == lt^(1-degree(F,x)
    259           while (is_rational(numerator, denumerator).isZero())
     259          while (numerator.genZero() == is_rational(numerator, denumerator))
    260260            numerator*= lt;
    261261          intermediate= is_rational(numerator,denumerator);
     
    270270          intermediate*= j.getItem().factor();
    271271        test1= mydivremt( intermediate,F,a,b);
    272         if ( test1 && b.isZero() ) // Yupp!
     272        if ( test1 && b == intermediate.genZero() ) // Yupp!
    273273        {
    274274          IntermediateList.append(CFFactor(1/a,1));
     
    288288          test= content(numerator,x);
    289289          test1= mydivremt(denumerator,test,a,b);
    290           if ( test1 && b.isZero() ) // Yupp!
     290          if ( test1 && b == numerator.genZero() ) // Yupp!
    291291          {
    292292            save_denumerator*= a;
     
    308308        // save_denumerator should be a multiple of the leading coeff
    309309        test1= mydivremt(save_denumerator,lt,a,b);
    310         if ( test1 && b.isZero() ) // Yupp!
     310        if ( test1 && b == save_denumerator.genZero() ) // Yupp!
    311311          // We have to multiply one of the factors with
    312312          // the multiplicity of the save_denumerator <-> lc
    313313          // the following will do what we want
    314           Returnlist= UnionCFFL( CFFList(CFFactor(1/a,1)),Returnlist) ;
     314          Returnlist= myUnion( CFFList(CFFactor(1/a,1)),Returnlist) ;
    315315        else
    316316        {
     
    363363  if ( degree(g) == deg ) // degrees match
    364364    if ( level(compress(g,m)) == (vars_left) ) // exactly one variable less
    365       if ( isSqrFree(g) ) // poly is sqrfree
     365      if ( SqrFreeTest(g,1) ) // poly is sqrfree
    366366        if ( gcd(g,g.deriv()).isOne() ) // Discriminante != 0
    367367           return 1;
     
    440440  return find_irreducible( degree_of_Extension, gen, Variable(1) );
    441441}
    442 
    443442
    444443///////////////////////////////////////////////////////////////
     
    720719      Outputlist_b = Factorized(ffuni,alpha);
    721720      DEBOUTLN(CERR, "Outputlist_b = ", Outputlist_b);
    722       Outputlist = UnionCFFL(Outputlist_a, Outputlist_b);
     721      Outputlist = myUnion(Outputlist_a, Outputlist_b);
    723722      // have to back-swapvar the factors....
    724723      for ( CFFListIterator i=Outputlist; i.hasItem(); i++ ){
     
    925924  // (If gcd is fast...)
    926925  ///////
    927   //  if ( ! isSqrFree(F) ){
     926  //  if ( ! SqrFreeTest(F) ){
    928927  if ( ! is_SqrFree )
    929928  {
    930929    TIMING_START(sqrfree_time);
    931     SqrFreeList = sqrFree(F,0,false) ; // first sqrfree the polynomial
    932     // Ex.: char=p   f= x^p*(y+1);
    933     // InternalSqrFree(f)= ( y+1, (x)^p ), sqrFree(f)= ( y+1 ) .
     930    SqrFreeList = SqrFreeMV(F) ; // first sqrfree the polynomial
     931    // don't use sqrFree(F), factory's internal sqrFree for multiv.
     932    // Polynomials; it's wrong!! Ex.: char=p   f= x^p*(y+1);
     933    // SqrFreeMV(f)= ( y+1, (x)^p ), sqrFree(f)= ( y+1 ) .
    934934    TIMING_END(sqrfree_time);
    935935
     
    941941  else
    942942    SqrFreeList.append(CFFactor(F,1));
    943   DEBOUTLN(CERR, "SqrFreeList= ", SqrFreeList);
     943  DEBOUTLN(CERR, "SqrFreeMV= ", SqrFreeList);
    944944  for ( i=SqrFreeList; i.hasItem(); i++ )
    945945  {
     
    977977        for ( j=Intermediatelist; j.hasItem(); j++ )
    978978          //Normally j.getItem().exp() should be 1
    979           Outputlist= appendCFFL( Outputlist, CFFactor(m(j.getItem().factor()),exp*j.getItem().exp()));
     979          Outputlist= myappend( Outputlist, CFFactor(m(j.getItem().factor()),exp*j.getItem().exp()));
    980980      }
    981981  }
     
    10661066  libfac_interruptflag=0;
    10671067  CFFList iF=Factorize(F,minpoly);
    1068   if ((libfac_interruptflag==0)||(iF.isEmpty()))
     1068  if ((libfac_interruptflag==0)&&(!iF.isEmpty()))
    10691069    H=iF;
    10701070  else
     
    11741174      {
    11751175        CFList as(minpoly);
    1176         CFFList sqF=sqrFree(F,0,false); // sqrFreeZ
     1176        CFFList sqF=sqrFree(F); // sqrFreeZ
    11771177        CFFList G,H;
    11781178        CanonicalForm fac;
     
    12241224  // (If gcd is fast...)
    12251225  ///////
    1226   //  if ( ! isSqrFree(F) ){
     1226  //  if ( ! SqrFreeTest(F) ){
    12271227  if ( ! is_SqrFree )
    12281228  {
    12291229    TIMING_START(sqrfree_time);
    1230     SqrFreeList = sqrFree(F, minpoly) ; // first sqrfree the polynomial
    1231     // Ex.: char=p   f= x^p*(y+1);
    1232     // InternalSqrFree(f)= ( y+1, (x)^p ), sqrFree(f)= ( y+1 ) .
     1230    SqrFreeList = SqrFreeMV(F, minpoly) ; // first sqrfree the polynomial
     1231    // don't use sqrFree(F), factory's internal sqrFree for multiv.
     1232    // Polynomials; it's wrong!! Ex.: char=p   f= x^p*(y+1);
     1233    // SqrFreeMV(f)= ( y+1, (x)^p ), sqrFree(f)= ( y+1 ) .
    12331234    TIMING_END(sqrfree_time);
    12341235
     
    12401241  else
    12411242    SqrFreeList.append(CFFactor(F,1));
    1242   DEBOUTLN(CERR, "SqrFreeList= ", SqrFreeList);
     1243  DEBOUTLN(CERR, "SqrFreeMV= ", SqrFreeList);
    12431244  for ( i=SqrFreeList; i.hasItem(); i++ )
    12441245  {
     
    12801281        for ( j=Intermediatelist; j.hasItem(); j++ )
    12811282          //Normally j.getItem().exp() should be 1
    1282           Outputlist= appendCFFL( Outputlist, CFFactor(m(j.getItem().factor()),exp*j.getItem().exp()));
     1283          Outputlist= myappend( Outputlist, CFFactor(m(j.getItem().factor()),exp*j.getItem().exp()));
    12831284      }
    12841285    }
     
    13301331/*
    13311332$Log: not supported by cvs2svn $
    1332 Revision 1.40  2008/01/25 14:19:40  Singular
    1333 *hannes: SqrFreeTest -> isSqrFree
    1334 
    1335 Revision 1.39  2008/01/22 09:51:37  Singular
    1336 *hannes: sqrFree/InternalSqrFree -> factory
    1337 
    13381333Revision 1.38  2008/01/07 13:34:56  Singular
    13391334*hannes: omse optiomzations(isOne)
  • libfac/factor/MVMultiHensel.cc

    rca847b re89e56  
    22///////////////////////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 // static char * rcsid = "$Id: MVMultiHensel.cc,v 1.16 2008-02-22 12:16:03 Singular Exp $";
     4// static char * rcsid = "$Id: MVMultiHensel.cc,v 1.17 2008-03-17 17:44:16 Singular Exp $";
    55///////////////////////////////////////////////////////////////////////////////
    66// FACTORY - Includes
     
    334334{
    335335  CanonicalForm V,Fk=F,Gk=G,Rk,W,D,S;
    336   int  levelU=level(U), degU=totaldegree(U,1,levelU); // degree(U,{x_1,..,x_(level(U)-1)})
     336  int  levelU=level(U), degU=subvardegree(U,levelU); // degree(U,{x_1,..,x_(level(U)-1)})
    337337  DiophantForm Retvalue;
    338338  RememberArray A(degree(F,levelU)+degree(G,levelU)+1);
     
    502502      CanonicalForm a,b;
    503503      // we add a division test now for intermediat.One and intermediat.Two
    504       if ( mydivremt (mF,intermediat.One,a,b) && b.isZero() )
     504      if ( mydivremt (mF,intermediat.One,a,b) && b == mF.genZero() )
    505505        Retlistinter.append(CFFactor(intermediat.One,1) );
    506       if ( mydivremt (mF,intermediat.Two,a,b) && b.isZero() )
     506      if ( mydivremt (mF,intermediat.Two,a,b) && b == mF.genZero() )
    507507        Retlistinter.append(CFFactor(intermediat.Two,1)  );
    508508
     
    520520/*
    521521$Log: not supported by cvs2svn $
    522 Revision 1.15  2008/01/22 09:51:37  Singular
    523 *hannes: sqrFree/InternalSqrFree -> factory
    524 
    525522Revision 1.14  2007/06/14 14:16:35  Singular
    526523*hannes: Factorize2 etc.
  • libfac/factor/SqrFree.cc

    rca847b re89e56  
    22///////////////////////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 static char * rcsid = "$Id: SqrFree.cc,v 1.14 2008-01-25 14:19:40 Singular Exp $";
     4static char * rcsid = "$Id: SqrFree.cc,v 1.15 2008-03-17 17:44:16 Singular Exp $";
    55static char * errmsg = "\nYou found a bug!\nPlease inform (Michael Messollen) michael@math.uni-sb.de .\n Please include above information and your input (the ideal/polynomial and characteristic) in your bug-report.\nThank you.";
    66///////////////////////////////////////////////////////////////////////////////
     
    4848
    4949static inline CFFactor
    50 Powerup( const CFFactor & F , int exp=1){
     50Powerup( const CFFactor & F , int exp=1)
     51{
    5152  return CFFactor(F.factor(), exp*F.exp()) ;
    5253}
    5354
    5455static CFFList
    55 Powerup( const CFFList & Inputlist , int exp=1 ){
     56Powerup( const CFFList & Inputlist , int exp=1 )
     57{
    5658  CFFList Outputlist;
    5759
     
    6769///////////////////////////////////////////////////////////////
    6870static CanonicalForm
    69 PthRoot( const CanonicalForm & f ){
     71PthRoot( const CanonicalForm & f )
     72{
    7073  CanonicalForm RES, R = f;
    7174  int n= max(level(R),getNumVars(R)), p= getCharacteristic();
    7275
    73   if (n==0){ // constant
     76  if (n==0)
     77  { // constant
    7478    if (R.inExtension()) // not in prime field; f over |F(q=p^k)
    7579    {
    7680      R = power(R,Powerup(p,getGFDegree() - 1)) ;
    77     } 
     81    }
    7882    // if f in prime field, do nothing
    7983    return R;
     
    9397///////////////////////////////////////////////////////////////
    9498static CanonicalForm
    95 PthRoot( const CanonicalForm & f ,const CanonicalForm & mipo){
     99PthRoot( const CanonicalForm & f ,const CanonicalForm & mipo)
     100{
    96101  CanonicalForm RES, R = f;
    97102  int n= max(level(R),getNumVars(R)), p= getCharacteristic();
    98103  int mipodeg=-1;
    99104  if (f.level()==mipo.level()) mipodeg=mipo.degree();
    100   else if ((f.level()==1) &&(mipo.level()!=-1000000))
     105  else if ((f.level()==1) &&(!mipo.isZero()))
    101106  {
    102107    Variable t;
     
    111116    {
    112117      R = power(R,Powerup(p,getGFDegree() - 1)) ;
    113     } 
     118    }
    114119    else if ((f.level()==mipo.level())
    115     ||((f.level()==1) &&(mipo.level()!=-1000000)))
     120    ||((f.level()==1) &&(!mipo.isZero())))
    116121    {
    117122      R = power(R,Powerup(p,mipodeg - 1)) ;
     
    130135
    131136///////////////////////////////////////////////////////////////
     137// A uni/multivariate SqrFreeTest routine.                   //
     138// Cheaper to run if all you want is a test.                 //
     139// Works for charcteristic 0 and q=p^m                       //
     140// Returns 1 if poly r is SqrFree, 0 if SqrFree will do some //
     141// kind of factorization.                                    //
     142// Would be much more effcient iff we had *good*             //
     143//  uni/multivariate gcd's and/or gcdtest's                  //
     144///////////////////////////////////////////////////////////////
     145int
     146SqrFreeTest( const CanonicalForm & r, int opt)
     147{
     148  CanonicalForm f=r, g;
     149  int n=level(f);
     150
     151  if (getNumVars(f)==0) return 1 ; // a constant is SqrFree
     152  if ( f.isUnivariate() ) {
     153    g= f.deriv();
     154    if ( getCharacteristic() > 0 && g.isZero() ) return 0 ;
     155    // Next: it would be best to have a *univariate* gcd-test which returns
     156    // 0 iff gcdtest(f,g) == 1 or a constant ( for real Polynomials )
     157    g = gcd(f,g);
     158    if ( g.isOne() || (-g).isOne() ) return 1;
     159    else
     160      if ( getNumVars(g) == 0 ) return 1;// <- totaldegree!!!
     161      else return 0 ;
     162  }
     163  else
     164  { // multivariate case
     165    for ( int k=1; k<=n; k++ )
     166    {
     167      g = swapvar(f,k,n); g = content(g);
     168      // g = 1 || -1 : sqr-free, g poly : not sqr-free, g number : opt helps
     169      if ( ! (g.isOne() || (-g).isOne() || getNumVars(g)==0 ) ) {
     170        if ( opt==0 ) return 0;
     171        else {
     172          if ( SqrFreeTest(g,1) == 0 ) return 0;
     173          g = swapvar(g,k,n);
     174          f /=g ;
     175        }
     176      }
     177    }
     178    // Now f is primitive
     179    n = level(f); // maybe less indeterminants
     180    //    if ( totaldegree(f) <= 1 ) return 1;
     181
     182    // Let`s look if it is a Pth root
     183    if ( getCharacteristic() > 0 )
     184      for (int k=1; k<=n; k++ )
     185      {
     186        g=swapvar(f,k,n); g=g.deriv();
     187        if ( ! g.isZero() ) break ;
     188        else if ( k==n) return 0 ; // really is Pth root
     189      }
     190    g = f.deriv() ;
     191    // Next: it would be best to have a *multivariate* gcd-test which returns
     192    // 0 iff gcdtest(f,g) == 1 or a constant ( for real Polynomials )
     193    g= gcd(f,g);
     194    if ( g.isOne() || (-g).isOne() || (g==f) || (getNumVars(g)==0) ) return 1 ;
     195    else return 0 ;
     196  }
     197#ifdef HAVE_SINGULAR_ERROR
     198  WerrorS("libfac: ERROR: SqrFreeTest: we should never fall trough here!");
     199#else
     200#ifndef NOSTREAMIO
     201  CERR << "\nlibfac: ERROR: SqrFreeTest: we should never fall trough here!\n"
     202       << rcsid << errmsg << "\n";
     203#endif
     204#endif
     205  return 0;
     206}
     207
     208///////////////////////////////////////////////////////////////
    132209// A uni/multivariate SqrFree routine.Works for polynomials  //
    133210// which don\'t have a constant as the content.              //
     
    136213// needs not to be 1 !!!!!                                   //
    137214///////////////////////////////////////////////////////////////
    138 
     215static CFFList
     216SqrFreed( const CanonicalForm & r , const CanonicalForm &mipo=0)
     217{
     218  CanonicalForm h, g, f = r;
     219  CFFList Outputlist;
     220  int n = level(f);
     221
     222  DEBINCLEVEL(CERR, "SqrFreed");
     223  DEBOUTLN(CERR, "Called with r= ", r);
     224  if (getNumVars(f)==0 )
     225  { // just a constant; return it
     226    Outputlist= myappend(Outputlist,CFFactor(f,1));
     227    return Outputlist ;
     228  }
     229
     230// We look if we do have a content; if so, SqrFreed the content
     231// and continue computations with pp(f)
     232  for (int k=1; k<=n; k++)
     233  {
     234    if ((mipo.isZero())/*||(k!=1)*/)
     235    {
     236      g = swapvar(f,k,n); g = content(g);
     237      if ( ! (g.isOne() || (-g).isOne() || degree(g)==0 ))
     238      {
     239        g = swapvar(g,k,n);
     240        DEBOUTLN(CERR, "We have a content: ", g);
     241        Outputlist = myUnion(SqrFreeMV(g,mipo),Outputlist); // should we add a
     242                                                // SqrFreeTest(g) first ?
     243        DEBOUTLN(CERR, "Outputlist is now: ", Outputlist);
     244        f /=g;
     245        DEBOUTLN(CERR, "f is now: ", f);
     246      }
     247    }
     248  }
     249
     250// Now f is primitive; Let`s look if f is univariate
     251  if ( f.isUnivariate() )
     252  {
     253    DEBOUTLN(CERR, "f is univariate: ", f);
     254    g = content(g);
     255    if ( ! (g.isOne() || (-g).isOne() ) )
     256    {
     257      Outputlist= myappend(Outputlist,CFFactor(g,1)) ;
     258      f /= g;
     259    }
     260    Outputlist = Union(sqrFree(f),Outputlist) ;
     261    DEBOUTLN(CERR, "Outputlist after univ. sqrFree(f) = ", Outputlist);
     262    DEBDECLEVEL(CERR, "SqrFreed");
     263    return Outputlist ;
     264  }
     265
     266// Linear?
     267  if ( totaldegree(f) <= 1 )
     268  {
     269    Outputlist= myappend(Outputlist,CFFactor(f,1)) ;
     270    DEBDECLEVEL(CERR, "SqrFreed");
     271    return Outputlist ;
     272  }
     273
     274// is it Pth root?
     275  n=level(f); // maybe less indeterminants
     276  g= f.deriv();
     277  if ( getCharacteristic() > 0 && g.isZero() )
     278  {  // Pth roots only apply to char > 0
     279    for (int k=1; k<=n; k++)
     280    {
     281      if ((mipo.isZero())/*||(k!=1)*/)
     282      {
     283        g=swapvar(f,k,n) ;
     284        g = g.deriv();
     285
     286        if ( ! g.isZero() )
     287        { // can`t be Pth root
     288          CFFList Outputlist2= SqrFreed(swapvar(f,k,n));
     289          for (CFFListIterator inter=Outputlist2; inter.hasItem(); inter++)
     290          {
     291            Outputlist= myappend(Outputlist, CFFactor(swapvar(inter.getItem().factor(),k,n), inter.getItem().exp()));
     292          }
     293          return Outputlist;
     294        }
     295      }
     296    }
     297    // really is Pth power
     298    DEBOUTLN(CERR, "f is a p'th root: ", f);
     299    CFMap m;
     300    g = compress(f,m);
     301    if (mipo.isZero())
     302      f = m(PthRoot(g));
     303    else
     304      f = m(PthRoot(g,mipo));
     305    DEBOUTLN(CERR, "  that is       : ", f);
     306    // now : Outputlist union ( SqrFreed(f) )^getCharacteristic()
     307    Outputlist=myUnion(Powerup(SqrFreeMV(f),getCharacteristic()),Outputlist);
     308    DEBDECLEVEL(CERR, "SqrFreed");
     309    return Outputlist ;
     310  }
     311  g = f.deriv();
     312  DEBOUTLN(CERR, "calculating gcd of ", f);
     313  DEBOUTLN(CERR, "               and ", g);
     314  h = gcd(f,pp(g));  h /= lc(h);
     315  DEBOUTLN(CERR,"gcd(f,g)= ",h);
     316  if ( (h.isOne()) || ( h==f) || ((-h).isOne()) || getNumVars(h)==0 )
     317  { // no common factor
     318    Outputlist= myappend(Outputlist,CFFactor(f,1)) ;
     319    DEBOUTLN(CERR, "Outputlist= ", Outputlist);
     320    DEBDECLEVEL(CERR, "SqrFreed");
     321    return Outputlist ;
     322  }
     323  else
     324  { // we can split into two nontrivial pieces
     325    f /= h; // Now we have split the poly into f and h
     326    g = lc(f);
     327    if ( g != f.genOne() && getNumVars(g) == 0 )
     328    {
     329       Outputlist= myappend(Outputlist,CFFactor(g,1)) ;
     330       f /= g;
     331    }
     332    DEBOUTLN(CERR, "Split into f= ", f);
     333    DEBOUTLN(CERR, "       and h= ", h);
     334    // For char > 0 the polys f and h can have Pth roots; so we need a test
     335    // Test is disabled because timing is the same
     336
     337//    if ( SqrFreeTest(f,0) )
     338//      Outputlist= myappend(Outputlist,CFFactor(f,1)) ;
     339//    else
     340    Outputlist=myUnion(Outputlist, SqrFreeMV(f));
     341//    if ( SqrFreeTest(h,0) )
     342//      Outputlist= myappend(Outputlist,CFFactor(h,1)) ;
     343//    else
     344    Outputlist=myUnion(Outputlist,SqrFreeMV(h));
     345    DEBOUTLN(CERR, "Returning list ", Outputlist);
     346    DEBDECLEVEL(CERR, "SqrFreed");
     347    return Outputlist ;
     348  }
     349#ifdef HAVE_SINGULAR_ERROR
     350  WerrorS("libfac: ERROR: SqrFreed: we should never fall trough here!");
     351#else
     352#ifndef NOSTREAMIO
     353  CERR << "\nlibfac: ERROR: SqrFreed: we should never fall trough here!\n"
     354       << rcsid << errmsg << "\n";
     355#endif
     356#endif
     357  DEBDECLEVEL(CERR, "SqrFreed");
     358  return Outputlist; // for safety purpose
     359}
     360
     361///////////////////////////////////////////////////////////////
     362// The user front-end for the SqrFreed routine.              //
     363// Input can have a constant as content                      //
     364///////////////////////////////////////////////////////////////
    139365CFFList
    140 SqrFree(const CanonicalForm & r ){
    141   CFFList outputlist, sqrfreelist = sqrFree(r,0,false);
     366SqrFreeMV( const CanonicalForm & r , const CanonicalForm & mipo )
     367{
     368  CanonicalForm g=icontent(r), f = r;
     369  CFFList Outputlist, Outputlist2;
     370
     371  DEBINCLEVEL(CERR, "SqrFreeMV");
     372  DEBOUTMSG(CERR, rcsid);
     373  DEBOUTLN(CERR,"Called with f= ", f);
     374
     375  // Take care of stupid users giving us constants
     376  if ( getNumVars(f) == 0 )
     377  { // a constant ; Exp==1 even if f==0
     378      Outputlist= myappend(Outputlist,CFFactor(f,1));
     379  }
     380  else
     381  {
     382      // Now we are sure: we have a nonconstant polynomial
     383      g = lc(f);
     384      while ( getNumVars(g) != 0 ) g=content(g);
     385      if ( ! g.isOne() ) Outputlist= myappend(Outputlist,CFFactor(g,1)) ;
     386      f /= g;
     387      if ( getNumVars(f) != 0 ) // a real polynomial
     388      {
     389        if (!mipo.isZero())
     390          Outputlist=myUnion(SqrFreed(f,mipo),Outputlist) ;
     391        else
     392          Outputlist=myUnion(SqrFreed(f),Outputlist) ;
     393      }
     394  }
     395  DEBOUTLN(CERR,"Outputlist = ", Outputlist);
     396  for ( CFFListIterator i=Outputlist; i.hasItem(); i++ )
     397    if ( getNumVars(i.getItem().factor()) > 0 )
     398      Outputlist2.append(i.getItem());
     399
     400  DEBOUTLN(CERR,"Outputlist2 = ", Outputlist2);
     401  DEBDECLEVEL(CERR, "SqrFreeMV");
     402  return Outputlist2 ;
     403}
     404
     405CFFList SqrFree(const CanonicalForm & r )
     406{
     407  CFFList outputlist, sqrfreelist = SqrFreeMV(r);
    142408  CFFListIterator i;
    143409  CanonicalForm elem;
     
    146412  DEBINCLEVEL(CERR, "SqrFree");
    147413
    148   if ( sqrfreelist.length() < 2 ){
     414  if ( sqrfreelist.length() < 2 )
     415  {
    149416    DEBDECLEVEL(CERR, "SqrFree");
    150417    return sqrfreelist;
    151418  }
    152   for ( int j=1; j<=n; j++ ){
     419  for ( int j=1; j<=n; j++ )
     420  {
    153421    elem =1;
    154     for ( i = sqrfreelist; i.hasItem() ; i++ ){
     422    for ( i = sqrfreelist; i.hasItem() ; i++ )
     423    {
    155424      if ( i.getItem().exp() == j ) elem *= i.getItem().factor();
    156425    }
     
    171440/*
    172441$Log: not supported by cvs2svn $
    173 Revision 1.13  2008/01/22 09:51:37  Singular
    174 *hannes: sqrFree/InternalSqrFree -> factory
    175 
    176 Revision 1.12  2008/01/07 13:34:56  Singular
    177 *hannes: omse optiomzations(isOne)
    178 
    179 Revision 1.11  2007/05/15 14:46:49  Singular
    180 *hannes: factorize in Zp(a)[x...]
    181 
    182442Revision 1.10  2006/05/16 14:46:50  Singular
    183443*hannes: gcc 4.1 fixes
  • libfac/factor/SqrFree.h

    rca847b re89e56  
    22////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 // $Id: SqrFree.h,v 1.6 2008-01-25 14:19:40 Singular Exp $
     4// $Id: SqrFree.h,v 1.7 2008-03-17 17:44:16 Singular Exp $
    55///////////////////////////////////////////////////////////////////////////////
    66#ifndef SQRFREE_H
     
    99/*BEGINPUBLIC*/
    1010// CFFList SqrFree( const CanonicalForm & f ) ;
     11CFFList SqrFreeMV( const CanonicalForm & f , const CanonicalForm & mipo=0) ;
    1112/*ENDPUBLIC*/
     13int     SqrFreeTest( const CanonicalForm & r, int opt=1) ;
    1214CFFList SqrFree( const CanonicalForm & f ) ;
    1315#endif /* SQRFREE_H */
     
    1618/*
    1719$Log: not supported by cvs2svn $
    18 Revision 1.5  2008/01/22 09:51:37  Singular
    19 *hannes: sqrFree/InternalSqrFree -> factory
    20 
    2120Revision 1.4  2002/08/19 11:11:34  Singular
    2221* hannes/pfister: alg_gcd etc.
  • libfac/factor/Truefactor.cc

    rca847b re89e56  
    22///////////////////////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 //static char * rcsid = "@(#) $Id: Truefactor.cc,v 1.13 2008-02-22 12:16:03 Singular Exp $";
     4//static char * rcsid = "@(#) $Id: Truefactor.cc,v 1.14 2008-03-17 17:44:16 Singular Exp $";
    55///////////////////////////////////////////////////////////////////////////////
    66// Factory - Includes
     
    229229  CFFactor factor;
    230230  CFFList L,FAC,E_all;
    231   int c,r = PiList.length(),degU, onemore,M, h = totaldegree(Ua,1,levelU) + 1;
     231  int c,r = PiList.length(),degU, onemore,M, h = subvardegree(Ua,levelU) + 1;
    232232  ListIterator<CFFactor> i;
    233233
     
    241241    //CERR << "           1:" << change_poly(factor.factor(),SubstitutionList,1) <<"\n";
    242242    c= mydivremt(U,test_f,a,b);
    243     if (  c  && b.isZero() && !hasAlgVar(test_f))
     243    if (  c  && b == U.genZero() && !hasAlgVar(test_f))
    244244    // factor.getFactor() divides U
    245245    {
     
    450450/*
    451451$Log: not supported by cvs2svn $
    452 Revision 1.12  2008/01/22 09:51:37  Singular
    453 *hannes: sqrFree/InternalSqrFree -> factory
    454 
    455452Revision 1.11  2008/01/07 13:34:56  Singular
    456453*hannes: omse optiomzations(isOne)
  • libfac/factor/helpstuff.cc

    rca847b re89e56  
    22////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 // static char * rcsid = "$Id: helpstuff.cc,v 1.6 2008-01-22 09:51:37 Singular Exp $";
     4// static char * rcsid = "$Id: helpstuff.cc,v 1.7 2008-03-17 17:44:17 Singular Exp $";
    55////////////////////////////////////////////////////////////
    66// FACTORY - Includes
     
    1212
    1313bool
    14 mydivremt ( const CanonicalForm& f, const CanonicalForm& g, CanonicalForm& a, CanonicalForm& b )
    15 {
     14mydivremt ( const CanonicalForm& f, const CanonicalForm& g, CanonicalForm& a, CanonicalForm& b ){
    1615  bool retvalue;
    1716  CanonicalForm aa,bb;
     
    2423
    2524void
    26 mydivrem( const CanonicalForm& f, const CanonicalForm& g, CanonicalForm& a, CanonicalForm& b )
    27 {
     25mydivrem( const CanonicalForm& f, const CanonicalForm& g, CanonicalForm& a, CanonicalForm& b ){
    2826  bool retvalue;
    2927  CanonicalForm aa,bb;
     
    3230  if ( aa==bb ) { b=bb; }
    3331  else { b=aa; }
     32}
     33
     34// Now some procedures used in SqrFree and in Factor
     35///////////////////////////////////////////////////////////////
     36///////////////////////////////////////////////////////////////
     37// We have to include a version of <CFFList>.append(CFFactor)//
     38// and Union( CFFList, CFFList)                              //
     39// because we have to look for multiplicities in SqrFree.    //
     40// e.g.: SqrFree( f^3 ) with char <> 3                       //
     41///////////////////////////////////////////////////////////////
     42CFFList
     43myappend( const CFFList & Inputlist, const CFFactor & TheFactor){
     44  CFFList Outputlist ;
     45  CFFactor copy;
     46  CFFListIterator i;
     47  int exp=0;
     48
     49  for ( i=Inputlist ; i.hasItem() ; i++ ){
     50    copy = i.getItem();
     51    if ( copy.factor() == TheFactor.factor() )
     52      exp += copy.exp();
     53    else
     54      Outputlist.append(copy);
     55  }
     56  Outputlist.append( CFFactor(TheFactor.factor(), exp + TheFactor.exp()));
     57  return Outputlist;
     58}
     59
     60CFFList
     61myUnion(const CFFList & Inputlist1,const CFFList & Inputlist2){
     62  CFFList Outputlist;
     63  CFFListIterator i;
     64
     65  for ( i=Inputlist1 ; i.hasItem() ; i++ )
     66    Outputlist = myappend(Outputlist, i.getItem() );
     67  for ( i=Inputlist2 ; i.hasItem() ; i++ )
     68    Outputlist = myappend(Outputlist, i.getItem() );
     69
     70  return Outputlist;
     71}
     72
     73int
     74Powerup( const int base , const int exp){
     75  int retvalue=1;
     76  if ( exp == 0 )  return retvalue ;
     77  else for ( int i=1 ; i <= exp; i++ ) retvalue *= base ;
     78
     79  return retvalue;
    3480}
    3581
     
    80126
    81127///////////////////////////////////////////////////////////////
     128// Return the deg of F in the Variables x_1,..,x_(levelF-1)  //
     129///////////////////////////////////////////////////////////////
     130int
     131subvardegree( const CanonicalForm & F, int levelF ){
     132  int n=0,m=degree(F,levelF),newn=0;
     133
     134  for ( int k=0; k<=m; k++ ){
     135    newn = totaldegree( F[k] );
     136    if ( newn > n ) n=newn;
     137  }
     138  return n;
     139}
     140
     141///////////////////////////////////////////////////////////////
    82142// Change poly:  x_i <- x_i +- a_i    for i= 1,..,level(f)-1 //
    83143///////////////////////////////////////////////////////////////
     
    115175/*
    116176$Log: not supported by cvs2svn $
    117 Revision 1.5  2007/05/25 12:59:05  Singular
    118 *hannes: fdivides2
    119 
    120177Revision 1.4  2001/06/19 15:29:04  Singular
    121178*hannes: optim.
  • libfac/factor/helpstuff.h

    rca847b re89e56  
    22////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 // $Id: helpstuff.h,v 1.5 2008-01-22 09:51:37 Singular Exp $
     4// $Id: helpstuff.h,v 1.6 2008-03-17 17:44:17 Singular Exp $
    55////////////////////////////////////////////////////////////
    66#ifndef HELPSTUFF_H
     
    1212///////////////////////////////////////////////////////////////
    1313CanonicalForm mod_power( const CanonicalForm & f, int k, int levelU);
     14int subvardegree( const CanonicalForm & F, int levelF );
    1415CanonicalForm change_poly( const CanonicalForm & f , const SFormList & Substitutionlist, int directionback );
    1516
     
    1718// Now some procedures used in SqrFree and in Factor
    1819///////////////////////////////////////////////////////////////
    19 inline int min ( const int a, const int b )
    20 {
     20CFFList myappend( const CFFList & Inputlist, const CFFactor & TheFactor) ;
     21CFFList myUnion(const CFFList & Inputlist1,const CFFList & Inputlist2);
     22int Powerup( const int base , const int exp=1);
     23inline int min ( const int a, const int b ){
    2124  return (a<=b ? a:b);
    2225}
    23 inline int max ( const int a, const int b )
    24 {
     26inline int max ( const int a, const int b ){
    2527  return (a>b ? a:b);
    2628}
     29
    2730#endif /* HELPSTUFF_H */
    2831
     
    3033/*
    3134$Log: not supported by cvs2svn $
    32 Revision 1.4  2007/05/15 14:46:49  Singular
    33 *hannes: factorize in Zp(a)[x...]
    34 
    3535Revision 1.3  1997/09/12 07:19:57  Singular
    3636* hannes/michael: libfac-0.3.0
Note: See TracChangeset for help on using the changeset viewer.