Changeset 281760 in git


Ignore:
Timestamp:
Jul 30, 1997, 9:53:32 AM (27 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', '82fc009ea2b0098c1a4896c841bb70860976bdfc')
Children:
f894fe76f06483776917c470ef9b608739619797
Parents:
13dc2e8b0a23ea7af7776b5b324c7fad636a953d
Message:
	* cf_ops.cc (fillVarsRec, getNumVars, getVars): moved from
	  canonicalform.cc to cf_ops.cc


git-svn-id: file:///usr/local/Singular/svn/trunk@580 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_ops.cc

    r13dc2e r281760  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_ops.cc,v 1.4 1997-07-30 07:40:20 schmidt Exp $ */
     2/* $Id: cf_ops.cc,v 1.5 1997-07-30 07:53:32 schmidt Exp $ */
    33
    44#include <config.h>
     
    270270//}}}
    271271
     272//{{{ static void fillVarsRec ( const CanonicalForm & f, int * vars )
     273//{{{ docu
     274//
     275// fillVarsRec - fill array describing occurences of variables in f.
     276//
     277// Only polynomial variables are looked up.  The information is
     278// stored in the arrary vars.  vars should be large enough to
     279// hold all information, i.e. larger than the level of f.
     280//
     281//}}}
     282static void
     283fillVarsRec ( const CanonicalForm & f, int * vars )
     284{
     285    int n;
     286    if ( (n = f.level()) > 0 ) {
     287        vars[n] = 1;
     288        CFIterator i;
     289        for ( i = f; i.hasTerms(); ++i )
     290            fillVarsRec( i.coeff(), vars );
     291    }
     292}
     293//}}}
     294
     295//{{{ int getNumVars( const CanonicalForm & f )
     296//{{{ docu
     297//
     298// getNumVars() - get number of polynomial variables in f.
     299//
     300//}}}
     301int
     302getNumVars( const CanonicalForm & f )
     303{
     304    int n;
     305    if ( f.inCoeffDomain() )
     306        return 0;
     307    else  if ( (n = f.level()) == 1 )
     308        return 1;
     309    else {
     310        int * vars = new int[ n+1 ];
     311        int i;
     312        for ( i = 0; i < n; i++ ) vars[i] = 0;
     313
     314        // look for variables
     315        for ( CFIterator I = f; I.hasTerms(); ++I )
     316            fillVarsRec( I.coeff(), vars );
     317
     318        // count them
     319        int m = 0;
     320        for ( i = 1; i < n; i++ )
     321            if ( vars[i] != 0 ) m++;
     322
     323        delete [] vars;
     324        // do not forget to count our own variable
     325        return m+1;
     326    }
     327}
     328//}}}
     329
     330//{{{ CanonicalForm getVars( const CanonicalForm & f )
     331//{{{ docu
     332//
     333// getVars() - get polynomial variables of f.
     334//
     335// Return the product of all of them, 1 if there are not any.
     336//
     337//}}}
     338CanonicalForm
     339getVars( const CanonicalForm & f )
     340{
     341    int n;
     342    if ( f.inCoeffDomain() )
     343        return 1;
     344    else  if ( (n = f.level()) == 1 )
     345        return Variable( 1 );
     346    else {
     347        int * vars = new int[ n+1 ];
     348        int i;
     349        for ( i = 0; i <= n; i++ ) vars[i] = 0;
     350
     351        // look for variables
     352        for ( CFIterator I = f; I.hasTerms(); ++I )
     353            fillVarsRec( I.coeff(), vars );
     354
     355        // multiply them all
     356        CanonicalForm result = 1;
     357        for ( i = n; i > 0; i-- )
     358            if ( vars[i] != 0 ) result *= Variable( i );
     359
     360        delete [] vars;
     361        // do not forget our own variable
     362        return f.mvar() * result;
     363    }
     364}
     365//}}}
     366
    272367//{{{ CanonicalForm resultant( const CanonicalForm & f, const CanonicalForm & g, const Variable & x )
    273368//{{{ docu
Note: See TracChangeset for help on using the changeset viewer.