Changeset 05d0b3 in git for factory


Ignore:
Timestamp:
Jan 22, 1998, 11:54:34 AM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38077648e7239f98078663eb941c3c979511150a')
Children:
77aa420ec44c556ecabc45845e40ff2c9a3bddca
Parents:
a0093a78296be293e083a8876f3aaaf0ce67c08c
Message:
	* int_cf.cc, int_int.cc int_rat.cc (bgcdsame, bgcdcoeff,
	  bextgcdsame, bextgcdcoeff): new methods.  Declarations added.


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

Legend:

Unmodified
Added
Removed
  • factory/int_cf.cc

    ra0093a7 r05d0b3  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: int_cf.cc,v 1.9 1997-12-17 11:30:06 schmidt Exp $ */
     2/* $Id: int_cf.cc,v 1.10 1998-01-22 10:54:00 schmidt Exp $ */
    33
    44#include <config.h>
     
    109109//}}}
    110110
     111//{{{ InternalCF * InternalCF::bgcdsame, bgcdcoeff ( const InternalCF * const )
     112// docu: see CanonicalForm::bgcd()
     113InternalCF *
     114InternalCF::bgcdsame ( const InternalCF * const ) const
     115{
     116    ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() );
     117    return CFFactory::basic( 0 );
     118}
     119
     120InternalCF *
     121InternalCF::bgcdcoeff ( const InternalCF * const )
     122{
     123    ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() );
     124    return CFFactory::basic( 0 );
     125}
     126//}}}
     127
     128//{{{ InternalCF * InternalCF::bextgcdsame ( InternalCF *, CanonicalForm & a, CanonicalForm & b )
     129// docu: see CanonicalForm::bextgcd()
     130InternalCF *
     131InternalCF::bextgcdsame ( InternalCF *, CanonicalForm & a, CanonicalForm & b )
     132{
     133    ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() );
     134    a = 0; b = 0;
     135    return CFFactory::basic( 0 );
     136}
     137
     138InternalCF *
     139InternalCF::bextgcdcoeff ( InternalCF *, CanonicalForm & a, CanonicalForm & b )
     140{
     141    ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() );
     142    a = 0; b = 0;
     143    return CFFactory::basic( 0 );
     144}
     145//}}}
     146
    111147int
    112148InternalCF::intval() const
  • factory/int_cf.h

    ra0093a7 r05d0b3  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: int_cf.h,v 1.8 1997-12-17 14:10:13 schmidt Exp $ */
     2/* $Id: int_cf.h,v 1.9 1998-01-22 10:54:07 schmidt Exp $ */
    33
    44#ifndef INCL_INT_CF_H
     
    6161
    6262    virtual InternalCF* neg() PVIRT_INTCF("neg");
    63     virtual InternalCF* invert(); // semantically const, changes refCount const
     63    virtual InternalCF* invert(); // semantically const, changes refCount
    6464    virtual int comparesame ( InternalCF * ) PVIRT_INT("comparesame");
    6565    virtual int comparecoeff ( InternalCF * ) PVIRT_INT("comparecoeff");
     
    8585    virtual bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool ) PVIRT_BOOL("divremcoefft");
    8686
     87    virtual InternalCF * bgcdsame ( const InternalCF * const ) const;
     88    virtual InternalCF * bgcdcoeff ( const InternalCF * const ); // semantically const, changes refcount
     89
     90    virtual InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & ); // semantically const, changes refcount
     91    virtual InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & ); // semantically const, changes refcount
     92
    8793    virtual InternalCF* sqrt();
    8894    virtual int ilog2();
  • factory/int_int.cc

    ra0093a7 r05d0b3  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: int_int.cc,v 1.10 1997-12-17 11:47:48 schmidt Exp $ */
     2/* $Id: int_int.cc,v 1.11 1998-01-22 10:54:15 schmidt Exp $ */
    33
    44#include <config.h>
     
    754754}
    755755
     756//{{{ InternalCF * InternalInteger::bgcdsame, bgcdcoeff ( const InternalCF * const c )
     757// docu: see CanonicalForm::bgcd()
     758InternalCF *
     759InternalInteger::bgcdsame ( const InternalCF * const c ) const
     760{
     761    ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
     762
     763    // simply return 1 if we are calculating over the rationals
     764    if ( cf_glob_switches.isOn( SW_RATIONAL ) )
     765         return int2imm( 1 );
     766
     767    // calculate gcd
     768    MP_INT result;
     769    mpz_init( &result );
     770    mpz_gcd( &result, &thempi, &MPI( c ) );
     771    mpz_abs( &result, &result );
     772
     773    // check for immediate result
     774    if ( mpz_is_imm( &result ) ) {
     775        InternalCF * res = int2imm( mpz_get_si( &result ) );
     776        mpz_clear( &result );
     777        return res;
     778    }
     779    else
     780        return new InternalInteger( result );
     781}
     782
     783InternalCF *
     784InternalInteger::bgcdcoeff ( const InternalCF * const c )
     785{
     786    ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
     787
     788    // simply return 1 if we are calculating over the rationals
     789    if ( cf_glob_switches.isOn( SW_RATIONAL ) )
     790         return int2imm( 1 );
     791
     792    int cInt = imm2int( c );
     793
     794    // trivial cases
     795    if ( cInt == 1 || cInt == -1 )
     796        return int2imm( 1 );
     797    else if ( cInt == 0 )
     798        return copyObject();
     799
     800    // calculate gcd.  We need a positive operand since
     801    // `mpz_gcd_ui()' operates an unsigned int's only.
     802    if ( cInt < 0 ) cInt = -cInt;
     803    MP_INT dummy;
     804    mpz_init( &dummy );
     805    // we do not need dummy since we know that cInt != 0
     806    cInt = mpz_gcd_ui( &dummy, &thempi, cInt );
     807    mpz_clear( &dummy );
     808    if ( cInt < 0 ) cInt = -cInt;
     809    return int2imm( cInt );
     810}
     811//}}}
     812
     813//{{{ InternalCF * InternalInteger::bextgcdsame( InternalCF * c, CanonicalForm & a, CanonicalForm & b )
     814InternalCF *
     815InternalInteger::bextgcdsame( InternalCF * c, CanonicalForm & a, CanonicalForm & b )
     816{
     817    ASSERT( ! ::is_imm( c ) && c->levelcoeff() == IntegerDomain, "incompatible base coefficients" );
     818
     819    // simply return 1 if we are calculating over the rationals
     820    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
     821        a = 1/CanonicalForm( copyObject() ); b = 0;
     822        return int2imm( 1 );
     823    }
     824
     825    // calculate extended gcd
     826    MP_INT result;
     827    MP_INT aMPI;
     828    MP_INT bMPI;
     829    mpz_init( &result );
     830    mpz_init( &aMPI );
     831    mpz_init( &bMPI );
     832    mpz_gcdext( &result, &aMPI, &bMPI, &thempi, &MPI( c ) );
     833   
     834    // check and modify signs
     835    if ( mpz_sgn( &result ) < 0 ) {
     836        mpz_neg( &result, &result );
     837        mpz_neg( &aMPI, &aMPI );
     838        mpz_neg( &bMPI, &bMPI );
     839    }
     840
     841    // postconditioning of result
     842    if ( mpz_is_imm( &aMPI ) ) {
     843        a = CanonicalForm( int2imm( mpz_get_si( &aMPI ) ) );
     844        mpz_clear( &aMPI );
     845    } else
     846        a = CanonicalForm( new InternalInteger( aMPI ) );
     847    if ( mpz_is_imm( &bMPI ) ) {
     848        b = CanonicalForm( int2imm( mpz_get_si( &bMPI ) ) );
     849        mpz_clear( &bMPI );
     850    } else
     851        b = CanonicalForm( new InternalInteger( bMPI ) );
     852    if ( mpz_is_imm( &result ) ) {
     853        InternalCF * res = int2imm( mpz_get_si( &result ) );
     854        mpz_clear( &result );
     855        return res;
     856    }
     857    else
     858        return new InternalInteger( result );
     859}
     860
     861InternalCF *
     862InternalInteger::bextgcdcoeff( InternalCF * c, CanonicalForm & a, CanonicalForm & b )
     863{
     864    ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
     865
     866    // simply return 1 if we are calculating over the rationals
     867    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
     868        a = 1/CanonicalForm( copyObject() ); b = 0;
     869        return int2imm( 1 );
     870    }
     871
     872    int cInt = imm2int( c );
     873
     874    // trivial cases
     875    if ( cInt == 1 || cInt == -1 ) {
     876        a = 0; b = cInt;
     877        return int2imm( 1 );
     878    } else if ( cInt == 0 ) {
     879        a = 1; b = 0;
     880        return copyObject();
     881    }
     882
     883    // calculate q and r such that CO = q*cInt + r
     884    InternalCF * q = 0, * r = 0;
     885    divremcoeff( c, q, r, false );
     886
     887    // we do not repeat all the code to calculate the gcd of two
     888    // immediates.  Note that r is an immediate since c != 0, so
     889    // we do not have to destroy it.  q is destroyed by the
     890    // CanonicalForm destructor, hence we do not need to worry
     891    // about it, either.
     892    CanonicalForm aPrime, bPrime;
     893    CanonicalForm result = bextgcd( c, r, aPrime, bPrime );
     894    a = bPrime;
     895    b = aPrime - CanonicalForm( q ) * bPrime;
     896
     897    return result.getval();
     898}
     899//}}}
     900
    756901int InternalInteger::intval() const
    757902{
  • factory/int_int.h

    ra0093a7 r05d0b3  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: int_int.h,v 1.6 1997-07-16 10:34:17 schmidt Exp $ */
     2/* $Id: int_int.h,v 1.7 1998-01-22 10:54:22 schmidt Exp $ */
    33
    44#ifndef INCL_INT_INT_H
     
    7171    bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
    7272
     73    InternalCF * bgcdsame ( const InternalCF * const ) const;
     74    InternalCF * bgcdcoeff ( const InternalCF * const );
     75
     76    InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & );
     77    InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & );
     78
    7379    int intval() const;
    7480
  • factory/int_rat.cc

    ra0093a7 r05d0b3  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: int_rat.cc,v 1.9 1997-12-17 11:39:32 schmidt Exp $ */
     2/* $Id: int_rat.cc,v 1.10 1998-01-22 10:54:28 schmidt Exp $ */
    33
    44#include <config.h>
     
    707707}
    708708
     709//{{{ InternalCF * InternalRational::bgcdsame, bgcdcoeff ( const InternalCF * const )
     710// docu: see CanonicalForm::bgcd()
     711InternalCF *
     712InternalRational::bgcdsame ( const InternalCF * const ) const
     713{
     714    return int2imm( 1 );
     715}
     716
     717InternalCF *
     718InternalRational::bgcdcoeff ( const InternalCF * const )
     719{
     720    return int2imm( 1 );
     721}
     722//}}}
     723
     724//{{{ InternalCF * InternalRational::bextgcdsame ( InternalCF * c, CanonicalForm & a, CanonicalForm & b )
     725// docu: see CanonicalForm::bextgcd()
     726InternalCF *
     727InternalRational::bextgcdsame ( InternalCF *, CanonicalForm & a, CanonicalForm & b )
     728{
     729    a = 1/CanonicalForm( copyObject() ); b = 0;
     730    return int2imm( 1 );
     731}
     732
     733InternalCF *
     734InternalRational::bextgcdcoeff ( InternalCF *, CanonicalForm & a, CanonicalForm & b )
     735{
     736    a = 1/CanonicalForm( copyObject() ); b = 0;
     737    return int2imm( 1 );
     738}
     739//}}}
     740
    709741InternalCF * InternalRational::normalize_myself()
    710742{
  • factory/int_rat.h

    ra0093a7 r05d0b3  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: int_rat.h,v 1.4 1997-06-19 12:22:22 schmidt Exp $ */
     2/* $Id: int_rat.h,v 1.5 1998-01-22 10:54:34 schmidt Exp $ */
    33
    44#ifndef INCL_INT_RAT_H
     
    1515#include "assert.h"
    1616
     17#include "canonicalform.h"
    1718#include "int_cf.h"
    18 
     19#include "imm.h"
    1920
    2021class InternalRational : public InternalCF
     
    8182    bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
    8283
     84    InternalCF * bgcdsame ( const InternalCF * const ) const;
     85    InternalCF * bgcdcoeff ( const InternalCF * const );
     86
     87    InternalCF * bextgcdsame ( InternalCF *, CanonicalForm &, CanonicalForm & );
     88    InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & );
     89
    8390    int intval() const;
    8491
Note: See TracChangeset for help on using the changeset viewer.