expression.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
39 
41 
42 
43 // ---------------------------------------------------------------------------------------------------
44 // IMPLEMENTATION OF THE CONSTRUCTORS:
45 // ---------------------------------------------------------------------------------------------------
46 
48 {
49  construct(VT_UNKNOWN, 0, 0, 0, "");
50 }
51 
52 Expression::Expression(const std::string& name_, uint nRows_, uint nCols_, VariableType variableType_, uint globalTypeID)
53 {
54  construct(variableType_, globalTypeID, nRows_, nCols_, name_);
55 }
56 
57 Expression::Expression(const std::string &name_)
58 {
59  construct(VT_UNKNOWN, 0, 0, 0, name_);
60 }
61 
62 Expression::Expression(uint nRows_, uint nCols_, VariableType variableType_, uint globalTypeID)
63 {
64  construct(variableType_, globalTypeID, nRows_, nCols_, "");
65 }
66 
67 Expression::Expression(int nRows_, int nCols_, VariableType variableType_, int globalTypeID)
68 {
69  construct(variableType_, globalTypeID, nRows_, nCols_, "");
70 }
71 
73 {
74  VariableType tmpType;
75  int tmpComp;
76 
77  if (tree_.isVariable(tmpType, tmpComp) == BT_TRUE)
78  {
79  construct(tmpType, tmpComp, 1, 1, "");
80  }
81  else
82  {
83  construct(VT_UNKNOWN, 0, 1, 1, "");
84  }
85 
86  delete element[0];
87  element[0] = tree_.clone();
88 }
89 
90 Expression::Expression( const double& rhs )
91 {
92  construct(VT_UNKNOWN, 0, 1, 1, "");
93  delete element[ 0 ];
95 }
96 
98 {
99  construct(VT_UNKNOWN, 0, rhs.getDim(), 1, "");
100  for(unsigned el = 0; el < rhs.getDim(); el++ )
101  {
102  delete element[ el ];
104  }
105 }
106 
108 {
109  construct(VT_UNKNOWN, 0, rhs.getNumRows(), rhs.getNumCols(), "");
110  for(unsigned run1 = 0; run1 < rhs.getNumRows(); run1++ )
111  {
112  for(unsigned run2 = 0; run2 < rhs.getNumCols(); run2++ )
113  {
114  delete element[rhs.getNumCols() * run1 + run2];
115  element[rhs.getNumCols() * run1 + run2] =
116  new DoubleConstant(rhs(run1, run2), NE_NEITHER_ONE_NOR_ZERO);
117  }
118  }
119 }
120 
122 {
123  copy(rhs);
124 }
125 
127 {
128  deleteAll();
129 }
130 
132 {
133  if (this != &rhs)
134  {
135  deleteAll();
136  copy(rhs);
137  }
138  return *this;
139 }
140 
142  if (getDim()==0) {operator=(arg);return *this;}
143  ASSERT(arg.getNumCols() == getNumCols());
144 
145  uint run1;
146  uint oldDim = dim;
147  dim += arg.dim;
148  nRows += arg.getNumRows();
149 
150  if( arg.variableType != variableType )
152  element = (Operator**)realloc(element, dim*sizeof(Operator*) );
153 
154  for( run1 = oldDim; run1 < dim; run1++ )
155  element[run1] = arg.element[run1-oldDim]->clone();
156 
157  return *this;
158 }
159 
160 // this is still very unefficient code
161 
163  if (getDim()==0) {operator=(arg);return *this;}
164  ASSERT(arg.getNumRows() == getNumRows());
165 
166 
168  E.appendRows(arg.transpose());
169 
170  operator=(E.transpose());
171 
172  return *this;
173 }
174 
176 
177  if( dim == 0 ) return operator=(arg);
178 
179  uint run1;
180  uint oldDim = dim;
181 
182  dim += arg.dim ;
183  nRows += arg.dim ;
184 
186 
187  if( arg.isVariable() == BT_FALSE ) variableType = VT_UNKNOWN;
188 
189  element = (Operator**)realloc(element, dim*sizeof(Operator*) );
190 
191  for( run1 = oldDim; run1 < dim; run1++ )
192  element[run1] = arg.element[run1-oldDim]->clone();
193 
194  return *this;
195 }
196 
197 
198 std::ostream& Expression::print(std::ostream& stream) const
199 {
200  uint run1;
201  stream << "[ ";
202  if (dim) {
203  for (run1 = 0; run1 < dim - 1; run1++)
204  stream << *element[run1] << " , ";
205  stream << *element[dim - 1];
206  }
207  stream << "]";
208 
209  return stream;
210 }
211 
212 
213 std::ostream& operator<<( std::ostream& stream, const Expression &arg )
214 {
215  return arg.print(stream);
216 }
217 
219 
220  ASSERT( idx < getDim( ) );
221 
222  Expression tmp(1);
223 
224  delete tmp.element[0];
225  tmp.element[0] = element[idx]->clone();
226 
227  tmp.component = component + idx;
229 
230  return tmp;
231 }
232 
233 Expression Expression::operator()( uint rowIdx, uint colIdx ) const{
234 
235  ASSERT( rowIdx < getNumRows( ) );
236  ASSERT( colIdx < getNumCols( ) );
237 
238  Expression tmp(1);
239 
240  delete tmp.element[0];
241  tmp.element[0] = element[rowIdx*getNumCols()+colIdx]->clone();
242 
243  tmp.component = component + rowIdx*getNumCols() + colIdx;
245 
246  return tmp;
247 }
248 
249 
251 
252  switch( variableType ){
253 
255  ASSERT( idx < getDim( ) );
256  return *element[idx];
257 
258  case VT_UNKNOWN:
259  ASSERT( idx < getDim( ) );
260  delete element[idx];
261  element[idx] = new TreeProjection();
262  return *element[idx];
263 
264  default:
265  ASSERT( idx < getDim( ) );
266  return *element[idx];
267  }
268  ASSERT( 1 == 0 );
269  return *element[0];
270 }
271 
272 
274 
275  switch( variableType ){
276 
278  ASSERT( rowIdx < getNumRows( ) );
279  ASSERT( colIdx < getNumCols( ) );
280  return *element[rowIdx*getNumCols()+colIdx];
281 
282 // case VT_UNKNOWN:
283  default:
284  ASSERT( rowIdx < getNumRows( ) );
285  ASSERT( colIdx < getNumCols( ) );
286  delete element[rowIdx*getNumCols()+colIdx];
287  element[rowIdx*getNumCols()+colIdx] = new TreeProjection();
288  return *element[rowIdx*getNumCols()+colIdx];
289 
290 // ASSERT( 1 == 0 );
291 // return *element[0];
292  }
293  ASSERT( 1 == 0 );
294  return *element[0];
295 }
296 
297 
298 Expression operator+( const Expression & arg1, const Expression & arg2 )
299 {return arg1.add(arg2);}
300 Expression operator-( const Expression & arg1, const Expression & arg2 )
301 {return arg1.sub(arg2);}
302 Expression operator*( const Expression & arg1, const Expression & arg2 )
303 {return arg1.mul(arg2);}
304 Expression operator/( const Expression & arg1, const Expression & arg2 )
305 {return arg1.div(arg2);}
306 
308 {return static_cast<Expression&>(*this) = static_cast<Expression*>(this)->add(arg);}
309 
311 {return static_cast<Expression&>(*this) = static_cast<Expression*>(this)->sub(arg);}
312 
314 {return static_cast<Expression&>(*this) = static_cast<Expression*>(this)->mul(arg);}
315 
317 {return static_cast<Expression&>(*this) = static_cast<Expression*>(this)->div(arg);}
318 
320 
321  ASSERT( getNumRows() == arg.getNumRows() );
322  ASSERT( getNumCols() == arg.getNumCols() );
323 
324  uint i,j;
325 
326  Expression tmp("", getNumRows(), getNumCols() );
327 
328  for( i=0; i<getNumRows(); ++i ){
329  for( j=0; j<getNumCols(); ++j ){
330 
331  delete tmp.element[i*getNumCols()+j];
332  if( element[i*getNumCols()+j]->isOneOrZero() != NE_ZERO ){
333  if( arg.element[i*getNumCols()+j]->isOneOrZero() != NE_ZERO )
334  tmp.element[i*getNumCols()+j] = new Addition( element[i*getNumCols()+j]->clone(),
335  arg.element[i*getNumCols()+j]->clone() );
336  else
337  tmp.element[i*getNumCols()+j] = element[i*getNumCols()+j]->clone();
338  }
339  else{
340  if( arg.element[i*getNumCols()+j]->isOneOrZero() != NE_ZERO )
341  tmp.element[i*getNumCols()+j] = arg.element[i*getNumCols()+j]->clone();
342  else tmp.element[i*getNumCols()+j] = new DoubleConstant(0.0,NE_ZERO);
343  }
344  }
345  }
346  return tmp;
347 }
348 
349 
351 
352  ASSERT( getNumRows() == arg.getNumRows() );
353  ASSERT( getNumCols() == arg.getNumCols() );
354 
355  uint i,j;
356 
357  Expression tmp("", getNumRows(), getNumCols() );
358 
359  for( i=0; i<getNumRows(); ++i ){
360  for( j=0; j<getNumCols(); ++j ){
361 
362  delete tmp.element[i*getNumCols()+j];
363  if( element[i*getNumCols()+j]->isOneOrZero() != NE_ZERO ){
364  if( arg.element[i*getNumCols()+j]->isOneOrZero() != NE_ZERO )
365  tmp.element[i*getNumCols()+j] = new Subtraction( element[i*getNumCols()+j]->clone(),
366  arg.element[i*getNumCols()+j]->clone() );
367  else
368  tmp.element[i*getNumCols()+j] = element[i*getNumCols()+j]->clone();
369  }
370  else{
371  if( arg.element[i*getNumCols()+j]->isOneOrZero() != NE_ZERO )
372  tmp.element[i*getNumCols()+j] = new Subtraction( new DoubleConstant(0.0,NE_ZERO),
373  arg.element[i*getNumCols()+j]->clone() );
374  else tmp.element[i*getNumCols()+j] = new DoubleConstant(0.0,NE_ZERO);
375  }
376  }
377  }
378  return tmp;
379 }
380 
381 
382 Operator* Expression::product( const Operator *a, const Operator *b ) const{
383 
384 
385  switch( a->isOneOrZero() ){
386 
387  case NE_ZERO:
388  return new DoubleConstant( 0.0, NE_ZERO );
389 
390  case NE_ONE:
391  return b->clone();
392 
393  default:
394 
395  switch( b->isOneOrZero() ){
396 
397  case NE_ZERO:
398  return new DoubleConstant( 0.0, NE_ZERO );
399 
400  case NE_ONE:
401  return a->clone();
402 
403  default:
404  return new Product( a->clone(), b->clone() );
405  }
406  }
407  return 0;
408 }
409 
410 
411 
413  if (getDim()==0 || arg.getDim()==0) return Expression();
414  // uninitialized expressions yield uninitialized results
415 
416  uint i,j,k;
417 
418  if( getNumRows() == 1 && getNumCols( ) == 1 ){
419 
420  Expression tmp("", arg.getNumRows(), arg.getNumCols() );
421 
422  for( i = 0; i< arg.getDim(); i++ ){
423 
424  delete tmp.element[i];
425  Operator *prod = product( element[0], arg.element[i] );
426  tmp.element[i] = prod->clone();
427 
428  delete prod;
429  }
430  return tmp;
431  }
432 
433 
434  if( arg.getNumRows() == 1 && arg.getNumCols( ) == 1 ){
435 
436  Expression tmp("", getNumRows(), getNumCols() );
437 
438  for( i = 0; i< getDim(); i++ ){
439 
440  delete tmp.element[i];
441  Operator *prod = product( arg.element[0], element[i] );
442  tmp.element[i] = prod->clone();
443 
444  delete prod;
445  }
446  return tmp;
447  }
448 
449 
450  ASSERT( getNumCols( ) == arg.getNumRows( ) );
451 
452  uint newNumRows = getNumRows( );
453  uint newNumCols = arg.getNumCols( );
454  IntermediateState tmp = zeros<double>( newNumRows, newNumCols );
455 
456  for( i=0; i<newNumRows; ++i ){
457  for( j=0; j<newNumCols; ++j ){
458  for( k=0; k<getNumCols( ); ++k ){
459 
460  Operator *tmpO = product( element[i*getNumCols()+k],
461  arg.element[k*arg.getNumCols()+j] );
462 
463  if( tmpO->isOneOrZero() != NE_ZERO )
464  tmp(i,j) += *tmpO;
465 
466  delete tmpO;
467  }
468  }
469  }
470  return tmp;
471 }
472 
473 
475 
476  ASSERT( arg.getNumRows() == 1 );
477  ASSERT( arg.getNumCols() == 1 );
478 
479  uint i;
480 
481  Expression tmp("", getNumRows(), getNumCols() );
482 
483  for( i = 0; i< getDim(); i++ ){
484  delete tmp.element[i];
485  tmp.element[i] = new Quotient( element[i]->clone(), arg.element[0]->clone() );
486  }
487  return tmp;
488 }
489 
491 
492  ASSERT( getNumRows() == getNumCols() );
493 
494  int i,j,k; // must really be int, never use uint here.
495  int M = getNumRows(); // must really be int, never use uint here.
496 
497  IntermediateState tmp("", M, 2 * M);
498 
499  for( i = 0; i < M; i++ ){
500  for( j = 0; j < 2*M; j++ ){
501  if( j < M ) tmp(i,j) = operator()(i,j);
502  else tmp(i,j) = 0.0 ;
503  if( j == M+i ) tmp(i,j) = 1.0 ;
504  }
505  }
506 
507  for( i = 0; i < M-1; i++ )
508  for( k = i+1; k < M; k++ )
509  for( j = 2*M-1; j >= i; j-- )
510  tmp(k,j) -= ( tmp(i,j)*tmp(k,i) )/tmp(i,i);
511 
512  for( i = M-1; i > 0; i-- )
513  for( k = i-1; k >= 0; k-- )
514  for( j = 2*M-1; j >= i; j-- )
515  tmp(k,j) -= (tmp(i,j)*tmp(k,i))/tmp(i,i);
516 
517  for( i = 0; i < M; i++ )
518  for( j = 2*M-1; j >= 0; j-- )
519  tmp(i,j) = tmp(i,j)/tmp(i,i);
520 
521  Expression I("", M,M);
522  for( i = 0; i < M; i++ ){
523  for( j = 0; j < M; j++ ){
524  delete I.element[i*M+j];
525  I.element[i*M+j] = tmp.element[i*2*M+j+M]->clone();
526  }
527  }
528 
529  return I;
530 }
531 
532 
533 Expression Expression::getRow( const uint& rowIdx ) const{
534 
535  uint run1;
536  ASSERT( rowIdx < getNumRows() );
537 
538  Expression tmp("", 1, (int) getNumCols() );
539 
540  for( run1 = 0; run1 < getNumCols(); run1++ ){
541  delete tmp.element[run1];
542  tmp.element[run1] = element[rowIdx*getNumCols()+run1]->clone();
543  }
544  return tmp;
545 }
546 
547 
548 Expression Expression::getRows( const uint& rowIdx1, const uint& rowIdx2 ) const{
549 
550  uint run1, run2, _nRows;
551  ASSERT( rowIdx1 < getNumRows() );
552  ASSERT( rowIdx2 <= getNumRows() );
553  _nRows = rowIdx2 - rowIdx1;
554 
555  Expression tmp("", _nRows, (int) getNumCols() );
556 
557  for( run1 = 0; run1 < _nRows; run1++ ){
558  for( run2 = 0; run2 < getNumCols(); run2++ ){
559  delete tmp.element[run1*getNumCols()+run2];
560  tmp.element[run1*getNumCols()+run2] = element[(rowIdx1+run1)*getNumCols()+run2]->clone();
561  }
562  }
563  return tmp;
564 }
565 
566 
567 Expression Expression::getCol( const uint& colIdx ) const{
568 
569  uint run1;
570  ASSERT( colIdx < getNumCols() );
571 
572  Expression tmp("", (int) getNumRows(), 1 );
573 
574  for( run1 = 0; run1 < getNumRows(); run1++ ){
575  delete tmp.element[run1];
576  tmp.element[run1] = element[run1*getNumCols()+colIdx]->clone();
577  }
578  return tmp;
579 }
580 
581 
582 Expression Expression::getCols( const uint& colIdx1, const uint& colIdx2 ) const{
583 
584  uint run1, run2, _nCols;
585  ASSERT( colIdx1 < getNumCols() );
586  ASSERT( colIdx2 <= getNumCols() );
587  _nCols = colIdx2 - colIdx1;
588 
589  Expression tmp("", (int) getNumRows(), _nCols );
590 
591  for( run1 = 0; run1 < getNumRows(); run1++ ){
592  for( run2 = 0; run2 < _nCols; run2++ ){
593  delete tmp.element[run1*_nCols+run2];
594  tmp.element[run1*_nCols+run2] = element[run1*getNumCols()+colIdx1+run2]->clone();
595  }
596  }
597  return tmp;
598 }
599 
600 
601 Expression Expression::getSubMatrix( const uint& rowIdx1, const uint& rowIdx2, const uint& colIdx1, const uint& colIdx2 ) const{
602 
603  uint run1, run2, _nRows, _nCols;
604  ASSERT( colIdx1 < getNumCols() );
605  ASSERT( colIdx2 <= getNumCols() );
606  _nCols = colIdx2 - colIdx1;
607  ASSERT( rowIdx1 < getNumRows() );
608  ASSERT( rowIdx2 <= getNumRows() );
609  _nRows = rowIdx2 - rowIdx1;
610 
611  Expression tmp("", _nRows, _nCols );
612 
613  for( run1 = 0; run1 < _nRows; run1++ ){
614  for( run2 = 0; run2 < _nCols; run2++ ){
615  delete tmp.element[run1*_nCols+run2];
616  tmp.element[run1*_nCols+run2] = element[(rowIdx1+run1)*getNumCols()+colIdx1+run2]->clone();
617  }
618  }
619  return tmp;
620 }
621 
622 
624 
625  DMatrix tmp;
626  if( arg.getDim() == 0 ) return tmp;
627 
628  Function f;
629  f << backwardDerivative( *this, arg );
630 
631 // FILE *test=fopen("test-getdep.txt","w");
632 // test << f;
633 // fclose(test);
634 
635  double *x = new double[ f.getNumberOfVariables()+1 ];
636  double *result = new double[ f.getDim() ];
637 
638  // TODO: DANGEROUS CODE --> TALK TO MILAN ABOUT THIS
639  int run1;
640  srand(1.0);
641  for( run1 = 0; run1 < f.getNumberOfVariables()+1; run1++ )
642  x[run1] = 1.0 + (double)rand() / RAND_MAX;
643 
644  // EVALUATE f AT THE POINT (tt,xx):
645  // ---------------------------------
646  f.evaluate( 0, x, result );
647 
648  tmp = DMatrix( getDim(), arg.getDim(), result );
649 
650  delete[] result;
651  delete[] x;
652 
653  return tmp;
654 }
655 
657 {
658  DMatrix res = zeros<double>(getNumRows(), getNumCols());
659 
660  for (unsigned el = 0; el < getDim(); ++el)
661  {
662  Operator* foo = getOperatorClone(el);
663  if (foo->isOneOrZero() != NE_ZERO)
664  res(el) = 1.0;
665  delete foo;
666  }
667 
668  return res;
669 }
670 
671 
672 
674 
675  Expression tmp("", nRows, nCols);
676  uint run1;
677 
678  for( run1 = 0; run1 < dim; run1++ ){
679  delete tmp.element[run1];
680  tmp.element[run1] = new Sin( element[run1]->clone() );
681  }
682  return tmp;
683 }
684 
686 
687  Expression tmp("", nRows, nCols);
688  uint run1;
689 
690  for( run1 = 0; run1 < dim; run1++ ){
691  delete tmp.element[run1];
692  tmp.element[run1] = new Cos( element[run1]->clone() );
693  }
694  return tmp;
695 }
696 
698 
699  Expression tmp("", nRows, nCols);
700  uint run1;
701 
702  for( run1 = 0; run1 < dim; run1++ ){
703  delete tmp.element[run1];
704  tmp.element[run1] = new Tan( element[run1]->clone() );
705  }
706  return tmp;
707 }
708 
710 
711  Expression tmp("", nRows, nCols);
712  uint run1;
713 
714  for( run1 = 0; run1 < dim; run1++ ){
715  delete tmp.element[run1];
716  tmp.element[run1] = new Asin( element[run1]->clone() );
717  }
718  return tmp;
719 }
720 
722 
723  Expression tmp("", nRows, nCols);
724  uint run1;
725 
726  for( run1 = 0; run1 < dim; run1++ ){
727  delete tmp.element[run1];
728  tmp.element[run1] = new Acos( element[run1]->clone() );
729  }
730  return tmp;
731 }
732 
734 
735  Expression tmp("", nRows, nCols);
736  uint run1;
737 
738  for( run1 = 0; run1 < dim; run1++ ){
739  delete tmp.element[run1];
740  tmp.element[run1] = new Atan( element[run1]->clone() );
741  }
742  return tmp;
743 }
744 
746 
747  Expression tmp("", nRows, nCols);
748  uint run1;
749 
750  for( run1 = 0; run1 < dim; run1++ ){
751  delete tmp.element[run1];
752  tmp.element[run1] = new Exp( element[run1]->clone() );
753  }
754  return tmp;
755 }
756 
758 
759  Expression tmp("", nRows, nCols);
760  uint run1;
761 
762  for( run1 = 0; run1 < dim; run1++ ){
763  delete tmp.element[run1];
764  tmp.element[run1] = new Power( element[run1]->clone(), new DoubleConstant( 0.5, NE_NEITHER_ONE_NOR_ZERO ) );
765  }
766  return tmp;
767 }
768 
770 
771  Expression tmp("", nRows, nCols);
772  uint run1;
773 
774  for( run1 = 0; run1 < dim; run1++ ){
775  delete tmp.element[run1];
776  tmp.element[run1] = new Logarithm( element[run1]->clone() );
777  }
778  return tmp;
779 }
780 
781 
783 
784  ASSERT( arg.getDim() == 1 );
785 
786  Expression tmp("", nRows, nCols);
787  uint run1;
788 
789  for( run1 = 0; run1 < dim; run1++ ){
790  delete tmp.element[run1];
791  tmp.element[run1] = new Power( element[run1]->clone(), arg.element[0]->clone() );
792  }
793  return tmp;
794 }
795 
796 
797 Expression Expression::getPowInt( const int &arg ) const{
798 
799  Expression tmp("", nRows, nCols);
800  uint run1;
801 
802  for( run1 = 0; run1 < dim; run1++ ){
803  delete tmp.element[run1];
804  tmp.element[run1] = new Power_Int( element[run1]->clone(), arg );
805  }
806  return tmp;
807 }
808 
809 
810 
812 
813  Expression tmp("", getNumCols(), getNumRows());
814 
815  uint run1, run2;
816 
817  for( run1 = 0; run1 < getNumRows(); run1++ ){
818  for( run2 = 0; run2 < getNumCols(); run2++ ){
819  delete tmp.element[run2*getNumRows()+run1];
820  tmp.element[run2*getNumRows()+run1] = element[run1*getNumCols()+run2]->clone();
821  }
822  }
823  return tmp;
824 }
825 
826 
827 
829 
830  uint run1;
831 
832  Expression result = operator*(transpose(), *this);
833 
835  CurvatureType cc;
836 
837  for( run1 = 0; run1 < getDim(); run1++ ){
838 
839  cc = element[run1]->getCurvature();
840 
841  if( cc != CT_CONSTANT ){
842  if( cc == CT_AFFINE &&
843  (c == CT_CONSTANT || c == CT_AFFINE) )
844  c = CT_AFFINE;
846  }
847  }
848 
849  if( c == CT_CONSTANT )
850  result.element[0]->setCurvature(CT_CONSTANT);
851 
852  if( c == CT_AFFINE )
853  result.element[0]->setCurvature(CT_CONVEX);
854 
855  return result;
856 
857 }
858 
859 
861 
862  uint run1;
863 
864  Expression result;
865  result = exp( operator()(0) );
866 
867  for( run1 = 1; run1 < getDim(); run1++ )
868  result = result + exp( operator()(run1) );
869 
870  result = ln( result );
871 
873  CurvatureType cc;
874 
875  for( run1 = 0; run1 < getDim(); run1++ ){
876 
877  cc = element[run1]->getCurvature();
878 
879  if( cc != CT_CONSTANT ){
880  if( cc == CT_AFFINE ){
881  if( c == CT_CONSTANT || c == CT_AFFINE )
882  c = CT_AFFINE;
883  else{
884  if( c == CT_CONVEX ){
885  c = CT_CONVEX;
886  }
887  else{
889  }
890  }
891  }
892  else{
893  if( cc == CT_CONVEX &&
894  (c == CT_CONSTANT || c == CT_AFFINE || c == CT_CONVEX ) )
895  c = CT_CONVEX;
896  else
898  }
899  }
900  }
901 
902  if( c == CT_CONSTANT )
903  result.element[0]->setCurvature(CT_CONSTANT);
904 
905  if( c == CT_AFFINE || c == CT_CONVEX )
906  result.element[0]->setCurvature(CT_CONVEX);
907 
908  return result;
909 }
910 
911 
913 
914  uint run1;
915 
916  Expression result = sqrt( getSumSquare() );
917 
919  CurvatureType cc;
920 
921  for( run1 = 0; run1 < getDim(); run1++ ){
922 
923  cc = element[run1]->getCurvature();
924 
925  if( cc != CT_CONSTANT ){
926  if( cc == CT_AFFINE &&
927  (c == CT_CONSTANT || c == CT_AFFINE) )
928  c = CT_AFFINE;
930  }
931  }
932 
933  if( c == CT_CONSTANT )
934  result.element[0]->setCurvature(CT_CONSTANT);
935 
936  if( c == CT_AFFINE )
937  result.element[0]->setCurvature(CT_CONVEX);
938 
939  return result;
940 }
941 
942 
943 
944 
946 
948  return *this;
949 }
950 
951 
953 
955 
957  ASSERT( 1 == 0 );
958  }
959 
961  return tmp;
962 }
963 
964 
966 
967  return getDot();
968 }
969 
970 
972 
973  ASSERT( getNumCols() == 1 );
974  ASSERT( arg.getNumCols() == 1 );
975 
976  Expression result("", getNumRows(), arg.getNumRows());
977 
978  uint run1, run2;
979 
980  Expression seed( arg.getNumRows() );
981 
982  for( run1 = 0; run1 < arg.getNumRows(); run1++ ){
983 
984  delete seed.element[run1];
985  seed.element[run1] = new DoubleConstant( 1.0, NE_ONE );
986 
987  Expression tmp = ADforward( arg, seed );
988 
989  delete seed.element[run1];
990  seed.element[run1] = new DoubleConstant( 0.0, NE_ZERO );
991 
992  for( run2 = 0; run2 < getNumRows(); run2++ ){
993  delete result.element[run2*arg.getNumRows()+run1];
994  result.element[run2*arg.getNumRows()+run1] = tmp.element[run2]->clone();
995  }
996  }
997 
998  return result;
999 }
1000 
1001 
1002 Expression Expression::ADforward ( const VariableType &varType_, const int *arg, int nV ) const{
1003 
1004  ASSERT( getNumCols() == 1 );
1005 
1006  Expression result("", (int) getNumRows(), nV);
1007 
1008  int run1, run2;
1009 
1010  IntermediateState seed( nV );
1011 
1012  for( run1 = 0; run1 < nV; run1++ ) seed(run1) = 0;
1013 
1014  for( run1 = 0; run1 < nV; run1++ ){
1015 
1016  seed(run1) = 1.0;
1017 
1018  Expression tmp = ADforward( varType_, arg, seed );
1019 
1020  seed(run1) = 0.0;
1021 
1022  for( run2 = 0; run2 < (int) getNumRows(); run2++ ){
1023  delete result.element[run2*nV+run1];
1024  result.element[run2*nV+run1] = tmp.element[run2]->clone();
1025  }
1026  }
1027  return result;
1028 }
1029 
1030 
1031 
1033 
1034  ASSERT( getNumCols() == 1 );
1035  ASSERT( arg.getNumCols() == 1 );
1036 
1037  Expression result("", getNumRows(), arg.getNumRows());
1038 
1039  uint run1, run2;
1040 
1041  Expression seed( getNumRows() );
1042 
1043  for( run1 = 0; run1 < getNumRows(); run1++ ){
1044 
1045  delete seed.element[run1];
1046  seed.element[run1] = new DoubleConstant( 1.0, NE_ONE );
1047 
1048  Expression tmp = ADbackward( arg, seed );
1049 
1050  delete seed.element[run1];
1051  seed.element[run1] = new DoubleConstant( 0.0, NE_ZERO );
1052 
1053  for( run2 = 0; run2 < arg.getNumRows(); run2++ ){
1054  delete result.element[run1*arg.getNumRows()+run2];
1055  result.element[run1*arg.getNumRows()+run2] = tmp.element[run2]->clone();
1056  }
1057  }
1058 
1059  return result;
1060 }
1061 
1062 
1063 Expression Expression::ADforward ( const Expression &arg, const Expression &seed ) const{
1064 
1065  unsigned int run1;
1066  const unsigned int n = arg.getDim();
1067 
1068  ASSERT( arg .isVariable() == BT_TRUE );
1069  ASSERT( seed.getDim () == n );
1070 
1071  VariableType *varType = new VariableType[n];
1072  int *Component = new int[n];
1073 
1074  for( run1 = 0; run1 < n; run1++ ){
1075  arg.element[run1]->isVariable(varType[run1],Component[run1]);
1076  }
1077 
1078  Expression result = ADforward( varType, Component, seed );
1079  delete[] Component;
1080  delete[] varType;
1081 
1082  return result;
1083 }
1084 
1085 
1087  const int *arg ,
1088  const Expression &seed ) const{
1089 
1090  VariableType *varType = new VariableType[seed.getDim()];
1091  for( uint run1 = 0; run1 < seed.getDim(); run1++ ) varType[run1] = varType_;
1092  Expression tmp = ADforward( varType, arg, seed );
1093  delete[] varType;
1094  return tmp;
1095 }
1096 
1097 
1099  const int *arg ,
1100  const Expression &seed ) const{
1101 
1102  unsigned int run1, run2;
1103  const unsigned int n = seed.getDim();
1104 
1105  Expression result("", getNumRows(), getNumCols());
1106 
1107  VariableType *varType = new VariableType[n];
1108  int *Component = new int [n];
1109  Operator **seed1 = new Operator* [n];
1110 
1111  for( run1 = 0; run1 < n; run1++ ){
1112  varType [run1] = varType_[run1];
1113  Component[run1] = arg[run1];
1114  seed1 [run1] = seed.element[run1]->clone();
1115  }
1116 
1117  for( run1 = 0; run1 < getDim(); run1++ ){
1118 
1119  delete result.element[run1];
1120 
1121  int Dim = n;
1122  int nIS = 0;
1123  TreeProjection **IS = 0;
1124 
1125  element[run1]->initDerivative();
1126  result.element[run1] = element[run1]->AD_forward( Dim, varType, Component, seed1, nIS, &IS );
1127 
1128  for( run2 = 0; (int) run2 < nIS; run2++ ){
1129  if( IS[run2] != 0 ){
1130  delete IS[run2];
1131  }
1132  }
1133  if( IS != 0 )
1134  free(IS);
1135  }
1136 
1137  delete[] varType ;
1138  delete[] Component;
1139 
1140  for( run1 = 0; run1 < n; run1++ )
1141  delete seed1[run1];
1142 
1143  delete[] seed1;
1144 
1145  return result;
1146 }
1147 
1148 
1149 Expression Expression::getODEexpansion( const int &order, const int *arg ) const{
1150 
1151  IntermediateState coeff("", (int) dim, order+2 );
1152 
1153  VariableType *vType = new VariableType[dim*(order+1)+1];
1154  int *Comp = new int [dim*(order+1)+1];
1155  Operator **seed = new Operator* [dim*(order+1)+1];
1156 
1157  Operator **der = new Operator*[dim*(order+1)];
1158 
1159  vType[0] = VT_TIME;
1160  Comp [0] = 0 ;
1161  seed [0] = new DoubleConstant( 1.0 , NE_ONE );
1162 
1163  for( uint i=0; i<dim; i++ ){
1164  coeff(i,0) = Expression("",1,1,VT_DIFFERENTIAL_STATE,arg[i]);
1165  coeff(i,1) = operator()(i);
1166  vType[i+1] = VT_DIFFERENTIAL_STATE;
1167  Comp [i+1] = arg[i];
1168  seed [i+1] = coeff.element[(order+2)*i+1];
1169  der[i] = element[i]->clone();
1170  }
1171 
1172  int nIS = 0;
1173  TreeProjection **IS = 0;
1174 
1175  for( int j=0; j<order; j++ ){
1176  for( uint i=0; i<dim; i++ ){
1177  der[dim*j+i]->initDerivative();
1178  der[dim*(j+1)+i] = der[dim*j+i]->AD_forward( (j+1)*dim+1, vType, Comp, seed, nIS, &IS );
1179  }
1180  for( uint i=0; i<dim; i++ ){
1181  coeff(i,j+2) = *der[dim*(j+1)+i];
1182  vType[dim*(j+1)+i+1] = VT_INTERMEDIATE_STATE;
1183  Comp [dim*(j+1)+i+1] = coeff.element[(order+2)*i+j+1]->getGlobalIndex();
1184  seed [dim*(j+1)+i+1] = coeff.element[(order+2)*i+j+2];
1185  }
1186  }
1187 
1188  for( int run = 0; run < nIS; run++ ){
1189 
1190  if( IS[run] != 0 ) delete IS[run];
1191  }
1192  if( IS != 0 ) free(IS);
1193 
1194  delete[] vType;
1195  delete[] Comp;
1196  for( uint i=0; i<dim*(order+1); i++ ) delete der[i];
1197  delete[] der;
1198  delete seed[0];
1199  delete[] seed;
1200 
1201  return coeff;
1202 }
1203 
1204 
1205 
1206 Expression Expression::ADbackward( const Expression &arg, const Expression &seed ) const{
1207 
1208  int Dim = arg.getDim();
1209  int run1, run2;
1210 
1211  ASSERT( arg .isVariable() == BT_TRUE );
1212  ASSERT( seed.getDim () == getDim() );
1213 
1214  Expression result("", arg.getNumRows(), arg.getNumCols());
1215 
1216  VariableType *varType = new VariableType[Dim];
1217  int *Component = new int [Dim];
1218  Operator **iresult = new Operator* [Dim];
1219 
1220  for( run1 = 0; run1 < Dim; run1++ ){
1221  arg.element[run1]->isVariable(varType[run1],Component[run1]);
1222  }
1223 
1224  int nIS = 0;
1225  TreeProjection **IS = 0;
1226 
1227  for( run1 = 0; run1 < (int) getDim(); run1++ ){
1228 
1229  Operator *seed1 = seed.element[run1]->clone();
1230 
1231  for( run2 = 0; run2 < Dim; run2++ )
1232  iresult[run2] = new DoubleConstant(0.0,NE_ZERO);
1233 
1234  element[run1]->initDerivative();
1235  element[run1]->AD_backward( Dim, varType, Component, seed1, iresult, nIS, &IS );
1236 
1237  for( run2 = 0; run2 < Dim; run2++ ){
1238  Operator *sum = result.element[run2]->clone();
1239  delete result.element[run2];
1240  result.element[run2] = new Addition( sum->clone(), iresult[run2]->clone() );
1241  delete sum;
1242  delete iresult[run2];
1243  }
1244  }
1245 
1246 
1247  for( int run = 0; run < nIS; run++ ){
1248 
1249  if( IS[run] != 0 ) delete IS[run];
1250  }
1251  if( IS != 0 ) free(IS);
1252 
1253  delete[] iresult ;
1254  delete[] varType ;
1255  delete[] Component ;
1256 
1257  return result;
1258 }
1259 
1261  const Expression &S ,
1262  const Expression &l ,
1263  Expression *dfS,
1264  Expression *ldf ) const{
1265 
1266  int Dim = arg.getDim();
1267  ASSERT( (int) S.getNumRows() == Dim );
1268  ASSERT( (int) S.getNumRows() == (int) S.getNumCols() );
1269 
1270  IntermediateState H = ADsymmetric( arg, l, dfS, ldf );
1271  IntermediateState sum = zeros<double>(Dim,Dim);
1272  IntermediateState sum2 = zeros<double>(Dim,Dim);
1273 
1274  int i,j,k;
1275  for( i=0; i<Dim; i++ )
1276  for( j=0; j<Dim; j++ ){
1277  for( k=0; k<=i; k++ ){
1278  sum(i,j) += H(i,k)*S(k,j);
1279  }
1280  for( k=i+1; k<Dim; k++ ){
1281  sum(i,j) += H(k,i)*S(k,j);
1282  }
1283  }
1284 
1285  for( i=0; i<Dim; i++ )
1286  for( j=0; j<=i; j++ )
1287  for( k=0; k<Dim; k++ )
1288  sum2(i,j) += S(k,i)*sum(k,j);
1289 
1290  for( i=0; i<Dim; i++ )
1291  for( j=0; j<i; j++ )
1292  sum2(j,i) = sum2(i,j);
1293 
1294  if( dfS != 0 ) {
1295  // multiplication with the proper forward seeds:
1296  *dfS = *dfS*S;
1297  }
1298 
1299  return sum2;
1300 }
1301 
1302 
1304  const Expression &l ,
1305  Expression *dfS,
1306  Expression *ldf ) const{
1307 
1308  int Dim = arg.getDim();
1309  int nS = Dim;
1310  int run1, run2;
1311 
1312  Expression S = eye<double>(Dim);
1313 
1314  ASSERT( arg .isVariable() == BT_TRUE );
1315  ASSERT( l.getDim() == getDim() );
1316 
1317  Expression result( nS, nS );
1318 
1319  VariableType *varType = new VariableType[Dim];
1320  int *Component = new int [Dim];
1321  Operator **dS = new Operator* [nS];
1322  Operator **ld = new Operator* [Dim];
1323  Operator **H = new Operator* [nS*nS];
1324 
1325  for( run1 = 0; run1 < Dim; run1++ ){
1326  arg.element[run1]->isVariable(varType[run1],Component[run1]);
1327  }
1328 
1329  int nLIS = 0;
1330  int nSIS = 0;
1331  int nHIS = 0;
1332  TreeProjection **LIS = 0;
1333  TreeProjection **SIS = 0;
1334  TreeProjection **HIS = 0;
1335 
1336  Expression tmp((int) getDim(),Dim);
1337  Expression tmp2(Dim);
1338 
1339  for( run1 = 0; run1 < (int) getDim(); run1++ ){
1340 
1341  Operator *l1 = l.element[run1]->clone();
1342  Operator **S1 = new Operator*[Dim*nS];
1343 
1344  for( run2 = 0; run2 < Dim*nS; run2++ )
1345  S1[run2] = S.element[run2]->clone();
1346 
1347  for( run2 = 0; run2 < nS; run2++ )
1348  dS[run2] = new DoubleConstant(0.0,NE_ZERO);
1349 
1350  for( run2 = 0; run2 < Dim; run2++ )
1351  ld[run2] = new DoubleConstant(0.0,NE_ZERO);
1352 
1353  for( run2 = 0; run2 < nS*nS; run2++ )
1354  H[run2] = new DoubleConstant(0.0,NE_ZERO);
1355 
1356  element[run1]->initDerivative();
1357  element[run1]->AD_symmetric( Dim, varType, Component, l1, S1, nS, dS, ld, H, nLIS, &LIS, nSIS, &SIS, nHIS, &HIS );
1358 
1359  int run3 = 0;
1360 
1361  for( run2 = 0; run2 < nS; run2++ ){
1362  for( run3 = 0; run3 < run2; run3++ ){
1363  Operator *sum = result.element[run2*nS+run3]->clone();
1364  delete result.element[run2*nS+run3];
1365  delete result.element[run3*nS+run2];
1366  result.element[run2*nS+run3] = sum->myAdd( sum, H[run2*nS+run3] );
1367  result.element[run3*nS+run2] = sum->myAdd( sum, H[run2*nS+run3] );
1368  delete sum;
1369  }
1370  Operator *sum = result.element[run2*nS+run2]->clone();
1371  delete result.element[run2*nS+run2];
1372  result.element[run2*nS+run2] = sum->myAdd( sum, H[run2*nS+run2] );
1373  delete sum;
1374  }
1375 
1376  if( dfS != 0 ){
1377  for( run2 = 0; run2 < nS; run2++ ){
1378  delete tmp.element[run1*nS+run2];
1379  tmp.element[run1*nS+run2] = dS[run2]->clone();
1380  }
1381  }
1382 
1383  if( ldf != 0 ){
1384  for( run2 = 0; run2 < nS; run2++ ){
1385  Operator *sum = tmp2.element[run2]->clone();
1386  delete tmp2.element[run2];
1387  tmp2.element[run2] = sum->myAdd( sum, ld[run2] );
1388  delete sum;
1389  }
1390  }
1391 
1392  for( run2 = 0; run2 < Dim*nS; run2++ )
1393  delete S1[run2];
1394 
1395  for( run2 = 0; run2 < nS; run2++ )
1396  delete dS[run2];
1397 
1398  for( run2 = 0; run2 < Dim; run2++ )
1399  delete ld[run2];
1400 
1401  for( run2 = 0; run2 < nS*nS; run2++ )
1402  delete H[run2];
1403 
1404  delete[] S1;
1405  }
1406 
1407  if( dfS != 0 ) *dfS = tmp ;
1408  if( ldf != 0 ) *ldf = tmp2;
1409 
1410 
1411  for( int run = 0; run < nLIS; run++ ){
1412  if( LIS[run] != 0 ) delete LIS[run];
1413  }
1414  if( LIS != 0 ) free(LIS);
1415 
1416  for( int run = 0; run < nSIS; run++ ){
1417  if( SIS[run] != 0 ) delete SIS[run];
1418  }
1419  if( SIS != 0 ) free(SIS);
1420 
1421  for( int run = 0; run < nHIS; run++ ){
1422  if( HIS[run] != 0 ) delete HIS[run];
1423  }
1424  if( HIS != 0 ) free(HIS);
1425 
1426  delete[] dS ;
1427  delete[] ld ;
1428  delete[] H ;
1429  delete[] varType ;
1430  delete[] Component ;
1431 
1432  return result;
1433 }
1434 
1435 
1436 returnValue Expression::substitute( int idx, const Expression &arg ) const{
1437 
1438  ASSERT( arg.getDim() == 1 );
1439 
1440  uint i;
1441  for( i = 0; i < getDim(); i++ )
1442  if( element[i] != 0 ) element[i]->substitute( idx, arg.element[0] );
1443 
1444  return SUCCESSFUL_RETURN;
1445 }
1446 
1447 
1449 
1450  uint run1, run2;
1451  Expression tmp("", getNumRows(), getNumCols());
1452 
1453  for( run1 = 0; run1 < getNumRows(); run1++ ){
1454  for( run2 = 0; run2 < getNumCols(); run2++ ){
1455  delete tmp.element[run1*getNumCols()+run2];
1456  tmp.element[run1*getNumCols()+run2] = new Subtraction( new DoubleConstant(0.0,NE_ZERO),
1457  element[run1*getNumCols()+run2]->clone() );
1458  }
1459  }
1460  return tmp;
1461 }
1462 
1463 
1464 
1465 
1466 
1467 //
1468 // PROTECTED MEMBER FUNCTIONS:
1469 //
1470 
1471 void Expression::construct( VariableType variableType_, uint globalTypeID, uint nRows_, uint nCols_, const std::string &name_ ){
1472 
1473  nRows = nRows_ ;
1474  nCols = nCols_ ;
1475  dim = nRows*nCols ;
1476  variableType = variableType_;
1477  component = globalTypeID ;
1478  name = name_ ;
1479 
1480  uint i;
1481  element = (Operator**)calloc(dim,sizeof(Operator*));
1482 
1483  for( i = 0; i < dim; i++ ){
1484 
1485  switch( variableType ){
1486  case VT_UNKNOWN : element[i] = new DoubleConstant( 0.0, NE_ZERO ); break;
1487  case VT_INTERMEDIATE_STATE:
1488  element[i] = new TreeProjection( "" );
1489  break;
1490  default : element[i] = new Projection( variableType_, globalTypeID+i, "" ); break;
1491  }
1492  }
1493 }
1494 
1495 
1497 {
1498  nRows = rhs.nRows;
1499  nCols = rhs.nCols;
1500  dim = rhs.dim;
1501  variableType = rhs.variableType;
1502  component = rhs.component;
1503 
1504  uint i;
1505  element = (Operator**) calloc(dim, sizeof(Operator*));
1506 
1507  for (i = 0; i < dim; i++)
1508  {
1509  if (rhs.element[i] != 0)
1510  element[i] = rhs.element[i]->clone();
1511  else
1512  element[i] = 0;
1513  }
1514 
1515  // Name not copied?
1516 }
1517 
1519 {
1520  deleteAll();
1521  nRows = arg.getNumRows();
1522  nCols = arg.getNumCols();
1523  dim = nRows * nCols;
1525 
1526  element = (Operator**) calloc(dim, sizeof(Operator*));
1527 
1528  VariableType tt = VT_UNKNOWN;
1529  int comp = 0;
1530 
1531  for (uint i = 0; i < dim; i++)
1532  {
1533  arg.element[i]->isVariable(tt, comp);
1534  if (tt == VT_INTERMEDIATE_STATE)
1535  element[i] = arg.element[i]->clone();
1536  else
1537  {
1538  std::stringstream tmpName;
1539  if (name.empty() == false)
1540  {
1541  if (dim > 1)
1542  tmpName << name << "[" << i << "]";
1543  else
1544  tmpName << name;
1545  }
1546  TreeProjection tmp(tmpName.str());
1547  tmp.operator=(*(arg.element[i]));
1548  element[i] = tmp.clone();
1549  }
1550  }
1551  return *this;
1552 }
1553 
1554 
1556 
1557  uint i;
1558 
1559  for( i = 0; i < dim; i++ )
1560  if( element[i] != 0 )
1561  delete element[i];
1562 
1563  if( element != 0 ) free(element);
1564 }
1565 
1566 
1567 
1568 
1570 
1571  uint run1;
1572 
1573  for( run1 = 0; run1 < getDim(); run1++ )
1574  if( element[run1]->isDependingOn(type) == BT_TRUE )
1575  return BT_TRUE;
1576 
1577  return BT_FALSE;
1578 }
1579 
1580 
1581 
1583  ASSERT( e.getDim() ==1 );
1585 
1586  if( fabs(sum(0) - EPS) > 0 ) return BT_TRUE;
1587  return BT_FALSE;
1588 }
1589 
1591 
1592  ASSERT( idx < getDim() );
1593 
1594  Operator *tmp = element[idx]->passArgument();
1595  if( tmp == 0 ) tmp = element[idx];
1596 
1597  return tmp->clone();
1598 }
1599 
1600 
1602 
1603 // end of file.
VariableType variableType
Definition: expression.hpp:314
Operator * getOperatorClone(uint idx) const
virtual int getGlobalIndex() const
Definition: operator.cpp:103
virtual ~Expression()
Definition: expression.cpp:126
Expression getAtan() const
Definition: expression.cpp:733
BooleanType isVariable() const
Expression & operator-=(const Expression &arg)
Definition: expression.cpp:310
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
Expression getEntropy() const
Definition: expression.cpp:945
IntermediateState sqrt(const Expression &arg)
Expression getPow(const Expression &arg) const
Definition: expression.cpp:782
friend Expression operator+(const Expression &arg1, const Expression &arg2)
Definition: expression.cpp:298
Expression backwardDerivative(const Expression &arg1, const Expression &arg2)
returnValue substitute(int idx, const Expression &arg) const
Abstract base class for all scalar-valued symbolic operators.
Definition: operator.hpp:60
Expression ADsymmetric(const Expression &arg, const Expression &S, const Expression &l, Expression *dfS=0, Expression *ldf=0) const
Expression getCol(const uint &colIdx) const
Definition: expression.cpp:567
Implements the scalar sine operator within the symbolic operators family.
Definition: sin.hpp:55
virtual NeutralElement isOneOrZero() const =0
Expression operator-() const
Expression getRow(const uint &rowIdx) const
Definition: expression.cpp:533
BEGIN_NAMESPACE_ACADO const double EPS
Expression div(const Expression &arg) const
Definition: expression.cpp:474
Allows to pass back messages to the calling function.
DVector evaluate(const EvaluationPoint &x, const int &number=0)
Definition: function.cpp:520
Implements the scalar power operator within the symbolic operators family.
Definition: power.hpp:56
uint getNumCols() const
virtual Operator * clone() const =0
uint getNumRows() const
virtual Operator * substitute(int index, const Operator *sub)=0
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
Expression getCols(const uint &colIdx1, const uint &colIdx2) const
Definition: expression.cpp:582
void copy(const Expression &rhs)
Expression operator()(uint idx) const
Definition: expression.cpp:218
Expression getLogSumExp() const
Definition: expression.cpp:860
Expression getDot() const
Definition: expression.cpp:952
#define CLOSE_NAMESPACE_ACADO
Implements the scalar inverse tangens operator (arctan) within the symbolic operators family...
Definition: atan.hpp:55
std::ostream & print(std::ostream &stream) const
Definition: expression.cpp:198
Expression mul(const Expression &arg) const
Definition: expression.cpp:412
GenericMatrix< double > DMatrix
Definition: matrix.hpp:457
Expression sub(const Expression &arg) const
Definition: expression.cpp:350
VariableType
Definition: acado_types.hpp:95
Operator * product(const Operator *a, const Operator *b) const
Definition: expression.cpp:382
Expression getSqrt() const
Definition: expression.cpp:757
std::string name
Definition: expression.hpp:316
BooleanType isDependingOn(VariableType type) const
Expression & operator*=(const Expression &arg)
Definition: expression.cpp:313
Base class for all variables within the symbolic expressions family.
Definition: expression.hpp:56
Expression getPowInt(const int &arg) const
Definition: expression.cpp:797
virtual Operator * AD_forward(int dim, VariableType *varType, int *component, Operator **seed, int &nNewIS, TreeProjection ***newIS)=0
Expression getInverse() const
Definition: expression.cpp:490
Expression getExp() const
Definition: expression.cpp:745
virtual Expression * clone() const
Definition: expression.hpp:105
Expression getTan() const
Definition: expression.cpp:697
Expression getSumSquare() const
Definition: expression.cpp:828
Operator ** element
Definition: expression.hpp:311
Expression ADforward(const Expression &arg) const
Definition: expression.cpp:971
void construct(VariableType variableType_, uint globalTypeID_, uint nRows_, uint nCols_, const std::string &name_)
Implements the scalar cosine operator within the symbolic operators family.
Definition: cos.hpp:55
Expression getAsin() const
Definition: expression.cpp:709
Implements the scalar tangens operator within the symbolic operators family.
Definition: tan.hpp:55
Expression add(const Expression &arg) const
Definition: expression.cpp:319
unsigned getDim() const
Definition: vector.hpp:172
int getDim() const
Expression & operator<<(const Expression &arg)
Definition: expression.cpp:175
Implements the scalar power operator with integer exponent within the symbolic operators family...
Definition: powerint.hpp:55
Expression & operator=(const Expression &arg)
Definition: expression.cpp:131
Implements the scalar exponential operator within the symbolic operators family.
Definition: exp.hpp:55
#define E
DMatrix getDependencyPattern(const Expression &arg) const
Definition: expression.cpp:623
virtual returnValue AD_backward(int dim, VariableType *varType, int *component, Operator *seed, Operator **df, int &nNewIS, TreeProjection ***newIS)=0
virtual returnValue initDerivative()
Definition: operator.cpp:519
Expression & appendRows(const Expression &arg)
Definition: expression.cpp:141
Implements the scalar addition operator within the symbolic expressions family.
Definition: addition.hpp:54
Implements the scalar subtraction operator within the symbolic operators family.
Definition: subtraction.hpp:54
virtual returnValue initDerivative()
DMatrix getSparsityPattern() const
Definition: expression.cpp:656
virtual Operator * myAdd(Operator *a, Operator *b)
Definition: operator.cpp:246
friend Expression operator*(const Expression &arg1, const Expression &arg2)
Definition: expression.cpp:302
void rhs(const real_t *x, real_t *f)
Implements the projection operator within the symbolic operators family.
Definition: projection.hpp:55
uint component
Definition: expression.hpp:315
unsigned getNumRows() const
Definition: matrix.hpp:185
Expression transpose() const
Definition: expression.cpp:811
Expression getNext() const
Definition: expression.cpp:965
#define ASSERT(x)
#define BT_TRUE
Definition: acado_types.hpp:47
virtual BooleanType isVariable(VariableType &varType, int &component) const =0
Implements the scalar inverse sine operator (arcsin) within the symbolic operators family...
Definition: asin.hpp:55
friend Expression operator/(const Expression &arg1, const Expression &arg2)
Definition: expression.cpp:304
Implements the scalar quotient operator within the symbolic operators family.
Definition: quotient.hpp:55
unsigned getNumCols() const
Definition: matrix.hpp:189
virtual Operator * passArgument() const
Definition: operator.cpp:218
Expression & assignmentSetup(const Expression &arg)
void deleteAll()
Expression getODEexpansion(const int &order, const int *arg) const
GenericVector< T > sumRow() const
Definition: matrix.cpp:114
Expression getAcos() const
Definition: expression.cpp:721
IntermediateState ln(const Expression &arg)
virtual returnValue setCurvature(CurvatureType curvature_)=0
Implements the tree-projection operator within the family of SymbolicOperators.
CurvatureType
Expression getSin() const
Definition: expression.cpp:673
Implements the scalar inverse cosine operator (arccos) within the symbolic operators family...
Definition: acos.hpp:55
Expression getLn() const
Definition: expression.cpp:769
#define ACADOWARNING(retval)
Expression getSubMatrix(const uint &rowIdx1, const uint &rowIdx2, const uint &colIdx1, const uint &colIdx2) const
Definition: expression.cpp:601
#define BEGIN_NAMESPACE_ACADO
Implements the scalar logarithm operator within the symbolic operators family.
Definition: logarithm.hpp:55
Expression getEuclideanNorm() const
Definition: expression.cpp:912
#define BT_FALSE
Definition: acado_types.hpp:49
virtual CurvatureType getCurvature()=0
IntermediateState exp(const Expression &arg)
Expression ADbackward(const Expression &arg) const
Expression & operator+=(const Expression &arg)
Definition: expression.cpp:307
Expression & appendCols(const Expression &arg)
Definition: expression.cpp:162
Expression getCos() const
Definition: expression.cpp:685
Expression getRows(const uint &rowIdx1, const uint &rowIdx2) const
Definition: expression.cpp:548
virtual returnValue AD_symmetric(int dim, VariableType *varType, int *component, Operator *l, Operator **S, int dimS, Operator **dfS, Operator **ldf, Operator **H, int &nNewLIS, TreeProjection ***newLIS, int &nNewSIS, TreeProjection ***newSIS, int &nNewHIS, TreeProjection ***newHIS)=0
int getNumberOfVariables() const
Definition: function.cpp:264
Implements a scalar constant within the symbolic operators family.
Expression & operator/=(const Expression &arg)
Definition: expression.cpp:316
#define ACADOERROR(retval)
Implements the scalar product operator within the symbolic operators family.
Definition: product.hpp:55
uint getDim() const


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:34