Changeset 639047e in git for libfac/charset


Ignore:
Timestamp:
Aug 19, 2002, 1:11:34 PM (22 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
6acb298d347b4b82e942caa7518a2625dc747c1e
Parents:
b1476d0550d3e358e0fcafec0719ae421300980e
Message:
* hannes/pfister: alg_gcd etc.


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

Legend:

Unmodified
Added
Removed
  • libfac/charset/alg_factor.cc

    rb1476d0 r639047e  
    33// emacs edit mode for this file is -*- C++ -*-
    44////////////////////////////////////////////////////////////
    5 static char * rcsid = "$Id: alg_factor.cc,v 1.9 2002-07-30 15:16:19 Singular Exp $";
     5static char * rcsid = "$Id: alg_factor.cc,v 1.10 2002-08-19 11:11:29 Singular Exp $";
    66////////////////////////////////////////////////////////////
    77// FACTORY - Includes
     
    1919// some CC's need this:
    2020#include "alg_factor.h"
     21
     22//void out_cf(char *s1,const CanonicalForm &f,char *s2);
    2123
    2224#ifdef ALGFACTORDEBUG
     
    360362}
    361363
     364CanonicalForm alg_lc(const CanonicalForm &f)
     365{
     366  if (f.inCoeffDomain()) return f;
     367  if (f.level()>0)
     368  {
     369    return alg_lc(f.LC());
     370  }
     371
     372
    362373// the heart of the algorithm: the one from Trager
    363374static CFFList
     
    369380  DEBINCLEVEL(cout,"alg_factor");
    370381  DEBOUTLN(cout, "alg_factor: f= ", f);
     382  //out_cf("start alg_factor:",f,"\n");
    371383  substlist= simpleextension(Astar, vminpoly, Rstar);
    372384  DEBOUTLN(cout, "alg_factor: substlist= ", substlist);
     
    375387
    376388  sqrf_norm(f, Rstar, vminpoly, s, g, R );
     389  //out_cf("sqrf_norm R:",R,"\n");
     390  //out_cf("sqrf_norm s:",s,"\n");
     391  //out_cf("sqrf_norm g:",g,"\n");
    377392  DEBOUTLN(cout, "alg_factor: g= ", g);
    378393  DEBOUTLN(cout, "alg_factor: s= ", s);
     
    429444        // undo linear transformation!!!! and then gcd!
    430445        //cout << "algcd(" << g << "," << fnew << ",as" << as << ")" << endl;
    431         h= algcd(g,fnew, as, oldord);
     446        //out_cf("algcd g=",g,"\n");
     447        //out_cf("algcd fnew=",fnew,"\n");
     448        //h= algcd(g,fnew, as, oldord);
     449        //if (as.length() >1)
     450        //  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");
    432455        //cout << "algcd result:" << h << endl;
    433456        DEBOUTLN(cout, "  alg_factor: h= ", h);
     
    446469    if (degree(g, f.mvar())>0){ L.append(CFFactor(g,1)); }
    447470  }
    448   DEBOUTLN(cout, "alg_factor: L= ", L);
     471  CFFList LL;
     472  if (getCharacteristic()>0)
     473  {
     474    CFFListIterator i=L;
     475    CanonicalForm c_fac=1;
     476    CanonicalForm c;
     477    for(;i.hasItem(); i++ )
     478    {
     479      CanonicalForm ff=i.getItem().factor();
     480      c=alg_lc(ff);
     481      int e=i.getItem().exp();
     482      ff/=c;
     483      if (!ff.isOne()) LL.append(CFFactor(ff,e));
     484      while (e>0) { c_fac*=c;e--; }
     485    }
     486    if (!c_fac.isOne()) LL.insert(CFFactor(c_fac,1));
     487  }
     488  else
     489  {
     490    LL=L;
     491  }
     492  //CFFListIterator i=LL;
     493  //for(;i.hasItem(); i++ )
     494  //  out_cf("end alg_f:",i.getItem().factor(),"\n");
     495  //printf("end alg_factor\n");
     496  DEBOUTLN(cout, "alg_factor: L= ", LL);
    449497  DEBDECLEVEL(cout,"alg_factor");
    450   return L;
     498  return LL;
    451499}
    452500
     
    597645  // This is for now. we need alg_sqrfree implemented!
    598646  //cout << "algcd(" << f << "," << f.deriv() << " as:" << Astar <<endl;
    599   CanonicalForm Fgcd= algcd(f,f.deriv(),Astar,gcdord);
     647  //CanonicalForm Fgcd= algcd(f,f.deriv(),Astar,gcdord);
     648  CanonicalForm Fgcd;
     649        //if (Astar.length() >1)
     650        //  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");
    600655 // cout << "algcd result:"  << Fgcd << endl;
    601656  if ( Fgcd == 0 ) DEBOUTMSG(cerr, "WARNING: p'th root ?");
     
    683738/*
    684739$Log: not supported by cvs2svn $
     740Revision 1.9  2002/07/30 15:16:19  Singular
     741*hannes: fix for alg. extension
     742
    685743Revision 1.8  2001/08/06 08:32:53  Singular
    686744* hannes: code cleanup
  • libfac/charset/algfactor.cc

    rb1476d0 r639047e  
    33// emacs edit mode for this file is -*- C++ -*-
    44////////////////////////////////////////////////////////////
    5 static char * rcsid = "$Id: algfactor.cc,v 1.5 2001-06-27 13:58:05 Singular Exp $";
     5static char * rcsid = "$Id: algfactor.cc,v 1.6 2002-08-19 11:11:30 Singular Exp $";
    66////////////////////////////////////////////////////////////
    77// FACTORY - Includes
     
    354354    DEBOUT(cout, ",", fp(substback,vf));
    355355    DEBOUT(cout, ") over K_r wrt ", vf);
    356     fp= algcd(g,fp(substback,vf), as, oldord);
     356    fp=alg_gcd(g,fp(substback,vf), as);
     357    //fp= algcd(g,fp(substback,vf), as, oldord);
    357358    DEBOUTLN(cout, " = ", fp);
    358359    if ( degree(fp,vf) > 0 ){ //otherwise it's a constant
     
    372373    DEBOUT(cout, ",", fp(substback,vf));
    373374    DEBOUT(cout, ") over K_r wrt ", vf);
    374     fp= algcd(g,fp(substback,vf), as, oldord);
     375    fp= alg_gcd(g,fp(substback,vf), as);
     376    //fp= algcd(g,fp(substback,vf), as, oldord);
    375377    DEBOUTLN(cout, " = ", fp);
    376378    if ( degree(fp,vf) > 0 ){ //otherwise it's a constant
     
    448450/*
    449451$Log: not supported by cvs2svn $
     452Revision 1.5  2001/06/27 13:58:05  Singular
     453*hannes/GP: debug newfactoras, char_series, ...
     454
    450455Revision 1.4  2001/06/21 14:57:04  Singular
    451456*hannes/GP: Factorize, newfactoras, ...
  • libfac/charset/algfactor.h

    rb1476d0 r639047e  
    33// emacs edit mode for this file is -*- C++ -*-
    44////////////////////////////////////////////////////////////
    5 // $Id: algfactor.h,v 1.2 1997-09-12 07:19:39 Singular Exp $
     5// $Id: algfactor.h,v 1.3 2002-08-19 11:11:30 Singular Exp $
    66////////////////////////////////////////////////////////////
    77
     
    1616CFFList cfactor(const CanonicalForm & f, const CFList & as, int success );
    1717/*BEGINPUBLIC*/
     18int hasVar(const CanonicalForm &f, const Variable &v);
    1819/*ENDPUBLIC*/
    1920
  • libfac/charset/charset.cc

    rb1476d0 r639047e  
    22////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 static char * rcsid = "$Id: charset.cc,v 1.9 2001-08-08 14:26:54 Singular Exp $";
     4static char * rcsid = "$Id: charset.cc,v 1.10 2002-08-19 11:11:31 Singular Exp $";
    55/////////////////////////////////////////////////////////////
    66// FACTORY - Includes
     
    540540    DEBOUT(cout, "irras: factoring: ", elem);
    541541    if ( degree(elem) > 1 ) // linear poly's are irreduzible
     542    {
    542543      qs = Factorize(elem);
     544    }
    543545    else{
    544546      qs=(CFFactor(elem,1));
     
    581583            break;
    582584          }
    583           else
    584           {
    585 #ifdef HAVE_SINGULAR_ERROR
    586             WarnS("libfac: Factoring over algebraic function field required!");
    587 #else
    588 #ifndef NOSTREAMIO
    589             cerr << "libfac: Factoring over algebraic function field!" << endl;
    590 #endif
    591 #endif
    592           }
    593585        }
    594586      }
     
    602594/*
    603595$Log: not supported by cvs2svn $
     596Revision 1.9  2001/08/08 14:26:54  Singular
     597*hannes: Dan's HAVE_SINGULAR_ERROR
     598
    604599Revision 1.8  2001/08/06 08:32:53  Singular
    605600* hannes: code cleanup
  • libfac/charset/csutil.cc

    rb1476d0 r639047e  
    22////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 static char * rcsid = "$Id: csutil.cc,v 1.6 2002-01-21 09:11:07 Singular Exp $";
     4static char * rcsid = "$Id: csutil.cc,v 1.7 2002-08-19 11:11:31 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);
     17extern CanonicalForm alg_lc(const CanonicalForm &f);
     18extern int hasAlgVar(const CanonicalForm &f);
    1619
    1720static bool
     
    651654}
    652655
     656#if 0
     657static CanonicalForm alg_lc(const CanonicalForm &f, const CFList as)
     658{
     659  for(CFListIterator i=as; i.hasItem(); i++)
     660  {
     661    if (f.mvar()==i.getItem().mvar()) return f;
     662  } 
     663  if (f.level()>0)
     664  {
     665    return alg_lc(f.LC(),as);
     666  }
     667  return CanonicalForm(1);
     668}
     669#endif
     670
     671CanonicalForm alg_gcd(const CanonicalForm & fff, const CanonicalForm &ggg,
     672                      const CFList &as)
     673{
     674  //out_cf("alg_gcd(",fff," , ");
     675  //out_cf("",ggg,")\n");
     676  CanonicalForm f=fff;
     677  CanonicalForm g=ggg;
     678  CanonicalForm res;
     679  // does as appear in f and g ?
     680  bool has_alg_var=false;
     681  for ( CFListIterator j=as;j.hasItem(); j++ )
     682  {
     683    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  } 
     687  if (!has_alg_var)
     688  {
     689    if ((hasAlgVar(f))
     690    || (hasAlgVar(g)))
     691    {
     692      Varlist ord;
     693      for ( CFListIterator j=as;j.hasItem(); j++ )
     694        ord.append(j.getItem().mvar());
     695      res=algcd(f,g,as,ord);
     696    }
     697    else
     698      res=gcd(f,g);
     699    //out_cf("gcd=",res,"\n");
     700    return res;
     701  } 
     702
     703  int mvf=f.level();
     704  int mvg=g.level();
     705  if (mvg > mvf)
     706  {
     707    CanonicalForm tmp=f; f=g; g=tmp;
     708    int tmp2=mvf; mvf=mvg; mvg=tmp2;
     709  } 
     710  if (g.inBaseDomain() || f.inBaseDomain())
     711  {
     712    //printf("const\n");
     713    return CanonicalForm(1);
     714  } 
     715 
     716  // gcd of all coefficients:
     717  CFIterator i=f;
     718  CanonicalForm c_gcd=i.coeff(); i++;
     719  while( i.hasTerms())
     720  {
     721    c_gcd=alg_gcd(i.coeff(),c_gcd,as);
     722    if (c_gcd.inBaseDomain()) break;
     723    i++;
     724  }
     725  //printf("f.mvar=%d (%d), g.mvar=%d (%d)\n",f.level(),mvf,g.level(),mvg);
     726  if (mvf!=mvg) // => mvf > mvg
     727  {
     728    res=alg_gcd(g,c_gcd,as);
     729    //out_cf("alg_gcd1=",res,"\n");
     730    return res;
     731  }
     732  if (!c_gcd.inBaseDomain())
     733  {
     734    i=g;
     735    while( i.hasTerms())
     736    {
     737      c_gcd=alg_gcd(i.coeff(),c_gcd,as);
     738      if (c_gcd.inBaseDomain()) break;
     739      i++;
     740    }
     741  } 
     742
     743  f/=c_gcd;
     744  g/=c_gcd;
     745
     746  CanonicalForm r=1;
     747  CFList gg;
     748  while (!(r.isZero()))
     749  {
     750    //printf("f.mvar=%d, g.mvar=%d\n",f.level(),g.level());
     751    gg=as;
     752    gg.append(g);
     753    //out_cf("Prem(",f," , ");
     754    //out_cf("",g,")\n");
     755    if (g.inCoeffDomain()) r=0;
     756    else if (g.level()==f.level()) r=Prem(f,gg);
     757    else
     758    {
     759      // g and f have different levels
     760      return c_gcd;     
     761    }
     762    //out_cf("->",r,"\n");
     763    f=g;
     764    g=r;
     765  }
     766  if (degree(f,Variable(mvg))==0)
     767  {
     768  // remark: mvf == mvg == f.level() ==g.level()
     769    //out_cf("c_gcd=",c_gcd,"\n");
     770    return c_gcd;
     771  } 
     772  //out_cf("f=",f,"\n");
     773  i=f;
     774  CanonicalForm k=i.coeff(); i++;
     775  //out_cf("k=",k,"\n");
     776  while( i.hasTerms())
     777  {
     778    if (k.inCoeffDomain()) break;
     779    k=alg_gcd(i.coeff(),k,as);
     780    //out_cf("k=",k,"\n");
     781    i++;
     782  }
     783  f/=k;
     784  res=c_gcd*f;
     785  CanonicalForm r_lc=alg_lc(res);
     786  res/=r_lc;
     787  //CanonicalForm r_lc=alg_lc(res,as);
     788  //res/=r_lc;
     789  //out_cf("alg_gcd2=",res,"\n");
     790  return res;
     791}
     792
    653793/*
    654794$Log: not supported by cvs2svn $
     795Revision 1.6  2002/01/21 09:11:07  Singular
     796* hannes: handle empty set in removecontent
     797
    655798Revision 1.5  2001/06/21 14:57:04  Singular
    656799*hannes/GP: Factorize, newfactoras, ...
  • libfac/charset/csutil.h

    rb1476d0 r639047e  
    22////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 // $Id: csutil.h,v 1.3 1997-09-12 07:19:42 Singular Exp $
     4// $Id: csutil.h,v 1.4 2002-08-19 11:11:32 Singular Exp $
    55////////////////////////////////////////////////////////////
    66
     
    99
    1010#include <factory.h>
     11#include "algfactor.h"
    1112#include <tmpl_inst.h>
    1213
     
    5354CanonicalForm  Prem( const CanonicalForm &f, const CFList &L );
    5455CFList         Prem( const CFList &AS, const CFList &L );
     56CanonicalForm alg_gcd(const CanonicalForm &, const CanonicalForm &, const CFList &);
    5557/*ENDPUBLIC*/
    5658CanonicalForm  divide( const CanonicalForm & ff, const CanonicalForm & f, const CFList & as);
     
    7981/*
    8082$Log: not supported by cvs2svn $
     83Revision 1.3  1997/09/12 07:19:42  Singular
     84* hannes/michael: libfac-0.3.0
     85
    8186Revision 1.3  1997/04/25 22:51:48  michael
    8287Version for libfac-0.2.1
Note: See TracChangeset for help on using the changeset viewer.