generic_expression.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_GENERIC_EXPRESSION_HPP
27 #define CASADI_GENERIC_EXPRESSION_HPP
28 
29 #include "calculus.hpp"
30 
31 namespace casadi {
32 
38  struct CASADI_EXPORT GenericExpressionCommon {};
39 
40 #ifndef SWIG
50 template<typename ExType>
51 class GenericExpression : public GenericExpressionCommon {
52  protected:
53  // Helper functions
54  inline const ExType& self() const { return static_cast<const ExType&>(*this); }
55  inline ExType& self() { return static_cast<ExType&>(*this); }
56  public:
57 
64 
161  static ExType plus(const ExType &x, const ExType &y) {
162  return ExType::binary(OP_ADD, x, y);
163  }
164  friend inline ExType plus(const ExType &x, const ExType &y) {
165  return ExType::plus(x, y);
166  }
167  friend inline ExType operator+(const ExType &x, const ExType &y) {
168  return plus(x, y);
169  }
170  inline ExType& operator+=(const ExType &y) { return self() = self() + y; }
172 
174 
221  static ExType minus(const ExType &x, const ExType &y) {
222  return ExType::binary(OP_SUB, x, y);
223  }
224  friend inline ExType minus(const ExType &x, const ExType &y) {
225  return ExType::minus(x, y);
226  }
227  friend inline ExType operator-(const ExType &x, const ExType &y) {
228  return minus(x, y);
229  }
230  inline ExType& operator-=(const ExType &y) { return self() = self() - y; }
232 
234 
289  static ExType times(const ExType &x, const ExType &y) {
290  return ExType::binary(OP_MUL, x, y);
291  }
292  friend inline ExType times(const ExType &x, const ExType &y) {
293  return ExType::times(x, y);
294  }
295  friend inline ExType operator*(const ExType &x, const ExType &y) {
296  return times(x, y);
297  }
298  inline ExType& operator*=(const ExType &y) {return self() = self() * y;}
300 
302 
360  static ExType rdivide(const ExType &x, const ExType &y) {
361  return ExType::binary(OP_DIV, x, y);
362  }
363  friend inline ExType rdivide(const ExType &x, const ExType &y) {
364  return ExType::rdivide(x, y);
365  }
366  friend inline ExType operator/(const ExType &x, const ExType &y) {
367  return rdivide(x, y);
368  }
369  inline ExType& operator/=(const ExType &y) {return self() = self() / y;}
371 
373 
428  static ExType lt(const ExType &x, const ExType &y) {
429  return ExType::binary(OP_LT, x, y);
430  }
431  friend inline ExType lt(const ExType &x, const ExType &y) {
432  return ExType::lt(x, y);
433  }
434  friend inline ExType operator<(const ExType &x, const ExType &y) {
435  return lt(x, y);
436  }
438 
440 
478  static ExType le(const ExType &x, const ExType &y) {
479  return ExType::binary(OP_LE, x, y);
480  }
481  friend inline ExType le(const ExType &x, const ExType &y) {
482  return ExType::le(x, y);
483  }
484  friend inline ExType operator<=(const ExType &x, const ExType &y) {
485  return le(x, y);
486  }
488 
490 
525  static ExType gt(const ExType &x, const ExType &y) {
526  return ExType::lt(y, x);
527  }
528  friend inline ExType gt(const ExType &x, const ExType &y) {
529  return ExType::gt(x, y);
530  }
531  friend inline ExType operator>(const ExType &x, const ExType &y) {
532  return gt(x, y);
533  }
535 
537 
571  static ExType ge(const ExType &x, const ExType &y) {
572  return ExType::le(y, x);
573  }
574  friend inline ExType ge(const ExType &x, const ExType &y) {
575  return ExType::ge(x, y);
576  }
577  friend inline ExType operator>=(const ExType &x, const ExType &y) {
578  return ge(x, y);
579  }
581 
583 
641  static ExType eq(const ExType &x, const ExType &y) {
642  return ExType::binary(OP_EQ, x, y);
643  }
644  friend inline ExType eq(const ExType &x, const ExType &y) {
645  return ExType::eq(x, y);
646  }
647  friend inline ExType operator==(const ExType &x, const ExType &y) {
648  return eq(x, y);
649  }
651 
653 
691  static ExType ne(const ExType &x, const ExType &y) {
692  return ExType::binary(OP_NE, x, y);
693  }
694  friend inline ExType ne(const ExType &x, const ExType &y) {
695  return ExType::ne(x, y);
696  }
697  friend inline ExType operator!=(const ExType &x, const ExType &y) {
698  return ne(x, y);
699  }
701 
703 
753  static ExType logic_and(const ExType &x, const ExType &y) {
754  return ExType::binary(OP_AND, x, y);
755  }
756  friend inline ExType logic_and(const ExType &x, const ExType &y) {
757  return ExType::logic_and(x, y);
758  }
759  friend inline ExType operator&&(const ExType &x, const ExType &y) {
760  return logic_and(x, y);
761  }
763 
765 
802  static ExType logic_or(const ExType &x, const ExType &y) {
803  return ExType::binary(OP_OR, x, y);
804  }
805  friend inline ExType logic_or(const ExType &x, const ExType &y) {
806  return ExType::logic_or(x, y);
807  }
808  friend inline ExType operator||(const ExType &x, const ExType &y) {
809  return logic_or(x, y);
810  }
812 
814 
863  static ExType logic_not(const ExType& x) {
864  return ExType::unary(OP_NOT, x);
865  }
866  friend inline ExType logic_not(const ExType& x) {
867  return ExType::logic_not(x);
868  }
869  inline ExType operator!() const {
870  return logic_not(self());
871  }
873 
875 
925  static ExType abs(const ExType& x) {
926  return ExType::unary(OP_FABS, x);
927  }
928  friend inline ExType abs(const ExType& x) {
929  return ExType::abs(x);
930  }
931  friend inline ExType fabs(const ExType& x) {
932  return abs(x);
933  }
935 
937 
972  static ExType sqrt(const ExType& x) {
973  return ExType::unary(OP_SQRT, x);
974  }
975  friend inline ExType sqrt(const ExType& x) {
976  return ExType::sqrt(x);
977  }
979 
981 
1010  static ExType sq(const ExType& x) {
1011  return ExType::unary(OP_SQ, x);
1012  }
1013  friend inline ExType sq(const ExType& x) {
1014  return ExType::sq(x);
1015  }
1017 
1019 
1058  static ExType sin(const ExType& x) {
1059  return ExType::unary(OP_SIN, x);
1060  }
1061  friend inline ExType sin(const ExType& x) {
1062  return ExType::sin(x);
1063  }
1065 
1067 
1112  static ExType cos(const ExType& x) {
1113  return ExType::unary(OP_COS, x);
1114  }
1115  friend inline ExType cos(const ExType& x) {
1116  return ExType::cos(x);
1117  }
1119 
1121 
1149  static ExType tan(const ExType& x) {
1150  return ExType::unary(OP_TAN, x);
1151  }
1152  friend inline ExType tan(const ExType& x) {
1153  return ExType::tan(x);
1154  }
1156 
1158 
1187  static ExType atan(const ExType& x) {
1188  return ExType::unary(OP_ATAN, x);
1189  }
1190  friend inline ExType atan(const ExType& x) {
1191  return ExType::atan(x);
1192  }
1194 
1196 
1224  static ExType asin(const ExType& x) {
1225  return ExType::unary(OP_ASIN, x);
1226  }
1227  friend inline ExType asin(const ExType& x) {
1228  return ExType::asin(x);
1229  }
1231 
1233 
1261  static ExType acos(const ExType& x) {
1262  return ExType::unary(OP_ACOS, x);
1263  }
1264  friend inline ExType acos(const ExType& x) {
1265  return ExType::acos(x);
1266  }
1268 
1270 
1298  static ExType tanh(const ExType& x) {
1299  return ExType::unary(OP_TANH, x);
1300  }
1301  friend inline ExType tanh(const ExType& x) {
1302  return ExType::tanh(x);
1303  }
1305 
1307 
1335  static ExType sinh(const ExType& x) {
1336  return ExType::unary(OP_SINH, x);
1337  }
1338  friend inline ExType sinh(const ExType& x) {
1339  return ExType::sinh(x);
1340  }
1342 
1344 
1372  static ExType cosh(const ExType& x) {
1373  return ExType::unary(OP_COSH, x);
1374  }
1375  friend inline ExType cosh(const ExType& x) {
1376  return ExType::cosh(x);
1377  }
1379 
1381 
1409  static ExType atanh(const ExType& x) {
1410  return ExType::unary(OP_ATANH, x);
1411  }
1412  friend inline ExType atanh(const ExType& x) {
1413  return ExType::atanh(x);
1414  }
1416 
1418 
1446  static ExType asinh(const ExType& x) {
1447  return ExType::unary(OP_ASINH, x);
1448  }
1449  friend inline ExType asinh(const ExType& x) {
1450  return ExType::asinh(x);
1451  }
1453 
1455 
1483  static ExType acosh(const ExType& x) {
1484  return ExType::unary(OP_ACOSH, x);
1485  }
1486  friend inline ExType acosh(const ExType& x) {
1487  return ExType::acosh(x);
1488  }
1490 
1492 
1531  static ExType exp(const ExType& x) {
1532  return ExType::unary(OP_EXP, x);
1533  }
1534  friend inline ExType exp(const ExType& x) {
1535  return ExType::exp(x);
1536  }
1538 
1540 
1575  static ExType log(const ExType& x) {
1576  return ExType::unary(OP_LOG, x);
1577  }
1578  friend inline ExType log(const ExType& x) {
1579  return ExType::log(x);
1580  }
1582 
1584 
1619  static ExType log10(const ExType& x) {
1620  return log(x)*(1/std::log(10.));
1621  }
1622  friend inline ExType log10(const ExType& x) {
1623  return ExType::log10(x);
1624  }
1626 
1628 
1663  static ExType log1p(const ExType& x) {
1664  return ExType::unary(OP_LOG1P, x);
1665  }
1666  friend inline ExType log1p(const ExType& x) {
1667  return ExType::log1p(x);
1668  }
1670 
1672 
1701  static ExType expm1(const ExType& x) {
1702  return ExType::unary(OP_EXPM1, x);
1703  }
1704  friend inline ExType expm1(const ExType& x) {
1705  return ExType::expm1(x);
1706  }
1708 
1710 
1751  static ExType floor(const ExType& x) {
1752  return ExType::unary(OP_FLOOR, x);
1753  }
1754  friend inline ExType floor(const ExType& x) {
1755  return ExType::floor(x);
1756  }
1758 
1760 
1789  static ExType ceil(const ExType& x) {
1790  return ExType::unary(OP_CEIL, x);
1791  }
1792  friend inline ExType ceil(const ExType& x) {
1793  return ExType::ceil(x);
1794  }
1796 
1798 
1826  static ExType erf(const ExType& x) {
1827  return ExType::unary(OP_ERF, x);
1828  }
1829  friend inline ExType erf(const ExType& x) {
1830  return ExType::erf(x);
1831  }
1833 
1835 
1864  static ExType erfinv(const ExType& x) {
1865  return ExType::unary(OP_ERFINV, x);
1866  }
1867  friend inline ExType erfinv(const ExType& x) {
1868  return ExType::erfinv(x);
1869  }
1871 
1873 
1912  static ExType sign(const ExType& x) {
1913  return ExType::unary(OP_SIGN, x);
1914  }
1915  friend inline ExType sign(const ExType& x) {
1916  return ExType::sign(x);
1917  }
1919 
1921 
1978  static ExType pow(const ExType& x, const ExType& y) {
1979  return ExType::binary(OP_POW, x, y);
1980  }
1981  friend inline ExType pow(const ExType& x, const ExType& y) {
1982  return ExType::pow(x, y);
1983  }
1985 
1987 
2036  static ExType mod(const ExType& x, const ExType& y) {
2037  return ExType::binary(OP_FMOD, x, y);
2038  }
2039  friend inline ExType mod(const ExType& x, const ExType& y) {
2040  return ExType::mod(x, y);
2041  }
2042  friend inline ExType fmod(const ExType& x, const ExType& y) {
2043  return mod(x, y);
2044  }
2046 
2048 
2099  static ExType remainder(const ExType& x, const ExType& y) {
2100  return ExType::binary(OP_REMAINDER, x, y);
2101  }
2102  friend inline ExType remainder(const ExType& x, const ExType& y) {
2103  return ExType::remainder(x, y);
2104  }
2106 
2108 
2146  static ExType atan2(const ExType& y, const ExType& x) {
2147  return ExType::binary(OP_ATAN2, y, x);
2148  }
2149  friend inline ExType atan2(const ExType& y, const ExType& x) {
2150  return ExType::atan2(y, x);
2151  }
2153 
2155 
2166  static ExType if_else_zero(const ExType& x, const ExType& y) {
2167  return ExType::binary(OP_IF_ELSE_ZERO, x, y);
2168  }
2169  friend inline ExType if_else_zero(const ExType& x, const ExType& y) {
2170  return ExType::if_else_zero(x, y);
2171  }
2173 
2175 
2232  static ExType fmin(const ExType& x, const ExType& y) {
2233  return ExType::binary(OP_FMIN, x, y);
2234  }
2235  friend inline ExType fmin(const ExType& x, const ExType& y) {
2236  return ExType::fmin(x, y);
2237  }
2239 
2241 
2289  static ExType fmax(const ExType& x, const ExType& y) {
2290  return ExType::binary(OP_FMAX, x, y);
2291  }
2292  friend inline ExType fmax(const ExType& x, const ExType& y) {
2293  return ExType::fmax(x, y);
2294  }
2296 
2298 
2369  friend inline bool is_equal(const ExType& x, const ExType& y, casadi_int depth=0) {
2370  return ExType::is_equal(x, y, depth);
2371  }
2373 
2375 
2417  static ExType copysign(const ExType& x, const ExType& y) {
2418  return ExType::binary(OP_COPYSIGN, x, y);
2419  }
2420  friend inline ExType copysign(const ExType& x, const ExType& y) {
2421  return ExType::copysign(x, y);
2422  }
2424 
2426 
2467  static ExType constpow(const ExType& x, const ExType& y) {
2468  return ExType::binary(OP_CONSTPOW, x, y);
2469  }
2470  friend inline ExType constpow(const ExType& x, const ExType& y) {
2471  return ExType::constpow(x, y);
2472  }
2474 
2476 
2515  static ExType printme(const ExType& x, const ExType& y) {
2516  return ExType::binary(OP_PRINTME, x, y);
2517  }
2518  friend inline ExType printme(const ExType& x, const ExType& y) {
2519  return ExType::binary(OP_PRINTME, x, y);
2520  }
2522 
2524 
2565  static ExType hypot(const ExType& x, const ExType& y) {
2566  return ExType::binary(OP_HYPOT, x, y);
2567  }
2568  friend inline ExType hypot(const ExType& x, const ExType& y) {
2569  return ExType::hypot(x, y);
2570  }
2572 
2573 
2578 };
2579 #endif // SWIG
2580 
2581 } // namespace casadi
2582 
2583 #endif // CASADI_GENERIC_EXPRESSION_HPP
The casadi namespace.
Definition: archiver.hpp:32