00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_POLYNOMIAL_QUOTIENT_INL
00044 #define LASS_GUARDIAN_OF_INCLUSION_NUM_POLYNOMIAL_QUOTIENT_INL
00045
00046 #include "num_common.h"
00047 #include "polynomial.h"
00048
00049 namespace lass
00050 {
00051 namespace num
00052 {
00053
00054
00055
00056 template <typename T>
00057 PolynomialQuotient<T>::PolynomialQuotient():
00058 numerator_(),
00059 denominator_(TNumTraits::one)
00060 {
00061 }
00062
00063
00064 template <typename T>
00065 PolynomialQuotient<T>::PolynomialQuotient(TParam scalar):
00066 numerator_(scalar),
00067 denominator_(TNumTraits::one)
00068 {
00069 }
00070
00071
00072
00073 template <typename T>
00074 PolynomialQuotient<T>::PolynomialQuotient(const TCoefficients& numerator):
00075 numerator_(numerator),
00076 denominator_(TNumTraits::one)
00077 {
00078 }
00079
00080
00081
00082 template <typename T>
00083 PolynomialQuotient<T>::PolynomialQuotient(const TPolynomial& numerator):
00084 numerator_(numerator),
00085 denominator_(TNumTraits::one)
00086 {
00087 }
00088
00089
00090
00091 template <typename T>
00092 PolynomialQuotient<T>::PolynomialQuotient(const TCoefficientsPair& numeratorDenominator):
00093 numerator_(numeratorDenominator.first),
00094 denominator_(numeratorDenominator.second)
00095 {
00096 }
00097
00098
00099
00100 template <typename T>
00101 PolynomialQuotient<T>::PolynomialQuotient(TParam scalar, const TCoefficients& denominator):
00102 numerator_(scalar),
00103 denominator_(denominator)
00104 {
00105 }
00106
00107
00108
00109 template <typename T>
00110 PolynomialQuotient<T>::PolynomialQuotient(TParam scalar, const TPolynomial& denominator):
00111 numerator_(scalar),
00112 denominator_(denominator)
00113 {
00114 }
00115
00116
00117
00118 template <typename T>
00119 PolynomialQuotient<T>::PolynomialQuotient(const TCoefficients& numerator, const TCoefficients& denominator):
00120 numerator_(numerator),
00121 denominator_(denominator)
00122 {
00123 }
00124
00125
00126
00127 template <typename T>
00128 PolynomialQuotient<T>::PolynomialQuotient(const TPolynomial& numerator, const TPolynomial& denominator):
00129 numerator_(numerator),
00130 denominator_(denominator)
00131 {
00132 }
00133
00134
00135 template <typename T>
00136 template <typename InputIterator>
00137 PolynomialQuotient<T>::PolynomialQuotient(InputIterator numFirst, InputIterator numLast):
00138 numerator_(numFirst, numLast),
00139 denominator_(TNumTraits::one)
00140 {
00141 }
00142
00143
00144 template <typename T>
00145 template <typename InputIterator>
00146 PolynomialQuotient<T>::PolynomialQuotient(
00147 InputIterator numFirst, InputIterator numLast, InputIterator denFirst, InputIterator denLast):
00148 numerator_(numFirst, numLast),
00149 denominator_(denFirst, denLast)
00150 {
00151 }
00152
00153
00154
00155 template <typename T> inline
00156 const typename PolynomialQuotient<T>::TPolynomial&
00157 PolynomialQuotient<T>::numerator() const
00158 {
00159 return numerator_;
00160 }
00161
00162
00163
00164 template <typename T> inline
00165 const typename PolynomialQuotient<T>::TPolynomial&
00166 PolynomialQuotient<T>::denominator() const
00167 {
00168 return denominator_;
00169 }
00170
00171
00172
00173 template <typename T>
00174 const typename PolynomialQuotient<T>::TValue
00175 PolynomialQuotient<T>::operator()(TParam x) const
00176 {
00177 return numerator_(x) / denominator_(x);
00178 }
00179
00180
00181
00182 template <typename T>
00183 const PolynomialQuotient<T>& PolynomialQuotient<T>::operator+() const
00184 {
00185 return *this;
00186 }
00187
00188
00189
00190 template <typename T>
00191 const PolynomialQuotient<T> PolynomialQuotient<T>::operator-() const
00192 {
00193 return TSelf(-numerator_, denominator_);
00194 }
00195
00196
00197
00198 template <typename T>
00199 PolynomialQuotient<T>& PolynomialQuotient<T>::operator+=(const TSelf& other)
00200 {
00201 numerator_ = numerator_ * other.denominator_ + other.numerator_ * other.denominator_;
00202 denominator_ *= other.denominator_;
00203 return *this;
00204 }
00205
00206
00207
00208 template <typename T>
00209 PolynomialQuotient<T>& PolynomialQuotient<T>::operator-=(const TSelf& other)
00210 {
00211 numerator_ = numerator_ * other.denominator_ - other.numerator_ * other.denominator_;
00212 denominator_ *= other.denominator_;
00213 return *this;
00214 }
00215
00216
00217
00218 template <typename T>
00219 PolynomialQuotient<T>& PolynomialQuotient<T>::operator*=(const TSelf& other)
00220 {
00221 numerator_ *= other.numerator_;
00222 denominator_ *= other.denominator_;
00223 return *this;
00224 }
00225
00226
00227
00228 template <typename T>
00229 PolynomialQuotient<T>& PolynomialQuotient<T>::operator/=(const TSelf& other)
00230 {
00231 numerator_ *= other.denominator_;
00232 denominator_ *= other.numerator_;
00233 return *this;
00234 }
00235
00236
00237
00238 template <typename T>
00239 PolynomialQuotient<T>& PolynomialQuotient<T>::operator+=(const Polynomial<T>& other)
00240 {
00241 numerator_ += other * denominator_;
00242 return *this;
00243 }
00244
00245
00246
00247 template <typename T>
00248 PolynomialQuotient<T>& PolynomialQuotient<T>::operator-=(const Polynomial<T>& other)
00249 {
00250 numerator_ -= other * denominator_;
00251 return *this;
00252 }
00253
00254
00255
00256 template <typename T>
00257 PolynomialQuotient<T>& PolynomialQuotient<T>::operator*=(const Polynomial<T>& other)
00258 {
00259 numerator_ *= other;
00260 return *this;
00261 }
00262
00263
00264
00265 template <typename T>
00266 PolynomialQuotient<T>& PolynomialQuotient<T>::operator/=(const Polynomial<T>& other)
00267 {
00268 denominator_ *= other;
00269 return *this;
00270 }
00271
00272
00273
00274 template <typename T>
00275 PolynomialQuotient<T>& PolynomialQuotient<T>::operator+=(TParam scalar)
00276 {
00277 numerator_ += scalar * denominator_;
00278 return *this;
00279 }
00280
00281
00282
00283 template <typename T>
00284 PolynomialQuotient<T>& PolynomialQuotient<T>::operator-=(TParam scalar)
00285 {
00286 numerator_ -= scalar * denominator_;
00287 return *this;
00288 }
00289
00290
00291
00292 template <typename T>
00293 PolynomialQuotient<T>& PolynomialQuotient<T>::operator*=(TParam scalar)
00294 {
00295 numerator_ *= scalar;
00296 return *this;
00297 }
00298
00299
00300
00301 template <typename T>
00302 PolynomialQuotient<T>& PolynomialQuotient<T>::operator/=(TParam scalar)
00303 {
00304 numerator_ /= scalar;
00305 return *this;
00306 }
00307
00308
00309
00310 template <typename T>
00311 PolynomialQuotient<T> PolynomialQuotient<T>::derivative() const
00312 {
00313 const TPolynomial num = denominator_ * numerator_.derivative() - denominator_.derivative() * numerator_;
00314 const TPolynomial den = denominator_ * denominator_;
00315 return TSelf(num, den);
00316 }
00317
00318
00319
00320 template <typename T>
00321 PolynomialQuotient<T> PolynomialQuotient<T>::pow(unsigned power) const
00322 {
00323 return PolynomialQuotient<T>(numerator_.pow(power), denominator_.pow(power));
00324 }
00325
00326
00327
00328 template <typename T>
00329 PolynomialQuotient<T> PolynomialQuotient<T>::one()
00330 {
00331 static PolynomialQuotient result(1);
00332 return result;
00333 }
00334
00335
00336
00337 template <typename T>
00338 PolynomialQuotient<T> PolynomialQuotient<T>::x()
00339 {
00340 static TValue coefficients[2] = { 0, 1 };
00341 static PolynomialQuotient result(coefficients, coefficients + 2);
00342 return result;
00343 }
00344
00345
00346
00347
00348
00349 template <typename T>
00350 bool operator==(const PolynomialQuotient<T>& a, const PolynomialQuotient<T>& b)
00351 {
00352 return a.numerator() == b.numerator() && a.denominator() == b.denominator();
00353 }
00354
00355
00356
00357 template <typename T> inline
00358 bool operator!=(const PolynomialQuotient<T>& a, const PolynomialQuotient<T>& b)
00359 {
00360 return !(a == b);
00361 }
00362
00363
00364
00365 template <typename T> inline
00366 PolynomialQuotient<T> operator+(const PolynomialQuotient<T>& a, const PolynomialQuotient<T>& b)
00367 {
00368 PolynomialQuotient<T> result(a);
00369 result += b;
00370 return result;
00371 }
00372
00373
00374
00375 template <typename T> inline
00376 PolynomialQuotient<T> operator-(const PolynomialQuotient<T>& a, const PolynomialQuotient<T>& b)
00377 {
00378 PolynomialQuotient<T> result(a);
00379 result -= b;
00380 return result;
00381 }
00382
00383
00384
00385 template <typename T> inline
00386 PolynomialQuotient<T> operator*(const PolynomialQuotient<T>& a, const PolynomialQuotient<T>& b)
00387 {
00388 PolynomialQuotient<T> result(a);
00389 result *= b;
00390 return result;
00391 }
00392
00393
00394
00395 template <typename T> inline
00396 PolynomialQuotient<T> operator/(const PolynomialQuotient<T>& a, const PolynomialQuotient<T>& b)
00397 {
00398 PolynomialQuotient<T> result(a);
00399 result /= b;
00400 return result;
00401 }
00402
00403
00404
00405 template <typename T> inline
00406 PolynomialQuotient<T> operator+(const PolynomialQuotient<T>& a, const Polynomial<T>& b)
00407 {
00408 PolynomialQuotient<T> result(a);
00409 result += b;
00410 return result;
00411 }
00412
00413
00414
00415 template <typename T> inline
00416 PolynomialQuotient<T> operator-(const PolynomialQuotient<T>& a, const Polynomial<T>& b)
00417 {
00418 PolynomialQuotient<T> result(a);
00419 result -= b;
00420 return result;
00421 }
00422
00423
00424
00425 template <typename T> inline
00426 PolynomialQuotient<T> operator*(const PolynomialQuotient<T>& a, const Polynomial<T>& b)
00427 {
00428 PolynomialQuotient<T> result(a);
00429 result *= b;
00430 return result;
00431 }
00432
00433
00434
00435 template <typename T> inline
00436 PolynomialQuotient<T> operator/(const PolynomialQuotient<T>& a, const Polynomial<T>& b)
00437 {
00438 PolynomialQuotient<T> result(a);
00439 result /= b;
00440 return result;
00441 }
00442
00443
00444
00445 template <typename T> inline
00446 PolynomialQuotient<T> operator+(const Polynomial<T>& a, const PolynomialQuotient<T>& b)
00447 {
00448 PolynomialQuotient<T> result(b);
00449 result += a;
00450 return result;
00451 }
00452
00453
00454
00455 template <typename T> inline
00456 PolynomialQuotient<T> operator-(const Polynomial<T>& a, const PolynomialQuotient<T>& b)
00457 {
00458 PolynomialQuotient<T> result(a);
00459 result -= b;
00460 return result;
00461 }
00462
00463
00464
00465 template <typename T> inline
00466 PolynomialQuotient<T> operator*(const Polynomial<T>& a, const PolynomialQuotient<T>& b)
00467 {
00468 PolynomialQuotient<T> result(b);
00469 result *= a;
00470 return result;
00471 }
00472
00473
00474
00475 template <typename T> inline
00476 PolynomialQuotient<T> operator/(const Polynomial<T>& a, const PolynomialQuotient<T>& b)
00477 {
00478 PolynomialQuotient<T> result(a);
00479 result /= b;
00480 return result;
00481 }
00482
00483
00484
00485 template <typename T> inline
00486 PolynomialQuotient<T> operator+(const T& a, const PolynomialQuotient<T>& b)
00487 {
00488 PolynomialQuotient<T> result(b);
00489 result += a;
00490 return result;
00491 }
00492
00493
00494
00495 template <typename T> inline
00496 PolynomialQuotient<T> operator-(const T& a, const PolynomialQuotient<T>& b)
00497 {
00498 PolynomialQuotient<T> result(-b);
00499 result += a;
00500 return result;
00501 }
00502
00503
00504
00505 template <typename T> inline
00506 PolynomialQuotient<T> operator*(const T& a, const PolynomialQuotient<T>& b)
00507 {
00508 PolynomialQuotient<T> result(b);
00509 result *= a;
00510 return result;
00511 }
00512
00513
00514
00515 template <typename T> inline
00516 PolynomialQuotient<T> operator/(const T& a, const PolynomialQuotient<T>& b)
00517 {
00518 PolynomialQuotient<T> result(a);
00519 result /= b;
00520 return result;
00521 }
00522
00523
00524
00525 template <typename T> inline
00526 PolynomialQuotient<T> operator+(const PolynomialQuotient<T>& a, const T& b)
00527 {
00528 PolynomialQuotient<T> result(a);
00529 result += b;
00530 return result;
00531 }
00532
00533
00534
00535 template <typename T> inline
00536 PolynomialQuotient<T> operator-(const PolynomialQuotient<T>& a, const T& b)
00537 {
00538 PolynomialQuotient<T> result(a);
00539 result -= b;
00540 return result;
00541 }
00542
00543
00544
00545 template <typename T> inline
00546 PolynomialQuotient<T> operator*(const PolynomialQuotient<T>& a, const T& b)
00547 {
00548 PolynomialQuotient<T> result(a);
00549 result *= b;
00550 return result;
00551 }
00552
00553
00554
00555 template <typename T> inline
00556 PolynomialQuotient<T> operator/(const PolynomialQuotient<T>& a, const T& b)
00557 {
00558 PolynomialQuotient<T> result(a);
00559 result /= b;
00560 return result;
00561 }
00562
00563
00564
00565 template <typename T> inline
00566 PolynomialQuotient<T> operator/(const Polynomial<T>& a, const Polynomial<T>& b)
00567 {
00568 return PolynomialQuotient<T>(a, b);
00569 }
00570
00571
00572
00573 template <typename T, typename Char, typename Traits>
00574 std::basic_ostream<Char, Traits>&
00575 operator<<(std::basic_ostream<Char, Traits>& s, const PolynomialQuotient<T>& a)
00576 {
00577 s << "(" << a.numerator() << ")/(" << a.denominator() << ")";
00578 return s;
00579 }
00580
00581
00582
00583 }
00584
00585 }
00586
00587 #endif
00588
00589