Changeset cbb3fa in git


Ignore:
Timestamp:
Sep 8, 1997, 6:02:02 PM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
06723319e8641168ca5cb089e3bdc6d0f24285d3
Parents:
8e6674ec04c524b77f3d7fdc1570fddadfaa16c3
Message:
	* cf_algorithm.cc (psr, psq, psqr): assertions added

	* cf_algorithm.cc (psq, psqr): return correct values now if deg(f)
	  < deg(g)
	  (psr, psq, psqr): return correct values now if f = 0

	* cf_algorithm.cc (cden): recursion terminates now for f in base
	  domain instead for f in coefficient domain


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

Legend:

Unmodified
Added
Removed
  • factory/cf_algorithm.cc

    r8e6674 rcbb3fa  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: cf_algorithm.cc,v 1.1 1997-09-04 15:30:20 schmidt Exp $ */
     2/* $Id: cf_algorithm.cc,v 1.2 1997-09-08 16:02:02 schmidt Exp $ */
    33
    44//{{{ docu
     
    1010// algorithm which gives structural information on polynomials.
    1111//
    12 // Compare these functions with the functions in cf_ops.cc, which
    13 // are structural algorithms.
     12// Compare these functions to the functions in cf_ops.cc, which are
     13// structural algorithms.
     14//
     15// Used by: cf_gcd.cc, cf_resultant.cc
    1416//
    1517//}}}
    1618
    1719#include <config.h>
     20
     21#include "assert.h"
    1822
    1923#include "cf_defs.h"
     
    2226#include "cf_iter.h"
    2327
     28//{{{ CanonicalForm psr ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x )
     29//{{{ docu
     30//
     31// psr() - calculate pseudo remainder of f and g with respect to x.
     32//
     33// x should be a polynomial variable.
     34//
     35// For f and g in R[x], R an integral domain, g != 0, there is a
     36// unique representation
     37//
     38//   lc(g)^s*f = g*q + r
     39//
     40// with r = 0 or deg(r) < deg(g) and s = 0 if f = 0 or
     41// s = max( 0, deg(f)-deg(g)+1 ) otherwise.
     42// Then r = psr(f, g) and q = psq(f, g) are called pseudo
     43// remainder and pseudo quotient, resp.
     44//
     45// See H.-J. Reiffen/G. Scheja/U. Vetter - 'Algebra', 2nd ed.,
     46// par. 15 for a reference.
     47//
     48//}}}
    2449CanonicalForm
    2550psr ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x )
    2651{
    27     int m = f.degree( x );
    28     int n = g.degree( x );
    29     if ( m < n )
     52    ASSERT( x.level() > 0, "cannot calculate pseudo remainder/quotient with respect to algebraic variables" );
     53    ASSERT( g != 0, "division by zero" );
     54
     55    int m = degree( f, x );
     56    int n = degree( g, x );
     57    if ( m < 0 || m < n )
    3058        return f;
    3159    else
    3260        return ( power( LC( g, x ), m-n+1 ) * f ) % g;
    3361}
     62//}}}
    3463
     64//{{{ CanonicalForm psq ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x )
     65//{{{ docu
     66//
     67// psq() - calculate pseudo quotient of f and g with respect to x.
     68//
     69// x should be a polynomial variable.  See psr() for more
     70// detailed information.
     71//
     72//}}}
    3573CanonicalForm
    3674psq ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x )
    3775{
    38     return ( power( LC( g, x ), degree( f, x )-degree( g, x )+1 ) * f ) / g;
     76    ASSERT( x.level() > 0, "cannot calculate pseudo remainder/quotient with respect to algebraic variables" );
     77    ASSERT( g != 0, "division by zero" );
     78
     79    int m = degree( f, x );
     80    int n = degree( g, x );
     81    if ( m < 0 || m < n )
     82        return 0;
     83    else
     84        return ( power( LC( g, x ), m-n+1 ) * f ) / g;
    3985}
     86//}}}
    4087
     88//{{{ void psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r, const Variable & x )
     89//{{{ docu
     90//
     91// psqr() - calculate pseudo quotient and remainder of f and g with respect to x.
     92//
     93// x should be a polynomial variable.  See psr() for more
     94// detailed information.
     95//
     96//}}}
    4197void
    4298psqr ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & q, CanonicalForm & r, const Variable& x )
    4399{
    44     divrem( power( LC( g, x ), degree( f, x )-degree( g, x )+1 ) * f, g, q, r );
     100    ASSERT( x.level() > 0, "cannot calculate pseudo remainder/quotient with respect to algebraic variables" );
     101    ASSERT( g != 0, "division by zero" );
     102
     103    int m = degree( f, x );
     104    int n = degree( g, x );
     105    if ( m < 0 || m < n ) {
     106        q = 0; r = f;
     107    }
     108    else
     109        divrem( power( LC( g, x ), m-n+1 ) * f, g, q, r );
    45110}
     111//}}}
    46112
     113//{{{ static CanonicalForm cden ( const CanonicalForm & f )
     114//{{{ docu
     115//
     116// cden() - recursively calculate multivariate common denominator
     117//   of coefficients of f.
     118//
     119// Used by: common_den()
     120//
     121//}}}
    47122static CanonicalForm
    48123cden ( const CanonicalForm & f )
    49124{
    50     if ( f.inCoeffDomain() )
     125    if ( f.inBaseDomain() )
    51126        return f.den();
    52127    else {
     
    58133    }
    59134}
     135//}}}
    60136
     137//{{{ CanonicalForm common_den ( const CanonicalForm & f )
     138//{{{ docu
     139//
     140// common_den() - calculate multivariate common denominator of
     141//   coefficients of f.
     142//
     143// The common denominator is calculated with respect to all
     144// coefficients of f which are in a base domain.  In other words,
     145// common_den( f ) * f is guaranteed to have integer
     146// coefficients only.
     147//
     148// Returns one for domains other than Q.
     149//
     150//}}}
    61151CanonicalForm
    62152common_den ( const CanonicalForm & f )
    63153{
    64154    if ( getCharacteristic() == 0 && isOn( SW_RATIONAL ) ) {
     155        // switch to Z so lcm() will work correctly
    65156        Off( SW_RATIONAL );
    66157        CanonicalForm cd = cden( f );
     
    71162        return 1;
    72163}
     164//}}}
Note: See TracChangeset for help on using the changeset viewer.