Changeset 54c17f in git for factory/cf_resultant.cc
- Timestamp:
- Sep 1, 1997, 12:33:42 PM (26 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 9a7a66619e0df89480e6c5daec5c873e32ef749d
- Parents:
- 2a9b48fb27aed3a76b0a6669296c923aaf304822
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/cf_resultant.cc
r2a9b48 r54c17f 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: cf_resultant.cc,v 1. 1 1997-09-01 09:01:15schmidt Exp $ */2 /* $Id: cf_resultant.cc,v 1.2 1997-09-01 10:33:42 schmidt Exp $ */ 3 3 4 4 //{{{ docu … … 17 17 #include "variable.h" 18 18 19 //{{{ CFArray subResChain ( const CanonicalForm & f, const CanonicalForm & g, Variablex )19 //{{{ CFArray subResChain ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ) 20 20 //{{{ docu 21 21 // … … 37 37 //}}} 38 38 CFArray 39 subResChain ( const CanonicalForm & f, const CanonicalForm & g, Variablex )39 subResChain ( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ) 40 40 { 41 41 ASSERT( x.level() > 0, "cannot calculate subresultant sequence with respect to algebraic variables" ); … … 130 130 } 131 131 //}}} 132 133 //{{{ static CanonicalForm trivialResultant( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ) 134 //{{{ docu 135 // 136 // trivialResultant - calculate trivial resultants. 137 // 138 // x's level should be larger than f's and g's levels. Either f 139 // or g should be constant or both linear. 140 // 141 //}}} 142 static CanonicalForm 143 trivialResultant( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ) 144 { 145 // f or g in R 146 if ( degree( f, x ) == 0 ) 147 return power( f, degree( g, x ) ); 148 if ( degree( g, x ) == 0 ) 149 return power( g, degree( f, x ) ); 150 151 // f and g are linear polynomials 152 return LC( f, x ) * g - LC( g, x ) * f; 153 } 154 //}}} 155 156 //{{{ CanonicalForm resultant( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ) 157 //{{{ docu 158 // 159 // resultant() - return resultant of f and g with respect to x. 160 // 161 // The chain is calculated from f and g with respect to variable 162 // x which should not be an algebraic variable. If f or q equals 163 // zero, zero is returned. If f is a coefficient with respect to 164 // x, f^degree(g, x) is returned, analogously for g. 165 // 166 // This algorithm serves as a wrapper around other resultant 167 // algorithms which do the real work. Here we use standard 168 // properties of resultants only. 169 // 170 //}}} 171 CanonicalForm 172 resultant( const CanonicalForm & f, const CanonicalForm & g, const Variable & x ) 173 { 174 ASSERT( x.level() > 0, "cannot calculate resultant with respect to algebraic variables" ); 175 176 // some checks on triviality. We will not use degree( v ) 177 // here because this may involve variable swapping. 178 if ( f.isZero() || g.isZero() ) 179 return 0; 180 if ( f.mvar() < x ) 181 return power( f, g.degree( x ) ); 182 if ( g.mvar() < x ) 183 return power( g, f.degree( x ) ); 184 185 // make x main variale 186 CanonicalForm F, G; 187 Variable X; 188 if ( f.mvar() > x || g.mvar() > x ) { 189 if ( f.mvar() > g.mvar() ) 190 X = f.mvar(); 191 else 192 X = g.mvar(); 193 F = swapvar( f, X, x ); 194 G = swapvar( g, X, x ); 195 } 196 else { 197 X = x; 198 F = f; 199 G = g; 200 } 201 // at this point, we have to calculate resultant( F, G, X ) 202 // where X is equal to or greater than the main variables 203 // of F and G 204 205 int m = degree( F, X ); 206 int n = degree( G, X ); 207 // catch trivial cases 208 if ( m+n <= 2 || m == 0 || n == 0 ) 209 return swapvar( trivialResultant( F, G, X ), X, x ); 210 211 // exchange F and G if necessary 212 int flipFactor; 213 if ( m < n ) { 214 CanonicalForm swap = F; 215 F = G; G = swap; 216 int degswap = m; 217 m = n; n = degswap; 218 if ( m & 1 && n & 1 ) 219 flipFactor = -1; 220 else 221 flipFactor = 1; 222 } else 223 flipFactor = 1; 224 225 // this is not an effective way to calculate the resultant! 226 CanonicalForm extFactor; 227 if ( m == n ) { 228 if ( n & 1 ) 229 extFactor = -LC( G, X ); 230 else 231 extFactor = LC( G, X ); 232 } else 233 extFactor = power( LC( F, X ), m-n-1 ); 234 235 CanonicalForm result; 236 result = subResChain( F, G, X )[0] / extFactor; 237 238 return swapvar( result, X, x ) * flipFactor; 239 } 240 //}}}
Note: See TracChangeset
for help on using the changeset viewer.