Changeset 9b25e7e in git


Ignore:
Timestamp:
Oct 24, 2002, 7:22:22 PM (21 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
Children:
616214197b0dbd8973606076355c2d6ccde48f2f
Parents:
e44bd88b22a2439b301aba30f2adc6bb930bbefc
Message:
* hannes: factoring in alg.ext., alg_gcd, NTL stuff


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

Legend:

Unmodified
Added
Removed
  • libfac/charset/alg_factor.cc

    re44bd88 r9b25e7e  
    33// emacs edit mode for this file is -*- C++ -*-
    44////////////////////////////////////////////////////////////
    5 static char * rcsid = "$Id: alg_factor.cc,v 1.10 2002-08-19 11:11:29 Singular Exp $";
     5static char * rcsid = "$Id: alg_factor.cc,v 1.11 2002-10-24 17:22:21 Singular Exp $";
    66////////////////////////////////////////////////////////////
    77// FACTORY - Includes
     
    2020#include "alg_factor.h"
    2121
    22 //void out_cf(char *s1,const CanonicalForm &f,char *s2);
     22void out_cf(char *s1,const CanonicalForm &f,char *s2);
    2323
    2424#ifdef ALGFACTORDEBUG
     
    198198      Variable X;
    199199      if (getAlgVar(R,X))
    200       { 
     200      {
    201201        if (R.isUnivariate())
    202           testlist=factorize( R, X );
    203         else 
     202          testlist=factorize( R, X );
     203        else
    204204          testlist= Factorize(R, X, 0);
    205205      }
    206       else 
     206      else
    207207        testlist= Factorize(R);
    208208      DEBOUTLN(cout, "testlist= ", testlist);
     
    369369    return alg_lc(f.LC());
    370370  }
    371 } 
     371}
    372372
    373373// the heart of the algorithm: the one from Trager
     
    400400//cout << "alg: "<< X << " mipo=" << getMipo(X,Variable('X')) <<endl;
    401401    if (R.isUnivariate())
     402    {
     403      DEBOUTLN(cout, "alg_factor: factorize( ", R);
    402404      Factorlist =  factorize( R, X );
     405    }
    403406    else
    404407    {
     
    407410      CanonicalForm mipo=getMipo(X,XX);
    408411      CFList as(mipo);
     412      DEBOUTLN(cout, "alg_factor: newfactoras( ", R);
    409413      Factorlist = newfactoras(R, as , 1);
    410414      #else
    411415      // factor R over k
     416      DEBOUTLN(cout, "alg_factor: Factorize( ", R);
    412417      Factorlist = Factorize(R);
    413418      #endif
     
    417422  {
    418423    // factor R over k
     424    DEBOUTLN(cout, "alg_factor: Factorize( ", R);
    419425    Factorlist = Factorize(R);
    420426  }
     
    444450        // undo linear transformation!!!! and then gcd!
    445451        //cout << "algcd(" << g << "," << fnew << ",as" << as << ")" << endl;
    446         //out_cf("algcd g=",g,"\n");
    447         //out_cf("algcd fnew=",fnew,"\n");
     452        //out_cf("algcd g=",g,"\n");
     453        //out_cf("algcd fnew=",fnew,"\n");
    448454        //h= algcd(g,fnew, as, oldord);
    449         //if (as.length() >1)
     455        //if (as.length() >1)
    450456        //  h= algcd(g,fnew, as, oldord);
    451         //else
    452           h=alg_gcd(g,fnew,as);
    453         //out_cf(" -> algcd=",algcd(g,fnew, as, oldord),"\n");
    454         //out_cf(" -> alg_gcd=",alg_gcd(g,fnew,as),"\n");
     457        //else
     458          h=alg_gcd(g,fnew,as);
     459        //out_cf(" -> algcd=",algcd(g,fnew, as, oldord),"\n");
     460        //out_cf(" -> alg_gcd=",alg_gcd(g,fnew,as),"\n");
    455461        //cout << "algcd result:" << h << endl;
    456462        DEBOUTLN(cout, "  alg_factor: h= ", h);
     
    647653  //CanonicalForm Fgcd= algcd(f,f.deriv(),Astar,gcdord);
    648654  CanonicalForm Fgcd;
    649         //if (Astar.length() >1)
     655        //if (Astar.length() >1)
    650656        //  Fgcd= algcd(f,f.deriv(),Astar,gcdord);
    651         //else
    652           Fgcd= alg_gcd(f,f.deriv(),Astar);
    653         //out_cf("algcd:",algcd(f,f.deriv(),Astar,gcdord),"\n");
    654         //out_cf("alg_gcd:",alg_gcd(f,f.deriv(),Astar),"\n");
     657        //else
     658          Fgcd= alg_gcd(f,f.deriv(),Astar);
     659        //out_cf("algcd:",algcd(f,f.deriv(),Astar,gcdord),"\n");
     660        //out_cf("alg_gcd:",alg_gcd(f,f.deriv(),Astar),"\n");
    655661 // cout << "algcd result:"  << Fgcd << endl;
    656662  if ( Fgcd == 0 ) DEBOUTMSG(cerr, "WARNING: p'th root ?");
     
    738744/*
    739745$Log: not supported by cvs2svn $
     746Revision 1.10  2002/08/19 11:11:29  Singular
     747* hannes/pfister: alg_gcd etc.
     748
    740749Revision 1.9  2002/07/30 15:16:19  Singular
    741750*hannes: fix for alg. extension
  • libfac/charset/csutil.cc

    re44bd88 r9b25e7e  
    22////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 static char * rcsid = "$Id: csutil.cc,v 1.7 2002-08-19 11:11:31 Singular Exp $";
     4static char * rcsid = "$Id: csutil.cc,v 1.8 2002-10-24 17:22:22 Singular Exp $";
    55/////////////////////////////////////////////////////////////
    66// FACTORY - Includes
     
    1414// Charset - Includes
    1515#include "csutil.h"
    16 //extern void out_cf(char *s1,const CanonicalForm &f,char *s2);
     16extern void out_cf(char *s1,const CanonicalForm &f,char *s2);
    1717extern CanonicalForm alg_lc(const CanonicalForm &f);
    1818extern int hasAlgVar(const CanonicalForm &f);
     
    660660  {
    661661    if (f.mvar()==i.getItem().mvar()) return f;
    662   } 
     662  }
    663663  if (f.level()>0)
    664664  {
     
    672672                      const CFList &as)
    673673{
     674  CanonicalForm f=fff;
     675  CanonicalForm g=ggg;
     676  f=Prem(f,as);
     677  g=Prem(g,as);
     678  if ( f.isZero() )
     679  {
     680    if ( g.lc().sign() < 0 ) return -g;
     681    else                     return g;
     682  }
     683  else  if ( g.isZero() )
     684  {
     685    if ( f.lc().sign() < 0 ) return -f;
     686    else                     return f;
     687  }
    674688  //out_cf("alg_gcd(",fff," , ");
    675689  //out_cf("",ggg,")\n");
    676   CanonicalForm f=fff;
    677   CanonicalForm g=ggg;
    678690  CanonicalForm res;
    679691  // does as appear in f and g ?
     
    682694  {
    683695    Variable v=j.getItem().mvar();
    684     if (hasVar(f,v)) {has_alg_var=true; break;}
    685     if (hasVar(g,v)) {has_alg_var=true; break;}
    686   } 
     696    if (hasVar(f,v)) {has_alg_var=true; /*break;*/}
     697    if (hasVar(g,v)) {has_alg_var=true; /*break;*/}
     698    //out_cf("as:",j.getItem(),"\n");
     699  }
    687700  if (!has_alg_var)
    688701  {
     
    698711      res=gcd(f,g);
    699712    //out_cf("gcd=",res,"\n");
     713    //out_cf("of f=",fff," , ");
     714    //out_cf("and g=",ggg,"\n");
     715
    700716    return res;
    701   } 
     717  }
    702718
    703719  int mvf=f.level();
    704720  int mvg=g.level();
    705721  if (mvg > mvf)
    706   { 
     722  {
    707723    CanonicalForm tmp=f; f=g; g=tmp;
    708724    int tmp2=mvf; mvf=mvg; mvg=tmp2;
    709   } 
     725  }
    710726  if (g.inBaseDomain() || f.inBaseDomain())
    711727  {
    712728    //printf("const\n");
     729    //out_cf("of f=",fff," , ");
     730    //out_cf("and g=",ggg,"\n");
    713731    return CanonicalForm(1);
    714   } 
    715  
     732  }
     733
    716734  // gcd of all coefficients:
    717735  CFIterator i=f;
     
    728746    res=alg_gcd(g,c_gcd,as);
    729747    //out_cf("alg_gcd1=",res,"\n");
     748    //out_cf("of f=",fff," , ");
     749    //out_cf("and g=",ggg,"\n");
    730750    return res;
    731751  }
     752  // now: mvf==mvg, f.level()==g.level()
    732753  if (!c_gcd.inBaseDomain())
    733754  {
     
    739760      i++;
    740761    }
    741   } 
     762  }
    742763
    743764  f/=c_gcd;
    744765  g/=c_gcd;
    745766
     767  CFList gg;
    746768  CanonicalForm r=1;
    747   CFList gg;
    748   while (!(r.isZero()))
     769  while (1)
    749770  {
    750771    //printf("f.mvar=%d, g.mvar=%d\n",f.level(),g.level());
    751772    gg=as;
    752     gg.append(g);
     773    if (!g.inCoeffDomain()) gg.append(g);
    753774    //out_cf("Prem(",f," , ");
    754775    //out_cf("",g,")\n");
    755     if (g.inCoeffDomain()) r=0;
     776    if (g.inCoeffDomain()|| g.isZero())
     777    {
     778      //printf("in coeff domain:");
     779      if (g.isZero()) { //printf("0\n");
     780        i=f;
     781        CanonicalForm f_gcd=i.coeff(); i++;
     782        while( i.hasTerms())
     783        {
     784          f_gcd=alg_gcd(i.coeff(),f_gcd,as);
     785          if (f_gcd.inBaseDomain()) break;
     786          i++;
     787        } 
     788        f/=f_gcd; 
     789        return f*c_gcd;
     790      }
     791      else { //printf("c\n");
     792        return c_gcd;}
     793    } 
    756794    else if (g.level()==f.level()) r=Prem(f,gg);
    757795    else
    758796    {
     797      //printf("diff. level: %d, %d\n", f.level(), g.level());
    759798      // g and f have different levels
    760       return c_gcd;     
     799      //out_cf("c_gcd=",c_gcd,"\n");
     800    //out_cf("of f=",fff," , ");
     801    //out_cf("and g=",ggg,"\n");
     802      return c_gcd;
    761803    }
    762804    //out_cf("->",r,"\n");
     
    764806    g=r;
    765807  }
    766   if (degree(f,Variable(mvg))==0) 
     808  if (degree(f,Variable(mvg))==0)
    767809  {
    768810  // remark: mvf == mvg == f.level() ==g.level()
    769811    //out_cf("c_gcd=",c_gcd,"\n");
     812    //out_cf("of f=",fff," , ");
     813    //out_cf("and g=",ggg,"\n");
    770814    return c_gcd;
    771   } 
     815  }
    772816  //out_cf("f=",f,"\n");
    773817  i=f;
     
    781825    i++;
    782826  }
     827  //out_cf("end-k=",k,"\n");
    783828  f/=k;
     829  //out_cf("f/k=",f,"\n");
    784830  res=c_gcd*f;
    785831  CanonicalForm r_lc=alg_lc(res);
     
    788834  //res/=r_lc;
    789835  //out_cf("alg_gcd2=",res,"\n");
    790   return res;
     836  //  out_cf("of f=",fff," , ");
     837  //  out_cf("and g=",ggg,"\n");
     838  //return res;
     839  //if (res.level()<fff.level() && res.level() < ggg.level())
     840  //  return alg_gcd(alg_gcd(fff,res,as),ggg,as);
     841  //else
     842    return res;
    791843}
    792844
    793845/*
    794846$Log: not supported by cvs2svn $
     847Revision 1.7  2002/08/19 11:11:31  Singular
     848* hannes/pfister: alg_gcd etc.
     849
    795850Revision 1.6  2002/01/21 09:11:07  Singular
    796851* hannes: handle empty set in removecontent
Note: See TracChangeset for help on using the changeset viewer.