Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Arithmetic.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file src/numeric/expression_parser/Arithmetic.hh
11 /// @brief Parse tree for arithmetic operations
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_numeric_expression_parser_Arithmetic_HH
15 #define INCLUDED_numeric_expression_parser_Arithmetic_HH
16 
17 /// Unit headers
19 
20 /// Numeric headers
21 #include <numeric/types.hh>
22 
23 /// Utility headers
25 
26 /// C++ headers
27 #include <sstream>
28 #include <list>
29 #include <map>
30 
31 #include <utility/vector1.hh>
32 
33 
34 namespace numeric {
35 namespace expression_parser {
36 
37 enum TokenType {
49  //TERMINAL_SYMBOL
50 };
51 
52 std::string
54 
56 {
57 public:
58  /// @brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
59  virtual ~Token();
60  virtual
61  TokenType
62  type() const = 0;
63 
64  virtual
65  std::string
66  to_string() const = 0;
67 };
68 
69 class LiteralToken : public Token
70 {
71 public:
72  LiteralToken();
74 
75  virtual
76  TokenType
77  type() const;
78 
79  virtual
80  std::string
81  to_string() const;
82 
84  value() const;
85 
86  void
87  value( numeric::Real setting );
88 private:
90 
91 };
92 
93 class VariableToken : public Token
94 {
95 public:
96  VariableToken();
97  VariableToken( std::string const & name );
98 
99  virtual
100  TokenType
101  type() const;
102 
103  virtual
104  std::string
105  to_string() const;
106 
107  std::string name() const;
108  void name( std::string const & name );
109 private:
110  std::string name_;
111 };
112 
113 class FunctionToken : public Token
114 {
115 public:
116  FunctionToken();
117  FunctionToken( std::string const & name, numeric::Size nargs );
118 
119  virtual
120  TokenType
121  type() const;
122 
123  virtual
124  std::string
125  to_string() const;
126 
127  std::string name() const;
128  void name( std::string const & name );
129 
130  numeric::Size nargs() const;
131  void nargs( Size setting);
132 private:
133  std::string name_;
135 };
136 
137 class SimpleToken : public Token
138 {
139 public:
140  SimpleToken();
142 
143  virtual
144  TokenType
145  type() const;
146 
147  virtual
148  std::string
149  to_string() const;
150 
151  void
152  set_token_type( TokenType type );
153 
154 private:
156 };
157 
159 {
160 public:
161  /// @brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
162  virtual ~TokenSet();
163  TokenSet();
164 
165  void append( TokenCOP token );
166 
167  /// @brief Are there no more tokens remaining?
168  bool empty() const;
169 
170  TokenCOP top() const;
171 
172  void pop();
173 
174  /// @brief Print contents after parser has encountered an error.
175  void log_error() const;
176  std::string print() const;
177 protected:
178 
179  /// @brief in the event of an error message, print the tokens up to the current token.
180  void
181  print_to_curr_pos() const;
182 
183 private:
184  std::list< TokenCOP > tokens_;
185  std::list< TokenCOP >::iterator curr_pos_;
186 };
187 
189 {
190 public:
191  /// @brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
192  virtual ~ArithmeticScanner();
193  /// @brief Constructor which adds the "standard" set of min, max and sqrt functions.
195  /// @brief Constructor which does not add the "standard" set of min, max and sqrt functions.
196  ArithmeticScanner( bool );
197  /// @brief Add the functions min, max and sqrt.
198  void add_standard_functions();
199 
200  void add_variable( std::string const & name );
201  void add_function( std::string const & name, numeric::Size nargs );
202  TokenSetOP scan( std::string const & input_string );
203 
204 private:
205  LiteralTokenOP scan_literal( std::string const & input_string ) const;
206  TokenOP scan_identifier( std::string const & input_string ) const;
207 
208  /// @brief print the contents of functions_ and variables_ to std error
209  void log_error() const;
210 
211 private:
212  std::map< std::string, numeric::Size > functions_;
213  std::map< std::string, numeric::Size > variables_; // Size is a placeholder; the name string is the only important data.
214 
215 };
216 
218 {
219 public:
220  /// Simply adds more functions in its constructor so that
221  /// a mixture of boolean and arithmetic expressions may be scanned.
223 };
224 
225 ///////////////////////////////////////////
226 //// BEGIN ABSTRAT SYNTAX TREE CLASSES ////
227 ///////////////////////////////////////////
228 
229 
230 /// @brief Base class for Abstract Syntax Tree (AST) for the simple
231 /// Arithmetic language defined here.
233 {
234 public:
235  /// @brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
236  virtual ~ArithmeticASTNode();
237  virtual
238  void
239  visit( ASTVisitor & visitor ) const = 0;
240 };
241 
243 {
244 public:
245  virtual
246  void
247  visit( ASTVisitor & visitor ) const;
248 
249  virtual
250  void
251  parse( TokenSet & tokens );
252 
254  children_begin() const;
255 
257  children_end() const;
258 
259 private:
260  std::list< ArithmeticASTNodeCOP > children_;
261 
262 };
263 
265 {
266 public:
268 
269  virtual
270  void
271  visit( ASTVisitor & visitor ) const;
272 
273  virtual
274  void
275  parse( TokenSet & tokens );
276 
278  function() const;
279 
281  children_begin() const;
282 
284  children_end() const;
285 
286 private:
288  std::list< ArithmeticASTNodeCOP > children_;
289 
290 };
291 
293 {
294 public:
295  virtual
296  void
297  visit( ASTVisitor & visitor ) const;
298 
299  virtual
300  void
301  parse( TokenSet & tokens );
302 
304  children_begin() const;
305 
307  children_end() const;
308 
309 private:
310  std::list< ArithmeticASTNodeCOP > children_;
311 
312 };
313 
315 {
316 public:
318 
319  virtual
320  void
321  visit( ASTVisitor & visitor ) const;
322 
323  virtual
324  void
325  parse( TokenSet & tokens );
326 
328  child() const;
329 private:
331 
332 };
333 
334 /// @brief either a variable or a literal.
336 {
337 public:
340 
341  virtual
342  void
343  visit( ASTVisitor & visitor ) const;
344 
345  virtual
346  void
347  parse( TokenSet & tokens );
348 
349  bool is_literal() const;
351 
352  std::string variable_name() const;
353 
354 private:
357  std::string variable_name_;
358 };
359 
361 {
362 public:
364 
365  virtual
366  void
367  visit( ASTVisitor & visitor ) const;
368 
369  virtual
370  void
371  parse( TokenSet & tokens );
372 
374  children_begin() const;
375 
377  children_end() const;
378 
379  TokenType
380  rest_term_token() const;
381 
382 private:
384  std::list< ArithmeticASTNodeCOP > children_;
385 
386 };
387 
389 {
390 public:
392 
393  virtual
394  void
395  visit( ASTVisitor & visitor ) const;
396 
397  virtual
398  void
399  parse( TokenSet & tokens );
400 
402  children_begin() const;
403 
405  children_end() const;
406 
407  TokenType
408  rest_expression_token() const;
409 
410 private:
412  std::list< ArithmeticASTNodeCOP > children_;
413 
414 };
415 
416 /// @brief Double-dispatch visitor pattern for abstract syntax tree
418 {
419 public:
420  /// @brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
421  virtual ~ASTVisitor();
422 
423  virtual
424  void
425  visit( ArithmeticASTExpression const & ) = 0;
426 
427 
428  virtual
429  void
430  visit( ArithmeticASTFunction const & ) = 0;
431 
432  virtual
433  void
434  visit( ArithmeticASTTerm const & ) = 0;
435 
436  virtual
437  void
438  visit( ArithmeticASTFactor const & ) = 0;
439 
440  virtual
441  void
442  visit( ArithmeticASTValue const & ) = 0;
443 
444  virtual
445  void
446  visit( ArithmeticASTRestTerm const & ) = 0;
447 
448  virtual
449  void
450  visit( ArithmeticASTRestExpression const & ) = 0;
451 
452  virtual
453  void
454  visit( ArithmeticASTNode const & ) = 0;
455 
456 };
457 
458 /// Traverse the AST and print it to standard out
459 class ASTPrinter : public ASTVisitor
460 {
461 public:
462  ASTPrinter();
463 
464  virtual
465  void
466  visit( ArithmeticASTExpression const & );
467 
468 
469  virtual
470  void
471  visit( ArithmeticASTFunction const & );
472 
473  virtual
474  void
475  visit( ArithmeticASTTerm const & );
476 
477  virtual
478  void
479  visit( ArithmeticASTFactor const & );
480 
481  virtual
482  void
483  visit( ArithmeticASTValue const & );
484 
485  virtual
486  void
487  visit( ArithmeticASTRestTerm const & );
488 
489  virtual
490  void
492 
493  virtual
494  void
495  visit( ArithmeticASTNode const & );
496 
497  std::string
498  ast_string( ArithmeticASTNode const & node );
499 
500  void
501  pretty( bool setting );
502 
503 private:
504  void increment_indentation();
505  void decrement_indentation();
506  void indent_line();
507  void finish_indented_line();
508 
509 private:
510  bool pretty_;
512  std::ostringstream ostrstream_;
514 
515 };
516 
517 /// @brief Class to traverse the abstract syntax tree
518 /// produced by the parsing of a properly-formed string in the
519 /// Arithmetic expression language. Produces an Expression tree
520 /// capable of performing arithmetic. Connects the "variable" nodes
521 /// in this tree to the owning WrapperOptEMultifunc so that their
522 /// values can be retrieved during expression evaluation inside
523 /// the WrapperOptEMultifunc functor.
525 {
526 public:
529 
530  virtual
531  void
532  visit( ArithmeticASTExpression const & );
533 
534  virtual
535  void
536  visit( ArithmeticASTFunction const & );
537 
538  virtual
539  void
540  visit( ArithmeticASTTerm const & );
541 
542  virtual
543  void
544  visit( ArithmeticASTFactor const & );
545 
546  virtual
547  void
548  visit( ArithmeticASTValue const & );
549 
550  virtual
551  void
552  visit( ArithmeticASTRestTerm const & );
553 
554  virtual
555  void
557 
558  virtual
559  void
560  visit( ArithmeticASTNode const & );
561 
564 
565  /// @brief Factory method to be implemented by derived classes
566  /// which may wish to handle variable expressions in a specific manner
567  virtual
570 
571  /// @brief Factory method to be implemented by derived classes
572  /// which may wish to handle function expressions in a specific manner
573  virtual
576  FunctionTokenCOP function,
578  );
579 
580 private:
581 
582  /// Created inside a traversal of the AST -- return expression trees
583  /// using this variable, and keep living trees alive
584  /// by storing them on the stack during the AST recursive traversal.
587 
588 };
589 
591 {
592 public:
594  SimpleExpressionCreator( std::list< std::string > const & varnames );
595 
596  void
597  add_variable( std::string const & varname );
598 
599  virtual
602 
604  get_variable( std::string const & varname );
605 
606  std::map< std::string, VariableExpressionOP >
607  variables() const;
608 
609 private:
610  std::map< std::string, VariableExpressionOP > variables_;
611 
612 };
613 
615 {
616 public:
619 public:
621  BooleanExpressionCreator( std::list< std::string > const & varnames );
622 
623  virtual
626  FunctionTokenCOP function,
628  );
629 
630 };
631 
632 
633 ///////////////////////////////////////////
634 ///// END ABSTRAT SYNTAX TREE CLASSES /////
635 ///////////////////////////////////////////
636 
637 /// @brief Pure virtual base class to define arbitrary expressions for
638 /// scripting arithmetic operations (e.g. addition and multipliction).
640 {
641 public:
642  /// @brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
643  virtual ~Expression();
644 
645  virtual
647  operator() () const = 0;
648 
649  /// @brief Returns the expression for the partial derivative of this expression
650  /// by the variable named varname. If the partial derivative is always zero with respect
651  /// to varname, returns null.
652  virtual
654  differentiate( std::string const & varname ) const = 0;
655 
656  virtual
657  std::list< std::string >
658  active_variables() const = 0;
659 
660 };
661 
663 {
664 public:
667 
668  void set_value( numeric::Real value );
669 
670  virtual
672  operator() () const;
673 
674  /// @brief Returns null, since the derivative for a literal is always zero
675  virtual
677  differentiate( std::string const & varname ) const;
678 
679  virtual
680  std::list< std::string >
681  active_variables() const;
682 
683 private:
685 
686 };
687 
689 {
690 public:
691  VariableExpression( std::string const & name );
692  VariableExpression( std::string const & name, numeric::Real value );
693 
694  virtual
696  operator() () const;
697 
698  void set_value( numeric::Real value );
699 
700  std::string name() const;
701 
702  /// @brief Returns the literal expression 1 if name_ == varname_ and null otherwise
703  virtual
705  differentiate( std::string const & varname ) const;
706 
707  virtual
708  std::list< std::string >
709  active_variables() const;
710 
711 private:
712  std::string name_;
714 };
715 
716 
718 {
719 public:
720  UnaryExpression();
723 
724  void set_expression( ExpressionCOP ex );
725 
726  virtual
727  std::list< std::string >
728  active_variables() const;
729 
730 public:
731  ExpressionCOP ex() const;
732 
733 private:
735 
736 };
737 
739 {
740 public:
744 
747 
748  virtual
749  std::list< std::string >
750  active_variables() const;
751 
752 public:
753  ExpressionCOP e1() const;
754  ExpressionCOP e2() const;
755 
756 private:
759 
760 };
761 
763 {
764 public:
765  NaryExpression();
766  NaryExpression( utility::vector1< ExpressionCOP > const & expressions );
767 
768  //void set_expressions( utility::vector1< ExpressionCOP > const & expressions );
769  //Size size() const;
770  //ExpressionCOP get_expression( Size id ) const;
771 
772 private:
775 };
776 
778 {
779 public:
782 
783  virtual
785  operator() () const;
786 
787  virtual
789  differentiate( std::string const & varname ) const;
790 
791 };
792 
794 {
795 public:
798 
799  virtual
801  operator() () const;
802 
803  virtual
805  differentiate( std::string const & varname ) const;
806 
807 };
808 
810 {
811 public:
812  AddExpression();
814 
815  /// @brief Returns the sum of expression 1 and expression 2.
816  virtual
818  operator() () const;
819 
820  virtual
822  differentiate( std::string const & varname ) const;
823 
824 };
825 
827 {
828 public:
831 
832  /// @brief Returns the difference between expression 1 and expression 2.
833  virtual
835  operator() () const;
836 
837  virtual
839  differentiate( std::string const & varname ) const;
840 
841 };
842 
843 
845 {
846 public:
849 
850  /// @brief Returns the product of expression 1 and expression 2
851  virtual
853  operator() () const;
854 
855  virtual
857  differentiate( std::string const & varname ) const;
858 
859 };
860 
862 {
863 public:
866 
867  /// @brief Returns the quotient of expression 1 and expression 2
868  virtual
870  operator() () const;
871 
872  virtual
874  differentiate( std::string const & varname ) const;
875 
876 };
877 
879 {
880 public:
881  MaxExpression();
883 
884  /// @brief Returns the max of e1 and e2.
885  virtual
887  operator() () const;
888 
889  virtual
891  differentiate( std::string const & varname ) const;
892 
893  virtual
894  std::list< std::string >
895  active_variables() const;
896 
897 };
898 
900 {
901 public:
902  MinExpression();
904 
905  /// @brief Returns the min of e1 and e2
906  virtual
908  operator() () const;
909 
910  virtual
912  differentiate( std::string const & varname ) const;
913 
914  virtual
915  std::list< std::string >
916  active_variables() const;
917 
918 };
919 
920 
921 /// @brief Evaluates ee1 when e1 is larger than e2; evaluates ee2 otherwise.
923 {
924 public:
925  //MetaMaxExpression();
927 
928  virtual
930  operator() () const;
931 
932  virtual
934  differentiate( std::string const & varname ) const;
935 
936  virtual
937  std::list< std::string >
938  active_variables() const;
939 
940 private:
943 
944 };
945 
946 /// @brief Evaluates ee1 when e1 is less than e2; evaluates ee2 otherwise.
948 {
949 public:
950  //MetaMinExpression();
952 
953  virtual
955  operator() () const;
956 
957  virtual
959  differentiate( std::string const & varname ) const;
960 
961  virtual
962  std::list< std::string >
963  active_variables() const;
964 
965 private:
968 
969 };
970 
971 /// BEGIN PSEUDO-BOOLEAN EXPRESSIONS
972 /// DO NOT TRY TO DIFFERENTIATE THEM
973 /// 1. Arithmetic Comparison Operators
975 {
976 public:
979  virtual ~EqualsExpression();
980 
981  virtual
983  operator() () const;
984 
985  virtual
987  differentiate( std::string const & varname ) const;
988 
989 };
990 
991 /// Greater Than
993 {
994 public:
995  GT_Expression();
997  virtual ~GT_Expression();
998 
999  virtual
1001  operator() () const;
1002 
1003  virtual
1005  differentiate( std::string const & varname ) const;
1006 
1007 };
1008 
1009 /// Greater Than or Equal To
1011 {
1012 public:
1013  GTE_Expression();
1015  virtual ~GTE_Expression();
1016 
1017  virtual
1019  operator() () const;
1020 
1021  virtual
1023  differentiate( std::string const & varname ) const;
1024 
1025 };
1026 
1027 /// Less Than
1029 {
1030 public:
1031  LT_Expression();
1033  virtual ~LT_Expression();
1034 
1035  virtual
1037  operator() () const;
1038 
1039  virtual
1041  differentiate( std::string const & varname ) const;
1042 
1043 };
1044 
1045 /// Less Than or Equal To
1047 {
1048 public:
1049  LTE_Expression();
1051  virtual ~LTE_Expression();
1052 
1053  virtual
1055  operator() () const;
1056 
1057  virtual
1059  differentiate( std::string const & varname ) const;
1060 
1061 };
1062 
1063 
1064 /// 2. Boolean Logic Operators
1066 {
1067 public:
1068  AndExpression();
1070  virtual ~AndExpression();
1071 
1072  virtual
1074  operator() () const;
1075 
1076  virtual
1078  differentiate( std::string const & varname ) const;
1079 
1080 };
1081 
1083 {
1084 public:
1085  OrExpression();
1087  virtual ~OrExpression();
1088 
1089  virtual
1091  operator() () const;
1092 
1093  virtual
1095  differentiate( std::string const & varname ) const;
1096 
1097 };
1098 
1100 {
1101 public:
1102  NotExpression();
1104  virtual ~NotExpression();
1105 
1106  virtual
1108  operator() () const;
1109 
1110  virtual
1112  differentiate( std::string const & varname ) const;
1113 
1114 };
1115 
1117 {
1118 public:
1119 
1120  ITEExpression(
1122  ExpressionCOP then_clause,
1123  ExpressionCOP else_clause
1124  );
1125 
1126  virtual
1128  operator() () const;
1129 
1130  virtual
1132  differentiate( std::string const & varname ) const;
1133 
1135  condition() const;
1136 
1138  then_expression() const;
1139 
1141  else_expression() const;
1142 
1143  virtual
1144  std::list< std::string >
1145  active_variables() const;
1146 
1147 
1148 private:
1152 
1153 };
1154 
1155 
1157 parse_string_to_expression( std::string const & input_string );
1158 
1160 parse_string_to_boolean_expression( std::string const & input_string );
1161 
1162 
1163 }
1164 }
1165 
1166 #endif
1167 
virtual void visit(ASTVisitor &visitor) const
Definition: Arithmetic.cc:833
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1932
std::list< ArithmeticASTNodeCOP >::const_iterator children_begin() const
Definition: Arithmetic.cc:710
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:2135
utility::pointer::shared_ptr< Expression const > ExpressionCOP
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1965
std::string ast_string(ArithmeticASTNode const &node)
Definition: Arithmetic.cc:1098
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:1926
std::map< std::string, VariableExpressionOP > variables() const
Definition: Arithmetic.cc:1439
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1693
void add_variable(std::string const &varname)
Definition: Arithmetic.cc:1404
std::map< std::string, numeric::Size > functions_
Definition: Arithmetic.hh:212
utility::pointer::shared_ptr< Token const > TokenCOP
void log_error() const
print the contents of functions_ and variables_ to std error
Definition: Arithmetic.cc:529
virtual std::string to_string() const =0
std::list< ArithmeticASTNodeCOP >::const_iterator children_end() const
Definition: Arithmetic.cc:594
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:2045
platform::Size Size
Definition: types.hh:42
virtual std::string to_string() const
Definition: Arithmetic.cc:108
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1816
virtual ~TokenSet()
Automatically generated virtual destructor for class deriving directly from ReferenceCount.
Definition: Arithmetic.cc:48
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
virtual ExpressionCOP differentiate(std::string const &varname) const =0
Returns the expression for the partial derivative of this expression by the variable named varname...
ReferenceCount base class – dispatch class.
Double-dispatch visitor pattern for abstract syntax tree.
Definition: Arithmetic.hh:417
virtual void visit(ASTVisitor &visitor) const =0
bool empty() const
Are there no more tokens remaining?
Definition: Arithmetic.cc:228
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:1998
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns null, since the derivative for a literal is always zero.
Definition: Arithmetic.cc:1511
virtual void visit(ASTVisitor &visitor) const
Definition: Arithmetic.cc:688
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:2121
std::list< ArithmeticASTNodeCOP >::const_iterator children_begin() const
Definition: Arithmetic.cc:676
virtual numeric::Real operator()() const
Returns the difference between expression 1 and expression 2.
Definition: Arithmetic.cc:1715
virtual ~ArithmeticASTNode()
Automatically generated virtual destructor for class deriving directly from ReferenceCount.
Definition: Arithmetic.cc:42
std::list< ArithmeticASTNodeCOP > children_
Definition: Arithmetic.hh:260
virtual void visit(ASTVisitor &visitor) const
Definition: Arithmetic.cc:890
virtual void visit(ArithmeticASTExpression const &)
Definition: Arithmetic.cc:951
virtual ~ASTVisitor()
Automatically generated virtual destructor for class deriving directly from ReferenceCount.
Definition: Arithmetic.cc:39
std::map< std::string, VariableExpressionOP > variables_
Definition: Arithmetic.hh:610
void add_standard_functions()
Add the functions min, max and sqrt.
Definition: Arithmetic.cc:293
LiteralTokenOP scan_literal(std::string const &input_string) const
Definition: Arithmetic.cc:457
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1893
utility::vector1< ExpressionCOP > expressions_
Definition: Arithmetic.hh:774
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:1907
std::list< ArithmeticASTNodeCOP > children_
Definition: Arithmetic.hh:384
std::list< TokenCOP >::iterator curr_pos_
Definition: Arithmetic.hh:185
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:2018
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:1504
virtual TokenType type() const
Definition: Arithmetic.cc:159
virtual numeric::Real operator()() const
Returns the min of e1 and e2.
Definition: Arithmetic.cc:1844
TokenSetOP scan(std::string const &input_string)
Definition: Arithmetic.cc:340
utility::pointer::shared_ptr< Token > TokenOP
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:2103
Evaluates ee1 when e1 is larger than e2; evaluates ee2 otherwise.
Definition: Arithmetic.hh:922
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:1887
virtual ExpressionCOP handle_variable_expression(ArithmeticASTValue const &)
Factory method to be implemented by derived classes which may wish to handle variable expressions in ...
Definition: Arithmetic.cc:1414
virtual ExpressionCOP differentiate(std::string const &varname) const
Definition: Arithmetic.cc:1643
virtual std::string to_string() const
Definition: Arithmetic.cc:136
virtual TokenType type() const
Definition: Arithmetic.cc:102
virtual numeric::Real operator()() const =0
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:1590
Base class for reference-counted polymorphic classes.
Traverse the AST and print it to standard out.
Definition: Arithmetic.hh:459
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:2085
virtual void visit(ASTVisitor &visitor) const
Definition: Arithmetic.cc:724
member1 value
Definition: Tag.cc:296
virtual numeric::Real operator()() const
Returns the sum of expression 1 and expression 2.
Definition: Arithmetic.cc:1687
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:2038
utility::pointer::shared_ptr< ArithmeticASTNode const > ArithmeticASTNodeCOP
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:1517
std::list< ArithmeticASTNodeCOP > children_
Definition: Arithmetic.hh:310
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:2005
std::list< ArithmeticASTNodeCOP > children_
Definition: Arithmetic.hh:288
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:2059
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:1636
virtual void visit(ASTVisitor &visitor) const
Definition: Arithmetic.cc:773
virtual ExpressionCOP handle_variable_expression(ArithmeticASTValue const &)
Factory method to be implemented by derived classes which may wish to handle variable expressions in ...
Definition: Arithmetic.cc:1353
virtual void visit(ArithmeticASTExpression const &)
Definition: Arithmetic.cc:1146
utility::pointer::shared_ptr< TokenSet > TokenSetOP
std::string token_type_name(TokenType tt)
Definition: Arithmetic.cc:54
virtual void visit(ASTVisitor &visitor) const
Definition: Arithmetic.cc:604
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the literal expression 1 if name_ == varname_ and null otherwise.
Definition: Arithmetic.cc:1556
ExpressionCOP parse_string_to_boolean_expression(std::string const &input_string)
Definition: Arithmetic.cc:2181
virtual TokenType type() const =0
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
Class to traverse the abstract syntax tree produced by the parsing of a properly-formed string in the...
Definition: Arithmetic.hh:524
utility::pointer::shared_ptr< VariableExpression > VariableExpressionOP
virtual ExpressionCOP handle_function_expression(FunctionTokenCOP function, utility::vector1< ExpressionCOP > const &args)
Factory method to be implemented by derived classes which may wish to handle function expressions in ...
Definition: Arithmetic.cc:1452
virtual numeric::Real operator()() const
Returns the max of e1 and e2.
Definition: Arithmetic.cc:1810
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:1958
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:1537
ExpressionCOP parse_string_to_expression(std::string const &input_string)
Definition: Arithmetic.cc:2170
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1721
void log_error() const
Print contents after parser has encountered an error.
Definition: Arithmetic.cc:251
virtual numeric::Real operator()() const
Returns the product of expression 1 and expression 2.
Definition: Arithmetic.cc:1744
std::list< ArithmeticASTNodeCOP >::const_iterator children_begin() const
Definition: Arithmetic.cc:913
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1985
utility::pointer::shared_ptr< FunctionToken const > FunctionTokenCOP
ArithmeticScanner()
Constructor which adds the "standard" set of min, max and sqrt functions.
Definition: Arithmetic.cc:283
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:2066
std::list< ArithmeticASTNodeCOP >::const_iterator children_begin() const
Definition: Arithmetic.cc:588
ExpressionCOP create_expression_tree(ArithmeticASTExpression const &)
Definition: Arithmetic.cc:1342
virtual TokenType type() const
Definition: Arithmetic.cc:198
vector1: std::vector with 1-based indexing
virtual ~Expression()
Automatically generated virtual destructor for class deriving directly from ReferenceCount.
Definition: Arithmetic.cc:36
TokenOP scan_identifier(std::string const &input_string) const
Definition: Arithmetic.cc:496
virtual void parse(TokenSet &tokens)
Definition: Arithmetic.cc:730
either a variable or a literal.
Definition: Arithmetic.hh:335
std::list< ArithmeticASTNodeCOP >::const_iterator children_end() const
Definition: Arithmetic.cc:919
virtual void parse(TokenSet &tokens)
Definition: Arithmetic.cc:695
std::list< ArithmeticASTNodeCOP >::const_iterator children_end() const
Definition: Arithmetic.cc:716
virtual ~Token()
Automatically generated virtual destructor for class deriving directly from ReferenceCount.
Definition: Arithmetic.cc:51
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:2158
void add_function(std::string const &name, numeric::Size nargs)
Definition: Arithmetic.cc:317
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1750
virtual void visit(ArithmeticASTExpression const &)=0
virtual ExpressionCOP differentiate(std::string const &varname) const
Definition: Arithmetic.cc:1668
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:2097
virtual std::list< std::string > active_variables() const =0
std::list< ArithmeticASTNodeCOP >::const_iterator children_end() const
Definition: Arithmetic.cc:682
void add_variable(std::string const &name)
Definition: Arithmetic.cc:301
rule< Scanner, string_closure::context_t > name
Definition: Tag.cc:376
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1850
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:2025
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:1978
std::list< ArithmeticASTNodeCOP >::const_iterator children_end() const
Definition: Arithmetic.cc:864
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:1622
virtual std::string to_string() const
Definition: Arithmetic.cc:165
Parse tree for arithmetic operations class forward declarations.
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:1565
virtual ExpressionCOP handle_function_expression(FunctionTokenCOP function, utility::vector1< ExpressionCOP > const &args)
Factory method to be implemented by derived classes which may wish to handle function expressions in ...
Definition: Arithmetic.cc:1360
VariableExpressionOP get_variable(std::string const &varname)
Definition: Arithmetic.cc:1428
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:1867
MetaMinExpression(ExpressionCOP e1, ExpressionCOP e2, ExpressionCOP ee1, ExpressionCOP ee2)
Definition: Arithmetic.cc:1913
Base class for Abstract Syntax Tree (AST) for the simple Arithmetic language defined here...
Definition: Arithmetic.hh:232
virtual void parse(TokenSet &tokens)
Definition: Arithmetic.cc:779
void print_to_curr_pos() const
in the event of an error message, print the tokens up to the current token.
Definition: Arithmetic.cc:270
utility::pointer::shared_ptr< LiteralToken > LiteralTokenOP
std::list< ArithmeticASTNodeCOP >::const_iterator children_begin() const
Definition: Arithmetic.cc:858
MetaMaxExpression(ExpressionCOP e1, ExpressionCOP e2, ExpressionCOP ee1, ExpressionCOP ee2)
Evaluates ee1 when e1 is larger than e2; evaluates ee2 otherwise.
Definition: Arithmetic.cc:1874
ITEExpression(ExpressionCOP condition, ExpressionCOP then_clause, ExpressionCOP else_clause)
Definition: Arithmetic.cc:2110
Evaluates ee1 when e1 is less than e2; evaluates ee2 otherwise.
Definition: Arithmetic.hh:947
virtual ~ArithmeticScanner()
Automatically generated virtual destructor for class deriving directly from ReferenceCount.
Definition: Arithmetic.cc:45
virtual TokenType type() const
Definition: Arithmetic.cc:130
virtual void visit(ASTVisitor &visitor) const
EXPRESSION.
Definition: Arithmetic.cc:565
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:1946
virtual ExpressionCOP differentiate(std::string const &varname) const
Returns the expression for the partial derivative of this expression by the variable named varname...
Definition: Arithmetic.cc:1780
virtual numeric::Real operator()() const
Returns the quotient of expression 1 and expression 2.
Definition: Arithmetic.cc:1774
virtual std::list< std::string > active_variables() const
Definition: Arithmetic.cc:1833
virtual std::string to_string() const
Definition: Arithmetic.cc:204
std::map< std::string, numeric::Size > variables_
Definition: Arithmetic.hh:213
Pure virtual base class to define arbitrary expressions for scripting arithmetic operations (e...
Definition: Arithmetic.hh:639
virtual numeric::Real operator()() const
Definition: Arithmetic.cc:2078