Changeset 32a335b in git for factory


Ignore:
Timestamp:
Dec 18, 1997, 6:05:33 PM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', 'd1b01e9d51ade4b46b745d3bada5c5f3696be3a8')
Children:
2819fdf06c242744ab232846f46e7da227b7efe0
Parents:
3bf67ab4766470c80c799a7fb75396a9af382ced
Message:
	* canonicalform.cc (operator ==, operator !=): rewritten and
	  speeded up
	  (operator >): slightly speeded up

	* canonicalform.cc (CanonicalForm::gcd): method removed.
	  Declaration adapted.

	* canonicalform.cc (degree, taildegree): one more time slightly
	  speeded up.  Hopefully for the last time.


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

Legend:

Unmodified
Added
Removed
  • factory/canonicalform.cc

    r3bf67ab r32a335b  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: canonicalform.cc,v 1.23 1997-10-27 14:15:36 schmidt Exp $ */
     2/* $Id: canonicalform.cc,v 1.24 1997-12-18 17:05:33 schmidt Exp $ */
    33
    44#include <config.h>
     
    423423    int what = is_imm( value );
    424424    if ( what )
    425         if ( what == GFMARK && imm_iszero_gf( value ) )
    426             return -1;
    427         else if ( what == FFMARK && imm_iszero_gf( value ) )
    428             return -1;
    429         else if ( what == INTMARK && imm_iszero( value ) )
    430             return -1;
     425        if ( what == FFMARK )
     426            return imm_iszero_p( value ) ? -1 : 0;
     427        else if ( what == INTMARK )
     428            return imm_iszero( value ) ? -1 : 0;
    431429        else
    432             return 0;
     430            return imm_iszero_gf( value ) ? -1 : 0;
    433431    else
    434432        return value->degree();
     
    440438    int what = is_imm( value );
    441439    if ( what )
    442         if ( what == GFMARK && imm_iszero_gf( value ) )
    443             return -1;
    444         else if ( what == FFMARK && imm_iszero_gf( value ) )
    445             return -1;
    446         else if ( what == INTMARK && imm_iszero( value ) )
    447             return -1;
     440        if ( what == FFMARK )
     441            return imm_iszero_p( value ) ? -1 : 0;
     442        else if ( what == INTMARK )
     443            return imm_iszero( value ) ? -1 : 0;
    448444        else
    449             return 0;
     445            return imm_iszero_gf( value ) ? -1 : 0;
    450446    else if ( value->inBaseDomain() )
    451447        return value->degree();
     
    507503    int what = is_imm( value );
    508504    if ( what )
    509         if ( what == GFMARK && imm_iszero_gf( value ) )
    510             return -1;
    511         else if ( what == FFMARK && imm_iszero_gf( value ) )
    512             return -1;
    513         else if ( what == INTMARK && imm_iszero( value ) )
    514             return -1;
     505        if ( what == FFMARK )
     506            return imm_iszero_p( value ) ? -1 : 0;
     507        else if ( what == INTMARK )
     508            return imm_iszero( value ) ? -1 : 0;
    515509        else
    516             return 0;
     510            return imm_iszero_gf( value ) ? -1 : 0;
    517511    else
    518512        return value->taildegree();
     
    10961090//
    10971091// deriv() derives CO with respect to its main variable.  Returns
    1098 // zero if f is in a coefficient domain.
     1092// zero from the current domain if f is in a coefficient domain.
    10991093//
    11001094// deriv( x ) derives CO with respect to x.  x should be a
    1101 // polynomial variable.  Returns zero if f is in a coefficient
    1102 // domain.
     1095// polynomial variable.  Returns zero from the current domain if
     1096// f is in a coefficient domain.
    11031097//
    11041098// See also: ::deriv()
     
    11471141//
    11481142// If CO is an integer or a rational number, the sign is defined
    1149 // as usual.  If CO is an element of a prime power domain or in a
    1150 // finite field and SW_SYMMETRIC_FF is on the sign of CO is the
    1151 // sign of the symmetric representation of CO.  If CO is in GF(q)
    1152 // or in a finite field and SW_SYMMETRIC_FF is off, the sign of
    1153 // CO is zero iff CO is zero, otherwise the sign is one.
     1143// as usual.  If CO is an element of a prime power domain or of
     1144// FF(p) and SW_SYMMETRIC_FF is on, the sign of CO is the sign of
     1145// the symmetric representation of CO.  If CO is in GF(q) or in
     1146// FF(p) and SW_SYMMETRIC_FF is off, the sign of CO is zero iff
     1147// CO is zero, otherwise the sign is one.
    11541148//
    11551149// If CO is a polynomial or in an extension of one of the base
     
    12421236//}}}
    12431237
    1244 //{{{ CanonicalForm CanonicalForm::gcd( const CanonicalForm & ) const
    1245 CanonicalForm
    1246 CanonicalForm::gcd( const CanonicalForm & ) const
    1247 {
    1248 //    return ::gcd( *this, f );
    1249     return 1;
    1250 }
    1251 //}}}
    1252 
    1253 //{{{ comparison operators
     1238//{{{ bool operator ==, operator != ( const CanonicalForm & lhs, const CanonicalForm & rhs )
     1239//{{{ docu
     1240//
     1241// operator ==(), operator !=() - compare canonical forms on
     1242//   (in)equality.
     1243//
     1244// operator ==() returns true iff lhs equals rhs.
     1245// operator !=() returns true iff lhs does not equal rhs.
     1246//
     1247// This is the point in factory where we essentially use that
     1248// CanonicalForms in fact are canonical.  There must not be two
     1249// different representations of the same mathematical object,
     1250// otherwise, such (in)equality will not be recognized by these
     1251// operators.  In other word, we rely on the fact that structural
     1252// different factory objects in any case represent different
     1253// mathematical objects.
     1254//
     1255// So we use the following procedure to test on equality (and
     1256// analogously on inequality).  First, we check whether lhs.value
     1257// equals rhs.value.  If so we are ready and return true.
     1258// Second, if one of the operands is immediate, but the other one
     1259// not, we return false.  Third, if the operand's levels differ
     1260// we return false.  Fourth, if the operand's levelcoeffs differ
     1261// we return false.  At last, we call the corresponding internal
     1262// method to compare both operands.
     1263//
     1264// Both operands should have coefficients from the same base domain.
     1265//
     1266// Note: To compare with the zero or the unit of the current domain,
     1267// you better use the methods `CanonicalForm::isZero()' or
     1268// `CanonicalForm::isOne()', resp., than something like `f == 0',
     1269// since the latter is quite a lot slower.
     1270//
     1271// See also: InternalCF::comparesame(),
     1272// InternalInteger::comparesame(), InternalRational::comparesame(),
     1273// InternalPrimePower::comparesame(), InternalPoly::comparesame()
     1274//
     1275//}}}
    12541276bool
    12551277operator == ( const CanonicalForm & lhs, const CanonicalForm & rhs )
    12561278{
    1257     int what = is_imm( lhs.value );
    1258     if ( what )
    1259         if ( what == is_imm( rhs.value ) )
    1260             return lhs.value == rhs.value;
     1279    if ( lhs.value == rhs.value )
     1280        return true;
     1281    else if ( is_imm( rhs.value ) || is_imm( lhs.value ) ) {
     1282        ASSERT( ! is_imm( rhs.value ) ||
     1283                ! is_imm( lhs.value ) ||
     1284                is_imm( rhs.value ) == is_imm( lhs.value ),
     1285                "incompatible operands" );
     1286        return false;
     1287    }
     1288    else  if ( lhs.value->level() != rhs.value->level() )
     1289        return false;
     1290    else  if ( lhs.value->levelcoeff() != rhs.value->levelcoeff() )
     1291        return false;
     1292    else
     1293        return rhs.value->comparesame( lhs.value ) == 0;
     1294}
     1295
     1296bool
     1297operator != ( const CanonicalForm & lhs, const CanonicalForm & rhs )
     1298{
     1299    if ( lhs.value == rhs.value )
     1300        return false;
     1301    else if ( is_imm( rhs.value ) || is_imm( lhs.value ) ) {
     1302        ASSERT( ! is_imm( rhs.value ) ||
     1303                ! is_imm( lhs.value ) ||
     1304                is_imm( rhs.value ) == is_imm( lhs.value ),
     1305                "incompatible operands" );
     1306        return true;
     1307    }
     1308    else  if ( lhs.value->level() != rhs.value->level() )
     1309        return true;
     1310    else  if ( lhs.value->levelcoeff() != rhs.value->levelcoeff() )
     1311        return true;
     1312    else        return rhs.value->comparesame( lhs.value ) != 0;
     1313}
     1314//}}}
     1315
     1316//{{{ bool operator >, operator < ( const CanonicalForm & lhs, const CanonicalForm & rhs )
     1317//{{{ docu
     1318//
     1319// operator >(), operator <() - compare canonical forms. on size or
     1320//   level.
     1321//
     1322// The most common and most useful application of these operators
     1323// is to compare two integers or rationals, of course.  However,
     1324// these operators are defined on all other base domains and on
     1325// polynomials, too.  From a mathematical point of view this may
     1326// seem meaningless, since there is no ordering on finite fields
     1327// or on polynomials respecting the algebraic structure.
     1328// Nevertheless, from a programmer's point of view it may be
     1329// sensible to order these objects, e.g. to sort them.
     1330//
     1331// For this reason, the ordering defined by these operators in
     1332// any case is a total ordering which fulfills the law of
     1333// trichotomy.
     1334//
     1335// It is clear how this is done in the case of the integers and
     1336// the rationals.  For finite fields, all you can say is that
     1337// zero is the minimal element w.r.t. the ordering, the other
     1338// elements are ordered in an arbitrary (but total!)  way.  For
     1339// polynomials, you have an ordering derived from the
     1340// lexicographical ordering of monomials.  E.g. if lm(f) < lm(g)
     1341// w.r.t. lexicographic ordering, then f < g.  For more details,
     1342// refer to the documentation of `InternalPoly::operator <()'.
     1343//
     1344// Both operands should have coefficients from the same base domain.
     1345//
     1346// The scheme how both operators are implemented is allmost the
     1347// same as for the assignment operators (check for immediates,
     1348// then check levels, then check levelcoeffs, then call the
     1349// appropriate internal comparesame()/comparecoeff() method).
     1350// For more information, confer to the overview for the
     1351// arithmetic operators.
     1352//
     1353// See also: InternalCF::comparesame(),
     1354// InternalInteger::comparesame(), InternalRational::comparesame(),
     1355// InternalPrimePower::comparesame(), InternalPoly::comparesame(),
     1356// InternalCF::comparecoeff(), InternalInteger::comparecoeff(),
     1357// InternalRational::comparecoeff(),
     1358// InternalPrimePower::comparecoeff(), InternalPoly::comparecoeff(),
     1359// imm_cmp(), imm_cmp_p(), imm_cmp_gf()
     1360//
     1361//}}}
     1362bool
     1363operator > ( const CanonicalForm & lhs, const CanonicalForm & rhs )
     1364{
     1365    int what = is_imm( rhs.value );
     1366    if ( is_imm( lhs.value ) ) {
     1367        ASSERT( ! what || (what == is_imm( lhs.value )), "incompatible operands" );
     1368        if ( what == 0 )
     1369            return rhs.value->comparecoeff( lhs.value ) < 0;
     1370        else if ( what == INTMARK )
     1371            return imm_cmp( lhs.value, rhs.value ) > 0;
     1372        else if ( what == FFMARK )
     1373            return imm_cmp_p( lhs.value, rhs.value ) > 0;
    12611374        else
    1262             return false;
    1263     else  if ( is_imm( rhs.value ) )
    1264         return false;
    1265     else  if ( lhs.level() == rhs.level() )
    1266         if ( lhs.value->levelcoeff() >= rhs.value->levelcoeff() )
    1267             return lhs.value->comparesame( rhs.value ) == 0;
    1268         else
    1269             return rhs.value->comparesame( lhs.value ) == 0;
    1270     else
    1271         return false;
    1272 }
    1273 
    1274 bool
    1275 operator != ( const CanonicalForm & lhs, const CanonicalForm & rhs )
    1276 {
    1277     int what = is_imm( lhs.value );
    1278     if ( what )
    1279         if ( what == is_imm( rhs.value ) )
    1280             return lhs.value != rhs.value;
    1281         else
    1282             return true;
    1283     else  if ( is_imm( rhs.value ) )
    1284         return true;
    1285     else  if ( lhs.level() == rhs.level() )
    1286         if ( lhs.value->levelcoeff() >= rhs.value->levelcoeff() )
    1287             return lhs.value->comparesame( rhs.value ) != 0;
    1288         else
    1289             return rhs.value->comparesame( lhs.value ) != 0;
    1290     else
    1291         return true;
    1292 }
    1293 
    1294 bool
    1295 operator > ( const CanonicalForm & lhs, const CanonicalForm & rhs )
    1296 {
    1297     int what = is_imm( lhs.value );
    1298     if ( what ) {
    1299         ASSERT ( ! is_imm( rhs.value ) || (what==is_imm( rhs.value )), "illegal base coefficients" );
    1300         if ( what == INTMARK ) {
    1301             if ( what == is_imm( rhs.value ) )
    1302                 return imm_cmp( lhs.value, rhs.value ) > 0;
    1303             else
    1304                 return rhs.value->comparecoeff( lhs.value ) < 0;
    1305         }
    1306         else  if ( what == FFMARK ) {
    1307             if ( what == is_imm( rhs.value ) )
    1308                 return imm_cmp_p( lhs.value, rhs.value ) > 0;
    1309             else
    1310                 return rhs.value->comparecoeff( lhs.value ) < 0;
    1311         }
    1312         else {
    1313             if ( what == is_imm( rhs.value ) )
    1314                 return imm_cmp_gf( lhs.value, rhs.value ) > 0;
    1315             else
    1316                 return rhs.value->comparecoeff( lhs.value ) < 0;
    1317         }
    1318     }
    1319     else  if ( is_imm( rhs.value ) )
     1375            return imm_cmp_gf( lhs.value, rhs.value ) > 0;
     1376    }
     1377    else  if ( what )
    13201378        return lhs.value->comparecoeff( rhs.value ) > 0;
    1321     else  if ( lhs.level() == rhs.level() )
     1379    else  if ( lhs.value->level() == rhs.value->level() )
    13221380        if ( lhs.value->levelcoeff() == rhs.value->levelcoeff() )
    13231381            return lhs.value->comparesame( rhs.value ) > 0;
     
    13331391operator < ( const CanonicalForm & lhs, const CanonicalForm & rhs )
    13341392{
    1335     int what = is_imm( lhs.value );
    1336     if ( what ) {
    1337         ASSERT ( ! is_imm( rhs.value ) || (what==is_imm( rhs.value )), "illegal base coefficients" );
    1338         if ( what == INTMARK ) {
    1339             if ( what == is_imm( rhs.value ) )
    1340                 return imm_cmp( lhs.value, rhs.value ) < 0;
    1341             else
    1342                 return rhs.value->comparecoeff( lhs.value ) > 0;
    1343         }
    1344         else  if ( what == FFMARK ) {
    1345             if ( what == is_imm( rhs.value ) )
    1346                 return imm_cmp( lhs.value, rhs.value ) < 0;
    1347             else
    1348                 return rhs.value->comparecoeff( lhs.value ) > 0;
    1349         }
    1350         else {
    1351             if ( what == is_imm( rhs.value ) )
    1352                 return imm_cmp( lhs.value, rhs.value ) < 0;
    1353             else
    1354                 return rhs.value->comparecoeff( lhs.value ) > 0;
    1355         }
    1356     }
    1357     else  if ( is_imm( rhs.value ) )
     1393    int what = is_imm( rhs.value );
     1394    if ( is_imm( lhs.value ) ) {
     1395        ASSERT( ! what || (what == is_imm( lhs.value )), "incompatible operands" );
     1396        if ( what == 0 )
     1397            return rhs.value->comparecoeff( lhs.value ) > 0;
     1398        else if ( what == INTMARK )
     1399            return imm_cmp( lhs.value, rhs.value ) < 0;
     1400        else if ( what == FFMARK )
     1401            return imm_cmp_p( lhs.value, rhs.value ) < 0;
     1402        else
     1403            return imm_cmp_gf( lhs.value, rhs.value ) < 0;
     1404    }
     1405    else  if ( what )
    13581406        return lhs.value->comparecoeff( rhs.value ) < 0;
    1359     else  if ( lhs.level() == rhs.level() )
     1407    else  if ( lhs.value->level() == rhs.value->level() )
    13601408        if ( lhs.value->levelcoeff() == rhs.value->levelcoeff() )
    13611409            return lhs.value->comparesame( rhs.value ) < 0;
Note: See TracChangeset for help on using the changeset viewer.