26 #ifndef CASADI_GENERIC_EXPRESSION_HPP
27 #define CASADI_GENERIC_EXPRESSION_HPP
29 #include "calculus.hpp"
50 template<
typename ExType>
54 inline const ExType&
self()
const {
return static_cast<const ExType&
>(*this); }
55 inline ExType&
self() {
return static_cast<ExType&
>(*this); }
67 static ExType plus(
const ExType &x,
const ExType &y) {
68 return ExType::binary(OP_ADD, x, y);
70 friend inline ExType plus(
const ExType &x,
const ExType &y) {
71 return ExType::plus(x, y);
73 friend inline ExType operator+(
const ExType &x,
const ExType &y) {
76 inline ExType& operator+=(
const ExType &y) {
return self() =
self() + y; }
83 static ExType minus(
const ExType &x,
const ExType &y) {
84 return ExType::binary(OP_SUB, x, y);
86 friend inline ExType minus(
const ExType &x,
const ExType &y) {
87 return ExType::minus(x, y);
89 friend inline ExType operator-(
const ExType &x,
const ExType &y) {
92 inline ExType& operator-=(
const ExType &y) {
return self() =
self() - y; }
99 static ExType times(
const ExType &x,
const ExType &y) {
100 return ExType::binary(OP_MUL, x, y);
102 friend inline ExType times(
const ExType &x,
const ExType &y) {
103 return ExType::times(x, y);
105 friend inline ExType operator*(
const ExType &x,
const ExType &y) {
108 inline ExType& operator*=(
const ExType &y) {
return self() =
self() * y;}
115 static ExType rdivide(
const ExType &x,
const ExType &y) {
116 return ExType::binary(OP_DIV, x, y);
118 friend inline ExType rdivide(
const ExType &x,
const ExType &y) {
119 return ExType::rdivide(x, y);
121 friend inline ExType operator/(
const ExType &x,
const ExType &y) {
122 return rdivide(x, y);
124 inline ExType& operator/=(
const ExType &y) {
return self() =
self() / y;}
131 static ExType lt(
const ExType &x,
const ExType &y) {
132 return ExType::binary(OP_LT, x, y);
134 friend inline ExType lt(
const ExType &x,
const ExType &y) {
135 return ExType::lt(x, y);
137 friend inline ExType operator<(
const ExType &x,
const ExType &y) {
146 static ExType le(
const ExType &x,
const ExType &y) {
147 return ExType::binary(OP_LE, x, y);
149 friend inline ExType le(
const ExType &x,
const ExType &y) {
150 return ExType::le(x, y);
152 friend inline ExType operator<=(
const ExType &x,
const ExType &y) {
161 static ExType gt(
const ExType &x,
const ExType &y) {
162 return ExType::lt(y, x);
164 friend inline ExType gt(
const ExType &x,
const ExType &y) {
165 return ExType::gt(x, y);
167 friend inline ExType operator>(
const ExType &x,
const ExType &y) {
176 static ExType ge(
const ExType &x,
const ExType &y) {
177 return ExType::le(y, x);
179 friend inline ExType ge(
const ExType &x,
const ExType &y) {
180 return ExType::ge(x, y);
182 friend inline ExType operator>=(
const ExType &x,
const ExType &y) {
191 static ExType eq(
const ExType &x,
const ExType &y) {
192 return ExType::binary(OP_EQ, x, y);
194 friend inline ExType eq(
const ExType &x,
const ExType &y) {
195 return ExType::eq(x, y);
197 friend inline ExType operator==(
const ExType &x,
const ExType &y) {
206 static ExType ne(
const ExType &x,
const ExType &y) {
207 return ExType::binary(OP_NE, x, y);
209 friend inline ExType ne(
const ExType &x,
const ExType &y) {
210 return ExType::ne(x, y);
212 friend inline ExType operator!=(
const ExType &x,
const ExType &y) {
224 static ExType logic_and(
const ExType &x,
const ExType &y) {
225 return ExType::binary(OP_AND, x, y);
227 friend inline ExType logic_and(
const ExType &x,
const ExType &y) {
228 return ExType::logic_and(x, y);
230 friend inline ExType operator&&(
const ExType &x,
const ExType &y) {
231 return logic_and(x, y);
242 static ExType logic_or(
const ExType &x,
const ExType &y) {
243 return ExType::binary(OP_OR, x, y);
245 friend inline ExType logic_or(
const ExType &x,
const ExType &y) {
246 return ExType::logic_or(x, y);
248 friend inline ExType operator||(
const ExType &x,
const ExType &y) {
249 return logic_or(x, y);
260 static ExType logic_not(
const ExType& x) {
261 return ExType::unary(OP_NOT, x);
263 friend inline ExType logic_not(
const ExType& x) {
264 return ExType::logic_not(x);
266 inline ExType operator!()
const {
267 return logic_not(
self());
275 static ExType abs(
const ExType& x) {
276 return ExType::unary(OP_FABS, x);
278 friend inline ExType abs(
const ExType& x) {
279 return ExType::abs(x);
281 friend inline ExType fabs(
const ExType& x) {
290 static ExType sqrt(
const ExType& x) {
291 return ExType::unary(OP_SQRT, x);
293 friend inline ExType sqrt(
const ExType& x) {
294 return ExType::sqrt(x);
302 static ExType sq(
const ExType& x) {
303 return ExType::unary(OP_SQ, x);
305 friend inline ExType sq(
const ExType& x) {
306 return ExType::sq(x);
314 static ExType sin(
const ExType& x) {
315 return ExType::unary(OP_SIN, x);
317 friend inline ExType sin(
const ExType& x) {
318 return ExType::sin(x);
326 static ExType cos(
const ExType& x) {
327 return ExType::unary(OP_COS, x);
329 friend inline ExType cos(
const ExType& x) {
330 return ExType::cos(x);
338 static ExType tan(
const ExType& x) {
339 return ExType::unary(OP_TAN, x);
341 friend inline ExType tan(
const ExType& x) {
342 return ExType::tan(x);
350 static ExType atan(
const ExType& x) {
351 return ExType::unary(OP_ATAN, x);
353 friend inline ExType atan(
const ExType& x) {
354 return ExType::atan(x);
362 static ExType asin(
const ExType& x) {
363 return ExType::unary(OP_ASIN, x);
365 friend inline ExType asin(
const ExType& x) {
366 return ExType::asin(x);
374 static ExType acos(
const ExType& x) {
375 return ExType::unary(OP_ACOS, x);
377 friend inline ExType acos(
const ExType& x) {
378 return ExType::acos(x);
386 static ExType tanh(
const ExType& x) {
387 return ExType::unary(OP_TANH, x);
389 friend inline ExType tanh(
const ExType& x) {
390 return ExType::tanh(x);
398 static ExType sinh(
const ExType& x) {
399 return ExType::unary(OP_SINH, x);
401 friend inline ExType sinh(
const ExType& x) {
402 return ExType::sinh(x);
410 static ExType cosh(
const ExType& x) {
411 return ExType::unary(OP_COSH, x);
413 friend inline ExType cosh(
const ExType& x) {
414 return ExType::cosh(x);
422 static ExType atanh(
const ExType& x) {
423 return ExType::unary(OP_ATANH, x);
425 friend inline ExType atanh(
const ExType& x) {
426 return ExType::atanh(x);
434 static ExType asinh(
const ExType& x) {
435 return ExType::unary(OP_ASINH, x);
437 friend inline ExType asinh(
const ExType& x) {
438 return ExType::asinh(x);
446 static ExType acosh(
const ExType& x) {
447 return ExType::unary(OP_ACOSH, x);
449 friend inline ExType acosh(
const ExType& x) {
450 return ExType::acosh(x);
458 static ExType exp(
const ExType& x) {
459 return ExType::unary(OP_EXP, x);
461 friend inline ExType exp(
const ExType& x) {
462 return ExType::exp(x);
470 static ExType log(
const ExType& x) {
471 return ExType::unary(OP_LOG, x);
473 friend inline ExType log(
const ExType& x) {
474 return ExType::log(x);
482 static ExType log10(
const ExType& x) {
483 return log(x)*(1/std::log(10.));
485 friend inline ExType log10(
const ExType& x) {
486 return ExType::log10(x);
494 static ExType log1p(
const ExType& x) {
495 return ExType::unary(OP_LOG1P, x);
497 friend inline ExType log1p(
const ExType& x) {
498 return ExType::log1p(x);
506 static ExType expm1(
const ExType& x) {
507 return ExType::unary(OP_EXPM1, x);
509 friend inline ExType expm1(
const ExType& x) {
510 return ExType::expm1(x);
518 static ExType floor(
const ExType& x) {
519 return ExType::unary(OP_FLOOR, x);
521 friend inline ExType floor(
const ExType& x) {
522 return ExType::floor(x);
530 static ExType ceil(
const ExType& x) {
531 return ExType::unary(OP_CEIL, x);
533 friend inline ExType ceil(
const ExType& x) {
534 return ExType::ceil(x);
542 static ExType erf(
const ExType& x) {
543 return ExType::unary(OP_ERF, x);
545 friend inline ExType erf(
const ExType& x) {
546 return ExType::erf(x);
554 static ExType erfinv(
const ExType& x) {
555 return ExType::unary(OP_ERFINV, x);
557 friend inline ExType erfinv(
const ExType& x) {
558 return ExType::erfinv(x);
571 static ExType sign(
const ExType& x) {
572 return ExType::unary(OP_SIGN, x);
574 friend inline ExType sign(
const ExType& x) {
575 return ExType::sign(x);
583 static ExType pow(
const ExType& x,
const ExType& y) {
584 return ExType::binary(OP_POW, x, y);
586 friend inline ExType pow(
const ExType& x,
const ExType& y) {
587 return ExType::pow(x, y);
607 static ExType mod(
const ExType& x,
const ExType& y) {
608 return ExType::binary(OP_FMOD, x, y);
610 friend inline ExType mod(
const ExType& x,
const ExType& y) {
611 return ExType::mod(x, y);
613 friend inline ExType fmod(
const ExType& x,
const ExType& y) {
634 static ExType remainder(
const ExType& x,
const ExType& y) {
635 return ExType::binary(OP_REMAINDER, x, y);
637 friend inline ExType remainder(
const ExType& x,
const ExType& y) {
638 return ExType::remainder(x, y);
648 static ExType atan2(
const ExType& y,
const ExType& x) {
649 return ExType::binary(OP_ATAN2, y, x);
651 friend inline ExType atan2(
const ExType& y,
const ExType& x) {
652 return ExType::atan2(y, x);
660 static ExType if_else_zero(
const ExType& x,
const ExType& y) {
661 return ExType::binary(OP_IF_ELSE_ZERO, x, y);
663 friend inline ExType if_else_zero(
const ExType& x,
const ExType& y) {
664 return ExType::if_else_zero(x, y);
672 static ExType fmin(
const ExType& x,
const ExType& y) {
673 return ExType::binary(OP_FMIN, x, y);
675 friend inline ExType fmin(
const ExType& x,
const ExType& y) {
676 return ExType::fmin(x, y);
684 static ExType fmax(
const ExType& x,
const ExType& y) {
685 return ExType::binary(OP_FMAX, x, y);
687 friend inline ExType fmax(
const ExType& x,
const ExType& y) {
688 return ExType::fmax(x, y);
703 friend inline bool is_equal(
const ExType& x,
const ExType& y, casadi_int depth=0) {
704 return ExType::is_equal(x, y, depth);
710 static ExType copysign(
const ExType& x,
const ExType& y) {
711 return ExType::binary(OP_COPYSIGN, x, y);
713 friend inline ExType copysign(
const ExType& x,
const ExType& y) {
714 return ExType::copysign(x, y);
720 static ExType constpow(
const ExType& x,
const ExType& y) {
721 return ExType::binary(OP_CONSTPOW, x, y);
723 friend inline ExType constpow(
const ExType& x,
const ExType& y) {
724 return ExType::constpow(x, y);
730 static ExType printme(
const ExType& x,
const ExType& y) {
731 return ExType::binary(OP_PRINTME, x, y);
733 friend inline ExType printme(
const ExType& x,
const ExType& y) {
734 return ExType::binary(OP_PRINTME, x, y);
742 static ExType hypot(
const ExType& x,
const ExType& y) {
743 return ExType::binary(OP_HYPOT, x, y);
745 friend inline ExType hypot(
const ExType& x,
const ExType& y) {
746 return ExType::hypot(x, y);