List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends
casadi::SXElem Class Reference

The basic scalar symbolic class of CasADi. More...

#include <sx_elem.hpp>

Detailed Description

SXElem is exposed only as an empty struct to SWIG

Author
Joel Andersson
Date
2010-2014

Extra doc: https://github.com/casadi/casadi/wiki/L_10i

Definition at line 74 of file sx_elem.hpp.

Inheritance diagram for casadi::SXElem:
Inheritance graph
[legend]
Collaboration diagram for casadi::SXElem:
Collaboration graph
[legend]

Public Member Functions

 SXElem ()
 Default constructor (not-a-number) More...
 
 SXElem (double val)
 Numerical constant constructor. More...
 
 SXElem (SXNode *node, bool dummy)
 
 SXElem (const SXElem &scalar)
 Copy constructor. More...
 
 ~SXElem ()
 Destructor. More...
 
SXElemoperator= (const SXElem &scalar)
 Assignment. More...
 
SXElemoperator= (double scalar)
 
 operator Matrix< SXElem > () const
 Convert to a 1-by-1 Matrix. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a description of the object. More...
 
SXNodeget () const
 Get a pointer to the node. More...
 
const SXNodeoperator-> () const
 Access functions of the node. More...
 
SXNodeoperator-> ()
 
bool __nonzero__ () const
 Check the truth value of this node. More...
 
bool is_leaf () const
 check if this SXElem is a leaf of the SX graph More...
 
bool is_constant () const
 
bool is_integer () const
 
bool is_symbolic () const
 
bool is_commutative () const
 Check whether a binary SXElem is commutative. More...
 
bool is_zero () const
 
bool is_almost_zero (double tol) const
 
bool is_one () const
 
bool is_minus_one () const
 
bool is_nan () const
 
bool is_inf () const
 
bool is_minus_inf () const
 
const std::string & name () const
 
casadi_int op () const
 
bool is_op (casadi_int op) const
 
bool is_call () const
 
bool is_output () const
 
bool has_output () const
 
Function which_function () const
 
casadi_int which_output () const
 
bool is_regular () const
 Checks if expression does not contain NaN or Inf. More...
 
bool is_nonnegative () const
 Check if a value is always nonnegative (false negatives are allowed) More...
 
SXElem dep (casadi_int ch=0) const
 
 operator double () const
 Type conversion to double. More...
 
 operator casadi_int () const
 Type conversion to casadi_int. More...
 
bool is_doubled () const
 Check if the node is the sum of two equal expressions. More...
 
casadi_int n_dep () const
 Get the number of dependencies of a binary SXElem. More...
 
SXElem get_output (casadi_int oind) const
 Get an output. More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given SXNode. More...
 
SXElem operator- () const
 Negation. More...
 
SXElem inv () const
 Element-wise inverse. More...
 
int get_temp () const
 
void set_temp (int t) const
 Set the temporary variable. More...
 
bool marked () const
 Check if marked (i.e. temporary is negative) More...
 
void mark () const
 Mark by flipping the sign of the temporary and decreasing by one. More...
 
void assignIfDuplicate (const SXElem &scalar, casadi_int depth=1)
 Assign to another expression, if a duplicate. More...
 
SXNodeassignNoDelete (const SXElem &scalar)
 Assign the node to something, without invoking the deletion of the node,. More...
 
bool is_null ()
 SXElem nodes are not allowed to be null. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
SXElemoperator+= (const SXElem &y)
 

Static Public Member Functions

static SXElem sym (const std::string &name)
 Create a symbolic primitive. More...
 
static SXElem create (SXNode *node)
 
static std::string type_name ()
 Type name. More...
 
static SXElem binary (casadi_int op, const SXElem &x, const SXElem &y)
 Perform operations by ID. More...
 
static SXElem unary (casadi_int op, const SXElem &x)
 
static std::vector< SXElemcall (const Function &f, const std::vector< SXElem > &deps)
 
static bool is_equal (const SXElem &x, const SXElem &y, casadi_int depth=0)
 Check equality up to a given depth. More...
 
static SXElem deserialize (DeserializingStream &s)
 
static SXElem plus (const SXElem &x, const SXElem &y)
 Addition: (x,y) -> x + y. More...
 
static SXElem lt (const SXElem &x, const SXElem &y)
 Logical less than: (x,y) -> x < y. More...
 
static SXElem le (const SXElem &x, const SXElem &y)
 Logical less or equal to: (x,y) -> x <= y. More...
 
static SXElem gt (const SXElem &x, const SXElem &y)
 Logical greater than: (x,y) -> x > y. More...
 
static SXElem ge (const SXElem &x, const SXElem &y)
 Logical greater or equal to: (x,y) -> x >= y. More...
 
static SXElem eq (const SXElem &x, const SXElem &y)
 Logical equal to: (x,y) -> x == y. More...
 
static SXElem ne (const SXElem &x, const SXElem &y)
 Logical not equal to: (x,y) -> x != y. More...
 
static SXElem logic_and (const SXElem &x, const SXElem &y)
 Logical and More...
 
static SXElem logic_or (const SXElem &x, const SXElem &y)
 Logical or More...
 
static SXElem abs (const SXElem &x)
 Absolute value: x -> abs(x) More...
 
static SXElem sqrt (const SXElem &x)
 Square root: x -> sqrt(x) More...
 
static SXElem sq (const SXElem &x)
 Square: x -> x^2. More...
 
static SXElem sin (const SXElem &x)
 Sine: x -> sin(x) More...
 
static SXElem cos (const SXElem &x)
 Cosine: x -> cos(x) More...
 
static SXElem tan (const SXElem &x)
 Tangent: x -> tan(x) More...
 
static SXElem atan (const SXElem &x)
 Arc tangent: x -> atan(x) More...
 
static SXElem asin (const SXElem &x)
 Arc sine: x -> asin(x) More...
 
static SXElem acos (const SXElem &x)
 Arc cosine: x -> acos(x) More...
 
static SXElem tanh (const SXElem &x)
 Hyperbolic tangent: x -> tanh(x) More...
 
static SXElem sinh (const SXElem &x)
 Hyperbolic sin: x -> sinh(x) More...
 
static SXElem cosh (const SXElem &x)
 Hyperbolic cosine: x -> cosh(x) More...
 
static SXElem atanh (const SXElem &x)
 Inverse hyperbolic tangent: x -> atanh(x) More...
 
static SXElem asinh (const SXElem &x)
 Inverse hyperbolic sin: x -> asinh(x) More...
 
static SXElem acosh (const SXElem &x)
 Inverse hyperbolic cosine: x -> acosh(x) More...
 
static SXElem exp (const SXElem &x)
 Elementwise exponential: x -> exp(x) More...
 
static SXElem log (const SXElem &x)
 Natural logarithm: x -> log(x) More...
 
static SXElem log10 (const SXElem &x)
 Base-10 logarithm: x -> log10(x) More...
 
static SXElem log1p (const SXElem &x)
 Precision variant for natural logarithm: x -> log(x+1) More...
 
static SXElem expm1 (const SXElem &x)
 Precision variant for elementwise exponential: x -> exp(x)-1. More...
 
static SXElem floor (const SXElem &x)
 Round down to nearest integer: x -> floor(x) More...
 
static SXElem ceil (const SXElem &x)
 Round up to nearest integer: x -> ceil(x) More...
 
static SXElem erf (const SXElem &x)
 Error function: x -> erf(x) More...
 
static SXElem erfinv (const SXElem &x)
 Inverse error function: x -> erfinv(x) More...
 
static SXElem sign (const SXElem &x)
 Sign function: More...
 
static SXElem pow (const SXElem &x, const SXElem &y)
 Elementwise power: (x,y) -> x.^y. More...
 
static SXElem mod (const SXElem &x, const SXElem &y)
 Remainder after division: (x,y) -> fmod(x,y) More...
 
static SXElem remainder (const SXElem &x, const SXElem &y)
 Remainder after division: (x,y) -> remainder(x,y) More...
 
static SXElem atan2 (const SXElem &y, const SXElem &x)
 Two argument arc tangent: (y,x) -> atan2(y,x) More...
 
static SXElem if_else_zero (const SXElem &x, const SXElem &y)
 Conditional assignment: (x,y) -> x ? y : 0. More...
 
static SXElem fmin (const SXElem &x, const SXElem &y)
 Smallest of two values: (x,y) -> min(x,y) More...
 
static SXElem fmax (const SXElem &x, const SXElem &y)
 Largest of two values: (x,y) -> max(x,y) More...
 
static SXElem copysign (const SXElem &x, const SXElem &y)
 
static SXElem constpow (const SXElem &x, const SXElem &y)
 
static SXElem printme (const SXElem &x, const SXElem &y)
 
static SXElem hypot (const SXElem &x, const SXElem &y)
 Precision variant for 2 norm: (x,y) -> sqrt(x^2+y^2) More...
 

Protected Member Functions

const SXElemself () const
 
SXElemself ()
 

Friends

class SXNode
 
class BinarySXNode
 
class Matrix< SXElem >
 
SXElem if_else (const SXElem &x, const SXElem &y, const SXElem &z)
 Ternary if_else: x ? y : z. More...
 
SXElemoperator-= (const SXElem &y)
 Subtraction: (x,y) -> x - y. More...
 
static SXElem minus (const SXElem &x, const SXElem &y)
 Subtraction: (x,y) -> x - y. More...
 
SXElemoperator*= (const SXElem &y)
 Elementwise multiplication: (x,y) -> x .* y. More...
 
static SXElem times (const SXElem &x, const SXElem &y)
 Elementwise multiplication: (x,y) -> x .* y. More...
 
SXElemoperator/= (const SXElem &y)
 Elementwise division: (x,y) -> x ./ y. More...
 
static SXElem rdivide (const SXElem &x, const SXElem &y)
 Elementwise division: (x,y) -> x ./ y. More...
 
SXElem operator! () const
 Logical not x -> !x. More...
 
static SXElem logic_not (const SXElem &x)
 Logical not x -> !x. More...
 

Constructor & Destructor Documentation

◆ SXElem() [1/4]

casadi::SXElem::SXElem ( )

Object is initialized as not-a-number.

Extra doc: https://github.com/casadi/casadi/wiki/L_10j

Definition at line 53 of file sx_elem.cpp.

53  {
54  node = casadi_limits<SXElem>::nan.node;
55  node->count++;
56  }
unsigned int count
Definition: sx_node.hpp:197
casadi_limits class

References casadi::SXNode::count.

Referenced by create(), and operator=().

◆ SXElem() [2/4]

casadi::SXElem::SXElem ( double  val)
Parameters
valNumerical value

Extra doc: https://github.com/casadi/casadi/wiki/L_10k

Definition at line 71 of file sx_elem.cpp.

71  {
72  // Only ints fit here, not casadi_int
73  int intval = static_cast<int>(val);
74  if (val-static_cast<double>(intval) == 0) { // check if integer
75  if (intval == 0) node = casadi_limits<SXElem>::zero.node;
76  else if (intval == 1) node = casadi_limits<SXElem>::one.node;
77  else if (intval == 2) node = casadi_limits<SXElem>::two.node;
78  else if (intval == -1) node = casadi_limits<SXElem>::minus_one.node;
79  else node = IntegerSX::create(intval);
80  node->count++;
81  } else {
82  if (isnan(val)) node = casadi_limits<SXElem>::nan.node;
83  else if (isinf(val)) node = val > 0 ? casadi_limits<SXElem>::inf.node :
85  else node = RealtypeSX::create(val);
86  node->count++;
87  }
88  }
static IntegerSX * create(casadi_int value)
Static creator function (use instead of constructor)
static RealtypeSX * create(double value)
Static creator function (use instead of constructor)

References casadi::SXNode::count, casadi::IntegerSX::create(), and casadi::RealtypeSX::create().

◆ SXElem() [3/4]

casadi::SXElem::SXElem ( SXNode node,
bool  dummy 
)

Create an expression from a node: extra dummy argument to avoid ambiguity for 0/NULL

Definition at line 58 of file sx_elem.cpp.

58  : node(node_) {
59  node->count++;
60  }

References casadi::SXNode::count.

◆ SXElem() [4/4]

casadi::SXElem::SXElem ( const SXElem scalar)

Extra doc: https://github.com/casadi/casadi/wiki/L_10m

Definition at line 66 of file sx_elem.cpp.

66  {
67  node = scalar.node;
68  node->count++;
69  }

References casadi::SXNode::count.

◆ ~SXElem()

casadi::SXElem::~SXElem ( )

Definition at line 94 of file sx_elem.cpp.

94  {
95  if (--node->count == 0) delete node;
96  }

References casadi::SXNode::count.

Member Function Documentation

◆ __hash__()

casadi_int casadi::SXElem::__hash__ ( ) const

If the SXElem does not point to any node, 0 is returned.

Extra doc: https://github.com/casadi/casadi/wiki/L_10w

Definition at line 571 of file sx_elem.cpp.

571  {
572  return reinterpret_cast<casadi_int>(node);
573  }

◆ __nonzero__()

bool casadi::SXElem::__nonzero__ ( ) const

Introduced to catch bool(x) situations in python

Extra doc: https://github.com/casadi/casadi/wiki/L_10q

Definition at line 157 of file sx_elem.cpp.

157  {
158  if (is_constant()) return !is_zero();
159  casadi_error("Cannot compute the truth value of a CasADi SXElem symbolic expression.");
160  }
bool is_zero() const
Definition: sx_elem.cpp:489
bool is_constant() const
Definition: sx_elem.cpp:457

References is_constant(), and is_zero().

◆ abs()

static SXElem casadi::GenericExpression< SXElem >::abs ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p0

Definition at line 275 of file generic_expression.hpp.

275  {
276  return ExType::unary(OP_FABS, x);
277  }

◆ acos()

static SXElem casadi::GenericExpression< SXElem >::acos ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p8

Definition at line 374 of file generic_expression.hpp.

374  {
375  return ExType::unary(OP_ACOS, x);
376  }

◆ acosh()

static SXElem casadi::GenericExpression< SXElem >::acosh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pe

Definition at line 446 of file generic_expression.hpp.

446  {
447  return ExType::unary(OP_ACOSH, x);
448  }

◆ asin()

static SXElem casadi::GenericExpression< SXElem >::asin ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p7

Definition at line 362 of file generic_expression.hpp.

362  {
363  return ExType::unary(OP_ASIN, x);
364  }

◆ asinh()

static SXElem casadi::GenericExpression< SXElem >::asinh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pd

Definition at line 434 of file generic_expression.hpp.

434  {
435  return ExType::unary(OP_ASINH, x);
436  }

◆ assignIfDuplicate()

void casadi::SXElem::assignIfDuplicate ( const SXElem scalar,
casadi_int  depth = 1 
)

Check for equality up to a given depth

Extra doc: https://github.com/casadi/casadi/wiki/L_110

Definition at line 111 of file sx_elem.cpp.

111  {
112  casadi_assert_dev(depth>=1);
113  if (!is_equal(*this, scalar, 0) && is_equal(*this, scalar, depth)) {
114  *this = scalar;
115  }
116  }
static bool is_equal(const SXElem &x, const SXElem &y, casadi_int depth=0)
Check equality up to a given depth.
Definition: sx_elem.cpp:529

References is_equal().

Referenced by casadi::SXFunction::eval_sx().

◆ assignNoDelete()

SXNode * casadi::SXElem::assignNoDelete ( const SXElem scalar)

if the count reaches 0

Extra doc: https://github.com/casadi/casadi/wiki/L_111

Definition at line 118 of file sx_elem.cpp.

118  {
119  // Return value
120  SXNode* ret = node;
121 
122  // quick return if the old and new pointers point to the same object
123  if (node == scalar.node) return ret;
124 
125  // decrease the counter but do not delete if this was the last pointer
126  --node->count;
127 
128  // save the new pointer
129  node = scalar.node;
130  node->count++;
131 
132  // Return a pointer to the old node
133  return ret;
134  }
Internal node class for SX.
Definition: sx_node.hpp:49

References casadi::SXNode::count.

Referenced by casadi::SXNode::safe_delete(), casadi::BinarySX::~BinarySX(), and casadi::UnarySX::~UnarySX().

◆ atan()

static SXElem casadi::GenericExpression< SXElem >::atan ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p6

Definition at line 350 of file generic_expression.hpp.

350  {
351  return ExType::unary(OP_ATAN, x);
352  }

◆ atan2()

static SXElem casadi::GenericExpression< SXElem >::atan2 ( const SXElem y,
const SXElem x 
)
inlinestaticinherited

theta = atan2(y,x) corresponds to x = r cos(theta), y = r sin(theta)

Extra doc: https://github.com/casadi/casadi/wiki/L_pr

Definition at line 648 of file generic_expression.hpp.

648  {
649  return ExType::binary(OP_ATAN2, y, x);
650  }

◆ atanh()

static SXElem casadi::GenericExpression< SXElem >::atanh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pc

Definition at line 422 of file generic_expression.hpp.

422  {
423  return ExType::unary(OP_ATANH, x);
424  }

◆ binary()

SXElem casadi::SXElem::binary ( casadi_int  op,
const SXElem x,
const SXElem y 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_10p

Definition at line 186 of file sx_elem.cpp.

186  {
187  // If-else-zero nodes are always simplified at top level to avoid NaN propagation
188  if (y.op() == OP_IF_ELSE_ZERO) {
189  if (op == OP_MUL) {
190  // (Rule 1.) x * if_else_zero(c, y), simplified to if_else_zero(c, x * y)
191  // Background: x is often a partial derivative and may evaluate to INF or NAN.
192  // The simplification ensures that the zero seed corresponding to an inactive branch does
193  // not give rise to any NaN contribution to the derivative due to NaN * 0 == NaN.
194  return if_else_zero(y.dep(0), x * y.dep(1));
195  } else if (op == OP_ADD && x.op() == OP_IF_ELSE_ZERO && is_equal(x.dep(0), y.dep(0))) {
196  // (Rule 2.) if_else_zero(c, x) + if_else_zero(c, y) is simplified to if_else_zero(c, x + y)
197  // Background: During the backward propagation, seeds are added together. Without this rule,
198  // the addition node can prevent rule (1.) from working in subsequent steps.
199  return if_else_zero(y.dep(0), x.dep(1) + y.dep(1));
200  }
201  } else if (x.op() == OP_IF_ELSE_ZERO && op == OP_MUL) {
202  // Same as Rule 1. above, but with factors swapped. For symmetry.
203  return if_else_zero(x.dep(0), x.dep(1) * y);
204  }
205  // Simplifications
207  switch (op) {
208  case OP_ADD:
209  if (x.is_zero())
210  return y;
211  else if (y->is_zero()) // term2 is zero
212  return x;
213  else if (y.is_op(OP_NEG)) // x + (-y) -> x - y
214  return x - (-y);
215  else if (x.is_op(OP_NEG)) // (-x) + y -> y - x
216  return y - x.dep();
217  else if (x.is_op(OP_MUL) && y.is_op(OP_MUL) &&
218  x.dep(0).is_constant() && static_cast<double>(x.dep(0))==0.5 &&
219  y.dep(0).is_constant() && static_cast<double>(y.dep(0))==0.5 &&
220  is_equal(y.dep(1), x.dep(1), SXNode::eq_depth_)) // 0.5x+0.5x = x
221  return x.dep(1);
222  else if (x.is_op(OP_DIV) && y.is_op(OP_DIV) &&
223  x.dep(1).is_constant() && static_cast<double>(x.dep(1))==2 &&
224  y.dep(1).is_constant() && static_cast<double>(y.dep(1))==2 &&
225  is_equal(y.dep(0), x.dep(0), SXNode::eq_depth_)) // x/2+x/2 = x
226  return x.dep(0);
227  else if (x.is_op(OP_SUB) && is_equal(x.dep(1), y, SXNode::eq_depth_))
228  return x.dep(0);
229  else if (y.is_op(OP_SUB) && is_equal(x, y.dep(1), SXNode::eq_depth_))
230  return y.dep(0);
231  else if (x.is_op(OP_SQ) && y.is_op(OP_SQ) &&
232  ((x.dep().is_op(OP_SIN) && y.dep().is_op(OP_COS))
233  || (x.dep().is_op(OP_COS) && y.dep().is_op(OP_SIN)))
234  && is_equal(x.dep().dep(), y.dep().dep(), SXNode::eq_depth_))
235  return 1; // sin^2 + cos^2 -> 1
236  break;
237  case OP_SUB:
238  if (y->is_zero()) // term2 is zero
239  return x;
240  if (x.is_zero()) // term1 is zero
241  return -y;
242  if (is_equal(x, y, SXNode::eq_depth_)) // the terms are equal
243  return 0;
244  else if (y.is_op(OP_NEG)) // x - (-y) -> x + y
245  return x + y.dep();
246  else if (x.is_op(OP_ADD) && is_equal(x.dep(1), y, SXNode::eq_depth_))
247  return x.dep(0);
248  else if (x.is_op(OP_ADD) && is_equal(x.dep(0), y, SXNode::eq_depth_))
249  return x.dep(1);
250  else if (y.is_op(OP_ADD) && is_equal(x, y.dep(1), SXNode::eq_depth_))
251  return -y.dep(0);
252  else if (y.is_op(OP_ADD) && is_equal(x, y.dep(0), SXNode::eq_depth_))
253  return -y.dep(1);
254  else if (x.is_op(OP_NEG))
255  return -(x.dep() + y);
256  break;
257  case OP_MUL:
258  if (is_equal(y, x, SXNode::eq_depth_))
259  return sq(x);
260  else if (!x.is_constant() && y.is_constant())
261  return y * x;
262  else if (x.is_zero() || y->is_zero()) // one of the terms is zero
263  return 0;
264  else if (x.is_one()) // term1 is one
265  return y;
266  else if (y->is_one()) // term2 is one
267  return x;
268  else if (y->is_minus_one())
269  return -x;
270  else if (x.is_minus_one())
271  return -y;
272  else if (y.is_op(OP_INV))
273  return x/y.inv();
274  else if (x.is_op(OP_INV))
275  return y / x.inv();
276  else if (x.is_constant() && y.is_op(OP_MUL) && y.dep(0).is_constant() &&
277  static_cast<double>(x)*static_cast<double>(y.dep(0))==1) // 5*(0.2*x) = x
278  return y.dep(1);
279  else if (x.is_constant() && y.is_op(OP_DIV) && y.dep(1).is_constant() &&
280  static_cast<double>(x)==static_cast<double>(y.dep(1))) // 5*(x/5) = x
281  return y.dep(0);
282  else if (x.is_op(OP_DIV) && is_equal(x.dep(1), y, SXNode::eq_depth_)) // ((2/x)*x)
283  return x.dep(0);
284  else if (y.is_op(OP_DIV) &&
285  is_equal(y.dep(1), x, SXNode::eq_depth_)) // ((2/x)*x)
286  return y.dep(0);
287  else if (x.is_op(OP_NEG))
288  return -(x.dep() * y);
289  else if (y.is_op(OP_NEG))
290  return -(x * y.dep());
291  break;
292  case OP_DIV:
293  if (y->is_zero()) // term2 is zero
295  else if (x.is_zero()) // term1 is zero
296  return 0;
297  else if (y->is_one()) // term2 is one
298  return x;
299  else if (y->is_minus_one())
300  return -x;
301  else if (is_equal(x, y, SXNode::eq_depth_)) // terms are equal
302  return 1;
303  else if (x.is_doubled() && is_equal(y, 2))
304  return x.dep(0);
305  else if (x.is_op(OP_MUL) && is_equal(y, x.dep(0), SXNode::eq_depth_))
306  return x.dep(1);
307  else if (x.is_op(OP_MUL) && is_equal(y, x.dep(1), SXNode::eq_depth_))
308  return x.dep(0);
309  else if (x.is_one())
310  return y.inv();
311  else if (y.is_op(OP_INV))
312  return x*y.inv();
313  else if (x.is_doubled() && y.is_doubled())
314  return x.dep(0) / y->dep(0);
315  else if (y.is_constant() && x.is_op(OP_DIV) && x.dep(1).is_constant() &&
316  static_cast<double>(y)*static_cast<double>(x.dep(1))==1) // (x/5)/0.2
317  return x.dep(0);
318  else if (y.is_op(OP_MUL) &&
319  is_equal(y.dep(1), x, SXNode::eq_depth_)) // x/(2*x) = 1/2
320  return BinarySX::create(OP_DIV, 1, y.dep(0));
321  else if (x.is_op(OP_NEG) &&
322  is_equal(x.dep(0), y, SXNode::eq_depth_)) // (-x)/x = -1
323  return -1;
324  else if (y.is_op(OP_NEG) &&
325  is_equal(y.dep(0), x, SXNode::eq_depth_)) // x/(-x) = 1
326  return -1;
327  else if (y.is_op(OP_NEG) && x.is_op(OP_NEG) &&
328  is_equal(x.dep(0), y.dep(0), SXNode::eq_depth_)) // (-x)/(-x) = 1
329  return 1;
330  else if (x.is_op(OP_DIV) && is_equal(y, x.dep(0), SXNode::eq_depth_))
331  return x.dep(1).inv();
332  else if (x.is_op(OP_NEG))
333  return -(x.dep() / y);
334  else if (y.is_op(OP_NEG))
335  return -(x / y.dep());
336  break;
337  case OP_POW:
338  if (y->is_constant()) {
339  if (y->is_integer()) {
340  casadi_int nn = y->to_int();
341  if (nn == 0) {
342  return 1;
343  } else if (nn>100 || nn<-100) { // maximum depth
344  return binary(OP_CONSTPOW, x, nn);
345  } else if (nn<0) { // negative power
346  return 1/pow(x, -nn);
347  } else if (nn%2 == 1) { // odd power
348  return x*pow(x, nn-1);
349  } else { // even power
350  SXElem rt = pow(x, static_cast<casadi_int>(nn/2));
351  return rt*rt;
352  }
353  } else if (y->to_double()==0.5) {
354  return sqrt(x);
355  } else {
356  return binary(OP_CONSTPOW, x, y);
357  }
358  }
359  break;
360  case OP_LE:
361  if ((y-x).is_nonnegative())
362  return 1;
363  break;
364  case OP_FMIN:
365  if (x.is_inf()) return y;
366  if (y.is_inf()) return x;
367  if (x.is_minus_inf() || y.is_minus_inf()) return -std::numeric_limits<double>::infinity();
368  if (is_equal(x, y, SXNode::eq_depth_)) return x;
369  break;
370  case OP_FMAX:
371  if (x.is_minus_inf()) return y;
372  if (y.is_minus_inf()) return x;
373  if (x.is_inf() || y.is_inf()) return std::numeric_limits<double>::infinity();
374  if (is_equal(x, y, SXNode::eq_depth_)) return x;
375  break;
376  case OP_LT:
377  if (((x)-y).is_nonnegative())
378  return 0;
379  break;
380  case OP_EQ:
381  if (is_equal(x, y))
382  return 1;
383  break;
384  case OP_NE:
385  if (is_equal(x, y))
386  return 0;
387  break;
388  case OP_IF_ELSE_ZERO:
389  if (y->is_zero()) {
390  return y;
391  } else if (x.is_constant()) {
392  if (static_cast<double>(x)!=0) {
393  return y;
394  } else {
395  return 0;
396  }
397  }
398  }
399  }
400  return BinarySX::create(Operation(op), x, y);
401  }
static SXElem create(unsigned char op, const SXElem &dep0, const SXElem &dep1)
Create a binary expression.
Definition: binary_sx.hpp:55
static bool simplification_on_the_fly
Indicates whether simplifications should be made on the fly.
The basic scalar symbolic class of CasADi.
Definition: sx_elem.hpp:75
SXElem dep(casadi_int ch=0) const
Definition: sx_elem.cpp:558
bool is_minus_inf() const
Definition: sx_elem.cpp:513
SXElem inv() const
Element-wise inverse.
Definition: sx_elem.cpp:166
bool is_minus_one() const
Definition: sx_elem.cpp:501
bool is_doubled() const
Check if the node is the sum of two equal expressions.
Definition: sx_elem.cpp:162
casadi_int op() const
Definition: sx_elem.cpp:521
static SXElem binary(casadi_int op, const SXElem &x, const SXElem &y)
Perform operations by ID.
Definition: sx_elem.cpp:186
bool is_op(casadi_int op) const
Definition: sx_elem.cpp:525
bool is_one() const
Definition: sx_elem.cpp:497
bool is_inf() const
Definition: sx_elem.cpp:509
bool is_nonnegative() const
Check if a value is always nonnegative (false negatives are allowed)
Definition: sx_elem.cpp:540
virtual const SXElem & dep(casadi_int i) const
get the reference of a child
Definition: sx_node.cpp:80
virtual bool is_zero() const
check properties of a node
Definition: sx_node.hpp:72
virtual bool is_minus_one() const
check properties of a node
Definition: sx_node.hpp:76
virtual bool is_one() const
check properties of a node
Definition: sx_node.hpp:75
virtual casadi_int to_int() const
Get value of a constant node.
Definition: sx_node.cpp:60
virtual bool is_integer() const
check properties of a node
Definition: sx_node.hpp:70
virtual double to_double() const
Get value of a constant node.
Definition: sx_node.cpp:56
static casadi_int eq_depth_
Definition: sx_node.hpp:179
virtual bool is_constant() const
check properties of a node
Definition: sx_node.hpp:69
static SXElem sqrt(const SXElem &x)
Square root: x -> sqrt(x)
static SXElem if_else_zero(const SXElem &x, const SXElem &y)
Conditional assignment: (x,y) -> x ? y : 0.
static SXElem sq(const SXElem &x)
Square: x -> x^2.
static SXElem pow(const SXElem &x, const SXElem &y)
Elementwise power: (x,y) -> x.^y.
Operation
Enum for quick access to any node.
Definition: calculus.hpp:60
@ OP_COS
Definition: calculus.hpp:68
@ OP_NE
Definition: calculus.hpp:70
@ OP_FMAX
Definition: calculus.hpp:72
@ OP_IF_ELSE_ZERO
Definition: calculus.hpp:71
@ OP_INV
Definition: calculus.hpp:73
@ OP_SIN
Definition: calculus.hpp:68
@ OP_LT
Definition: calculus.hpp:70
@ OP_EQ
Definition: calculus.hpp:70
@ OP_SUB
Definition: calculus.hpp:65
@ OP_FMIN
Definition: calculus.hpp:72
@ OP_POW
Definition: calculus.hpp:66
@ OP_ADD
Definition: calculus.hpp:65
@ OP_LE
Definition: calculus.hpp:70
@ OP_DIV
Definition: calculus.hpp:65
@ OP_NEG
Definition: calculus.hpp:66
@ OP_CONSTPOW
Definition: calculus.hpp:66
@ OP_MUL
Definition: calculus.hpp:65
@ OP_SQ
Definition: calculus.hpp:67

References casadi::BinarySX::create(), dep(), casadi::SXNode::dep(), casadi::SXNode::eq_depth_, casadi::GenericExpression< SXElem >::if_else_zero(), inv(), is_constant(), casadi::SXNode::is_constant(), is_doubled(), is_equal(), is_inf(), casadi::SXNode::is_integer(), is_minus_inf(), is_minus_one(), casadi::SXNode::is_minus_one(), is_nonnegative(), is_one(), casadi::SXNode::is_one(), is_op(), is_zero(), casadi::SXNode::is_zero(), op(), casadi::OP_ADD, casadi::OP_CONSTPOW, casadi::OP_COS, casadi::OP_DIV, casadi::OP_EQ, casadi::OP_FMAX, casadi::OP_FMIN, casadi::OP_IF_ELSE_ZERO, casadi::OP_INV, casadi::OP_LE, casadi::OP_LT, casadi::OP_MUL, casadi::OP_NE, casadi::OP_NEG, casadi::OP_POW, casadi::OP_SIN, casadi::OP_SQ, casadi::OP_SUB, casadi::GenericExpression< SXElem >::pow(), casadi::GlobalOptions::simplification_on_the_fly, casadi::GenericExpression< SXElem >::sq(), casadi::GenericExpression< SXElem >::sqrt(), casadi::SXNode::to_double(), and casadi::SXNode::to_int().

◆ call()

std::vector< SXElem > casadi::SXElem::call ( const Function f,
const std::vector< SXElem > &  deps 
)
static

Definition at line 403 of file sx_elem.cpp.

403  {
404  SXElem c = CallSX::create(f, deps);
405  return OutputSX::split(c, f.nnz_out());
406  }
static SXElem create(const Function &f, const std::vector< SXElem > &dep)
Create a binary expression.
Definition: call_sx.hpp:57
casadi_int nnz_out() const
Get number of output nonzeros.
Definition: function.cpp:855
static std::vector< SXElem > split(const SXElem &e, casadi_int n)
Definition: output_sx.hpp:139

References casadi::CallSX::create(), casadi::Function::nnz_out(), and casadi::OutputSX::split().

Referenced by casadi::SXFunction::ad_forward(), casadi::SXFunction::ad_reverse(), casadi::CallSX::eval_sx(), and casadi::SXFunction::eval_sx().

◆ ceil()

static SXElem casadi::GenericExpression< SXElem >::ceil ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pl

Definition at line 530 of file generic_expression.hpp.

530  {
531  return ExType::unary(OP_CEIL, x);
532  }

◆ constpow()

static SXElem casadi::GenericExpression< SXElem >::constpow ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Elementwise power with const power

Definition at line 720 of file generic_expression.hpp.

720  {
721  return ExType::binary(OP_CONSTPOW, x, y);
722  }

◆ copysign()

static SXElem casadi::GenericExpression< SXElem >::copysign ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Copy sign

Definition at line 710 of file generic_expression.hpp.

710  {
711  return ExType::binary(OP_COPYSIGN, x, y);
712  }

◆ cos()

static SXElem casadi::GenericExpression< SXElem >::cos ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p4

Definition at line 326 of file generic_expression.hpp.

326  {
327  return ExType::unary(OP_COS, x);
328  }

◆ cosh()

static SXElem casadi::GenericExpression< SXElem >::cosh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pb

Definition at line 410 of file generic_expression.hpp.

410  {
411  return ExType::unary(OP_COSH, x);
412  }

◆ create()

SXElem casadi::SXElem::create ( SXNode node)
static

Create an object given a node

Definition at line 62 of file sx_elem.cpp.

62  {
63  return SXElem(node, false);
64  }
SXElem()
Default constructor (not-a-number)
Definition: sx_elem.cpp:53

References SXElem().

Referenced by casadi::CallSX::create(), casadi::UnarySX::create(), casadi::BinarySX::create(), deserialize(), casadi::CallSX::get_output(), casadi::SXFunction::init(), casadi::SXFunction::order(), and sym().

◆ dep()

SXElem casadi::SXElem::dep ( casadi_int  ch = 0) const

Definition at line 558 of file sx_elem.cpp.

558  {
559  casadi_assert_dev(ch >= 0 || ch < n_dep());
560  return node->dep(ch);
561  }
casadi_int n_dep() const
Get the number of dependencies of a binary SXElem.
Definition: sx_elem.cpp:563

References casadi::SXNode::dep(), and n_dep().

Referenced by binary(), inv(), is_doubled(), operator-(), and unary().

◆ deserialize()

SXElem casadi::SXElem::deserialize ( DeserializingStream s)
static

Definition at line 659 of file sx_elem.cpp.

659  {
661  }
static SXElem create(SXNode *node)
Definition: sx_elem.cpp:62
static SXNode * deserialize(DeserializingStream &s)
Definition: sx_node.cpp:243

References create(), and casadi::SXNode::deserialize().

◆ disp()

void casadi::SXElem::disp ( std::ostream &  stream,
bool  more = false 
) const

Definition at line 140 of file sx_elem.cpp.

140  {
141  node->disp(stream, more);
142  }
virtual void disp(std::ostream &stream, bool more) const
print
Definition: sx_node.cpp:88

References casadi::SXNode::disp().

◆ eq()

static SXElem casadi::GenericExpression< SXElem >::eq ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ov

Definition at line 191 of file generic_expression.hpp.

191  {
192  return ExType::binary(OP_EQ, x, y);
193  }

◆ erf()

static SXElem casadi::GenericExpression< SXElem >::erf ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pm

Definition at line 542 of file generic_expression.hpp.

542  {
543  return ExType::unary(OP_ERF, x);
544  }

◆ erfinv()

static SXElem casadi::GenericExpression< SXElem >::erfinv ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pn

Definition at line 554 of file generic_expression.hpp.

554  {
555  return ExType::unary(OP_ERFINV, x);
556  }

◆ exp()

static SXElem casadi::GenericExpression< SXElem >::exp ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pf

Definition at line 458 of file generic_expression.hpp.

458  {
459  return ExType::unary(OP_EXP, x);
460  }

◆ expm1()

static SXElem casadi::GenericExpression< SXElem >::expm1 ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pj

Definition at line 506 of file generic_expression.hpp.

506  {
507  return ExType::unary(OP_EXPM1, x);
508  }

◆ floor()

static SXElem casadi::GenericExpression< SXElem >::floor ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pk

Definition at line 518 of file generic_expression.hpp.

518  {
519  return ExType::unary(OP_FLOOR, x);
520  }

◆ fmax()

static SXElem casadi::GenericExpression< SXElem >::fmax ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pu

Definition at line 684 of file generic_expression.hpp.

684  {
685  return ExType::binary(OP_FMAX, x, y);
686  }

◆ fmin()

static SXElem casadi::GenericExpression< SXElem >::fmin ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pt

Definition at line 672 of file generic_expression.hpp.

672  {
673  return ExType::binary(OP_FMIN, x, y);
674  }

◆ ge()

static SXElem casadi::GenericExpression< SXElem >::ge ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ou

Definition at line 176 of file generic_expression.hpp.

176  {
177  return ExType::le(y, x);
178  }

◆ get()

SXNode * casadi::SXElem::get ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10n

Definition at line 174 of file sx_elem.cpp.

174  {
175  return node;
176  }

Referenced by casadi::SXFunction::init(), is_equal(), and casadi::register_symbol().

◆ get_output()

SXElem casadi::SXElem::get_output ( casadi_int  oind) const

Extra doc: https://github.com/casadi/casadi/wiki/L_29f

Definition at line 567 of file sx_elem.cpp.

567  {
568  return node->get_output(oind);
569  }
virtual SXElem get_output(casadi_int oind) const
Get an output.
Definition: sx_node.cpp:227

References casadi::SXNode::get_output().

Referenced by casadi::OutputSX::split().

◆ get_temp()

int casadi::SXElem::get_temp ( ) const

Get the temporary variable

Definition at line 631 of file sx_elem.cpp.

631  {
632  return (*this)->temp;
633  }

◆ gt()

static SXElem casadi::GenericExpression< SXElem >::gt ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ot

Definition at line 161 of file generic_expression.hpp.

161  {
162  return ExType::lt(y, x);
163  }

◆ has_output()

bool casadi::SXElem::has_output ( ) const

Definition at line 469 of file sx_elem.cpp.

469  {
470  return node->has_output();
471  }
virtual bool has_output() const
check properties of a node
Definition: sx_node.hpp:82

References casadi::SXNode::has_output().

◆ hypot()

static SXElem casadi::GenericExpression< SXElem >::hypot ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pw

Definition at line 742 of file generic_expression.hpp.

742  {
743  return ExType::binary(OP_HYPOT, x, y);
744  }

◆ if_else_zero()

static SXElem casadi::GenericExpression< SXElem >::if_else_zero ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ps

Definition at line 660 of file generic_expression.hpp.

660  {
661  return ExType::binary(OP_IF_ELSE_ZERO, x, y);
662  }

◆ inv()

SXElem casadi::SXElem::inv ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10y

Definition at line 166 of file sx_elem.cpp.

166  {
167  if (is_op(OP_INV)) {
168  return dep(0);
169  } else {
170  return UnarySX::create(OP_INV, *this);
171  }
172  }
static SXElem create(unsigned char op, const SXElem &dep)
Create a unary expression.
Definition: unary_sx.hpp:55

References casadi::UnarySX::create(), dep(), is_op(), and casadi::OP_INV.

Referenced by binary().

◆ is_almost_zero()

bool casadi::SXElem::is_almost_zero ( double  tol) const

Definition at line 493 of file sx_elem.cpp.

493  {
494  return node->is_almost_zero(tol);
495  }
virtual bool is_almost_zero(double tol) const
check properties of a node
Definition: sx_node.hpp:74

References casadi::SXNode::is_almost_zero().

Referenced by casadi::casadi_limits< SXElem >::is_almost_zero().

◆ is_call()

bool casadi::SXElem::is_call ( ) const

Definition at line 461 of file sx_elem.cpp.

461  {
462  return node->is_call();
463  }
virtual bool is_call() const
check properties of a node
Definition: sx_node.hpp:80

References casadi::SXNode::is_call().

◆ is_commutative()

bool casadi::SXElem::is_commutative ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10s

Definition at line 452 of file sx_elem.cpp.

452  {
453  casadi_assert(n_dep(), "SX::is_commutative: must be binary");
454  return operation_checker<CommChecker>(op());
455  }

References n_dep(), and op().

◆ is_constant()

bool casadi::SXElem::is_constant ( ) const

◆ is_doubled()

bool casadi::SXElem::is_doubled ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10u

Definition at line 162 of file sx_elem.cpp.

162  {
163  return is_op(OP_ADD) && is_equal(dep(0), dep(1), SXNode::eq_depth_);
164  }

References dep(), casadi::SXNode::eq_depth_, is_equal(), is_op(), and casadi::OP_ADD.

Referenced by binary().

◆ is_equal()

bool casadi::SXElem::is_equal ( const SXElem x,
const SXElem y,
casadi_int  depth = 0 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_10z

Definition at line 529 of file sx_elem.cpp.

529  {
530  SXNode *x_node = x.get(), *y_node = y.get();
531  if (x_node==y_node) {
532  return true;
533  } else if (depth>0) {
534  return x_node->is_equal(y_node, depth);
535  } else {
536  return false;
537  }
538  }
SXNode * get() const
Get a pointer to the node.
Definition: sx_elem.cpp:174
virtual bool is_equal(const SXNode *node, casadi_int depth) const
Check if two nodes are equivalent up to a given depth.
Definition: sx_node.cpp:72

References get(), and casadi::SXNode::is_equal().

Referenced by assignIfDuplicate(), binary(), casadi::SXFunction::eval_sx(), is_doubled(), casadi::casadi_limits< SXElem >::is_equal(), casadi::BinarySX::is_equal(), and casadi::UnarySX::is_equal().

◆ is_inf()

bool casadi::SXElem::is_inf ( ) const

Definition at line 509 of file sx_elem.cpp.

509  {
510  return node->is_inf();
511  }
virtual bool is_inf() const
check properties of a node
Definition: sx_node.hpp:78

References casadi::SXNode::is_inf().

Referenced by binary(), casadi::casadi_limits< SXElem >::is_inf(), casadi::Matrix< Scalar >::is_regular(), and is_regular().

◆ is_integer()

bool casadi::SXElem::is_integer ( ) const

Definition at line 481 of file sx_elem.cpp.

481  {
482  return node->is_integer();
483  }

References casadi::SXNode::is_integer().

Referenced by casadi::casadi_limits< SXElem >::is_integer().

◆ is_leaf()

bool casadi::SXElem::is_leaf ( ) const

An SXElem qualifies as leaf when it has no dependencies.

Extra doc: https://github.com/casadi/casadi/wiki/L_10r

Definition at line 447 of file sx_elem.cpp.

447  {
448  if (!node) return true;
449  return is_constant() || is_symbolic();
450  }
bool is_symbolic() const
Definition: sx_elem.cpp:485

References is_constant(), and is_symbolic().

◆ is_minus_inf()

bool casadi::SXElem::is_minus_inf ( ) const

Definition at line 513 of file sx_elem.cpp.

513  {
514  return node->is_minus_inf();
515  }
virtual bool is_minus_inf() const
check properties of a node
Definition: sx_node.hpp:79

References casadi::SXNode::is_minus_inf().

Referenced by binary(), casadi::casadi_limits< SXElem >::is_minus_inf(), casadi::Matrix< Scalar >::is_regular(), and is_regular().

◆ is_minus_one()

bool casadi::SXElem::is_minus_one ( ) const

Definition at line 501 of file sx_elem.cpp.

501  {
502  return node->is_minus_one();
503  }

References casadi::SXNode::is_minus_one().

Referenced by binary(), casadi::casadi_limits< SXElem >::is_minus_one(), and operator-().

◆ is_nan()

bool casadi::SXElem::is_nan ( ) const

Definition at line 505 of file sx_elem.cpp.

505  {
506  return node->is_nan();
507  }
virtual bool is_nan() const
check properties of a node
Definition: sx_node.hpp:77

References casadi::SXNode::is_nan().

Referenced by casadi::casadi_limits< SXElem >::is_nan(), casadi::Matrix< Scalar >::is_regular(), and is_regular().

◆ is_nonnegative()

bool casadi::SXElem::is_nonnegative ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10t

Definition at line 540 of file sx_elem.cpp.

540  {
541  if (is_constant()) {
542  return static_cast<double>(*this)>=0;
543  } else if (is_op(OP_SQ) || is_op(OP_FABS)) {
544  return true;
545  } else {
546  return false;
547  }
548  }
@ OP_FABS
Definition: calculus.hpp:71

References is_constant(), is_op(), casadi::OP_FABS, and casadi::OP_SQ.

Referenced by binary().

◆ is_null()

bool casadi::SXElem::is_null ( )
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_112

Definition at line 280 of file sx_elem.hpp.

280 {return false;}

◆ is_one()

bool casadi::SXElem::is_one ( ) const

Definition at line 497 of file sx_elem.cpp.

497  {
498  return node->is_one();
499  }

References casadi::SXNode::is_one().

Referenced by binary(), casadi::casadi_limits< SXElem >::is_one(), and operator-().

◆ is_op()

bool casadi::SXElem::is_op ( casadi_int  op) const

Definition at line 525 of file sx_elem.cpp.

525  {
526  return node->is_op(op);
527  }
virtual bool is_op(casadi_int op) const
check properties of a node
Definition: sx_node.hpp:73

References casadi::SXNode::is_op(), and op().

Referenced by binary(), inv(), is_doubled(), is_nonnegative(), operator-(), and unary().

◆ is_output()

bool casadi::SXElem::is_output ( ) const

Definition at line 465 of file sx_elem.cpp.

465  {
466  return node->is_output();
467  }
virtual bool is_output() const
check properties of a node
Definition: sx_node.hpp:81

References casadi::SXNode::is_output().

◆ is_regular()

bool casadi::SXElem::is_regular ( ) const

Definition at line 647 of file sx_elem.cpp.

647  {
648  if (is_constant()) {
649  return !(is_nan() || is_inf() || is_minus_inf());
650  } else {
651  casadi_error("Cannot check regularity for symbolic SXElem");
652  }
653  }
bool is_nan() const
Definition: sx_elem.cpp:505

References is_constant(), is_inf(), is_minus_inf(), and is_nan().

◆ is_symbolic()

bool casadi::SXElem::is_symbolic ( ) const

Definition at line 485 of file sx_elem.cpp.

485  {
486  return node->is_symbolic();
487  }
virtual bool is_symbolic() const
check properties of a node
Definition: sx_node.hpp:71

References casadi::SXNode::is_symbolic().

Referenced by is_leaf(), and casadi::register_symbol().

◆ is_zero()

bool casadi::SXElem::is_zero ( ) const

Definition at line 489 of file sx_elem.cpp.

489  {
490  return node->is_zero();
491  }

References casadi::SXNode::is_zero().

Referenced by __nonzero__(), binary(), casadi::casadi_limits< SXElem >::is_zero(), operator-(), and unary().

◆ le()

static SXElem casadi::GenericExpression< SXElem >::le ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_os

Definition at line 146 of file generic_expression.hpp.

146  {
147  return ExType::binary(OP_LE, x, y);
148  }

◆ log()

static SXElem casadi::GenericExpression< SXElem >::log ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pg

Definition at line 470 of file generic_expression.hpp.

470  {
471  return ExType::unary(OP_LOG, x);
472  }

◆ log10()

static SXElem casadi::GenericExpression< SXElem >::log10 ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ph

Definition at line 482 of file generic_expression.hpp.

482  {
483  return log(x)*(1/std::log(10.));
484  }
static SXElem log(const SXElem &x)
Natural logarithm: x -> log(x)

◆ log1p()

static SXElem casadi::GenericExpression< SXElem >::log1p ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pi

Definition at line 494 of file generic_expression.hpp.

494  {
495  return ExType::unary(OP_LOG1P, x);
496  }

◆ logic_and()

static SXElem casadi::GenericExpression< SXElem >::logic_and ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Returns (an expression evaluating to) 1 if both expressions are nonzero and 0 otherwise

Extra doc: https://github.com/casadi/casadi/wiki/L_ox

Definition at line 224 of file generic_expression.hpp.

224  {
225  return ExType::binary(OP_AND, x, y);
226  }

◆ logic_not()

static SXElem casadi::GenericExpression< SXElem >::logic_not ( const SXElem x)
inlinestaticinherited

Returns (an expression evaluating to) 1 if expression is zero and 0 otherwise

Extra doc: https://github.com/casadi/casadi/wiki/L_oz

Definition at line 260 of file generic_expression.hpp.

260  {
261  return ExType::unary(OP_NOT, x);
262  }

◆ logic_or()

static SXElem casadi::GenericExpression< SXElem >::logic_or ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

returns (an expression evaluating to) 1 if at least one expression is nonzero and 0 otherwise

Extra doc: https://github.com/casadi/casadi/wiki/L_oy

Definition at line 242 of file generic_expression.hpp.

242  {
243  return ExType::binary(OP_OR, x, y);
244  }

◆ lt()

static SXElem casadi::GenericExpression< SXElem >::lt ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_or

Definition at line 131 of file generic_expression.hpp.

131  {
132  return ExType::binary(OP_LT, x, y);
133  }

◆ mark()

void casadi::SXElem::mark ( ) const

Definition at line 643 of file sx_elem.cpp.

643  {
644  (*this)->mark();
645  }

◆ marked()

bool casadi::SXElem::marked ( ) const

Definition at line 639 of file sx_elem.cpp.

639  {
640  return (*this)->marked();
641  }

◆ minus()

static SXElem casadi::GenericExpression< SXElem >::minus ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_oo

Definition at line 83 of file generic_expression.hpp.

83  {
84  return ExType::binary(OP_SUB, x, y);
85  }

◆ mod()

static SXElem casadi::GenericExpression< SXElem >::mod ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/fmod

Notably:

  • fmod(5,3) -> 2
  • fmod(5,-3) -> 2
  • fmod(-5,3) -> -2
  • fmod(-5,-3) -> -2

This is equivalent to Python's numpy.fmod and Matlab's rem.

\seealso remainder

Extra doc: https://github.com/casadi/casadi/wiki/L_pq 

Definition at line 607 of file generic_expression.hpp.

607  {
608  return ExType::binary(OP_FMOD, x, y);
609  }

◆ n_dep()

casadi_int casadi::SXElem::n_dep ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10v

Definition at line 563 of file sx_elem.cpp.

563  {
564  return node->n_dep();
565  }
virtual casadi_int n_dep() const
Number of dependencies.
Definition: sx_node.hpp:124

References casadi::SXNode::n_dep().

Referenced by dep(), and is_commutative().

◆ name()

const std::string & casadi::SXElem::name ( ) const

Definition at line 517 of file sx_elem.cpp.

517  {
518  return node->name();
519  }
virtual const std::string & name() const
Definition: sx_node.cpp:76

References casadi::SXNode::name().

Referenced by sym().

◆ ne()

static SXElem casadi::GenericExpression< SXElem >::ne ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ow

Definition at line 206 of file generic_expression.hpp.

206  {
207  return ExType::binary(OP_NE, x, y);
208  }

◆ op()

casadi_int casadi::SXElem::op ( ) const

Definition at line 521 of file sx_elem.cpp.

521  {
522  return node->op();
523  }
virtual casadi_int op() const =0
get the operation

References casadi::SXNode::op().

Referenced by binary(), is_commutative(), is_op(), and unary().

◆ operator casadi_int()

casadi::SXElem::operator casadi_int ( ) const
explicit

Definition at line 554 of file sx_elem.cpp.

554  {
555  return node->to_int();
556  }

◆ operator double()

casadi::SXElem::operator double ( ) const
explicit

Definition at line 550 of file sx_elem.cpp.

550  {
551  return node->to_double();
552  }

◆ operator Matrix< SXElem >()

casadi::SXElem::operator Matrix< SXElem > ( ) const

◆ operator!()

SXElem casadi::GenericExpression< SXElem >::operator! ( ) const
inlineinherited

Returns (an expression evaluating to) 1 if expression is zero and 0 otherwise

Extra doc: https://github.com/casadi/casadi/wiki/L_oz

Definition at line 266 of file generic_expression.hpp.

266  {
267  return logic_not(self());
268  }
static SXElem logic_not(const SXElem &x)
Logical not x -> !x.

◆ operator*=()

SXElem & casadi::GenericExpression< SXElem >::operator*= ( const SXElem y)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_op

Definition at line 108 of file generic_expression.hpp.

108 {return self() = self() * y;}

◆ operator+=()

SXElem & casadi::GenericExpression< SXElem >::operator+= ( const SXElem y)
inlineinherited

Definition at line 76 of file generic_expression.hpp.

76 { return self() = self() + y; }

◆ operator-()

SXElem casadi::SXElem::operator- ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10x

Definition at line 144 of file sx_elem.cpp.

144  {
145  if (is_op(OP_NEG))
146  return dep();
147  else if (is_zero())
148  return 0;
149  else if (is_minus_one())
150  return 1;
151  else if (is_one())
152  return -1;
153  else
154  return UnarySX::create(OP_NEG, *this);
155  }

References casadi::UnarySX::create(), dep(), is_minus_one(), is_one(), is_op(), is_zero(), and casadi::OP_NEG.

◆ operator-=()

SXElem & casadi::GenericExpression< SXElem >::operator-= ( const SXElem y)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_oo

Definition at line 92 of file generic_expression.hpp.

92 { return self() = self() - y; }

◆ operator->() [1/2]

SXNode * casadi::SXElem::operator-> ( )

Definition at line 182 of file sx_elem.cpp.

182  {
183  return node;
184  }

◆ operator->() [2/2]

const SXNode * casadi::SXElem::operator-> ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_10o

Definition at line 178 of file sx_elem.cpp.

178  {
179  return node;
180  }

◆ operator/=()

SXElem & casadi::GenericExpression< SXElem >::operator/= ( const SXElem y)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_oq

Definition at line 124 of file generic_expression.hpp.

124 {return self() = self() / y;}

◆ operator=() [1/2]

SXElem & casadi::SXElem::operator= ( const SXElem scalar)

Definition at line 98 of file sx_elem.cpp.

98  {
99  // quick return if the old and new pointers point to the same object
100  if (node == scalar.node) return *this;
101 
102  // decrease the counter and delete if this was the last pointer
103  if (--node->count == 0) delete node;
104 
105  // save the new pointer
106  node = scalar.node;
107  node->count++;
108  return *this;
109  }

References casadi::SXNode::count.

◆ operator=() [2/2]

SXElem & casadi::SXElem::operator= ( double  scalar)

Definition at line 136 of file sx_elem.cpp.

136  {
137  return *this = SXElem(scalar);
138  }

References SXElem().

◆ plus()

static SXElem casadi::GenericExpression< SXElem >::plus ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_on

Definition at line 67 of file generic_expression.hpp.

67  {
68  return ExType::binary(OP_ADD, x, y);
69  }

◆ pow()

static SXElem casadi::GenericExpression< SXElem >::pow ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pp

Definition at line 583 of file generic_expression.hpp.

583  {
584  return ExType::binary(OP_POW, x, y);
585  }

◆ printme()

static SXElem casadi::GenericExpression< SXElem >::printme ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Debug printing

Definition at line 730 of file generic_expression.hpp.

730  {
731  return ExType::binary(OP_PRINTME, x, y);
732  }

◆ rdivide()

static SXElem casadi::GenericExpression< SXElem >::rdivide ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_oq

Definition at line 115 of file generic_expression.hpp.

115  {
116  return ExType::binary(OP_DIV, x, y);
117  }

◆ remainder()

static SXElem casadi::GenericExpression< SXElem >::remainder ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/remainder

Notably:

  • remainder(5,3) -> -1
  • remainder(5,-3) -> -1
  • remainder(-5,3) -> 1
  • remainder(-5,-3) -> 1

This is equivalent to Python's math.remainder. There is no equivalence in Matlab.

\seealso fmod

Extra doc: https://github.com/casadi/casadi/wiki/L_24x 

Definition at line 634 of file generic_expression.hpp.

634  {
635  return ExType::binary(OP_REMAINDER, x, y);
636  }

◆ self() [1/2]

SXElem & casadi::GenericExpression< SXElem >::self ( )
inlineprotectedinherited

Definition at line 55 of file generic_expression.hpp.

55 { return static_cast<ExType&>(*this); }

◆ self() [2/2]

const SXElem & casadi::GenericExpression< SXElem >::self ( ) const
inlineprotectedinherited

Definition at line 54 of file generic_expression.hpp.

54 { return static_cast<const ExType&>(*this); }

◆ serialize()

void casadi::SXElem::serialize ( SerializingStream s) const

Extra doc: https://github.com/casadi/casadi/wiki/L_114

Definition at line 655 of file sx_elem.cpp.

655  {
656  return (*this)->serialize(s);
657  }

◆ set_temp()

void casadi::SXElem::set_temp ( int  t) const

Definition at line 635 of file sx_elem.cpp.

635  {
636  (*this)->temp = t;
637  }

◆ sign()

static SXElem casadi::GenericExpression< SXElem >::sign ( const SXElem x)
inlinestaticinherited

sign(x) := -1 for x<0 sign(x) := 1 for x>0, sign(0) := 0 sign(NaN) := NaN

Extra doc: https://github.com/casadi/casadi/wiki/L_po

Definition at line 571 of file generic_expression.hpp.

571  {
572  return ExType::unary(OP_SIGN, x);
573  }

◆ sin()

static SXElem casadi::GenericExpression< SXElem >::sin ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p3

Definition at line 314 of file generic_expression.hpp.

314  {
315  return ExType::unary(OP_SIN, x);
316  }

◆ sinh()

static SXElem casadi::GenericExpression< SXElem >::sinh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_pa

Definition at line 398 of file generic_expression.hpp.

398  {
399  return ExType::unary(OP_SINH, x);
400  }

◆ sq()

static SXElem casadi::GenericExpression< SXElem >::sq ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p2

Definition at line 302 of file generic_expression.hpp.

302  {
303  return ExType::unary(OP_SQ, x);
304  }

◆ sqrt()

static SXElem casadi::GenericExpression< SXElem >::sqrt ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p1

Definition at line 290 of file generic_expression.hpp.

290  {
291  return ExType::unary(OP_SQRT, x);
292  }

◆ sym()

SXElem casadi::SXElem::sym ( const std::string &  name)
static
Parameters
nameName of the symbolic primitive

This is the name that will be used by the "operator<<" and "str" methods. The name is not used as identifier; you may construct distinct SXElem objects with non-unique names.

Extra doc: https://github.com/casadi/casadi/wiki/L_10l

Definition at line 90 of file sx_elem.cpp.

90  {
91  return create(new SymbolicSX(name));
92  }
const std::string & name() const
Definition: sx_elem.cpp:517
Represents a scalar symbolic expression.
Definition: symbolic_sx.hpp:42

References create(), and name().

Referenced by casadi::Matrix< Scalar >::_sym(), and casadi::register_symbol().

◆ tan()

static SXElem casadi::GenericExpression< SXElem >::tan ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p5

Definition at line 338 of file generic_expression.hpp.

338  {
339  return ExType::unary(OP_TAN, x);
340  }

◆ tanh()

static SXElem casadi::GenericExpression< SXElem >::tanh ( const SXElem x)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_p9

Definition at line 386 of file generic_expression.hpp.

386  {
387  return ExType::unary(OP_TANH, x);
388  }

◆ times()

static SXElem casadi::GenericExpression< SXElem >::times ( const SXElem x,
const SXElem y 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_op

Definition at line 99 of file generic_expression.hpp.

99  {
100  return ExType::binary(OP_MUL, x, y);
101  }

◆ type_name()

static std::string casadi::SXElem::type_name ( )
inlinestatic

Definition at line 135 of file sx_elem.hpp.

135 {return "SXElem";}

◆ unary()

SXElem casadi::SXElem::unary ( casadi_int  op,
const SXElem x 
)
static

Definition at line 408 of file sx_elem.cpp.

408  {
409  // Simplifications
411  switch (op) {
412  case OP_SQ:
413  if (x.is_op(OP_SQRT))
414  return x.dep();
415  else if (x.is_op(OP_NEG))
416  return sq(x.dep());
417  break;
418  case OP_FABS:
419  if (x.is_op(OP_FABS) || x.is_op(OP_SQ))
420  return x;
421  break;
422  case OP_NOT:
423  if (x.is_op(OP_NOT))
424  return x.dep();
425  break;
426  case OP_SINH:
427  case OP_TANH:
428  case OP_ATANH:
429  case OP_ACOSH:
430  case OP_ASINH:
431  if (x.is_zero())
432  return 0;
433  break;
434  case OP_COSH:
435  if (x.is_zero())
436  return 1;
437  break;
438  case OP_SQRT:
439  if (x.is_op(OP_SQ))
440  return fabs(x.dep());
441  break;
442  }
443  }
444  return UnarySX::create(Operation(op), x);
445  }
friend SXElem fabs(const SXElem &x)
@ OP_SINH
Definition: calculus.hpp:74
@ OP_COSH
Definition: calculus.hpp:74
@ OP_ASINH
Definition: calculus.hpp:75
@ OP_SQRT
Definition: calculus.hpp:67
@ OP_ACOSH
Definition: calculus.hpp:75
@ OP_ATANH
Definition: calculus.hpp:75
@ OP_TANH
Definition: calculus.hpp:74
@ OP_NOT
Definition: calculus.hpp:70

References casadi::UnarySX::create(), dep(), casadi::GenericExpression< SXElem >::fabs, is_op(), is_zero(), op(), casadi::OP_ACOSH, casadi::OP_ASINH, casadi::OP_ATANH, casadi::OP_COSH, casadi::OP_FABS, casadi::OP_NEG, casadi::OP_NOT, casadi::OP_SINH, casadi::OP_SQ, casadi::OP_SQRT, casadi::OP_TANH, casadi::GlobalOptions::simplification_on_the_fly, and casadi::GenericExpression< SXElem >::sq().

◆ which_function()

Function casadi::SXElem::which_function ( ) const

Definition at line 473 of file sx_elem.cpp.

473  {
474  return node->which_function();
475  }
virtual Function which_function() const
Get called function.
Definition: sx_node.cpp:64

References casadi::SXNode::which_function().

◆ which_output()

casadi_int casadi::SXElem::which_output ( ) const

Definition at line 477 of file sx_elem.cpp.

477  {
478  return node->which_output();
479  }
virtual casadi_int which_output() const
Get function output.
Definition: sx_node.cpp:68

References casadi::SXNode::which_output().

Friends And Related Function Documentation

◆ BinarySXNode

friend class BinarySXNode
friend

Definition at line 77 of file sx_elem.hpp.

◆ if_else

SXElem if_else ( const SXElem x,
const SXElem y,
const SXElem z 
)
friend

Extra doc: https://github.com/casadi/casadi/wiki/L_113

Definition at line 285 of file sx_elem.hpp.

285  {
286  return if_else_zero(x, y) + if_else_zero(!x, z);
287  }

◆ Matrix< SXElem >

friend class Matrix< SXElem >
friend

Definition at line 77 of file sx_elem.hpp.

◆ SXNode

friend class SXNode
friend

Definition at line 76 of file sx_elem.hpp.


The documentation for this class was generated from the following files: