Changeset 398b15 in git for factory/cf_gcd.cc


Ignore:
Timestamp:
Feb 2, 1998, 9:58:49 AM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
b0c783ccfcf6a8ce8a60e2e650e31f1b523d11cc
Parents:
f3b98ad1c11ea4bf6d3b9525f75480b2abf56cac
Message:
	* cf_gcd.cc (iextgcd, igcd): functions removed.  All references
	  replaced by `bextgcd()' and `bgcd()', resp.


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

Legend:

Unmodified
Added
Removed
  • factory/cf_gcd.cc

    rf3b98ad r398b15  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_gcd.cc,v 1.16 1998-01-27 10:18:33 pohl Exp $ */
     2/* $Id: cf_gcd.cc,v 1.17 1998-02-02 08:58:43 schmidt Exp $ */
    33
    44#include <config.h>
     
    115115//}}}
    116116
    117 //{{{ CanonicalForm igcd ( const CanonicalForm & f, const CanonicalForm & g )
    118 //{{{ docu
    119 //
    120 // igcd() - return integer gcd of f and g.
    121 //
    122 // Calculates the integer gcd of f and g using the euclidean
    123 // algorithm if f and g are integers and we are not calculating
    124 // in Q.  Returns one in all other cases.  Normalizes result.
    125 //
    126 //}}}
    127 CanonicalForm
    128 igcd ( const CanonicalForm & f, const CanonicalForm & g )
    129 {
    130     CanonicalForm a, b, c, dummy;
    131 
    132     if ( f.inZ() && g.inZ() && ! isOn( SW_RATIONAL ) ) {
    133         if ( f.sign() < 0 ) a = -f; else a = f;
    134         if ( g.sign() < 0 ) b = -g; else b = g;
    135         while ( ! b.isZero() ) {
    136             divrem( a, b, dummy, c );
    137             a = b;
    138             b = c;
    139         }
    140         return a;
    141     }
    142     else
    143         return 1;
    144 }
    145 //}}}
    146 
    147117//{{{ static CanonicalForm icontent ( const CanonicalForm & f, const CanonicalForm & c )
    148118//{{{ docu
     
    179149{
    180150    return icontent( f, 0 );
    181 }
    182 //}}}
    183 
    184 //{{{ CanonicalForm iextgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a, CanonicalForm & b )
    185 //{{{ docu
    186 //
    187 // iextgcd() - calculate extended integer gcd.
    188 //
    189 // Returns gcd(f, g) and a and b sucht that f*a+g*b=gcd(f, g).
    190 // The gcd is calculated using an extended euclidean polynomial
    191 // remainder sequence.  Normalizes result.
    192 //
    193 // Note: be sure you are calculating in Z, and not in Q!
    194 //
    195 //}}}
    196 CanonicalForm
    197 iextgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a, CanonicalForm & b )
    198 {
    199     CanonicalForm p0 = f, p1 = g;
    200     CanonicalForm f0 = 1, f1 = 0, g0 = 0, g1 = 1, q, r;
    201 
    202     while ( ! p1.isZero() ) {
    203         divrem( p0, p1, q, r );
    204         p0 = p1; p1 = r;
    205         r = g0 - g1 * q;
    206         g0 = g1; g1 = r;
    207         r = f0 - f1 * q;
    208         f0 = f1; f1 = r;
    209     }
    210     a = f0;
    211     b = g0;
    212     if ( p0.sign() < 0 ) {
    213         p0 = -p0;
    214         a = -a;
    215         b = -b;
    216     }
    217     return p0;
    218151}
    219152//}}}
     
    277210        f = F / cF;
    278211        g = G / cG;
    279         c = igcd( cF, cG );
     212        c = bgcd( cF, cG );
    280213    }
    281214    cg = gcd( f.lc(), g.lc() );
     
    550483    else  if ( f.inBaseDomain() )
    551484        if ( g.inBaseDomain() )
    552             return igcd( f, g );
     485            return bgcd( f, g );
    553486        else
    554487            return cf_content( g, f );
Note: See TracChangeset for help on using the changeset viewer.