Changeset dad0bc5 in git


Ignore:
Timestamp:
Dec 9, 2005, 9:35:38 AM (18 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'a7324b6e0b44a1a8ed3fa4d9ca3e2ff210ddd52c')
Children:
172b7ae49955a6c96c685cbe68ee3f257d89bd46
Parents:
1b82a2e051a986276fd759237c823aecfb97b2be
Message:
*hannes: factorization of homog.polys, SORT for factorize


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

Legend:

Unmodified
Added
Removed
  • factory/NTLconvert.cc

    r1b82a2 rdad0bc5  
    1 /* $Id: NTLconvert.cc,v 1.13 2004-01-19 11:26:19 Singular Exp $ */
     1/* $Id: NTLconvert.cc,v 1.14 2005-12-09 08:35:37 Singular Exp $ */
    22#include <config.h>
    33
     
    419419}
    420420
    421 int NTLcmpCF( const CFFactor & f, const CFFactor & g )
    422 {
    423   if (f.exp() > g.exp()) return 1;
    424   if (f.exp() < g.exp()) return 0;
    425   if (f.factor() > g.factor()) return 1;
    426   return 0;
    427 }
    428 
    429421////////////////////////////////////////////////////////////////////////////////
    430422// NAME: convertNTLvec_pair_ZZpX_long2FacCFFList                              //
     
    468460    rueckgabe.append(CFFactor(convertNTLZZpX2CF(e[i].a,x),e[i].b));
    469461  }
    470   if(isOn(SW_USE_NTL_SORT)) rueckgabe.sort(NTLcmpCF);
    471462  // the multiplicity at pos 1
    472463  if (!IsOne(multi))
     
    495486    rueckgabe.append(CFFactor(convertNTLzzpX2CF(e[i].a,x),e[i].b));
    496487  }
    497   if(isOn(SW_USE_NTL_SORT)) rueckgabe.sort(NTLcmpCF);
    498488  // the multiplicity at pos 1
    499489  if (!IsOne(multi))
     
    556546    rueckgabe.append(CFFactor(bigone,exponent));
    557547  }
    558   if(isOn(SW_USE_NTL_SORT)) rueckgabe.sort(NTLcmpCF);
    559548  return rueckgabe;
    560549}
     
    777766    rueckgabe.append(CFFactor(bigone,exponent));
    778767  }
    779   if(isOn(SW_USE_NTL_SORT)) rueckgabe.sort(NTLcmpCF);
    780768  // the multiplicity at pos 1
    781769  //if (!IsOne(multi))
     
    869857    rueckgabe.append(CFFactor(bigone,exponent));
    870858  }
    871   if(isOn(SW_USE_NTL_SORT)) rueckgabe.sort(NTLcmpCF);
    872859  // Start by appending the multiplicity
    873860  if (!IsOne(multi))
     
    914901    rueckgabe.append(CFFactor(bigone,exponent));
    915902  }
    916   if(isOn(SW_USE_NTL_SORT)) rueckgabe.sort(NTLcmpCF);
    917903  // Start by appending the multiplicity
    918904  if (!IsOne(multi))
     
    1007993
    1008994  }
    1009   if(isOn(SW_USE_NTL_SORT)) rueckgabe.sort(NTLcmpCF);
    1010995  // return the computed CFFList
    1011996  return rueckgabe;
  • factory/canonicalform.cc

    r1b82a2 rdad0bc5  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: canonicalform.cc,v 1.35 2005-10-18 12:33:00 Singular Exp $ */
     2/* $Id: canonicalform.cc,v 1.36 2005-12-09 08:35:37 Singular Exp $ */
    33
    44#include <config.h>
     
    1212#include "int_cf.h"
    1313#include "cf_factory.h"
     14#include "cf_algorithm.h"
    1415#include "imm.h"
    1516#include "gfops.h"
     
    181182        return value->isUnivariate();
    182183}
     184
     185// is_homogeneous returns 1 iff f is homogeneous, 0 otherwise//
     186bool
     187CanonicalForm::isHomogeneous() const
     188{
     189  if (this->isZero()) return true;
     190  else if (this->inCoeffDomain()) return true;
     191  else
     192  {
     193#if 0
     194    CFIterator i;
     195    int cdeg = -2, dummy;
     196    for ( i = *this; i.hasTerms(); i++ )
     197    {
     198      if (!(i.coeff().isHomogeneous())) return false;
     199      if ( (dummy = totaldegree( i.coeff() ) + i.exp()) != cdeg )
     200      {
     201         if (cdeg == -2) cdeg = dummy;
     202         else return false;
     203      }
     204    }
     205    return true;
     206#else
     207    CFList termlist= get_Terms(*this);
     208    CFListIterator i;
     209    int deg= totaldegree(termlist.getFirst());
     210
     211    for ( i=termlist; i.hasItem(); i++ )
     212      if ( totaldegree(i.getItem()) != deg ) return false;
     213    return true;
     214#endif
     215  }
     216}
     217
    183218//}}}
    184219
  • factory/canonicalform.h

    r1b82a2 rdad0bc5  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: canonicalform.h,v 1.29 2005-10-18 13:16:14 Singular Exp $ */
     2/* $Id: canonicalform.h,v 1.30 2005-12-09 08:35:37 Singular Exp $ */
    33
    44#ifndef INCL_CANONICALFORM_H
     
    8989    bool isFFinGF() const;
    9090    bool isUnivariate() const;
     91    bool isHomogeneous() const;
    9192
    9293    // conversion functions
  • factory/cf_algorithm.cc

    r1b82a2 rdad0bc5  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_algorithm.cc,v 1.9 2003-05-31 12:35:05 Singular Exp $ */
     2/* $Id: cf_algorithm.cc,v 1.10 2005-12-09 08:35:37 Singular Exp $ */
    33
    44//{{{ docu
     
    119119  else { l = 1; }
    120120  d= dr-dv+1;
    121   while ( ( dv <= dr  ) && ( r != r.genZero()) ){
     121  while ( ( dv <= dr  ) && ( r != r.genZero()) )
     122  {
    122123    test = power(x,dr-dv)*v*LC(r,x);
    123124    if ( dr == 0 ) { r= CanonicalForm(0); }
  • factory/cf_algorithm.h

    r1b82a2 rdad0bc5  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_algorithm.h,v 1.11 1998-06-30 16:31:24 schmidt Exp $ */
     2/* $Id: cf_algorithm.h,v 1.12 2005-12-09 08:35:37 Singular Exp $ */
    33
    44#ifndef INCL_CF_ALGORITHM_H
     
    6161
    6262bool isSqrFree ( const CanonicalForm & f );
     63
     64CanonicalForm homogenize( const CanonicalForm & f, const Variable & x);
     65Variable get_max_degree_Variable(const CanonicalForm & f);
     66CFList get_Terms( const CanonicalForm & f );
     67void getTerms( const CanonicalForm & f, const CanonicalForm & t, CFList & result );
     68
     69
    6370//}}}
    6471
  • factory/cf_factor.cc

    r1b82a2 rdad0bc5  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_factor.cc,v 1.26 2005-08-22 17:24:01 Singular Exp $ */
     2/* $Id: cf_factor.cc,v 1.27 2005-12-09 08:35:38 Singular Exp $ */
    33
    44//{{{ docu
     
    172172}
    173173
     174///////////////////////////////////////////////////////////////
     175// get_max_degree_Variable returns Variable with             //
     176// highest degree. We assume f is *not* a constant!          //
     177///////////////////////////////////////////////////////////////
     178Variable
     179get_max_degree_Variable(const CanonicalForm & f)
     180{
     181  ASSERT( ( ! f.inCoeffDomain() ), "no constants" );
     182  int max=0, maxlevel=0, n=level(f);
     183  for ( int i=1; i<=n; i++ )
     184  {
     185    if (degree(f,Variable(i)) >= max)
     186    {
     187      max= degree(f,Variable(i)); maxlevel= i;
     188    }
     189  }
     190  return Variable(maxlevel);
     191}
     192
     193///////////////////////////////////////////////////////////////
     194// get_Terms: Split the polynomial in the containing terms.  //
     195// getTerms: the real work is done here.                     //
     196///////////////////////////////////////////////////////////////
     197void
     198getTerms( const CanonicalForm & f, const CanonicalForm & t, CFList & result )
     199{
     200  if ( getNumVars(f) == 0 ) result.append(f*t);
     201  else{
     202    Variable x(level(f));
     203    for ( CFIterator i=f; i.hasTerms(); i++ )
     204      getTerms( i.coeff(), t*power(x,i.exp()), result);
     205  }
     206}
     207CFList
     208get_Terms( const CanonicalForm & f ){
     209  CFList result,dummy,dummy2;
     210  CFIterator i;
     211  CFListIterator j;
     212
     213  if ( getNumVars(f) == 0 ) result.append(f);
     214  else{
     215    Variable _x(level(f));
     216    for ( i=f; i.hasTerms(); i++ ){
     217      getTerms(i.coeff(), 1, dummy);
     218      for ( j=dummy; j.hasItem(); j++ )
     219        result.append(j.getItem() * power(_x, i.exp()));
     220
     221      dummy= dummy2; // have to initalize new
     222    }
     223  }
     224  return result;
     225}
     226
     227
     228///////////////////////////////////////////////////////////////
     229// homogenize homogenizes f with Variable x                  //
     230///////////////////////////////////////////////////////////////
     231
     232CanonicalForm
     233homogenize( const CanonicalForm & f, const Variable & x)
     234{
     235#if 0
     236  int maxdeg=totaldegree(f), deg;
     237  CFIterator i;
     238  CanonicalForm elem, result=f.genZero();
     239 
     240  for (i=f; i.hasTerms(); i++)
     241  {
     242    elem= i.coeff()*power(f.mvar(),i.exp());
     243    deg = totaldegree(elem);
     244    if ( deg < maxdeg )
     245      result += elem * power(x,maxdeg-deg);
     246    else
     247      result+=elem;
     248  }
     249  return result;
     250#else
     251  CFList Newlist, Termlist= get_Terms(f);
     252  int maxdeg=totaldegree(f), deg;
     253  CFListIterator i;
     254  CanonicalForm elem, result=f.genZero();
     255
     256  for (i=Termlist; i.hasItem(); i++){
     257    elem= i.getItem();
     258    deg = totaldegree(elem);
     259    if ( deg < maxdeg )
     260      Newlist.append(elem * power(x,maxdeg-deg));
     261    else
     262      Newlist.append(elem);
     263  }
     264  for (i=Newlist; i.hasItem(); i++) // rebuild
     265    result += i.getItem();
     266
     267  return result;
     268#endif
     269}
     270
     271#ifdef SINGULAR
     272extern int singular_homog_flag;
     273#else
     274#define singular_homog_flag 1
     275#endif
     276static int cmpCF( const CFFactor & f, const CFFactor & g )
     277{
     278  if (f.exp() > g.exp()) return 1;
     279  if (f.exp() < g.exp()) return 0;
     280  if (f.factor() > g.factor()) return 1;
     281  return 0;
     282}
     283
    174284CFFList factorize ( const CanonicalForm & f, bool issqrfree )
    175285{
    176286  if ( f.inCoeffDomain() )
    177287        return CFFList( f );
    178   //out_cf("factorize:",f,"==================================\n");
    179288  int mv=f.level();
    180289  int org_v=mv;
     290  //out_cf("factorize:",f,"==================================\n");
    181291  if (! f.isUnivariate() )
    182292  {
     293    if ( singular_homog_flag && f.isHomogeneous())
     294    {
     295      Variable xn = get_max_degree_Variable(f);
     296      int d_xn = degree(f,xn);
     297      CFMap n;
     298      CanonicalForm F = compress(f(1,xn),n);
     299      CFFList Intermediatelist;
     300      Intermediatelist = factorize(F);
     301      CFFList Homoglist;
     302      CFFListIterator j;
     303      for ( j=Intermediatelist; j.hasItem(); j++ )
     304      {
     305        Homoglist.append(
     306            CFFactor( n(j.getItem().factor()), j.getItem().exp()) );
     307      }
     308      CFFList Unhomoglist;
     309      CanonicalForm unhomogelem;
     310      for ( j=Homoglist; j.hasItem(); j++ )
     311      {
     312        unhomogelem= homogenize(j.getItem().factor(),xn);
     313        Unhomoglist.append(CFFactor(unhomogelem,j.getItem().exp()));
     314        d_xn -= (degree(unhomogelem,xn)*j.getItem().exp());
     315      }
     316      if ( d_xn != 0 ) // have to append xn^(d_xn)
     317        Unhomoglist.append(CFFactor(CanonicalForm(xn),d_xn)); 
     318      if(isOn(SW_USE_NTL_SORT)) Unhomoglist.sort(cmpCF);
     319      return Unhomoglist;
     320    }
    183321    mv=find_mvar(f);
    184322    if ( getCharacteristic() == 0 )
     
    365503  }
    366504  //out_cff(F);
     505  if(isOn(SW_USE_NTL_SORT)) F.sort(cmpCF);
    367506  return F;
    368507}
  • factory/fac_cantzass.cc

    r1b82a2 rdad0bc5  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: fac_cantzass.cc,v 1.7 2004-10-11 10:49:20 Singular Exp $ */
     2/* $Id: fac_cantzass.cc,v 1.8 2005-12-09 08:35:38 Singular Exp $ */
    33
    44#include <config.h>
     
    105105    if ( numext > 0 )
    106106        mpz_clear( &qq );
    107 #ifdef HAVE_NTL
    108     extern  int NTLcmpCF( const CFFactor & f, const CFFactor & g );
    109     if(isOn(SW_USE_NTL_SORT)) H.sort(NTLcmpCF);
    110 #endif   
    111107    return H;
    112108}
Note: See TracChangeset for help on using the changeset viewer.