Changeset 2085fc in git for factory


Ignore:
Timestamp:
Dec 17, 1997, 3:09:05 PM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', 'd1b01e9d51ade4b46b745d3bada5c5f3696be3a8')
Children:
818a5178f956c11702e9d2e0ebbf9922b7d13967
Parents:
55a5e8daa96ab4a7ccbc1691628558adb1f15196
Message:
	* int_poly.cc (comparesame): doc and assertion fix


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

Legend:

Unmodified
Added
Removed
  • factory/int_poly.cc

    r55a5e8d r2085fc  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: int_poly.cc,v 1.7 1997-12-09 09:05:44 schmidt Exp $ */
     2/* $Id: int_poly.cc,v 1.8 1997-12-17 14:09:05 schmidt Exp $ */
    33
    44#include <config.h>
     
    232232}
    233233
    234 int
    235 InternalPoly::comparesame ( InternalCF* acoeff )
    236 {
    237     InternalPoly* apoly = (InternalPoly*)acoeff;
    238     if ( this == apoly )
    239         return 0;
    240     else {
    241         termList cur1 = firstTerm;
    242         termList cur2 = apoly->firstTerm;
    243         for ( ; cur1 && cur2; cur1 = cur1->next, cur2 = cur2->next )
    244             if ( ( cur1->exp != cur2->exp ) || ( cur1->coeff != cur2->coeff ) )
    245                 if ( cur1->exp > cur2->exp )
    246                     return 1;
    247                 else  if ( cur1->exp < cur2->exp )
    248                     return -1;
    249                 else  if ( cur1->coeff > cur2->coeff )
    250                     return 1;
    251                 else
    252                     return -1;
    253         return cur1 != cur2;
    254     }
    255 }
    256 
    257234InternalCF*
    258235InternalPoly::addsame( InternalCF* aCoeff )
     
    628605}
    629606
     607//{{{ int InternalPoly::comparesame, comparecoeff ( InternalCF * acoeff )
     608//{{{ docu
     609//
     610// comparesame(), comparecoeff() - compare with an
     611//   InternalPoly.
     612//
     613// comparecoeff() always returns 1 since CO is defined to be
     614// larger than anything which is a coefficient w.r.t. CO.
     615//
     616// comparesame() compares the coefficient vectors of f=CO and
     617// g=acoeff w.r.t to a lexicographic order in the following way:
     618// f < g iff there exists an 0 <= i <= max(deg(f),deg(g)) s.t.
     619// i) f[j] = g[j] for all i < j <= max(deg(f),deg(g)) and
     620// ii) g[i] occurs in g (i.e. is not equal to zero) and
     621//     f[i] does not occur in f or f[i] < g[i] if f[i] occurs
     622// where f[i] denotes the coefficient to the power x^i of f.
     623//
     624// As usual, comparesame() returns 1 if CO is larger than c, 0 if
     625// CO equals c, and -1 if CO is less than c.  However, this
     626// function is optimized to test on equality since this is its
     627// most important and frequent usage.
     628//
     629// See the respective `CanonicalForm'-methods for an explanation
     630// why we define such a strange (but total) ordering on
     631// polynomials.
     632//
     633//}}}
    630634int
    631 InternalPoly::comparecoeff ( InternalCF* )
     635InternalPoly::comparesame ( InternalCF * acoeff )
     636{
     637    ASSERT( ! ::is_imm( acoeff ) && acoeff->level() > LEVELBASE, "incompatible base coefficients" );
     638    InternalPoly* apoly = (InternalPoly*)acoeff;
     639    // check on triviality
     640    if ( this == apoly )
     641        return 0;
     642    else {
     643        termList cursor1 = firstTerm;
     644        termList cursor2 = apoly->firstTerm;
     645        for ( ; cursor1 && cursor2; cursor1 = cursor1->next, cursor2 = cursor2->next )
     646            // we test on inequality of coefficients at this
     647            // point instead of testing on "less than" at the
     648            // last `else' in the enclosed `if' statement since a
     649            // test on inequaltiy in general is cheaper
     650            if ( (cursor1->exp != cursor2->exp) || (cursor1->coeff != cursor2->coeff) )
     651                if ( cursor1->exp > cursor2->exp )
     652                    return 1;
     653                else  if ( cursor1->exp < cursor2->exp )
     654                    return -1;
     655                else  if ( cursor1->coeff > cursor2->coeff )
     656                    return 1;
     657                else
     658                    return -1;
     659        // check trailing terms
     660        if ( cursor1 == cursor2 )
     661            return 0;
     662        else if ( cursor1 != 0 )
     663            return 1;
     664        else
     665            return -1;
     666    }
     667}
     668
     669int
     670InternalPoly::comparecoeff ( InternalCF * )
    632671{
    633672    return 1;
    634673}
     674//}}}
    635675
    636676InternalCF*
Note: See TracChangeset for help on using the changeset viewer.