00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SYNAPS_ARITHM_ALGEBRAIC_MPOLY_2_2_H
00018 #define SYNAPS_ARITHM_ALGEBRAIC_MPOLY_2_2_H
00019
00020
00021 #include <synaps/init.h>
00022 #include <synaps/usolve/Algebraic_config.h>
00023 #include <synaps/arithm/let.h>
00024 #include <synaps/mpol.h>
00025
00026
00027 __ALGEBRAIC_BEGIN_NAMESPACE
00028
00029
00030 template< typename RT > struct MPoly_2_2;
00031
00032 template < typename POLY,
00033 typename RT >
00034 POLY
00035 specialize_y(const MPoly_2_2<RT>& f, const typename NumberTraits<RT>::FT& a);
00036
00037
00042 template< typename RT_ >
00043 struct MPoly_2_2 {
00044
00045 static unsigned long counter;
00046
00047 typedef NumberTraits<RT_> NTR;
00048 typedef typename NTR::RT RT;
00049 typedef typename NTR::FT FT;
00050
00051 typedef std::vector<RT> Vector;
00052
00053 typedef RT value_type;
00054 typedef unsigned size_type;
00055
00056 std::vector<RT> C_;
00057 unsigned long id_;
00058 FT xc_;
00059 FT yc_;
00060
00061
00062 MPoly_2_2() : C_(6)
00063 {
00064 id_ = counter++;
00065 }
00066
00067 MPoly_2_2(const Vector& v)
00068 : C_(v)
00069 {
00070 id_ = counter++;
00071 }
00072
00073 MPoly_2_2(RT* C)
00074 : C_(6)
00075 {
00076 id_ = counter++;
00077 for (int i = 0; i < 6; ++i)
00078 C_[i] = C[i];
00079 }
00080
00081 MPoly_2_2(
00082 const RT& c5, const RT& c4, const RT& c3, const RT& c2, const RT& c1, const RT& c0
00083 ) : C_(6)
00084 {
00085 id_ = counter++;
00086 C_[5] = c5;
00087 C_[4] = c4;
00088 C_[3] = c3;
00089 C_[2] = c2;
00090 C_[1] = c1;
00091 C_[0] = c0;
00092 }
00093
00094
00095
00096 MPoly_2_2( const FT& c5, const FT& c4, const FT& c3,
00097 const FT& c2, const FT& c1, const FT& c0)
00098 : C_(6)
00099 {
00100 id_ = counter++;
00101 RT d = RT(1);
00102
00103 if (numerator(c5) != 0) d *= denominator(c5);
00104 if (numerator(c4) != 0) d *= denominator(c4);
00105 if (numerator(c3) != 0) d *= denominator(c3);
00106 if (numerator(c2) != 0) d *= denominator(c2);
00107 if (numerator(c1) != 0) d *= denominator(c1);
00108 if (numerator(c0) != 0) d *= denominator(c0);
00109
00110 C_[5] = numerator(c5) * (d / denominator(c5));
00111 C_[4] = numerator(c4) * (d / denominator(c4));
00112 C_[3] = numerator(c3) * (d / denominator(c3));
00113 C_[2] = numerator(c2) * (d / denominator(c2));
00114 C_[1] = numerator(c1) * (d / denominator(c1));
00115 C_[0] = numerator(c0) * (d / denominator(c0));
00116 }
00117
00119 MPoly_2_2& make_lcoeff_positive()
00120 {
00121 int i = 5;
00122 while (C_[i] == RT(0)) --i;
00123
00124 assert(i >= 1);
00125 if (C_[i] < RT(0)) {
00126 for (int j = i; j >= 0; --j)
00127 C_[j] = -C_[j];
00128 }
00129 return *this;
00130 }
00131
00133 MPoly_2_2& make_lcoeff_X_positive()
00134 {
00135 int pos;
00136 if (C_[5] != 0) pos = 5;
00137 else if (C_[2] != 0) pos = 2;
00138 else pos = 3;
00139
00140 if (pos != 3) {
00141 if (C_[pos] < 0) {
00142 for (int i = 0; i < 5; ++i) {
00143 C_[i] = -C_[i];
00144 }
00145 }
00146 }
00147 return *this;
00148 }
00149
00151 MPoly_2_2& make_lcoeff_Y_positive()
00152 {
00153 int pos;
00154 if (C_[4] != 0) pos = 4;
00155 else if (C_[1] != 0) pos = 1;
00156 else pos = 3;
00157
00158 if (pos != 3) {
00159 if (C_[pos] < 0) {
00160 for (int i = 0; i < 5; ++i) {
00161 C_[i] = -C_[i];
00162 }
00163 }
00164 }
00165 return *this;
00166 }
00167
00168
00170 MPoly_2_2& revertXY()
00171 {
00172 std::swap(C_[5], C_[4]);
00173 std::swap(C_[2], C_[1]);
00174 return *this;
00175 }
00176
00178 int degree(const int& idx) const
00179 {
00180
00181
00182 if (idx == 0) {
00183 if (C_[5] != RT(0)) return 2;
00184 if ((C_[3] != RT(0)) || (C_[2] != RT(0))) return 1;
00185 return 0;
00186 }
00187 if (C_[4] != RT(0)) return 2;
00188 if ((C_[3] != RT(0)) || (C_[1] != RT(0))) return 1;
00189 return 0;
00190 }
00191
00193 int degree() const
00194 {
00195 if ((C_[5] != RT(0)) || (C_[4] != RT(0)) || (C_[3] != RT(0))) return 2;
00196 if ((C_[2] != RT(0)) || (C_[1] != RT(0))) return 1;
00197 if (C_[0] != RT(0)) return 0;
00198 return -1;
00199 }
00200
00201 void set_center( const FT& xc, const FT& yc)
00202 {
00203 xc_ = xc;
00204 yc_ = yc;
00205 }
00206
00207 FT xc() const
00208 {
00209 return xc_;
00210 }
00211
00212 FT yc() const
00213 {
00214 return yc_;
00215 }
00216
00217
00218 void set_coeff(const size_type& i, const RT& x)
00219 { C_[i] = x; }
00220
00221 RT coeff(const size_type& i, const size_type& j) const
00222 {
00223 assert(i <= 2);
00224 assert(j <= 2);
00225
00226 switch (i) {
00227 case 2:
00228 return C_[5];
00229 break;
00230 case 1:
00231 if (j == 1) return C_[3];
00232 if (j == 0) return C_[2];
00233 break;
00234 default:
00235 if (j == 2) return C_[4];
00236 if (j == 1) return C_[1];
00237 if (j == 0) return C_[0];
00238 break;
00239 }
00240 }
00241
00242 RT operator[](const size_type& i) const
00243 {
00244 return C_[i];
00245 }
00246
00247 unsigned long id() const { return id_; }
00248
00249 template< typename POLY >
00250 int sign_at(const FT& x, const FT& y) const
00251 {
00252 return sign(eval(specialize_y<RT, POLY>(*this, y), x));
00253 }
00254 };
00255 template < typename RT >
00256 unsigned long MPoly_2_2<RT>::counter = 0;
00257
00258
00259 template < typename RT >
00260 bool operator==( const MPoly_2_2<RT>& f1, const MPoly_2_2<RT>& f2)
00261 {
00262 return (
00263 f1[0] == f2[0] &&
00264 f1[1] == f2[1] &&
00265 f1[2] == f2[2] &&
00266 f1[3] == f2[3] &&
00267 f1[4] == f2[4] &&
00268 f1[5] == f2[5] );
00269 }
00270
00271 template < typename RT >
00272 bool operator!=( const MPoly_2_2<RT>& f1, const MPoly_2_2<RT>& f2)
00273 {
00274 return !(f1 == f2);
00275 }
00276
00277
00278
00279 template < typename RT >
00280 std::ostream&
00281 print(std::ostream& os, const MPoly_2_2<RT>& f)
00282 {
00283 if (f[5] != 0)
00284 os << "(" << f[5] << ")" << "*X^2";
00285 if (f[4] != 0)
00286 os << " + (" << f[4] << ")" << "*Y^2";
00287 if (f[3] != 0)
00288 os << "+ (" << f[3] << ")" << "*X*Y";
00289 if (f[2] != 0)
00290 os << " + (" << f[2] << ")" << "*X";
00291 if (f[1] != 0)
00292 os << " + (" << f[1] << ")" << "*Y";
00293 if (f[0] != 0)
00294 os << " + (" << f[0] << ")";
00295 return os;
00296 }
00297
00298
00299 template < typename RT >
00300 std::ostream&
00301 operator<<(std::ostream& output, const MPoly_2_2<RT>& f)
00302 {
00303 return print(output, f);
00304 }
00305
00306
00307
00308 template < typename RT >
00309 MPoly_2_2<RT>
00310 diff(const MPoly_2_2<RT>& f, const int& idx)
00311 {
00312
00313
00314
00315 RT coeff[6] = {0, 0, 0, 0, 0, 0};
00316 if (idx == 0) {
00317 coeff[2] = RT(2) * f[5];
00318 coeff[1] = f[3];
00319 coeff[0] = f[2];
00320 } else {
00321 coeff[2] = f[3];
00322 coeff[1] = RT(2) * f[4];
00323 coeff[0] = f[1];
00324 }
00325 return MPoly_2_2<RT>(coeff);
00326 }
00327
00328
00329
00330 template < typename RT >
00331 MPoly_2_2<RT>
00332 diff_x(const MPoly_2_2<RT>& f)
00333 {
00334
00335
00336 RT coeff[6] = {0, 0, 0, 0, 0, 0};
00337 coeff[2] = RT(2) * f[5];
00338 coeff[1] = f[3];
00339 coeff[0] = f[2];
00340 return MPoly_2_2<RT>(coeff);
00341 }
00342
00343
00344
00345
00346 template < typename RT >
00347 MPoly_2_2<RT>
00348 diff_y(const MPoly_2_2<RT>& f)
00349 {
00350
00351
00352 RT coeff[6] = {0, 0, 0, 0, 0, 0};
00353 coeff[2] = f[3];
00354 coeff[1] = RT(2) * f[4];
00355 coeff[0] = f[1];
00356 return MPoly_2_2<RT>(coeff);
00357 }
00358
00359
00360 template < typename POLY,
00361 typename RT >
00362 POLY
00363 specialize_x(const MPoly_2_2<RT>& f, const typename NumberTraits<RT>::FT& a)
00364 {
00365 POLY p(3, AsSize());
00366
00367 RT n = numerator(a);
00368 RT d = denominator(a);
00369 RT d_2 = SQR(d);
00370 p[2] = f[4] * d_2;
00371 p[1] = d * ( f[1] * d + f[3] * n );
00372 p[0] = (f[5] * n + f[2] * d ) * n + f[0] * d_2;
00373
00374 return p;
00375 }
00376
00377
00378
00379 template < typename POLY,
00380 typename RT >
00381 POLY
00382 specialize_y(const MPoly_2_2<RT>& f, const typename NumberTraits<RT>::FT& a)
00383 {
00384
00385 POLY p(3, AsSize());
00386
00387 RT n = numerator(a);
00388 RT d = denominator(a);
00389 RT d_2 = SQR(d);
00390 p[2] = f[5] * d_2;
00391 p[1] = d * ( f[2] * d + f[3] * n );
00392 p[0] = (f[4] * n + f[1] * d) * n + f[0] * d_2;
00393
00394 return p;
00395 }
00396
00397
00398
00399
00400 template < typename POLY,
00401 typename RT >
00402 void
00403 resultant_y_2_2(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00404 {
00405 POLY A(2, AsSize());
00406 POLY B(3, AsSize());
00407 POLY R(5, AsSize());
00408
00409 RT t8 = g[3];
00410 RT t5 = g[1];
00411 RT t69 = ( t8 * t5);
00412 RT t28 = -2 * t69;
00413 RT t13 = f[0];
00414 RT t27 = -2 * t13;
00415 RT t15 = g[0];
00416 RT t22 = 2 * t15;
00417 RT t1 = g[4];
00418 RT t2 = f[1];
00419 RT t3 = ( t1 * t2);
00420 RT t10 = f[3];
00421 RT t17 = ( t3 * t10);
00422 RT t18 = f[2];
00423 RT t29 = ( t1 * t1);
00424 RT t12 = ( t29 * t18);
00425 RT t11 = (t2 * t8 + t10 * t5);
00426 RT t14 = t1 * t13;
00427 RT t32 = (t2 * t5);
00428 RT t9 = -2 * t14 - t32;
00429 RT t19 = t1 * t18;
00430 RT t4 = f[4];
00431 RT t20 = g[2];
00432 RT t21 = ( t4 * t20);
00433 RT t7 = t21 + t19;
00434 RT t6 = 2 * t21 + t11;
00435 A[0] = (-t3 + t4 * t5) * t1;
00436 A[1] = (t4 * t8 - t1 * t10) * t1;
00437 RT t16 = t4 * t15;
00438 B[0] = (-t14 + t16) * t1;
00439 B[1] = (-t19 + t21) * t1;
00440 RT t23 = f[5];
00441 RT t24 = t1 * t23;
00442 RT t25 = g[5];
00443 RT t26 = t4 * t25;
00444 B[2] = -(t24 - t26) * t1;
00445 RT t37 = (t2 * t2);
00446 RT t38 = t1 * t37;
00447 RT t40 = t4 * t4;
00448 RT t43 = t13 * t4;
00449 RT t44 = t5 * t5;
00450 R[0] = -t1 * (t29 * t13 * t13 - t14 * t32 + t43 * t44 + t9 * t16 + (t38 + t15 * t40) * t15);
00451 RT t52 = t1 * t4;
00452 RT t72 = t18 * t4;
00453 R[1] = -t1 * (2 * t13 * t12 + t17 * t22 + 2 * t43 * t69 + t72 * t44 - t7 * t32 - t11 * t14 + (t38 + t52 * t27 + t40 * t22) * t20 + (-2 * t19 - t11) * t16);
00454 RT t94 = t8 * t10;
00455 RT t96 = t10 * t10;
00456 RT t110 = t8 * t8;
00457 R[2] = t1 * (t72 * t28 - t9 * t26 + (-t44 * t23 - t110 * t13) * t4 + t11 * t21 + (-t20 * t20 - 2 * t15 * t25) * t40 - 2 * t20 * t17 + (-t15 * t96 - t25 * t37) * t1 + t6 * t19 + (-t18 * t18 + t23 * t27) * t29 + (t16 + t14) * t94 + (t32 + 2 * t16) * t24);
00458 RT t133 = t1 * t96;
00459 RT t144 = t23 * t4;
00460 R[3] = t1 * (-2 * t23 * t12 + t28 * t144 - t133 * t20 - t72 * t110 + t11 * t26 + t7 * t94 + 2 * (-t17 + t52 * t18 - t40 * t20) * t25 + t6 * t24);
00461 R[4] = -t1 * (t29 * t23 * t23 + (-t26 - t24) * t94 + t144 * t110 - 2 * t24 * t26 + (t133 + t40 * t25) * t25);
00462
00463 AA = A;
00464 BB = B;
00465 RR = R;
00466 return;
00467 }
00468
00469
00470 template < typename POLY,
00471 typename RT >
00472 void
00473 resultant_y_2_1(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00474 {
00475
00476
00477
00478
00479 POLY A(2, AsSize());
00480 POLY B(3, AsSize());
00481 POLY R(5, AsSize());
00482
00483 A[0] = g[1];
00484 A[1] = g[3];
00485 RT t11 = -2 * A[1] * A[0];
00486 RT t7 = f[4];
00487 B[2] = g[5];
00488 RT t9 = -2 * B[2] * t7;
00489 B[1] = g[2];
00490 RT t6 = B[2] * A[0] + B[1] * A[1];
00491 B[0] = g[0];
00492 RT t3 = B[1] * A[0] + B[0] * A[1];
00493 RT t1 = pow( A[0], 2);
00494 RT t2 = f[0];
00495 RT t4 = B[0] * A[0];
00496 RT t5 = f[1];
00497 R[0] = -t1 * t2 + t4 * t5 - t7 * pow( B[0], 2);
00498 RT t15 = f[3];
00499 RT t20 = f[2];
00500 R[1] = -t20 * t1 + t2 * t11 + t4 * t15 - 2 * B[1] * t7 * B[0] + t3 * t5;
00501 RT t36 = f[5];
00502 RT t39 = pow(A[1], 2);
00503 R[2] = B[0] * t9 + t20 * t11 - t1 * t36 - pow( B[1], 2) * t7 - t39 * t2 + t3 * t15 + t6 * t5;
00504 RT t41 = B[2] * A[1];
00505 R[3] = t41 * t5 + B[1] * t9 - t39 * t20 + t36 * t11 + t6 * t15;
00506 R[4] = -t39 * t36 - pow( B[2], 2) * t7 + t41 * t15;
00507
00508 AA = A;
00509 BB = B;
00510 RR = R;
00511 return;
00512 }
00513
00514
00515 template < typename POLY,
00516 typename RT >
00517 void
00518 resultant_y_1_2(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00519 {
00520
00521 resultant_y_2_1<POLY>(g, f, AA, BB, RR);
00522 return;
00523 }
00524
00525
00526
00527 template < typename POLY,
00528 typename RT >
00529 void
00530 resultant_y_2_0(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00531 {
00532
00533
00534
00535 POLY A(2, AsSize());
00536 POLY B(3, AsSize());
00537 POLY R(5, AsSize());
00538
00539 B[0] = g[0];
00540 B[1] = g[2];
00541 B[2] = g[5];
00542 RT t1 = f[4];
00543 R[0] = -f[4] * pow(B[0], 2);
00544 R[1] = -2 * f[4] * B[0] * B[1];
00545 R[2] = -t1 * (2 * B[0] * B[2] + pow(B[1], 2));
00546 R[3] = -2 * f[4] * B[1] * B[2];
00547 R[4] = -f[4] * pow(B[2], 2);
00548
00549 AA = A;
00550 BB = B;
00551 RR = R;
00552 return;
00553 }
00554
00555
00556
00557 template < typename POLY,
00558 typename RT >
00559 void
00560 resultant_y_0_2(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00561 {
00562 return resultant_y_2_0<POLY>(g, f, AA, BB, RR);
00563 }
00564
00565
00566 template < typename POLY,
00567 typename RT >
00568 void
00569 resultant_y_1_1(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00570 {
00571
00572
00573
00574 POLY A(2, AsSize());
00575 POLY B(3, AsSize());
00576 POLY R(5, AsSize());
00577
00578 A[1] = g[3];
00579 A[0] = g[1];
00580 RT t5 = -2 * A[1] * A[0];
00581 B[1] = g[2];
00582 B[2] = g[5];
00583 RT t4 = A[1] * B[1] + A[0] * B[2];
00584 B[0] = g[0];
00585 RT t2 = A[1] * B[0] + A[0] * B[1];
00586 RT t1 = f[0];
00587 RT t3 = f[1];
00588 R[0] = (-A[0] * t1 + B[0] * t3) * A[0];
00589 RT t11 = pow(A[0], 2);
00590 RT t12 = f[2];
00591 RT t17 = f[3];
00592 R[1] = t1 * t5 - t11 * t12 + A[0] * B[0] * t17 + t2 * t3;
00593 RT t21 = pow( A[1], 2);
00594 RT t27 = f[5];
00595 R[2] = t12 * t5 - t21 * t1 - t11 * t27 + t4 * t3 + t2 * t17;
00596 R[3] = t27 * t5 - t21 * t12 + A[1] * B[2] * t3 + t4 * t17;
00597 R[4] = -(A[1] * t27 - B[2] * t17) * A[1];
00598
00599 AA = A;
00600 BB = B;
00601 RR = R;
00602 return;
00603 }
00604
00605
00606
00607 template < typename POLY,
00608 typename RT >
00609 void
00610 resultant_y_1_0(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00611 {
00612
00613
00614
00615 POLY A(2, AsSize());
00616 POLY B(3, AsSize());
00617 POLY R(5, AsSize());
00618
00619 A[0] = f[1];
00620 A[1] = f[3];
00621 B[0] = f[0];
00622 B[1] = f[2];
00623 B[2] = f[5];
00624 R[0] = g[0];
00625 R[1] = g[2];
00626 R[2] = g[5];
00627
00628 AA = A;
00629 BB = B;
00630 RR = R;
00631 return;
00632 }
00633
00634
00635
00636 template < typename POLY,
00637 typename RT >
00638 void
00639 resultant_y_0_1(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00640 {
00641 return resultant_y_1_0<POLY>(g, f, AA, BB, RR);
00642 }
00643
00644
00645 template < typename POLY,
00646 typename RT >
00647 void
00648 resultant_y_0_0(const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& AA, POLY& BB, POLY& RR)
00649 {
00650 POLY A(2, AsSize());
00651 POLY B(3, AsSize());
00652 POLY R(5, AsSize());
00653
00654 B[0] = f[0];
00655 B[1] = f[2];
00656 B[2] = f[5];
00657
00658 R[0] = g[0];
00659 R[1] = g[2];
00660 R[2] = g[5];
00661
00662 AA = A;
00663 BB = B;
00664 RR = R;
00665 return;
00666 }
00667
00668
00681 template < typename POLY,
00682 typename RT >
00683 void
00684 resultant_y(const MPoly_2_2<RT>& f1, const MPoly_2_2<RT>& f2,
00685 POLY& A, POLY& B, POLY& R)
00686 {
00687 typedef void (* ResultantFunc)
00688 (const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& A, POLY& B, POLY& R);
00689
00690 const ResultantFunc restab_[3][3] = {
00691 { resultant_y_0_0<POLY, RT>, resultant_y_0_1<POLY, RT>, resultant_y_0_2<POLY, RT> },
00692 { resultant_y_1_0<POLY, RT>, resultant_y_1_1<POLY, RT>, resultant_y_1_2<POLY, RT> },
00693 { resultant_y_2_0<POLY, RT>, resultant_y_2_1<POLY, RT>, resultant_y_2_2<POLY, RT> }
00694 };
00695
00696
00697 restab_[f1.degree(1)][f2.degree(1)](f1, f2, A, B, R);
00698 return;
00699 }
00700
00701
00702
00703
00712 template < typename POLY,
00713 typename RT >
00714 POLY
00715 resultant_y(const MPoly_2_2<RT>& f1, const MPoly_2_2<RT>& f2)
00716 {
00717 POLY A;
00718 POLY B;
00719 POLY R;
00720 resultant_y(f1, f2, A, B, R);
00721 return R;
00722 }
00723
00724
00725
00726
00739 template < typename POLY,
00740 typename RT >
00741 void
00742 resultant_x(const MPoly_2_2<RT>& f1, const MPoly_2_2<RT>& f2,
00743 POLY& A, POLY& B, POLY& R)
00744 {
00745 typedef void (* ResultantFunc)
00746 (const MPoly_2_2<RT>& f, const MPoly_2_2<RT>& g, POLY& A, POLY& B, POLY& R);
00747
00748 const ResultantFunc restab_[3][3] = {
00749 { resultant_y_0_0<POLY, RT>, resultant_y_0_1<POLY, RT>, resultant_y_0_2<POLY, RT> },
00750 { resultant_y_1_0<POLY, RT>, resultant_y_1_1<POLY, RT>, resultant_y_1_2<POLY, RT> },
00751 { resultant_y_2_0<POLY, RT>, resultant_y_2_1<POLY, RT>, resultant_y_2_2<POLY, RT> }
00752 };
00753
00754
00755 MPoly_2_2<RT> f(f1[4], f1[5], f1[3], f1[1], f1[2], f1[0]);
00756 MPoly_2_2<RT> g(f2[4], f2[5], f2[3], f2[1], f2[2], f2[0]);
00757
00758 restab_[f.degree(1)][g.degree(1)](f, g, A, B, R);
00759 return;
00760 }
00761
00762
00763
00772 template < typename POLY,
00773 typename RT >
00774 POLY
00775 resultant_x(const MPoly_2_2<RT>& f1, const MPoly_2_2<RT>& f2)
00776 {
00777 POLY A;
00778 POLY B;
00779 POLY R;
00780 resultant_x(f1, f2, A, B, R);
00781 return R;
00782
00783 }
00784
00785 __ALGEBRAIC_END_NAMESPACE
00786
00787
00788
00789
00790 __BEGIN_NAMESPACE_SYNAPS
00791
00792
00793 namespace let {
00794
00795
00796 template < typename RT, typename O, typename R >
00797 MPol<RT, O, R>
00798 convert(const ALGEBRAIC::MPoly_2_2<RT>& f, type::As<MPol<RT, O, R> >)
00799 {
00800 typedef typename MPol<RT, O, R>::monom_t Monom;
00801
00802 MPol<RT, O, R> h;
00803 MPol<RT, O, R> h5 = f[5] * Monom("x", 2);
00804 MPol<RT, O, R> h4 = f[4] * Monom("y", 2);
00805 MPol<RT, O, R> h3x = f[3] * Monom("x", 1) * Monom("y", 1);
00806 MPol<RT, O, R> h3y = Monom("y", 1);
00807 MPol<RT, O, R> h2 = f[2] * Monom("x", 1);
00808 MPol<RT, O, R> h1 = f[1] * Monom("y", 1);
00809 MPol<RT, O, R> h0 = f[0] * Monom("x", 0);
00810
00811 h = h0 + h1 + h2 + (h3x) + h4 + h5;
00812 return h;
00813 }
00814
00815 template < typename RT, typename O, typename R >
00816 ALGEBRAIC::MPoly_2_2<RT> convert(const MPol<RT, O, R>& f, type::As< ALGEBRAIC::MPoly_2_2<RT> > )
00817 {
00818 typedef typename MPol<RT, O, R>::monom_t Monom;
00819
00820 ALGEBRAIC::MPoly_2_2<RT> h;
00821 h.set_coeff(5, MPOLDST::coeffof(f, Monom("x", 2)));
00822 h.set_coeff(4, MPOLDST::coeffof(f, Monom("y", 2)));
00823 h.set_coeff(3, MPOLDST::coeffof(f, Monom("x", 1) * Monom("y", 1)));
00824 h.set_coeff(2, MPOLDST::coeffof(f, Monom("x", 1)));
00825 h.set_coeff(1, MPOLDST::coeffof(f, Monom("y", 1)));
00826 h.set_coeff(0, MPOLDST::coeffof(f, Monom("x", 0)));
00827
00828 return h;
00829 }
00830 }
00831
00832 __END_NAMESPACE_SYNAPS
00833
00834 #endif // SYNAPS_ARITHM_ALGEBRAIC_MPOLY_2_2_H
00835