00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_OPERATORS_HPP
00014 #define __MMX_OPERATORS_HPP
00015 #include <basix/int.hpp>
00016 #include <basix/double.hpp>
00017 #include <basix/port.hpp>
00018 #include <basix/identifiers.hpp>
00019
00021
00022 namespace mmx {
00023
00024
00025
00026
00027
00028 #define TMPL template<typename T>
00029
00030 TMPL T neg_operator (const T& x) { return -x; }
00031 TMPL T add_operator (const T& x, const T& y) { return x+y; }
00032 TMPL T sub_operator (const T& x, const T& y) { return x-y; }
00033 TMPL T mul_operator (const T& x, const T& y) { return x*y; }
00034 TMPL T div_operator (const T& x, const T& y) { return x/y; }
00035
00036 TMPL bool equal_operator (const T& x, const T& y) { return x==y; }
00037 TMPL bool unequal_operator (const T& x, const T& y) { return x!=y; }
00038 TMPL bool less_operator (const T& x, const T& y) { return x<y; }
00039 TMPL bool lesseq_operator (const T& x, const T& y) { return x<=y; }
00040 TMPL bool gtr_operator (const T& x, const T& y) { return x>y; }
00041 TMPL bool gtreq_operator (const T& x, const T& y) { return x>=y; }
00042
00043 #undef TMPL
00044
00045
00046
00047
00048
00049 template<typename R> inline void
00050 neg (R& x) { x= -x; }
00051 template<typename R, typename C1> inline void
00052 neg (R& x, const C1& y1) { x= -y1; }
00053 template<typename R, typename C1, typename C2> inline void
00054 add (R& x, const C1& y1, const C2& y2) { x= y1 + y2; }
00055 template<typename R, typename C1, typename C2> inline void
00056 sub (R& x, const C1& y1, const C2& y2) { x= y1 - y2; }
00057 template<typename R, typename C1, typename C2> inline void
00058 mul (R& x, const C1& y1, const C2& y2) { x= y1 * y2; }
00059 template<typename R, typename C1, typename C2> inline void
00060 div (R& x, const C1& y1, const C2& y2) { x= y1 / y2; }
00061 template<typename R, typename C1, typename C2> inline void
00062 mul_add (R& x, const C1& y1, const C2& y2) { x += y1 * y2; }
00063 template<typename R, typename C1, typename C2> inline void
00064 mul_sub (R& x, const C1& y1, const C2& y2) { x -= y1 * y2; }
00065
00066
00067
00068
00069
00070 template<typename C, C (*fun) (const C&)>
00071 struct unary_op {
00072 static inline C
00073 op (const C& x) { return fun (x); }
00074 };
00075
00076 template<typename C, C (*fun) (const C&, const C&)>
00077 struct binary_op {
00078 static inline C
00079 op (const C& x, const C& y) { return fun (x, y); }
00080 };
00081
00082
00083
00084
00085
00086 template<typename Op, typename R>
00087 struct replace_return_op {
00088 static generic name () { return Op::name (); }
00089 static inline R
00090 op () { return Op::template op<R> (); }
00091 template<typename X1> static inline R
00092 op (const X1& x1) { return Op::template op<R> (x1); }
00093 template<typename X1, typename X2> static inline R
00094 op (const X1& x1, const X2& x2) { return Op::template op<R> (x1, x2); }
00095 static inline void
00096 set_op (R& r) { Op::set_op (r); }
00097 template<typename X1> static inline void
00098 set_op (R& r, const X1& x1) { Op::set_op (r, x1); }
00099 template<typename X1, typename X2> static inline void
00100 set_op (R& r, const X1& x1, const X2& x2) { Op::set_op (r, x1, x2); }
00101 };
00102
00103 template<typename Op, typename R, typename C>
00104 struct unary_return_type_helper<replace_return_op<Op,R>,C> {
00105 typedef R RET;
00106 };
00107
00108 template<typename Op, typename R, typename C1, typename C2>
00109 struct binary_return_type_helper<replace_return_op<Op,R>,C1,C2> {
00110 typedef R RET;
00111 };
00112
00113 template<typename Op, typename R, typename C1, typename C2, typename C3>
00114 struct ternary_return_type_helper<replace_return_op<Op,R>,C1,C2,C3> {
00115 typedef R RET;
00116 };
00117
00118 template<typename Op, typename R>
00119 struct return_op_helper {
00120 typedef Op Rop;
00121 };
00122
00123 #define REPLACEABLE_RETURN(Op) \
00124 template<typename R> \
00125 struct return_op_helper<Op,R> { \
00126 typedef replace_return_op<Op,R> Rop; \
00127 };
00128
00129 #define Return_op(Op,R) \
00130 typename return_op_helper<Op,R>::Rop
00131
00132
00133
00134
00135
00136 template<typename Op>
00137 struct in_place_op {
00138 template<typename R> static inline void
00139 op (R& r) { (void) Op::set_op (r); }
00140 template<typename R, typename S1> static inline void
00141 op (R& r, const S1& s1) { (void) Op::set_op (r, s1); }
00142 template<typename R, typename S1, typename S2> static inline void
00143 op (R& r, const S1& s1, const S2& s2) { (void) Op::set_op (r, s1, s2); }
00144 static inline syntactic
00145 op (const syntactic& s1) {
00146 return apply (Op::set_name (), s1); }
00147 static inline syntactic
00148 op (const syntactic& s1, const syntactic& s2) {
00149 return apply (Op::set_name (), s1, s2); }
00150 static inline syntactic
00151 op (const syntactic& s1, const syntactic& s2, const syntactic& s3) {
00152 return apply (Op::set_name (), s1, s2, s3); }
00153 };
00154
00155
00156
00157
00158
00159 struct no_op {
00160 static generic set_name () { return GEN_NOOP; }
00161 template<typename C1> static inline void
00162 set_op (C1& x1) { (void) x1; }
00163 template<typename C1, typename C2> static inline void
00164 set_op (C1& x1, C2& x2) { (void) x1; (void) x2; }
00165 template<typename C1, typename C2, typename C3> static inline void
00166 set_op (C1& x1, C2& x2, C3& x3) { (void) x1; (void) x2; (void) x3; }
00167 };
00168
00169 struct id_op {
00170 static generic name () { return GEN_IDENTITY; }
00171 static generic set_name () { return GEN_ASSIGN; }
00172 template<typename C> static inline C
00173 op (const C& x) { return x; }
00174 template<typename R, typename C> static inline void
00175 set_op (R& x, const C& y) { x= y; }
00176 };
00177
00178 struct as_op {
00179 template<typename R, typename C> static inline R
00180 op (const C& x) { return as<R> (x); }
00181 template<typename R, typename C> static inline void
00182 set_op (R& x, const C& y) { set_as (x, y); }
00183 };
00184
00185 REPLACEABLE_RETURN(as_op);
00186
00187 struct copy_op {
00188 template<typename C> static inline C
00189 op (const C& x) { return copy (x); }
00190 template<typename R, typename C> static inline void
00191 set_op (R& x, const C& y) { x= copy (y); }
00192 static inline generic
00193 op (const generic& x) { return x; }
00194 static inline syntactic
00195 op (const syntactic& x) { return x; }
00196 template<typename R> static inline void
00197 set_op (R& x, const generic& y) { x= y; }
00198 template<typename R> static inline void
00199 set_op (R& x, const syntactic& y) { x= y; }
00200 };
00201
00202 struct clear_op {
00203 template<typename C> static inline void
00204 set_op (C& x) { clear (x); }
00205 };
00206
00207 struct duplicate_op {
00208 template<typename C> static inline C
00209 op (const C& x) { return duplicate (x); }
00210 template<typename R, typename C> static inline void
00211 set_op (R& x, const C& y) { x= duplicate (y); }
00212 };
00213
00214 struct fast_op {
00215 static generic name () { return GEN_FAST; }
00216 template<typename C> static inline Fast_type(C)
00217 op (const C& x) { return fast (x); }
00218 template<typename R, typename C> static inline void
00219 set_op (R& x, const C& y) { x= fast (y); }
00220 };
00221
00222 struct slow_op {
00223 static generic name () { return GEN_SLOW; }
00224 template<typename C> static inline C
00225 op (const Fast_type(C)& x) { return slow (x); }
00226 template<typename R, typename C> static inline void
00227 set_op (R& x, const C& y) { x= slow_as<R> (y); }
00228 };
00229
00230 struct swap_op {
00231 template<typename C> static inline void
00232 set_op (C& x, C& y) { C aux= x; x= y; y= aux; }
00233 };
00234
00235 struct flatten_op {
00236 template<typename C> static inline syntactic
00237 op (const C& x) { return flatten (x); }
00238 template<typename R, typename C> static inline void
00239 set_op (R& x, const C& y) { x= flatten (y); }
00240 };
00241
00242 template<typename C>
00243 struct unary_return_type_helper<flatten_op,C> {
00244 typedef syntactic RET;
00245 };
00246
00247
00248
00249
00250
00251 struct default_as_op {
00252 template<typename R> static inline R
00253 op () { return Default (R); }
00254 template<typename R> static inline void
00255 set_op (R& x) { set_default (x); }
00256 };
00257
00258 struct log2_as_op {
00259 template<typename R> static inline R
00260 op () { return Log2 (R); }
00261 template<typename R> static inline void
00262 set_op (R& x) { set_log2 (x); }
00263 };
00264
00265 struct pi_as_op {
00266 template<typename R> static inline R
00267 op () { return Pi (R); }
00268 template<typename R> static inline void
00269 set_op (R& x) { set_pi (x); }
00270 };
00271
00272 struct euler_as_op {
00273 template<typename R> static inline R
00274 op () { return Euler (R); }
00275 template<typename R> static inline void
00276 set_op (R& x) { set_euler (x); }
00277 };
00278
00279 struct catalan_as_op {
00280 template<typename R> static inline R
00281 op () { return Catalan (R); }
00282 template<typename R> static inline void
00283 set_op (R& x) { set_catalan (x); }
00284 };
00285
00286 struct smallest_as_op {
00287 template<typename R> static inline R
00288 op () { return Smallest (R); }
00289 template<typename R> static inline void
00290 set_op (R& x) { set_smallest (x); }
00291 };
00292
00293 struct largest_as_op {
00294 template<typename R> static inline R
00295 op () { return Largest (R); }
00296 template<typename R> static inline void
00297 set_op (R& x) { set_largest (x); }
00298 };
00299
00300 struct accuracy_as_op {
00301 template<typename R> static inline R
00302 op () { return Accuracy (R); }
00303 template<typename R> static inline void
00304 set_op (R& x) { set_accuracy (x); }
00305 };
00306
00307 struct imaginary_as_op {
00308 template<typename R> static inline R
00309 op () { return Imaginary (R); }
00310 template<typename R> static inline void
00311 set_op (R& x) { set_imaginary (x); }
00312 };
00313
00314 struct nan_as_op {
00315 template<typename R> static inline R
00316 op () { return Nan (R); }
00317 template<typename R> static inline void
00318 set_op (R& x) { set_nan (x); }
00319 };
00320
00321 struct infinity_as_op {
00322 template<typename R> static inline R
00323 op () { return Infinity (R); }
00324 template<typename R> static inline void
00325 set_op (R& x) { set_infinity (x); }
00326 };
00327
00328 struct maximal_as_op {
00329 template<typename R> static inline R
00330 op () { return Maximal (R); }
00331 template<typename R> static inline void
00332 set_op (R& x) { set_maximal (x); }
00333 };
00334
00335 struct minimal_as_op {
00336 template<typename R> static inline R
00337 op () { return Minimal (R); }
00338 template<typename R> static inline void
00339 set_op (R& x) { set_minimal (x); }
00340 };
00341
00342 struct fuzz_as_op {
00343 template<typename R> static inline R
00344 op () { return Fuzz (R); }
00345 template<typename R> static inline void
00346 set_op (R& x) { set_fuzz (x); }
00347 };
00348
00349 REPLACEABLE_RETURN(default_as_op);
00350 REPLACEABLE_RETURN(log2_as_op);
00351 REPLACEABLE_RETURN(pi_as_op);
00352 REPLACEABLE_RETURN(euler_as_op);
00353 REPLACEABLE_RETURN(catalan_as_op);
00354 REPLACEABLE_RETURN(smallest_as_op);
00355 REPLACEABLE_RETURN(largest_as_op);
00356 REPLACEABLE_RETURN(accuracy_as_op);
00357 REPLACEABLE_RETURN(imaginary_as_op);
00358 REPLACEABLE_RETURN(infinity_as_op);
00359 REPLACEABLE_RETURN(nan_as_op);
00360 REPLACEABLE_RETURN(maximal_as_op);
00361 REPLACEABLE_RETURN(minimal_as_op);
00362 REPLACEABLE_RETURN(fuzz_as_op);
00363
00364
00365
00366
00367
00368 struct hash_op {
00369 static generic name () { return GEN_HASH; }
00370 template<typename C> static inline nat
00371 op (const C& x) { return hash (x); }
00372 };
00373
00374 struct exact_hash_op {
00375 static generic name () { return GEN_EXACT_HASH; }
00376 template<typename C> static inline nat
00377 op (const C& x) { return exact_hash (x); }
00378 };
00379
00380 struct hard_hash_op {
00381 static generic name () { return GEN_HARD_HASH; }
00382 template<typename C> static inline nat
00383 op (const C& x) { return hard_hash (x); }
00384 };
00385
00386
00387
00388
00389
00390 struct zero_op {
00391 template<typename T> static inline T
00392 op (const T& x) { return T(0); }
00393 };
00394
00395 struct neg_op {
00396 static generic name () { return GEN_MINUS; }
00397 template<typename C> static inline C
00398 op (const C& x) { return -x; }
00399 template<typename C> static inline void
00400 set_op (C& x) { neg (x); }
00401 template<typename R, typename C> static inline void
00402 set_op (R& x, const C& y) { neg (x, y); }
00403 template<typename C> static inline C
00404 diff_op (const C& me, const C& x) {
00405 (void) me; return -derive (x); }
00406
00407 template<typename C, typename M> static inline C
00408 op_mod (const C& x, const M& p) {
00409 C y; neg_mod (y, x, p); return y; }
00410 template<typename C, typename M> static inline C
00411 op_mod (const C& x, const M& p, C& carry) {
00412 C y; neg_mod (y, x, p, carry); return y; }
00413 template<typename C, typename M> static inline void
00414 set_op_mod (C& x, const M& p) {
00415 neg_mod (x, p); }
00416 template<typename C, typename M> static inline void
00417 set_op_mod (C& x, const M& p, C& carry) {
00418 neg_mod (x, p, carry); }
00419 template<typename C, typename M> static inline void
00420 set_op_mod (C& x, const C& y, const M& p) {
00421 neg_mod (x, y, p); }
00422 template<typename C, typename M> static inline void
00423 set_op_mod (C& x, const C& y, const M& p, C& carry) {
00424 neg_mod (x, y, p, carry); }
00425 };
00426
00427 struct add_op {
00428 typedef id_op lop;
00429 typedef id_op rop;
00430 static generic name () { return GEN_PLUS; }
00431 static generic set_name () { return GEN_PLUS_ASSIGN; }
00432 template<typename C> static inline C
00433 neutral () { return 0; }
00434 template<typename R> static inline void
00435 set_neutral (R& r) { set_zero (r); }
00436 template<typename C> static inline C
00437 op (const C& x, const C& y) { return x + y; }
00438 template<typename R, typename C> static inline void
00439 set_op (R& x, const C& y) { x += y; }
00440 template<typename R, typename C1, typename C2> static inline void
00441 set_op (R& x, const C1& y1, const C2& y2) { add (x, y1, y2); }
00442 template<typename C> static inline C
00443 diff_op (const C& me, const C& x, const C& y) {
00444 (void) me; return derive (x) + derive (y); }
00445 template<typename C, typename M> static inline C
00446 op_mod (const C& x, const C& y, const M& p) {
00447 C z; add_mod (z, x, y, p); return z; }
00448 template<typename C, typename M> static inline C
00449 op_mod (const C& x, const C& y, const M& p, C& carry) {
00450 C z; add_mod (z, x, y, p, carry); return z; }
00451 template<typename C, typename M> static inline void
00452 set_op_mod (C& x, const C& y, const M& p) {
00453 add_mod (x, y, p); }
00454 template<typename C, typename M> static inline void
00455 set_op_mod (C& x, const C& y, const M& p, C& carry) {
00456 add_mod (x, y, p, carry); }
00457 template<typename C, typename M> static inline void
00458 set_op_mod (C& x, const C& y1, const C& y2, const M& p) {
00459 add_mod (x, y1, y2, p); }
00460 template<typename C, typename M> static inline void
00461 set_op_mod (C& x, const C& y1, const C& y2, const M& p, C& carry) {
00462 add_mod (x, y1, y2, p, carry); }
00463 };
00464
00465 struct radd_op {
00466 static generic name () { return GEN_PLUS; }
00467 template<typename C,typename S> static inline C
00468 op (const C& x, const S& y) { return x + y; }
00469 template<typename C,typename S> static inline void
00470 set_op (C& x, const S& y) { x += y; }
00471 template<typename R, typename C1, typename C2> static inline void
00472 set_op (R& x, const C1& y1, const C2& y2) { add (x, y1, y2); }
00473 };
00474
00475 struct ladd_op {
00476 static generic name () { return GEN_PLUS; }
00477 template<typename C,typename S> static inline C
00478 op (const C& y, const S& x) { return x + y; }
00479 template<typename R, typename C1, typename C2> static inline void
00480 set_op (R& x, const C1& y2, const C2& y1) { add (x, y1, y2); }
00481 };
00482
00483 struct sub_op {
00484 typedef id_op lop;
00485 typedef neg_op rop;
00486 static generic name () { return GEN_MINUS; }
00487 static generic set_name () { return GEN_MINUS_ASSIGN; }
00488 template<typename C> static inline C
00489 op (const C& x, const C& y) { return x - y; }
00490 template<typename R, typename C> static inline void
00491 set_op (R& x, const C& y) { x -= y; }
00492 template<typename R, typename C1, typename C2> static inline void
00493 set_op (R& x, const C1& y1, const C2& y2) { sub (x, y1, y2); }
00494 template<typename C> static inline C
00495 diff_op (const C& me, const C& x, const C& y) {
00496 (void) me; return derive (x) - derive (y); }
00497 template<typename C, typename M> static inline C
00498 op_mod (const C& x, const C& y, const M& p) {
00499 C z; sub_mod (z, x, y, p); return z; }
00500 template<typename C, typename M> static inline C
00501 op_mod (const C& x, const C& y, const M& p, C& carry) {
00502 C z; sub_mod (z, x, y, p, carry); return z; }
00503 template<typename C, typename M> static inline void
00504 set_op_mod (C& x, const C& y, const M& p) {
00505 sub_mod (x, y, p); }
00506 template<typename C, typename M> static inline void
00507 set_op_mod (C& x, const C& y, const M& p, C& carry) {
00508 sub_mod (x, y, p, carry); }
00509 template<typename C, typename M> static inline void
00510 set_op_mod (C& x, const C& y1, const C& y2, const M& p) {
00511 sub_mod (x, y1, y2, p); }
00512 template<typename C, typename M> static inline void
00513 set_op_mod (C& x, const C& y1, const C& y2, const M& p, C& carry) {
00514 sub_mod (x, y1, y2, p, carry); }
00515 };
00516
00517 struct rsub_op {
00518 static generic name () { return GEN_MINUS; }
00519 template<typename C,typename S> static inline C
00520 op (const C& x, const S& y) { return x - y; }
00521 template<typename C,typename S> static inline void
00522 set_op (C& x, const S& y) { x -= y; }
00523 template<typename R, typename C1, typename C2> static inline void
00524 set_op (R& x, const C1& y1, const C2& y2) { sub (x, y1, y2); }
00525 };
00526
00527 struct lsub_op {
00528 static generic name () { return GEN_MINUS; }
00529 template<typename C,typename S> static inline C
00530 op (const C& y, const S& x) { return x - y; }
00531 template<typename R, typename C1, typename C2> static inline void
00532 set_op (R& x, const C1& y2, const C2& y1) { sub (x, y1, y2); }
00533 };
00534
00535 struct lmul_op;
00536 struct rmul_op;
00537 struct mul_add_op;
00538
00539 struct mul_op {
00540 typedef lmul_op sc_left;
00541 typedef rmul_op sc_right;
00542 typedef id_op nomul_op;
00543 typedef clear_op clr_op;
00544 typedef mul_add_op acc_op;
00545 static generic name () { return GEN_TIMES; }
00546 static generic set_name () { return GEN_TIMES_ASSIGN; }
00547 template<typename C> static inline C
00548 neutral () { return 1; }
00549 template<typename R> static inline void
00550 set_neutral (R& r) { set_one (r); }
00551 template<typename C> static inline C
00552 op (const C& x, const C& y) { return x * y; }
00553 template<typename R, typename C> static inline void
00554 set_op (R& x, const C& y) { x *= y; }
00555 template<typename R, typename C1, typename C2> static inline void
00556 set_op (R& x, const C1& y1, const C2& y2) { mul (x, y1, y2); }
00557 template<typename C> static inline C
00558 diff_op (const C& me, const C& x, const C& y) {
00559 (void) me; return derive (x)*y + x*derive (y); }
00560 template<typename C,typename M> static inline C
00561 op_mod (const C& x, const C& y, const M& p) {
00562 C z; mul_mod (z, x, y, p); return z; }
00563 template<typename C,typename M> static inline C
00564 op_mod (const C& x, const C& y, const M& p, C& carry) {
00565 C z; mul_mod (z, x, y, p, carry); return z; }
00566 template<typename C,typename M> static inline void
00567 set_op_mod (C& x, const C& y, const M& p) {
00568 mul_mod (x, y, p); }
00569 template<typename C,typename M> static inline void
00570 set_op_mod (C& x, const C& y, const M& p, C& carry) {
00571 mul_mod (x, y, p, carry); }
00572 template<typename C, typename M> static inline void
00573 set_op (C& x, const C& y1, const C& y2, const M& p) {
00574 mul_mod (x, y1, y2, p); }
00575 template<typename C, typename M> static inline void
00576 set_op (C& x, const C& y1, const C& y2, const M& p, C& carry) {
00577 mul_mod (x, y1, y2, p, carry); }
00578 };
00579
00580 struct rmul_op {
00581 static generic name () { return GEN_TIMES; }
00582 template<typename C,typename S> static inline C
00583 op (const C& x, const S& y) { return x * y; }
00584 template<typename C,typename S> static inline void
00585 set_op (C& x, const S& y) { x *= y; }
00586 template<typename R, typename C1, typename C2> static inline void
00587 set_op (R& x, const C1& y1, const C2& y2) { mul (x, y1, y2); }
00588 template<typename C,typename S> static inline C
00589 diff_op (const C& me, const C& x, const S& y) {
00590 (void) me; return derive (x) * y; }
00591 template<typename C,typename M> static inline C
00592 op_mod (const C& x, const C& y, const M& p) {
00593 C z; mul_mod (z, x, y, p); return z; }
00594 template<typename C,typename M> static inline C
00595 op_mod (const C& x, const C& y, const M& p, C& carry) {
00596 C z; mul_mod (z, x, y, p, carry); return z; }
00597 };
00598
00599 struct lmul_op {
00600 static generic name () { return GEN_TIMES; }
00601 template<typename C,typename S> static inline C
00602 op (const C& y, const S& x) { return x * y; }
00603 template<typename R, typename C1, typename C2> static inline void
00604 set_op (R& x, const C1& y2, const C2& y1) { mul (x, y1, y2); }
00605 template<typename C,typename S> static inline C
00606 diff_op (const C& me, const C& y, const S& x) {
00607 (void) me; return x * derive (y); }
00608 template<typename C,typename M> static inline C
00609 op_mod (const C& y, const C& x, const M& p) {
00610 C z; mul_mod (z, x, y, p); return z; }
00611 template<typename C,typename M> static inline C
00612 op_mod (const C& y, const C& x, const M& p, C& carry) {
00613 C z; mul_mod (z, x, y, p, carry); return z; }
00614 };
00615
00616 struct mul_add_op {
00617 typedef add_op nomul_op;
00618 typedef mul_op rhs_op;
00619 typedef no_op clr_op;
00620 typedef mul_add_op acc_op;
00621 static generic name () { return GEN_MUL_ADD; }
00622 template<typename C> static inline C
00623 neutral () { return 0; }
00624 template<typename R> static inline void
00625 set_neutral (R& r) { set_zero (r); }
00626 template<typename C> static inline C
00627 op (const C& x, const C& y, const C& z) { return x + y * z; }
00628 template<typename R, typename C1, typename C2> static inline void
00629 set_op (R& x, const C1& y, const C2& z) { mul_add (x, y, z); }
00630 };
00631
00632 struct rmul_add_op {
00633 static generic name () { return GEN_MUL_ADD; }
00634 template<typename R, typename C,typename S> static inline void
00635 set_op (R& x, const C& y, const S& z) { mul_add (x, y, z); }
00636 };
00637
00638 struct lmul_add_op {
00639 static generic name () { return GEN_MUL_ADD; }
00640 template<typename R, typename C,typename S> static inline void
00641 set_op (R& x, const C& z, const S& y) { mul_add (x, y, z); }
00642 };
00643
00644 struct mul_sub_op {
00645 typedef sub_op nomul_op;
00646 typedef mul_op rhs_op;
00647 typedef no_op clr_op;
00648 typedef mul_sub_op acc_op;
00649 static generic name () { return GEN_MUL_SUB; }
00650 template<typename C> static inline C
00651 neutral () { return 0; }
00652 template<typename R> static inline void
00653 set_neutral (R& r) { set_zero (r); }
00654 template<typename C> static inline C
00655 op (const C& x, const C& y, const C& z) { return x - y * z; }
00656 template<typename R, typename C1, typename C2> static inline void
00657 set_op (R& x, const C1& y, const C2& z) { mul_sub (x, y, z); }
00658 };
00659
00660 struct square_op {
00661 static generic name () { return GEN_SQUARE; }
00662 template<typename C> static inline C
00663 op (const C& x) { return square (x); }
00664 template<typename R> static inline void
00665 set_op (R& x) { x= square (x); }
00666 template<typename R, typename C> static inline void
00667 set_op (R& x, const C& y) { x= square (y); }
00668 template<typename C> static inline C
00669 diff_op (const C& me, const C& x) {
00670 (void) me; return 2*derive (x)*x; }
00671 };
00672
00673 struct graeffe_op {
00674 static generic name () { return GEN_GRAEFFE; }
00675 template<typename C> static inline C
00676 op (const C& x) { return graeffe (x); }
00677 template<typename R> static inline void
00678 set_op (R& x) { x= graeffe (x); }
00679 template<typename R, typename C> static inline void
00680 set_op (R& x, const C& y) { x= graeffe (y); }
00681 };
00682
00683 struct invert_op {
00684 static generic name () { return GEN_INVERT; }
00685 template<typename C> static inline C
00686 op (const C& x) { return invert (x); }
00687 template<typename C> static inline void
00688 set_op (C& x) { x= invert (x); }
00689 template<typename R, typename C> static inline void
00690 set_op (R& x, const C& y) { x= invert (y); }
00691 template<typename C> static inline C
00692 diff_op (const C& me, const C& x) {
00693 (void) me; return -derive (x) / square (x); }
00694 template<typename C> static inline C
00695 def (const C& me, const C& f) {
00696 return (C(1) - lshiftz (me * rshiftz (f))) / f[0]; }
00697 };
00698
00699 struct ldiv_op;
00700 struct rdiv_op;
00701
00702 struct div_op {
00703 typedef ldiv_op sc_left;
00704 typedef rdiv_op sc_right;
00705 static generic name () { return GEN_OVER; }
00706 static generic set_name () { return GEN_OVER_ASSIGN; }
00707 template<typename C> static inline C
00708 op (const C& x, const C& y) { return x / y; }
00709 template<typename R, typename C> static inline void
00710 set_op (R& x, const C& y) { x /= y; }
00711 template<typename R, typename C1, typename C2> static inline void
00712 set_op (R& x, const C1& y1, const C2& y2) { div (x, y1, y2); }
00713 template<typename C> static inline C
00714 diff_op (const C& me, const C& x, const C& y) {
00715 (void) me; return (derive (x)*y - x*derive (y)) / square (y); }
00716 static inline nat nr_init () { return 0; }
00717 template<typename C> static inline C
00718 def (const C& me, const C& f, const C& g) {
00719 if (is_zero (g[0])) {
00720 nat val;
00721 for (val=0; g[val]==0; val++)
00722 ASSERT (val != C::get_cancel_order (),
00723 "valuation of denominator too high");
00724 return rshiftz (f, (int) val) / rshiftz (g, (int) val);
00725 }
00726 return (f - lshiftz (me * rshiftz (g))) / g[0]; }
00727 };
00728
00729 struct rdiv_op {
00730 static generic name () { return GEN_OVER; }
00731 template<typename C,typename S> static inline C
00732 op (const C& x, const S& y) { return x / y; }
00733 template<typename C,typename S> static inline void
00734 set_op (C& x, const S& y) { x /= y; }
00735 template<typename R, typename C1, typename C2> static inline void
00736 set_op (R& x, const C1& y1, const C2& y2) { div (x, y1, y2); }
00737 template<typename C,typename S> static inline C
00738 diff_op (const C& me, const C& x, const S& y) {
00739 (void) me; return derive (x) / y; }
00740 };
00741
00742 struct ldiv_op {
00743 static generic name () { return GEN_OVER; }
00744 template<typename C,typename S> static inline C
00745 op (const C& y, const S& x) { return x / y; }
00746 template<typename R, typename C1, typename C2> static inline void
00747 set_op (R& x, const C1& y2, const C2& y1) { div (x, y1, y2); }
00748 template<typename C,typename S> static inline C
00749 diff_op (const C& me, const C& y, const S& x) {
00750 (void) me; return -x * derive (y) / square (y); }
00751 };
00752
00753 struct quo_op {
00754 static generic name () { return GEN_DIV; }
00755 template<typename C> static inline C
00756 op (const C& x, const C& y) { return quo (x, y); }
00757 template<typename R, typename C1, typename C2> static inline void
00758 set_op (R& x, const C1& y1, const C2& y2) { x= quo (y1, y2); }
00759 static inline nat nr_init () { return 0; }
00760 template<typename C> static inline C
00761 def (const C& me, const C& f, const C& g) {
00762 if (g[0] == 0) {
00763 nat val;
00764 for (val=0; g[val]==0; val++)
00765 if (val == C::get_cancel_order ()) return 0;
00766 return quo (rshiftz (f, (int) val), rshiftz (g, (int) val));
00767 }
00768 return quo (f - lshiftz (me * rshiftz (g)), g[0]); }
00769 };
00770
00771 struct pquo_op {
00772 static generic name () { return "pquo"; }
00773 template<typename C> static inline C
00774 op (const C& x, const C& y) { return pquo (x, y); }
00775 template<typename R, typename C1, typename C2> static inline void
00776 set_op (R& x, const C1& y1, const C2& y2) { x= pquo (y1, y2); }
00777 };
00778
00779 struct rquo_op {
00780 static generic name () { return GEN_DIV; }
00781 template<typename C,typename S> static inline C
00782 op (const C& x, const S& y) { return quo (x, y); }
00783 template<typename R, typename C1, typename C2> static inline void
00784 set_op (R& x, const C1& y1, const C2& y2) { x= quo (y1, y2); }
00785 };
00786
00787 struct rem_op {
00788 static generic name () { return GEN_MOD; }
00789 template<typename C> static inline C
00790 op (const C& x, const C& y) { return rem (x, y); }
00791 template<typename R, typename C1, typename C2> static inline void
00792 set_op (R& x, const C1& y1, const C2& y2) { x= rem (y1, y2); }
00793 template<typename C> static inline C
00794 op (const C& x, const C& y, nat n) { return rem (x, y); }
00795 };
00796
00797 struct prem_op {
00798 static generic name () { return "prem"; }
00799 template<typename C> static inline C
00800 op (const C& x, const C& y) { return prem (x, y); }
00801 template<typename R, typename C1, typename C2> static inline void
00802 set_op (R& x, const C1& y1, const C2& y2) { x= prem (y1, y2); }
00803 template<typename C> static inline C
00804 op (const C& x, const C& y, nat n) {
00805 if (x == 0 || y == 0) return x;
00806 nat m= deg (y);
00807 C z= m >= n ? C(1) : C(binpow (y[m], n - m));
00808 return z * prem (x, y); }
00809 };
00810
00811 struct rrem_op {
00812 static generic name () { return GEN_MOD; }
00813 template<typename C,typename S> static inline C
00814 op (const C& x, const S& y) { return rem (x, y); }
00815 template<typename R, typename C1, typename C2> static inline void
00816 set_op (R& x, const C1& y1, const C2& y2) { x= rem (y1, y2); }
00817 };
00818
00819 struct lshift2_op {
00820 template<typename C,typename S> static inline C
00821 op (const C& x, const S& sh) { return lshift2 (x, sh); }
00822 template<typename C,typename S> static inline void
00823 set_op (C& x, const S& sh) { lshift2_assign (x, sh); }
00824 template<typename R, typename C1, typename C2> static inline void
00825 set_op (R& x, const C1& y1, const C2& y2) { lshift2 (x, y1, y2); }
00826 };
00827
00828 struct rshift2_op {
00829 template<typename C,typename S> static inline C
00830 op (const C& x, const S& sh) { return rshift2 (x, sh); }
00831 template<typename C,typename S> static inline void
00832 set_op (C& x, const S& sh) { rshift2_assign (x, sh); }
00833 template<typename R, typename C1, typename C2> static inline void
00834 set_op (R& x, const C1& y1, const C2& y2) { rshift2 (x, y1, y2); }
00835 };
00836
00837 struct lshiftz_op {
00838 template<typename C,typename S> static inline C
00839 op (const C& x, const S& sh) { return lshiftz (x, sh); }
00840 template<typename C,typename S> static inline void
00841 set_op (C& x, const S& sh) { lshiftz_assign (x, sh); }
00842 template<typename R, typename C1, typename C2> static inline void
00843 set_op (R& x, const C1& y1, const C2& y2) { lshiftz (x, y1, y2); }
00844 };
00845
00846 struct rshiftz_op {
00847 template<typename C,typename S> static inline C
00848 op (const C& x, const S& sh) { return rshiftz (x, sh); }
00849 template<typename C,typename S> static inline void
00850 set_op (C& x, const S& sh) { rshiftz_assign (x, sh); }
00851 template<typename R, typename C1, typename C2> static inline void
00852 set_op (R& x, const C1& y1, const C2& y2) { rshiftz (x, y1, y2); }
00853 };
00854
00855 struct incexp2_op {
00856 template<typename C,typename S> static inline C
00857 op (const C& x, const S& sh) { return incexp2 (x, sh); }
00858 template<typename C,typename S> static inline void
00859 set_op (C& x, const S& sh) { incexp2_assign (x, sh); }
00860 template<typename R, typename C1, typename C2> static inline void
00861 set_op (R& x, const C1& y1, const C2& y2) { incexp2 (x, y1, y2); }
00862 };
00863
00864 struct decexp2_op {
00865 template<typename C,typename S> static inline C
00866 op (const C& x, const S& sh) { return decexp2 (x, sh); }
00867 template<typename C,typename S> static inline void
00868 set_op (C& x, const S& sh) { decexp2_assign (x, sh); }
00869 template<typename R, typename C1, typename C2> static inline void
00870 set_op (R& x, const C1& y1, const C2& y2) { decexp2 (x, y1, y2); }
00871 };
00872
00873 struct or_op {
00874 template<typename C> static inline C
00875 neutral () { return false; }
00876 template<typename R> static inline void
00877 set_neutral (R& r) { set_false (r); }
00878 template<typename C> static inline C
00879 op (const C& x, const C& y) { return x | y; }
00880 template<typename R, typename C> static inline void
00881 set_op (R& x, const C& y) { x |= y; }
00882 template<typename R, typename C1, typename C2> static inline void
00883 set_op (R& x, const C1& y1, const C2& y2) { x= y1 | y2; }
00884 };
00885
00886 struct and_op {
00887 template<typename C> static inline C
00888 neutral () { return true; }
00889 template<typename R> static inline void
00890 set_neutral (R& r) { set_true (r); }
00891 template<typename C> static inline C
00892 op (const C& x, const C& y) { return x & y; }
00893 template<typename R, typename C> static inline void
00894 set_op (R& x, const C& y) { x &= y; }
00895 template<typename R, typename C1, typename C2> static inline void
00896 set_op (R& x, const C1& y1, const C2& y2) { x= y1 & y2; }
00897 };
00898
00899
00900
00901
00902
00903 struct gcd_op {
00904 static generic name () { return GEN_GCD; }
00905 template<typename C> static inline C
00906 neutral () { return C(0); }
00907 template<typename R> static inline void
00908 set_neutral (R& r) { set_zero (r); }
00909 template<typename C> static inline C
00910 op (const C& x, const C& y) { return gcd (x, y); }
00911 template<typename R, typename C> static inline void
00912 set_op (R& x, const C& y) { x= gcd (x, y); }
00913 template<typename R, typename C1, typename C2> static inline void
00914 set_op (R& x, const C1& y1, const C2& y2) { x= gcd (y1, y2); }
00915 };
00916
00917 struct lcm_op {
00918 static generic name () { return GEN_LCM; }
00919 template<typename C> static inline C
00920 neutral () { return C(1); }
00921 template<typename R> static inline void
00922 set_neutral (R& r) { set_one (r); }
00923 template<typename C> static inline C
00924 op (const C& x, const C& y) { return lcm (x, y); }
00925 template<typename R, typename C> static inline void
00926 set_op (R& x, const C& y) { x= lcm (x, y); }
00927 template<typename R, typename C1, typename C2> static inline void
00928 set_op (R& x, const C1& y1, const C2& y2) { x= lcm (y1, y2); }
00929 };
00930
00931 template<typename C> struct xgcd_matrix;
00932
00933 struct xgcd_op {
00934 template<typename C> static inline xgcd_matrix<C>
00935 op (const C& x, const C& y) { return xgcd (x, y); }
00936 template<typename R, typename C1, typename C2> static inline void
00937 set_op (R& x, const C1& y1, const C2& y2) { x= xgcd (y1, y2); }
00938 };
00939
00940
00941
00942
00943
00944 struct hard_eq_op {
00945 static generic name () { return GEN_HARD_EQ; }
00946 template<typename C> static inline bool
00947 op (const C& x, const C& y) { return hard_eq (x, y); }
00948 static inline syntactic
00949 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
00950 template<typename C> static inline bool
00951 not_op (const C& x, const C& y) { return hard_neq (x, y); }
00952 template<typename C> static inline nat
00953 hash_op (const C& x) { return hard_hash (x); }
00954 };
00955
00956 struct hard_neq_op {
00957 static generic name () { return GEN_HARD_NEQ; }
00958 template<typename C> static inline bool
00959 op (const C& x, const C& y) { return hard_neq (x, y); }
00960 static inline syntactic
00961 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
00962 template<typename C> static inline bool
00963 not_op (const C& x, const C& y) { return hard_eq (x, y); }
00964 template<typename C> static inline nat
00965 hash_op (const C& x) { return hard_hash (x); }
00966 };
00967
00968 struct hard_less_op {
00969 static generic name () { return GEN_HARD_LESS; }
00970 template<typename C> static inline bool
00971 op (const C& x, const C& y) { return hard_less (x, y); }
00972 };
00973
00974 struct hard_gtr_op {
00975 static generic name () { return GEN_HARD_GTR; }
00976 template<typename C> static inline bool
00977 op (const C& x, const C& y) { return hard_gtr (x, y); }
00978 };
00979
00980 struct exact_eq_op {
00981 static generic name () { return GEN_EXACT_EQ; }
00982 template<typename C> static inline bool
00983 op (const C& x, const C& y) { return exact_eq (x, y); }
00984 static inline syntactic
00985 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
00986 template<typename C> static inline bool
00987 not_op (const C& x, const C& y) { return exact_neq (x, y); }
00988 template<typename C> static inline nat
00989 hash_op (const C& x) { return exact_hash (x); }
00990 };
00991
00992 struct exact_neq_op {
00993 static generic name () { return GEN_EXACT_NEQ; }
00994 template<typename C> static inline bool
00995 op (const C& x, const C& y) { return exact_neq (x, y); }
00996 static inline syntactic
00997 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
00998 template<typename C> static inline bool
00999 not_op (const C& x, const C& y) { return exact_eq (x, y); }
01000 template<typename C> static inline nat
01001 hash_op (const C& x) { return exact_hash (x); }
01002 };
01003
01004 struct equal_op {
01005 static generic name () { return GEN_EQUAL; }
01006 template<typename C> static inline bool
01007 op (const C& x, const C& y) { return x == y; }
01008 static inline syntactic
01009 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
01010 template<typename C> static inline bool
01011 not_op (const C& x, const C& y) { return x != y; }
01012 template<typename C> static inline nat
01013 hash_op (const C& x) { return hash (x); }
01014 };
01015
01016 struct unequal_op {
01017 static generic name () { return GEN_UNEQUAL; }
01018 template<typename C> static inline bool
01019 op (const C& x, const C& y) { return x != y; }
01020 static inline syntactic
01021 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
01022 template<typename C> static inline bool
01023 not_op (const C& x, const C& y) { return x == y; }
01024 template<typename C> static inline nat
01025 hash_op (const C& x) { return hash (x); }
01026 };
01027
01028 struct less_op {
01029 static generic name () { return GEN_LESS; }
01030 template<typename C> static inline bool
01031 op (const C& x, const C& y) { return x < y; }
01032 static inline syntactic
01033 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
01034 template<typename C> static inline bool
01035 not_op (const C& x, const C& y) { return !(x < y); }
01036 };
01037
01038 struct lesseq_op {
01039 static generic name () { return GEN_LESSEQ; }
01040 template<typename C> static inline bool
01041 op (const C& x, const C& y) { return x <= y; }
01042 static inline syntactic
01043 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
01044 template<typename C> static inline bool
01045 not_op (const C& x, const C& y) { return !(x <= y); }
01046 };
01047
01048 struct gtr_op {
01049 static generic name () { return GEN_GTR; }
01050 template<typename C> static inline bool
01051 op (const C& x, const C& y) { return x > y; }
01052 static inline syntactic
01053 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
01054 template<typename C> static inline bool
01055 not_op (const C& x, const C& y) { return !(x > y); }
01056 };
01057
01058 struct gtreq_op {
01059 static generic name () { return GEN_GTREQ; }
01060 template<typename C> static inline bool
01061 op (const C& x, const C& y) { return x >= y; }
01062 static inline syntactic
01063 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
01064 template<typename C> static inline bool
01065 not_op (const C& x, const C& y) { return !(x >= y); }
01066 };
01067
01068 template<typename C> struct binary_return_type_helper<hard_eq_op,C,C> {
01069 typedef bool RET; };
01070 template<typename C> struct binary_return_type_helper<hard_neq_op,C,C> {
01071 typedef bool RET; };
01072 template<typename C> struct binary_return_type_helper<exact_eq_op,C,C> {
01073 typedef bool RET; };
01074 template<typename C> struct binary_return_type_helper<exact_neq_op,C,C> {
01075 typedef bool RET; };
01076 template<typename C> struct binary_return_type_helper<equal_op,C,C> {
01077 typedef bool RET; };
01078 template<typename C> struct binary_return_type_helper<unequal_op,C,C> {
01079 typedef bool RET; };
01080 template<typename C> struct binary_return_type_helper<less_op,C,C> {
01081 typedef bool RET; };
01082 template<typename C> struct binary_return_type_helper<lesseq_op,C,C> {
01083 typedef bool RET; };
01084 template<typename C> struct binary_return_type_helper<gtr_op,C,C> {
01085 typedef bool RET; };
01086 template<typename C> struct binary_return_type_helper<gtreq_op,C,C> {
01087 typedef bool RET; };
01088
01089
01090
01091
01092
01093 struct min_op {
01094 static generic name () { return GEN_MIN; }
01095 template<typename C> static inline C
01096 neutral () { return Maximal (C); }
01097 template<typename R> static inline void
01098 set_neutral (R& x) { set_maximal (x); }
01099 template<typename C> static inline C
01100 op (const C& x, const C& y) { return min (x, y); }
01101 template<typename R, typename C> static inline void
01102 set_op (R& x, const C& y) { x= min (x, y); }
01103 template<typename R, typename C1, typename C2> static inline void
01104 set_op (R& x, const C1& y1, const C2& y2) { x= min (y1, y2); }
01105 };
01106
01107 struct max_op {
01108 static generic name () { return GEN_MAX; }
01109 template<typename C> static inline C
01110 neutral () { return Minimal (C); }
01111 template<typename R> static inline void
01112 set_neutral (R& x) { set_minimal (x); }
01113 template<typename C> static inline C
01114 op (const C& x, const C& y) { return max (x, y); }
01115 template<typename R, typename C> static inline void
01116 set_op (R& x, const C& y) { x= max (x, y); }
01117 template<typename R, typename C1, typename C2> static inline void
01118 set_op (R& x, const C1& y1, const C2& y2) { x= max (y1, y2); }
01119 };
01120
01121 struct inf_op {
01122 static generic name () { return GEN_INF; }
01123 template<typename C> static inline C
01124 neutral () { return Maximal (C); }
01125 template<typename R> static inline void
01126 set_neutral (R& x) { set_maximal (x); }
01127 template<typename C> static inline C
01128 op (const C& x, const C& y) { return inf (x, y); }
01129 template<typename R, typename C> static inline void
01130 set_op (R& x, const C& y) { x= inf (x, y); }
01131 template<typename R, typename C1, typename C2> static inline void
01132 set_op (R& x, const C1& y1, const C2& y2) { x= inf (y1, y2); }
01133 };
01134
01135 struct sup_op {
01136 static generic name () { return GEN_SUP; }
01137 template<typename C> static inline C
01138 neutral () { return Minimal (C); }
01139 template<typename R> static inline void
01140 set_neutral (R& x) { set_minimal (x); }
01141 template<typename C> static inline C
01142 op (const C& x, const C& y) { return sup (x, y); }
01143 template<typename R, typename C> static inline void
01144 set_op (R& x, const C& y) { x= sup (x, y); }
01145 template<typename R, typename C1, typename C2> static inline void
01146 set_op (R& x, const C1& y1, const C2& y2) { x= sup (y1, y2); }
01147 };
01148
01149 struct abs_op {
01150 static generic name () { return GEN_ABS; }
01151 template<typename C> static inline Abs_type(C)
01152 op (const C& x) { return abs (x); }
01153 static inline generic
01154 op (const generic& x) { return abs (x); }
01155 static inline syntactic
01156 op (const syntactic& x) { return abs (x); }
01157 template<typename R, typename C> static inline void
01158 set_op (R& x, const C& y) { x= abs (y); }
01159 };
01160
01161 struct abs_as_op {
01162 static generic name () { return GEN_ABS; }
01163 template<typename R, typename C> static inline R
01164 op (const C& x) { return as<R> (abs (x)); }
01165 template<typename R, typename C> static inline void
01166 set_op (R& x, const C& y) { x= as<R> (abs (y)); }
01167 };
01168
01169 REPLACEABLE_RETURN(abs_as_op);
01170
01171 struct sign_op {
01172 static generic name () { return GEN_SIGN; }
01173 template<typename C> static inline int
01174 op (const C& x) { return sign (x); }
01175 static inline generic
01176 op (const generic& x) { return gen (GEN_SIGN, x); }
01177 static inline syntactic
01178 op (const syntactic& x) { return apply (GEN_SIGN, x); }
01179 template<typename C> static inline void
01180 set_op (int& x, const C& y) { x= sign (y); }
01181 };
01182
01183
01184
01185
01186
01187 struct sqrt_op {
01188 static generic name () { return GEN_SQRT; }
01189 template<typename C> static inline C
01190 op (const C& x) { return sqrt (x); }
01191 template<typename R, typename C> static inline void
01192 set_op (R& x, const C& y) { x= sqrt (y); }
01193 template<typename C, typename I> static inline C
01194 op_init (const C& x, const I& i) { return sqrt_init (x, i); }
01195 template<typename C> static inline C
01196 diff_op (const C& me, const C& x) {
01197 return derive (x) / (2 * me); }
01198 static inline nat nr_init () { return 1; }
01199 template<typename C> static inline C
01200 def (const C& me, const C& f) {
01201 if (f[0] == 0) {
01202 nat val= 0;
01203 for (val=0; val< C::get_cancel_order () && f[val] == 0; val++) {};
01204 ASSERT (val< C::get_cancel_order () , "valuation too high");
01205 ASSERT ((val&1) == 0, "square root is not a series");
01206 return lshiftz (sqrt (rshiftz (f, (int) val)), (int) (val/2));
01207 }
01208 return integrate (derive (f) / (2*me)); }
01209 };
01210
01211 struct cbrt_op {
01212 static generic name () { return GEN_CBRT; }
01213 template<typename C> static inline C
01214 op (const C& x) { return cbrt (x); }
01215 template<typename R, typename C> static inline void
01216 set_op (R& x, const C& y) { x= cbrt (y); }
01217 };
01218
01219 struct hypot_op {
01220 static generic name () { return GEN_HYPOT; }
01221 template<typename C> static inline C
01222 op (const C& x, const C& y) { return hypot (x, y); }
01223 template<typename R, typename C1, typename C2> static inline void
01224 set_op (R& x, const C1& y1, const C2& y2) { x= hypot (y1, y2); }
01225 };
01226
01227 struct exp_op {
01228 static generic name () { return GEN_EXP; }
01229 template<typename C> static inline C
01230 op (const C& x) { return exp (x); }
01231 template<typename R, typename C> static inline void
01232 set_op (R& x, const C& y) { x= exp (y); }
01233 template<typename C, typename I> static inline C
01234 op_init (const C& x, const I& i) { (void) i; return exp (x); }
01235 template<typename C> static inline C
01236 diff_op (const C& me, const C& x) {
01237 return derive (x) * me; }
01238 static inline nat nr_init () { return 1; }
01239 template<typename C> static inline C
01240 def (const C& me, const C& f) {
01241 return integrate (diff_op (me, f)); }
01242 };
01243
01244 struct exp2_op {
01245 static generic name () { return GEN_EXP2; }
01246 template<typename C> static inline C
01247 op (const C& x) { return exp2 (x); }
01248 template<typename R, typename C> static inline void
01249 set_op (R& x, const C& y) { x= exp2 (y); }
01250 };
01251
01252 struct exp10_op {
01253 static generic name () { return GEN_EXP10; }
01254 template<typename C> static inline C
01255 op (const C& x) { return exp10 (x); }
01256 template<typename R, typename C> static inline void
01257 set_op (R& x, const C& y) { x= exp10 (y); }
01258 };
01259
01260 struct log_op {
01261 static generic name () { return GEN_LOG; }
01262 template<typename C> static inline C
01263 op (const C& x) { return log (x); }
01264 template<typename R, typename C> static inline void
01265 set_op (R& x, const C& y) { x= log (y); }
01266 template<typename C,typename I> static inline C
01267 op_init (const C& x, const I& i) { return log_init (x, i); }
01268 template<typename C> static inline C
01269 diff_op (const C& me, const C& x) {
01270 (void) me; return derive (x) / x; }
01271 static inline nat nr_init () { return 1; }
01272 template<typename C> static inline C
01273 def (const C& me, const C& f) {
01274 return integrate (diff_op (me, f)); }
01275 };
01276
01277 struct log2_op {
01278 static generic name () { return GEN_LOG2; }
01279 template<typename C> static inline C
01280 op (const C& x) { return log2 (x); }
01281 template<typename R, typename C> static inline void
01282 set_op (R& x, const C& y) { x= log2 (y); }
01283 };
01284
01285 struct log10_op {
01286 static generic name () { return GEN_LOG10; }
01287 template<typename C> static inline C
01288 op (const C& x) { return log10 (x); }
01289 template<typename R, typename C> static inline void
01290 set_op (R& x, const C& y) { x= log10 (y); }
01291 };
01292
01293 struct pow_op {
01294 static generic name () { return GEN_POWER; }
01295 template<typename C1, typename C2> static inline C1
01296 op (const C1& x, const C2& y) { return pow (x, y); }
01297 template<typename R, typename C1, typename C2> static inline void
01298 set_op (R& x, const C1& y1, const C2& y2) { x= pow (y1, y2); }
01299 };
01300
01301 typedef pow_op rpow_op;
01302
01303 struct lpow_op {
01304 static generic name () { return GEN_POWER; }
01305 template<typename C1, typename C2> static inline C1
01306 op (const C1& y, const C2& x) { return pow (x, y); }
01307 template<typename R, typename C1, typename C2> static inline void
01308 set_op (R& x, const C1& y2, const C2& y1) { x= pow (y1, y2); }
01309 };
01310
01311 struct trig_op {
01312 template<typename C> static inline C
01313 op (const C& x) { return trig (x); }
01314 template<typename R, typename C> static inline void
01315 set_op (R& x, const C& y) { x= trig (y); }
01316 template<typename C, typename I> static inline C
01317 op_init (const C& x, const I& i) { (void) i; return trig (x); }
01318 static inline generic
01319 op (const generic& x) { return xsqtuple (comma (cos (x), sin (x))); }
01320 static inline syntactic
01321 op (const syntactic& x) { return as_syntactic (op (as_generic (x))); }
01322 template<typename C> static inline C
01323 diff_op (const C& me, const C& x);
01324 static inline nat nr_init () { return 1; }
01325 template<typename V,typename C> static inline V
01326 def (const V& me, const C& f) {
01327 return integrate (diff_op (me, f)); }
01328 };
01329
01330 struct cos_op {
01331 static generic name () { return GEN_COS; }
01332 template<typename C> static inline C
01333 op (const C& x) { return cos (x); }
01334 template<typename R, typename C> static inline void
01335 set_op (R& x, const C& y) { x= cos (y); }
01336 template<typename C, typename I> static inline C
01337 op_init (const C& x, const I& i) { (void) i; return cos (x); }
01338 template<typename C> static inline C
01339 diff_op (const C& me, const C& x) {
01340 (void) me; return -derive (x) * sin (x); }
01341 static inline nat nr_init () { return 1; }
01342 template<typename C> static inline C
01343 def (const C& me, const C& f) {
01344 (void) me; return cos_sin (f) [0]; }
01345 };
01346
01347 struct sin_op {
01348 static generic name () { return GEN_SIN; }
01349 template<typename C> static inline C
01350 op (const C& x) { return sin (x); }
01351 template<typename R, typename C> static inline void
01352 set_op (R& x, const C& y) { x= sin (y); }
01353 template<typename C, typename I> static inline C
01354 op_init (const C& x, const I& i) { (void) i; return sin (x); }
01355 template<typename C> static inline C
01356 diff_op (const C& me, const C& x) {
01357 (void) me; return derive (x) * cos (x); }
01358 static inline nat nr_init () { return 1; }
01359 template<typename C> static inline C
01360 def (const C& me, const C& f) {
01361 (void) me; return cos_sin (f) [1]; }
01362 };
01363
01364 struct tan_op {
01365 static generic name () { return GEN_TAN; }
01366 template<typename C> static inline C
01367 op (const C& x) { return tan (x); }
01368 template<typename R, typename C> static inline void
01369 set_op (R& x, const C& y) { x= tan (y); }
01370 template<typename C, typename I> static inline C
01371 op_init (const C& x, const I& i) { (void) i; return tan (x); }
01372 template<typename C> static inline C
01373 diff_op (const C& me, const C& x) {
01374 (void) me; return derive (x) / square (cos (x)); }
01375 static inline nat nr_init () { return 1; }
01376 template<typename C> static inline C
01377 def (const C& me, const C& f);
01378 };
01379
01380 struct acos_op {
01381 static generic name () { return GEN_ARCCOS; }
01382 template<typename C> static inline C
01383 op (const C& x) { return acos (x); }
01384 template<typename R, typename C> static inline void
01385 set_op (R& x, const C& y) { x= acos (y); }
01386 template<typename C, typename I> static inline C
01387 op_init (const C& x, const I& i) { return acos_init (x, i); }
01388 template<typename C> static inline C
01389 diff_op (const C& me, const C& x) {
01390 (void) me; return -derive (x) / sqrt (1 - square (x)); }
01391 static inline nat nr_init () { return 1; }
01392 template<typename C> static inline C
01393 def (const C& me, const C& f) {
01394 return integrate (diff_op (me, f)); }
01395 };
01396
01397 struct asin_op {
01398 static generic name () { return GEN_ARCSIN; }
01399 template<typename C> static inline C
01400 op (const C& x) { return asin (x); }
01401 template<typename R, typename C> static inline void
01402 set_op (R& x, const C& y) { x= asin (y); }
01403 template<typename C, typename I> static inline C
01404 op_init (const C& x, const I& i) { return asin_init (x, i); }
01405 template<typename C> static inline C
01406 diff_op (const C& me, const C& x) {
01407 (void) me; return derive (x) / sqrt (1 - square (x)); }
01408 static inline nat nr_init () { return 1; }
01409 template<typename C> static inline C
01410 def (const C& me, const C& f) {
01411 return integrate (diff_op (me, f)); }
01412 };
01413
01414 struct atan_op {
01415 static generic name () { return GEN_ARCTAN; }
01416 template<typename C> static inline C
01417 op (const C& x) { return atan (x); }
01418 template<typename R, typename C> static inline void
01419 set_op (R& x, const C& y) { x= atan (y); }
01420 template<typename C, typename I> static inline C
01421 op_init (const C& x, const I& i) { return atan_init (x, i); }
01422 template<typename C> static inline C
01423 diff_op (const C& me, const C& x) {
01424 (void) me; return derive (x) / (square (x) + 1); }
01425 static inline nat nr_init () { return 1; }
01426 template<typename C> static inline C
01427 def (const C& me, const C& f) {
01428 return integrate (diff_op (me, f)); }
01429 };
01430
01431 struct atan2_op {
01432 static generic name () { return GEN_ARCTAN2; }
01433 template<typename C> static inline C
01434 op (const C& x, const C& y) { return atan2 (x, y); }
01435 template<typename R, typename C1, typename C2> static inline void
01436 set_op (R& x, const C1& y1, const C2& y2) { x= atan2 (y1, y2); }
01437 };
01438
01439 struct cosh_op {
01440 static generic name () { return GEN_CH; }
01441 template<typename C> static inline C
01442 op (const C& x) { return cosh (x); }
01443 template<typename R, typename C> static inline void
01444 set_op (R& x, const C& y) { x= cosh (y); }
01445 template<typename C, typename I> static inline C
01446 op_init (const C& x, const I& i) { (void) i; return cosh (x); }
01447 template<typename C> static inline C
01448 diff_op (const C& me, const C& x) {
01449 (void) me; return derive (x) * sinh (x); }
01450 };
01451
01452 struct sinh_op {
01453 static generic name () { return GEN_SH; }
01454 template<typename C> static inline C
01455 op (const C& x) { return sinh (x); }
01456 template<typename R, typename C> static inline void
01457 set_op (R& x, const C& y) { x= sinh (y); }
01458 template<typename C, typename I> static inline C
01459 op_init (const C& x, const I& i) { (void) i; return sinh (x); }
01460 template<typename C> static inline C
01461 diff_op (const C& me, const C& x) {
01462 (void) me; return derive (x) * cosh (x); }
01463 };
01464
01465 struct tanh_op {
01466 static generic name () { return GEN_TH; }
01467 template<typename C> static inline C
01468 op (const C& x) { return tanh (x); }
01469 template<typename R, typename C> static inline void
01470 set_op (R& x, const C& y) { x= tanh (y); }
01471 template<typename C, typename I> static inline C
01472 op_init (const C& x, const I& i) { (void) i; return tanh (x); }
01473 template<typename C> static inline C
01474 diff_op (const C& me, const C& x) {
01475 (void) me; return derive (x) / square (cosh (x)); }
01476 };
01477
01478 struct acosh_op {
01479 static generic name () { return GEN_ARGCH; }
01480 template<typename C> static inline C
01481 op (const C& x) { return acosh (x); }
01482 template<typename R, typename C> static inline void
01483 set_op (R& x, const C& y) { x= acosh (y); }
01484 template<typename C, typename I> static inline C
01485 op_init (const C& x, const I& i) { return acosh_init (x, i); }
01486 template<typename C> static inline C
01487 diff_op (const C& me, const C& x) {
01488 (void) me; return derive (x) / sqrt (square (x) - 1); }
01489 };
01490
01491 struct asinh_op {
01492 static generic name () { return GEN_ARGSH; }
01493 template<typename C> static inline C
01494 op (const C& x) { return asinh (x); }
01495 template<typename R, typename C> static inline void
01496 set_op (R& x, const C& y) { x= asinh (y); }
01497 template<typename C, typename I> static inline C
01498 op_init (const C& x, const I& i) { return asinh_init (x, i); }
01499 template<typename C> static inline C
01500 diff_op (const C& me, const C& x) {
01501 (void) me; return derive (x) / sqrt (square (x) + 1); }
01502 };
01503
01504 struct atanh_op {
01505 static generic name () { return GEN_ARGTH; }
01506 template<typename C> static inline C
01507 op (const C& x) { return atanh (x); }
01508 template<typename R, typename C> static inline void
01509 set_op (R& x, const C& y) { x= atanh (y); }
01510 template<typename C, typename I> static inline C
01511 op_init (const C& x, const I& i) { return atanh_init (x, i); }
01512 template<typename C> static inline C
01513 diff_op (const C& me, const C& x) {
01514 (void) me; return derive (x) / (1 - square (x)); }
01515 };
01516
01517
01518
01519
01520
01521 struct gamma_op {
01522 static generic name () { return GEN_GAMMA; }
01523 template<typename C> static inline C
01524 op (const C& x) { return gamma (x); }
01525 template<typename R, typename C> static inline void
01526 set_op (R& x, const C& y) { x= gamma (y); }
01527 };
01528
01529 struct zeta_op {
01530 static generic name () { return GEN_ZETA; }
01531 template<typename C> static inline C
01532 op (const C& x) { return zeta (x); }
01533 template<typename R, typename C> static inline void
01534 set_op (R& x, const C& y) { x= zeta (y); }
01535 };
01536
01537 struct erf_op {
01538 static generic name () { return GEN_ERF; }
01539 template<typename C> static inline C
01540 op (const C& x) { return erf (x); }
01541 template<typename R, typename C> static inline void
01542 set_op (R& x, const C& y) { x= erf (y); }
01543 };
01544
01545
01546
01547
01548
01549 struct is_finite_op {
01550 template<typename T> static inline bool
01551 op (const T& x) { return is_finite (x); }
01552 template<typename T> static inline bool
01553 not_op (const T& x) { return !is_finite (x); }
01554 };
01555
01556 struct is_infinite_op {
01557 template<typename T> static inline bool
01558 op (const T& x) { return is_infinite (x); }
01559 template<typename T> static inline bool
01560 not_op (const T& x) { return !is_infinite (x); }
01561 };
01562
01563 struct is_fuzz_op {
01564 template<typename T> static inline bool
01565 op (const T& x) { return is_fuzz (x); }
01566 template<typename T> static inline bool
01567 not_op (const T& x) { return !is_fuzz (x); }
01568 };
01569
01570 struct is_nan_op {
01571 template<typename T> static inline bool
01572 op (const T& x) { return is_nan (x); }
01573 template<typename T> static inline bool
01574 not_op (const T& x) { return !is_nan (x); }
01575 };
01576
01577 struct is_reliable_op {
01578
01579 template<typename T> static inline bool
01580 op (const T& x) { return is_reliable (x); }
01581 template<typename T> static inline bool
01582 not_op (const T& x) { return !is_reliable (x); }
01583 };
01584
01585 struct and_is_finite_op {
01586 template<typename B> static inline B
01587 neutral () { return true; }
01588 template<typename R> static inline void
01589 set_neutral (R& r) { set_true (r); }
01590 template<typename B, typename C> static inline void
01591 set_op (B& x, const C& y) { x= x && is_finite (y); }
01592 template<typename T> static inline bool
01593 op (const T& x) { return is_finite (x); }
01594 };
01595
01596 struct or_is_infinite_op {
01597 template<typename B> static inline B
01598 neutral () { return false; }
01599 template<typename R> static inline void
01600 set_neutral (R& r) { set_false (r); }
01601 template<typename B, typename C> static inline void
01602 set_op (B& x, const C& y) { x= x || is_infinite (y); }
01603 template<typename T> static inline bool
01604 op (const T& x) { return is_infinite (x); }
01605 };
01606
01607 struct or_is_fuzz_op {
01608 template<typename B> static inline B
01609 neutral () { return false; }
01610 template<typename R> static inline void
01611 set_neutral (R& r) { set_false (r); }
01612 template<typename B, typename C> static inline void
01613 set_op (B& x, const C& y) { x= x || is_fuzz (y); }
01614 template<typename T> static inline bool
01615 op (const T& x) { return is_fuzz (x); }
01616 };
01617
01618 struct or_is_nan_op {
01619 template<typename B> static inline B
01620 neutral () { return false; }
01621 template<typename R> static inline void
01622 set_neutral (R& r) { set_false (r); }
01623 template<typename B, typename C> static inline void
01624 set_op (B& x, const C& y) { x= x || is_nan (y); }
01625 template<typename T> static inline bool
01626 op (const T& x) { return is_nan (x); }
01627 };
01628
01629 template<typename C> struct unary_return_type_helper<is_finite_op,C> {
01630 typedef bool RET; };
01631 template<typename C> struct unary_return_type_helper<is_infinite_op,C> {
01632 typedef bool RET; };
01633 template<typename C> struct unary_return_type_helper<is_fuzz_op,C> {
01634 typedef bool RET; };
01635 template<typename C> struct unary_return_type_helper<is_nan_op,C> {
01636 typedef bool RET; };
01637 template<typename C> struct unary_return_type_helper<and_is_finite_op,C> {
01638 typedef bool RET; };
01639 template<typename C> struct unary_return_type_helper<or_is_infinite_op,C> {
01640 typedef bool RET; };
01641 template<typename C> struct unary_return_type_helper<or_is_fuzz_op,C> {
01642 typedef bool RET; };
01643 template<typename C> struct unary_return_type_helper<or_is_nan_op,C> {
01644 typedef bool RET; };
01645
01646 struct exponent_op {
01647
01648 static generic name () { return GEN_EXPONENT; }
01649 template<typename C> static inline xint
01650 op (const C& x) { return exponent (x); }
01651 template<typename R, typename C> static inline void
01652 set_op (R& x, const C& y) { x= exponent (y); }
01653 };
01654
01655 struct max_exponent_op {
01656 template<typename C> static inline C
01657 neutral () { return Minimal (C); }
01658 template<typename R> static inline void
01659 set_neutral (R& x) { set_minimal (x); }
01660 template<typename R, typename C> static inline void
01661 set_op (R& x, const C& y) { x= max (x, exponent (y)); }
01662 };
01663
01664 template<typename C> struct unary_return_type_helper<exponent_op,C> {
01665 typedef xint RET; };
01666 template<typename C> struct unary_return_type_helper<max_exponent_op,C> {
01667 typedef xint RET; };
01668
01669 struct magnitude_op {
01670
01671
01672
01673 static generic name () { return GEN_MAGNITUDE; }
01674 template<typename C> static inline double
01675 op (const C& x) { return magnitude (x); }
01676 template<typename R, typename C> static inline void
01677 set_op (R& x, const C& y) { x= magnitude (y); }
01678 };
01679
01680 struct max_magnitude_op {
01681 template<typename C> static inline C
01682 neutral () { return Minimal (C); }
01683 template<typename R> static inline void
01684 set_neutral (R& x) { set_minimal (x); }
01685 template<typename R, typename C> static inline void
01686 set_op (R& x, const C& y) { x= max (x, magnitude (y)); }
01687 };
01688
01689 template<typename C> struct unary_return_type_helper<magnitude_op,C> {
01690 typedef double RET; };
01691 template<typename C> struct unary_return_type_helper<max_magnitude_op,C> {
01692 typedef double RET; };
01693
01694 struct precision_op {
01695
01696
01697 static generic name () { return GEN_PRECISION; }
01698 template<typename C> static inline xnat
01699 op (const C& x) { return precision (x); }
01700 template<typename R, typename C> static inline void
01701 set_op (R& x, const C& y) { x= precision (y); }
01702 };
01703
01704 struct min_precision_op {
01705 template<typename C> static inline C
01706 neutral () { return Maximal (C); }
01707 template<typename R> static inline void
01708 set_neutral (R& x) { set_minimal (x); }
01709 template<typename R, typename C> static inline void
01710 set_op (R& x, const C& y) { x= min (x, precision (y)); }
01711 };
01712
01713 template<typename C> struct unary_return_type_helper<precision_op,C> {
01714 typedef xnat RET; };
01715 template<typename C> struct unary_return_type_helper<min_precision_op,C> {
01716 typedef xnat RET; };
01717
01718 struct change_precision_op {
01719
01720
01721 static generic name () { return GEN_CHANGE_PRECISION; }
01722 template<typename C> static inline C
01723 op (const C& x, xnat p) { return change_precision (x, p); }
01724 template<typename R, typename C> static inline void
01725 set_op (R& x, const C& y, xnat p) { x= change_precision (y, p); }
01726 };
01727
01728 struct rounding_error_op {
01729
01730
01731
01732
01733
01734 static generic name () { return GEN_ROUNDING_ERROR; }
01735 template<typename C> static inline Abs_type(C)
01736 op (const C& x) { return rounding_error (x); }
01737 template<typename R, typename C> static inline void
01738 set_op (R& x, const C& y) { x= as<R> (rounding_error (y)); }
01739 };
01740
01741 struct additive_error_op {
01742
01743
01744 static generic name () { return GEN_ADDITIVE_ERROR; }
01745 template<typename C> static inline Abs_type(C)
01746 op (const C& x) { return additive_error (x); }
01747 template<typename R, typename C> static inline void
01748 set_op (R& x, const C& y) { x= as<R> (additive_error (y)); }
01749 };
01750
01751 struct multiplicative_error_op {
01752
01753
01754
01755 static generic name () { return GEN_MULTIPLICATIVE_ERROR; }
01756 template<typename C> static inline Abs_type(C)
01757 op (const C& x) { return multiplicative_error (x); }
01758 template<typename R, typename C> static inline void
01759 set_op (R& x, const C& y) { x= as<R> (multiplicative_error (y)); }
01760 };
01761
01762 struct elementary_error_op {
01763
01764
01765 static generic name () { return GEN_ELEMENTARY_ERROR; }
01766 template<typename C> static inline Abs_type(C)
01767 op (const C& x) { return elementary_error (x); }
01768 template<typename R, typename C> static inline void
01769 set_op (R& x, const C& y) { x= as<R> (elementary_error (y)); }
01770 };
01771
01772 struct floor_op {
01773
01774 static generic name () { return GEN_FLOOR; }
01775 template<typename C> static inline C
01776 op (const C& x) { return floor (x); }
01777 template<typename C> static inline void
01778 set_op (C& x) { x= floor (x); }
01779 template<typename R, typename C> static inline void
01780 set_op (R& x, const C& y) { x= floor (y); }
01781 };
01782
01783 struct trunc_op {
01784
01785 static generic name () { return GEN_TRUNC; }
01786 template<typename C> static inline C
01787 op (const C& x) { return trunc (x); }
01788 template<typename C> static inline void
01789 set_op (C& x) { x= trunc (x); }
01790 template<typename R, typename C> static inline void
01791 set_op (R& x, const C& y) { x= trunc (y); }
01792 };
01793
01794 struct ceil_op {
01795
01796 static generic name () { return GEN_CEIL; }
01797 template<typename C> static inline C
01798 op (const C& x) { return ceil (x); }
01799 template<typename C> static inline void
01800 set_op (C& x) { x= ceil (x); }
01801 template<typename R, typename C> static inline void
01802 set_op (R& x, const C& y) { x= ceil (y); }
01803 };
01804
01805 struct round_op {
01806
01807 static generic name () { return GEN_ROUND; }
01808 template<typename C> static inline C
01809 op (const C& x) { return round (x); }
01810 template<typename C> static inline void
01811 set_op (C& x) { x= round (x); }
01812 template<typename R, typename C> static inline void
01813 set_op (R& x, const C& y) { x= round (y); }
01814 };
01815
01816
01817
01818
01819
01820 struct gaussian_op {
01821 static generic name () { return GEN_GAUSSIAN; }
01822 template<typename C> static inline Complex_type(C)
01823 op (const C& x, const C& y) { return gaussian (x, y); }
01824 static inline generic
01825 op (const generic& x, const generic& y) { return gaussian (x, y); }
01826 static inline syntactic
01827 op (const syntactic& x, const syntactic& y) { return gaussian (x, y); }
01828 template<typename R, typename C1, typename C2> static inline void
01829 set_op (R& x, const C1& y1, const C2& y2) { gaussian_as (x, y1, y2); }
01830 };
01831
01832 struct polar_op {
01833 static generic name () { return GEN_POLAR; }
01834 template<typename C> static inline Complex_type(C)
01835 op (const C& x, const C& y) { return polar (x, y); }
01836 static inline generic
01837 op (const generic& x, const generic& y) { return polar (x, y); }
01838 template<typename R, typename C1, typename C2> static inline void
01839 set_op (R& x, const C1& y1, const C2& y2) { x= polar (y1, y2); }
01840 };
01841
01842 template<typename C>
01843 struct binary_return_type_helper<polar_op,C,C> {
01844 typedef Complex_type(C) RET;
01845 };
01846
01847 struct Re_op {
01848 static generic name () { return GEN_RE; }
01849 template<typename C> static inline Real_type(C)
01850 op (const C& z) { return Re (z); }
01851 static inline generic
01852 op (const generic& z) { return Re (z); }
01853 static inline syntactic
01854 op (const syntactic& z) { return Re (z); }
01855 template<typename R, typename C> static inline void
01856 set_op (R& x, const C& y) { x= Re (y); }
01857 };
01858
01859 struct Im_op {
01860 static generic name () { return GEN_IM; }
01861 template<typename C> static inline Real_type(C)
01862 op (const C& z) { return Im (z); }
01863 static inline generic
01864 op (const generic& z) { return Im (z); }
01865 static inline syntactic
01866 op (const syntactic& z) { return Im (z); }
01867 template<typename R, typename C> static inline void
01868 set_op (R& x, const C& y) { x= Im (y); }
01869 };
01870
01871 template<typename C>
01872 struct unary_return_type_helper<Im_op,C> {
01873 typedef Real_type(C) RET;
01874 };
01875
01876 struct arg_op {
01877 static generic name () { return GEN_ARG; }
01878 template<typename C> static inline Real_type(C)
01879 op (const C& z) { return arg (z); }
01880 static inline generic
01881 op (const generic& z) { return arg (z); }
01882 static inline syntactic
01883 op (const syntactic& z) { return arg (z); }
01884 template<typename R, typename C> static inline void
01885 set_op (R& x, const C& y) { x= arg (y); }
01886 };
01887
01888 template<typename C>
01889 struct unary_return_type_helper<arg_op,C> {
01890 typedef Real_type(C) RET;
01891 };
01892
01893 struct conj_op {
01894 static generic name () { return GEN_CONJ; }
01895 template<typename C> static inline C
01896 op (const C& z) { return conj (z); }
01897 template<typename R, typename C> static inline void
01898 set_op (R& x, const C& y) { x= conj (y); }
01899 };
01900
01901 struct times_i_op {
01902 static generic name () { return GEN_TIMES_I; }
01903 template<typename C> static inline C
01904 op (const C& z) { return times_i (z); }
01905 template<typename R, typename C> static inline void
01906 set_op (R& x, const C& y) { x= times_i (y); }
01907 };
01908
01909 struct over_i_op {
01910 static generic name () { return GEN_OVER_I; }
01911 template<typename C> static inline C
01912 op (const C& z) { return over_i (z); }
01913 template<typename R, typename C> static inline void
01914 set_op (R& x, const C& y) { x= over_i (y); }
01915 };
01916
01917
01918
01919
01920
01921 struct ball_op {
01922 static generic name () { return GEN_BALL; }
01923 template<typename B, typename C, typename R> static inline B
01924 op (const C& c, const R& r) {
01925 return make_ball<B> (c, r); }
01926 template<typename B, typename C, typename R> static inline void
01927 set_op (B& b, const C& c, const R& r) {
01928 b= make_ball<B> (c, r); }
01929 };
01930
01931 struct center_op {
01932 static generic name () { return GEN_CENTER; }
01933 template<typename C> static inline Center_type(C)
01934 op (const C& x) { return center (x); }
01935 template<typename R, typename C> static inline void
01936 set_op (R& x, const C& y) { x= center (y); }
01937 };
01938
01939 struct radius_op {
01940 static generic name () { return GEN_RADIUS; }
01941 template<typename C> static inline Radius_type(C)
01942 op (const C& x) { return radius (x); }
01943 template<typename R, typename C> static inline void
01944 set_op (R& x, const C& y) { x= radius (y); }
01945 };
01946
01947 struct interval_op {
01948 static generic name () { return GEN_INTERVAL; }
01949 template<typename B, typename R> static inline B
01950 op (const R& l, const R& r) {
01951 return make_interval<B> (l, r); }
01952 template<typename B, typename R> static inline void
01953 set_op (B& b, const R& l, const R& r) {
01954 b= make_interval<B> (l, r); }
01955 };
01956
01957 struct lower_op {
01958 static generic name () { return GEN_LOWER; }
01959 template<typename C> static inline Center_type(C)
01960 op (const C& x) { return lower (x); }
01961 template<typename R, typename C> static inline void
01962 set_op (R& x, const C& y) { x= lower (y); }
01963 };
01964
01965 template<typename C>
01966 struct unary_return_type_helper<lower_op,C> {
01967 typedef Center_type(C) RET;
01968 };
01969
01970 struct upper_op {
01971 static generic name () { return GEN_UPPER; }
01972 template<typename C> static inline Center_type(C)
01973 op (const C& x) { return upper (x); }
01974 template<typename R, typename C> static inline void
01975 set_op (R& x, const C& y) { x= upper (y); }
01976 };
01977
01978 template<typename C>
01979 struct unary_return_type_helper<upper_op,C> {
01980 typedef Center_type(C) RET;
01981 };
01982
01983 struct sharpen_op {
01984
01985 static generic name () { return GEN_SHARPEN; }
01986 template<typename C> static inline C
01987 op (const C& x) { return sharpen (x); }
01988 template<typename R, typename C> static inline void
01989 set_op (R& x, const C& y) { x= sharpen (y); }
01990 };
01991
01992 struct blur_op {
01993
01994 static generic name () { return GEN_BLUR; }
01995 template<typename C, typename D> static inline C
01996 op (const C& x, const D& y) { return blur (x, y); }
01997 template<typename R, typename C, typename D> static inline void
01998 set_op (R& x, const C& y, const D& z) { x= blur (y, z); }
01999 };
02000
02001 struct included_op {
02002 static generic name () { return GEN_INCLUDED; }
02003 template<typename C> static inline bool
02004 op (const C& x, const C& y) { return included (x, y); }
02005 static inline syntactic
02006 op (const syntactic& x, const syntactic& y) { return apply (name(), x, y); }
02007 template<typename C> static inline bool
02008 not_op (const C& x, const C& y) { return !included (x, y); }
02009 };
02010
02011
02012
02013
02014
02015 struct numerator_op {
02016 static generic name () { return GEN_NUMERATOR; }
02017 template<typename C> static inline Numerator_type(C)
02018 op (const C& z) { return numerator (z); }
02019 static inline generic
02020 op (const generic& z) { return numerator (z); }
02021 static inline syntactic
02022 op (const syntactic& z) { return numerator (z); }
02023 template<typename R, typename C> static inline void
02024 set_op (R& x, const C& y) { x= numerator (y); }
02025 };
02026
02027 struct denominator_op {
02028 static generic name () { return GEN_DENOMINATOR; }
02029 template<typename C> static inline Denominator_type(C)
02030 op (const C& z) { return denominator (z); }
02031 static inline generic
02032 op (const generic& z) { return denominator (z); }
02033 static inline syntactic
02034 op (const syntactic& z) { return denominator (z); }
02035 template<typename R, typename C> static inline void
02036 set_op (R& x, const C& y) { x= denominator (y); }
02037 };
02038
02039
02040
02041
02042
02043 struct evaluate_op {
02044 static generic name () { return GEN_EVALUATE; }
02045 template<typename C,typename D> static inline Evaluate_type(C,D)
02046 op (const C& x, const D& y) { return evaluate (x, y); }
02047 template<typename R, typename C, typename D> static inline void
02048 set_op (R& r, const C& x, const D& y) { set_as (r, evaluate (x, y)); }
02049 };
02050
02051
02052
02053
02054
02055 struct lift_op {
02056 static generic name () { return GEN_LIFT; }
02057 template<typename R, typename C> static inline void
02058 set_op (R& y, const C& x) { lift_helper<C>::set_op (y, x); }
02059 template<typename C> static inline Lift_type(C)
02060 op (const C& x) { return lift_helper<C>::op (x); }
02061 };
02062
02063 struct project_op {
02064 static generic name () { return GEN_PROJECT; }
02065 template<typename R, typename C> static inline void
02066 set_op (R& y, const C& x) { project_helper<C>::set_op (y, x); }
02067 template<typename C> static inline Project_type(C)
02068 op (const C& x) { return project_helper<C>::op (x); }
02069 };
02070
02071 struct reconstruct_op {
02072 static generic name () { return GEN_RECONSTRUCT; }
02073 template<typename C> static inline Reconstruct_type(C)
02074 op (const C& x) { return reconstruct (x); }
02075 template<typename R, typename C> static inline void
02076 set_op (R& y, const C& x) { set_as (y, reconstruct (x)); }
02077 };
02078
02079
02080
02081
02082
02083 struct truncate_op {
02084 static generic name () { return GEN_TRUNCATE; }
02085 template<typename C> static inline Truncate_type(C)
02086 op (const C& x, nat n) { return truncate (x, n); }
02087 template<typename R, typename C> static inline void
02088 set_op (R& y, const C& x, nat n) { set_as (y, truncate (x, n)); }
02089 };
02090
02091 struct complete_op {
02092 static generic name () { return GEN_COMPLETE; }
02093 template<typename C> static inline Complete_type(C)
02094 op (const C& x) { return complete (x); }
02095 template<typename R, typename C> static inline void
02096 set_op (R& y, const C& x) { set_as (y, complete (x)); }
02097 };
02098
02099
02100
02101
02102
02103 struct derive_op {
02104 static generic name () { return GEN_DERIVE; }
02105 template<typename C> static inline C
02106 op (const C& x) { return derive (x); }
02107 template<typename R, typename C> static inline void
02108 set_op (R& x, const C& y) { x= derive (y); }
02109 template<typename C,typename V> static inline C
02110 op (const C& x, const V& v) { return derive (x, v); }
02111 template<typename R, typename C, typename V> static inline void
02112 set_op (R& x, const C& y, const V& v) { x= derive (y, v); }
02113 };
02114
02115 struct xderive_op {
02116 static generic name () { return GEN_XDERIVE; }
02117 template<typename C> static inline C
02118 op (const C& x) { return xderive (x); }
02119 template<typename R, typename C> static inline void
02120 set_op (R& x, const C& y) { return xderive (y); }
02121 template<typename C,typename V> static inline C
02122 op (const C& x, const V& v) { return xderive (x, v); }
02123 template<typename R, typename C, typename V> static inline void
02124 set_op (R& x, const C& y, const V& v) { x= xderive (y, v); }
02125 };
02126
02127 struct integrate_op {
02128 static generic name () { return GEN_INTEGRATE; }
02129 template<typename C> static inline C
02130 op (const C& x) { return integrate (x); }
02131 template<typename R, typename C> static inline void
02132 set_op (R& x, const C& y) { x= integrate (y); }
02133 template<typename C,typename V> static inline C
02134 op (const C& x, const V& v) { return integrate (x, v); }
02135 template<typename R, typename C, typename V> static inline void
02136 set_op (R& x, const C& y, const V& v) { x= integrate (y, v); }
02137 template<typename C,typename I> static inline C
02138 op_init (const C& x, const I& i) { return integrate_init (x, i); }
02139 template<typename C,typename V,typename I> static inline C
02140 op_init (const C& x, const V& v, const I& i) {
02141 return integrate_init (x, v, i); }
02142 };
02143
02144 struct integrate_init_op {
02145 static generic name () { return GEN_INTEGRATE_INIT; }
02146 template<typename C, typename I> static inline C
02147 op (const C& x, const I& i) { return integrate_init (x, i); }
02148 template<typename R, typename C, typename I> static inline void
02149 set_op (R& x, const C& y, const I& i) { x= integrate_init (y, i); }
02150 };
02151
02152 struct compose_op {
02153 static generic name () { return GEN_COMPOSE; }
02154 template<typename C1,typename C2> static inline C1
02155 op (const C1& x, const C2& y) { return compose (x, y); }
02156 template<typename R, typename C1, typename C2> static inline void
02157 set_op (R& x, const C1& y1, const C2& y2) { x= compose (y1, y2); }
02158 template<typename C> static inline C
02159 diff_op (const C& me, const C& x, const C& y) {
02160 (void) me; return derive (y) * compose (derive (x), y); }
02161 };
02162
02163 struct reverse_op {
02164 static generic name () { return GEN_REVERSE; }
02165 template<typename C> static inline C
02166 op (const C& x) { return reverse (x); }
02167 template<typename R, typename C> static inline void
02168 set_op (R& x, const C& y) { x= reverse (y); }
02169 template<typename C> static inline C
02170 diff_op (const C& me, const C& x) {
02171 return 1 / compose (derive (x), me); }
02172 };
02173
02174 struct append_op {
02175 static generic name () { return GEN_APPEND; }
02176 template<typename C1,typename C2> static inline C1
02177 op (const C1& x, const C2& y) { return append (x, y); }
02178 template<typename R, typename C1, typename C2> static inline void
02179 set_op (R& x, const C1& y1, const C2& y2) { x= append (y1, y2); }
02180 };
02181
02182 struct solve_vector_lde_op {
02183 template<typename C> static inline C
02184 op (const C& x) { ERROR ("must initialize (solve_vector_lde_op::op)"); }
02185 template<typename C, typename I> static inline C
02186 op_init (const C& x, const I& i) { return solve_vector_lde_init (x, i); }
02187 static inline generic op_init (const generic& x, const generic& i) {
02188 return solve_lde_init (x, i); }
02189 static inline syntactic op_init (const syntactic& x, const syntactic& i) {
02190 return solve_lde_init (x, i); }
02191 template<typename C> static inline C
02192 diff_op (const C& me, const C& x);
02193 static inline nat nr_init () { return 1; }
02194 template<typename C> static inline C
02195 def (const C& me, const C& f) {
02196 return integrate (diff_op (me, f)); }
02197 };
02198
02199 struct solve_matrix_lde_op {
02200 template<typename C> static inline C
02201 op (const C& x) { ERROR ("must initialize (solve_matrix_lde_op::op)"); }
02202 template<typename C, typename I> static inline C
02203 op_init (const C& x, const I& i) { return solve_matrix_lde_init (x, i); }
02204 static inline generic op_init (const generic& x, const generic& i) {
02205 return solve_lde_init (x, i); }
02206 static inline syntactic op_init (const syntactic& x, const syntactic& i) {
02207 return solve_lde_init (x, i); }
02208 template<typename C> static inline C diff_op (const C& me, const C& x) {
02209 return x * me; }
02210 static inline nat nr_init () { return 1; }
02211 template<typename C> static inline C def (const C& me, const C& f) {
02212 return integrate (diff_op (me, f)); }
02213 };
02214
02215
02216
02217
02218
02219 struct is_infinitesimal_op {
02220 template<typename T> static inline bool
02221 op (const T& x) { return x << 1; }
02222 template<typename T> static inline bool
02223 not_op (const T& x) { return !(x << 1); }
02224 };
02225
02226 struct is_non_infinitesimal_op {
02227 template<typename T> static inline bool
02228 op (const T& x) { return !(x << 1); }
02229 template<typename T> static inline bool
02230 not_op (const T& x) { return x << 1; }
02231 };
02232
02233 struct is_bounded_op {
02234 template<typename T> static inline bool
02235 op (const T& x) { return x <<= 1; }
02236 template<typename T> static inline bool
02237 not_op (const T& x) { return !(x <<= 1); }
02238 };
02239
02240 struct is_non_bounded_op {
02241 template<typename T> static inline bool
02242 op (const T& x) { return !(x <<= 1); }
02243 template<typename T> static inline bool
02244 not_op (const T& x) { return x <<= 1; }
02245 };
02246
02247 struct is_infinitely_large_op {
02248 template<typename T> static inline bool
02249 op (const T& x) { return x >> 1; }
02250 template<typename T> static inline bool
02251 not_op (const T& x) { return !(x >> 1); }
02252 };
02253
02254 struct is_non_infinitely_large_op {
02255 template<typename T> static inline bool
02256 op (const T& x) { return !(x >> 1); }
02257 template<typename T> static inline bool
02258 not_op (const T& x) { return x >> 1; }
02259 };
02260
02261 struct is_constant_op {
02262 template<typename T> static inline bool
02263 op (const T& x) { return x == 1; }
02264 template<typename T> static inline bool
02265 not_op (const T& x) { return x != 1; }
02266 };
02267
02268 struct is_non_constant_op {
02269 template<typename T> static inline bool
02270 op (const T& x) { return x != 1; }
02271 template<typename T> static inline bool
02272 not_op (const T& x) { return x == 1; }
02273 };
02274
02275 struct smaller_equal_op {
02276 template<typename T1, typename T2> static inline bool
02277 op (const T1& x1, const T2& x2) { return x1 <<= x2; }
02278 template<typename T1, typename T2> static inline bool
02279 not_op (const T1& x1, const T2& x2) { return !(x1 <<= x2); }
02280 };
02281
02282 struct not_smaller_equal_op {
02283 template<typename T1, typename T2> static inline bool
02284 op (const T1& x1, const T2& x2) { return !(x1 <<= x2); }
02285 template<typename T1, typename T2> static inline bool
02286 not_op (const T1& x1, const T2& x2) { return x1 <<= x2; }
02287 };
02288
02289 struct smaller_op {
02290 template<typename T1, typename T2> static inline bool
02291 op (const T1& x1, const T2& x2) { return x1 << x2; }
02292 template<typename T1, typename T2> static inline bool
02293 not_op (const T1& x1, const T2& x2) { return !(x1 << x2); }
02294 };
02295
02296 struct not_smaller_op {
02297 template<typename T1, typename T2> static inline bool
02298 op (const T1& x1, const T2& x2) { return !(x1 << x2); }
02299 template<typename T1, typename T2> static inline bool
02300 not_op (const T1& x1, const T2& x2) { return x1 << x2; }
02301 };
02302
02303 struct larger_equal_op {
02304 template<typename T> static inline bool
02305 op (const T& x1, const T& x2) { return x1 >>= x2; }
02306 template<typename T> static inline bool
02307 not_op (const T& x1, const T& x2) { return !(x1 >>= x2); }
02308 };
02309
02310 struct not_larger_equal_op {
02311 template<typename T> static inline bool
02312 op (const T& x1, const T& x2) { return !(x1 >>= x2); }
02313 template<typename T> static inline bool
02314 not_op (const T& x1, const T& x2) { return x1 >>= x2; }
02315 };
02316
02317 struct larger_op {
02318 template<typename T> static inline bool
02319 op (const T& x1, const T& x2) { return x1 >> x2; }
02320 template<typename T> static inline bool
02321 not_op (const T& x1, const T& x2) { return !(x1 >> x2); }
02322 };
02323
02324 struct not_larger_op {
02325 template<typename T> static inline bool
02326 op (const T& x1, const T& x2) { return !(x1 >> x2); }
02327 template<typename T> static inline bool
02328 not_op (const T& x1, const T& x2) { return x1 >> x2; }
02329 };
02330
02331
02332
02333
02334
02335 struct common_part_op {
02336 typedef zero_op lop;
02337 typedef zero_op rop;
02338 static generic name () { return "common_part"; }
02339 template<typename T> static inline T
02340 op (const T& x, const T& y) { return common_part (x, y); }
02341 };
02342
02343 struct dominant_part_op {
02344 static generic name () { return "dominant_part"; }
02345 template<typename T> static inline T
02346 op (const T& x) { return dominant_part (x); }
02347 };
02348
02349 struct remainder_part_op {
02350 static generic name () { return "remainder_part"; }
02351 template<typename T> static inline T
02352 op (const T& x) { return remainder_part (x); }
02353 };
02354
02355 struct infinitesimal_part_op {
02356 typedef is_infinitesimal_op pred;
02357 static generic name () { return "infinitesimal_part"; }
02358 template<typename T> static inline T
02359 op (const T& x) { return infinitesimal_part (x); }
02360 };
02361
02362 struct non_infinitesimal_part_op {
02363 typedef is_non_infinitesimal_op pred;
02364 static generic name () { return "non_infinitesimal_part"; }
02365 template<typename T> static inline T
02366 op (const T& x) { return non_infinitesimal_part (x); }
02367 };
02368
02369 struct bounded_part_op {
02370 typedef is_bounded_op pred;
02371 static generic name () { return "bounded_part"; }
02372 template<typename T> static inline T
02373 op (const T& x) { return bounded_part (x); }
02374 };
02375
02376 struct non_bounded_part_op {
02377 typedef is_non_bounded_op pred;
02378 static generic name () { return "non_bounded_part"; }
02379 template<typename T> static inline T
02380 op (const T& x) { return non_bounded_part (x); }
02381 };
02382
02383 struct infinite_part_op {
02384 typedef is_infinitely_large_op pred;
02385 static generic name () { return "infinite_part"; }
02386 template<typename T> static inline T
02387 op (const T& x) { return infinite_part (x); }
02388 };
02389
02390 struct non_infinite_part_op {
02391 typedef is_non_infinitely_large_op pred;
02392 static generic name () { return "non_infinite_part"; }
02393 template<typename T> static inline T
02394 op (const T& x) { return non_infinite_part (x); }
02395 };
02396
02397 struct constant_part_op {
02398 typedef is_constant_op pred;
02399 static generic name () { return "constant_part"; }
02400 template<typename T> static inline T
02401 op (const T& x) { return constant_part (x); }
02402 };
02403
02404 struct non_constant_part_op {
02405 typedef is_non_constant_op pred;
02406 static generic name () { return "non_constant_part"; }
02407 template<typename T> static inline T
02408 op (const T& x) { return non_constant_part (x); }
02409 };
02410
02411
02412
02413
02414
02415 struct access_op {
02416 static generic name () { return GEN_ACCESS; }
02417 template<typename C, typename I>
02418 static inline Binary_return_type(access_op,C,I)
02419 op (const C& x, const I& i) { return x[i]; }
02420 template<typename R, typename C, typename I> static inline void
02421 set_op (R& x, const C& y, const I& i) { x= y[i]; }
02422 };
02423
02424 struct mv_inject_op {
02425 static generic name () { return "inject"; }
02426 template<typename C, typename I, typename D> static inline C
02427 op (const C& x, const I& i, const D& d) { return inject (x, i, d); }
02428 template<typename R, typename C, typename I, typename D> static inline void
02429 set_op (R& x, const C& y, const I& i, const D& d) { x= inject (y, i, d); }
02430 };
02431
02432 struct mv_project_op {
02433 static generic name () { return "project"; }
02434 template<typename C, typename I> static inline C
02435 op (const C& x, const I& i) { return project (x, i); }
02436 template<typename R, typename C, typename I> static inline void
02437 set_op (R& x, const C& y, const I& i) { x= project (y, i); }
02438 };
02439
02440 }
02441 #endif // __MMX_OPERATORS_HPP