diff --git a/src/ExprNode.cc b/src/ExprNode.cc index a0a62ca41b88651fd5c4854f28d0caae244ba68f..f3f11156527bfb9789ad19e6626728d66974ac80 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -3109,74 +3109,6 @@ UnaryOpNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) diff_table[sthis][arg_max_lag] = const_cast<UnaryOpNode *>(this); } -void -UnaryOpNode::getDiffArgUnaryOperatorIfAny(string &op_handle) const -{ - switch (op_code) - { - case oExp: - op_handle = "@exp"; - break; - case oLog: - op_handle = "@log"; - break; - case oLog10: - op_handle = "@log10"; - break; - case oCos: - op_handle = "@cos"; - break; - case oSin: - op_handle = "@sin"; - break; - case oTan: - op_handle = "@tan"; - break; - case oAcos: - op_handle = "@acos"; - break; - case oAsin: - op_handle = "@asin"; - break; - case oAtan: - op_handle = "@atan"; - break; - case oCosh: - op_handle = "@cosh"; - break; - case oSinh: - op_handle = "@sinh"; - break; - case oTanh: - op_handle = "@tanh"; - break; - case oAcosh: - op_handle = "@acosh"; - break; - case oAsinh: - op_handle = "@asinh"; - break; - case oAtanh: - op_handle = "@atanh"; - break; - case oSqrt: - op_handle = "@sqrt"; - break; - case oAbs: - op_handle = "@abs"; - break; - case oSign: - op_handle = "@sign"; - break; - case oErf: - op_handle = "@erf"; - break; - default: - op_handle = ""; - break; - } -} - expr_t UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const @@ -3214,28 +3146,11 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst, vn->get_symb_id(), vn->get_lag()); else { - UnaryOpNode *diffarg = dynamic_cast<UnaryOpNode *>(argsubst); - if (diffarg != NULL) - { - string op; - diffarg->getDiffArgUnaryOperatorIfAny(op); - VariableNode *vnarg = dynamic_cast<VariableNode *>(diffarg->get_arg()); - if (vnarg != NULL) - symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst, - vnarg->get_symb_id(), vnarg->get_lag(), op); - else - { - // The case where we have diff(log(exp(x))) for example - cerr << "diffs of nested non-diff expressions are not yet supported" << endl; - exit(EXIT_FAILURE); - } - } - else - { - cerr << "diffs of non unary expressions are not yet supported" << endl; - exit(EXIT_FAILURE); - } + // We know that the supported unary ops have already been substituted + cerr << "you can only use the `diff` operator on variables and certain unary ops" << endl; + exit(EXIT_FAILURE); } + // make originating aux var & equation last_arg_max_lag = rit->first; last_aux_var = datatree.AddVariable(symb_id, 0); diff --git a/src/ExprNode.hh b/src/ExprNode.hh index 428ecc6cf64aee6b2330df6c65a2188107aa7eef..f96bd50cb3f2029a08eab67ec7c0f8d0a7eefb4c 100644 --- a/src/ExprNode.hh +++ b/src/ExprNode.hh @@ -790,7 +790,6 @@ public: virtual void findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const; bool createAuxVarForUnaryOpNodeInDiffOp() const; virtual void findUnaryOpNodesForAuxVarCreation(DataTree &static_datatree, diff_table_t &nodes) const; - void getDiffArgUnaryOperatorIfAny(string &op_handle) const; virtual expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const; virtual expr_t substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nodes, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const; virtual expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table); diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index 17cf1437a2295cae692fb96d99b9a63712a7e99d..a8f82f5d3299612e2e36cdd820a30551439519fd 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -25,20 +25,6 @@ #include "SymbolTable.hh" -AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg, int orig_lead_lag_arg, - int equation_number_for_multiplier_arg, int information_set_arg, - expr_t expr_node_arg, string &unary_op_handle_arg) : - symb_id(symb_id_arg), - type(type_arg), - orig_symb_id(orig_symb_id_arg), - orig_lead_lag(orig_lead_lag_arg), - equation_number_for_multiplier(equation_number_for_multiplier_arg), - information_set(information_set_arg), - expr_node(expr_node_arg), - unary_op_handle(unary_op_handle_arg) -{ -} - AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg, int orig_lead_lag_arg, int equation_number_for_multiplier_arg, int information_set_arg, expr_t expr_node_arg) : @@ -48,8 +34,7 @@ AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg orig_lead_lag(orig_lead_lag_arg), equation_number_for_multiplier(equation_number_for_multiplier_arg), information_set(information_set_arg), - expr_node(expr_node_arg), - unary_op_handle("") + expr_node(expr_node_arg) { } @@ -395,12 +380,6 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) if (aux_vars[i].get_orig_symb_id() >= 0) output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl << "M_.aux_vars(" << i+1 << ").orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl; - - output << "M_.aux_vars(" << i+1 << ").unary_op_handle = "; - if (!aux_vars[i].get_unary_op_handle().empty()) - output << aux_vars[i].get_unary_op_handle() << ";" << endl; - else - output << "'';" << endl; break; } } @@ -779,29 +758,6 @@ SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, i return symb_id; } -int -SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag, string &unary_op_handle) throw (FrozenException) -{ - ostringstream varname; - int symb_id; - - varname << "AUX_DIFF_" << index; - - try - { - symb_id = addSymbol(varname.str(), eEndogenous); - } - catch (AlreadyDeclaredException &e) - { - cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl; - exit(EXIT_FAILURE); - } - - aux_vars.push_back(AuxVarInfo(symb_id, avDiff, orig_symb_id, orig_lag, 0, 0, expr_arg, unary_op_handle)); - - return symb_id; -} - int SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException) { @@ -1166,7 +1122,7 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio case avDiffLag: if (aux_vars[i].get_orig_symb_id() >= 0) output << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) + 1 << ", " - << aux_vars[i].get_orig_lead_lag() << ", NaN, NaN," << aux_vars[i].get_unary_op_handle(); + << aux_vars[i].get_orig_lead_lag() << ", NaN, NaN"; break; case avMultiplier: output << "NaN, NaN, " << aux_vars[i].get_equation_number_for_multiplier() + 1 diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh index 1649f96349cc70f3a2eb1858db3ce26ae5f5b0cf..83056679d969132f7f391f09b51fc3ef15cac57d 100644 --- a/src/SymbolTable.hh +++ b/src/SymbolTable.hh @@ -60,10 +60,8 @@ private: int equation_number_for_multiplier; //!< Stores the original constraint equation number associated with this aux var. Only used for avMultiplier. int information_set; //! Argument of expectation operator. Only used for avExpectation. expr_t expr_node; //! Auxiliary variable definition - string unary_op_handle; //!Unary op potentially opplied to aux vars of type avDiff public: AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg, int information_set_arg, expr_t expr_node_arg); - AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg, int information_set_arg, expr_t expr_node_arg, string &unary_op_handle); int get_symb_id() const { @@ -99,11 +97,6 @@ public: { return expr_node; }; - string - get_unary_op_handle() const - { - return unary_op_handle; - } }; //! Stores the symbol table @@ -298,7 +291,6 @@ public: //! Adds an auxiliary variable when the diff operator is encountered int addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException); int addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) throw (FrozenException); - int addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag, string &unary_op_handle) throw (FrozenException); //! Takes care of timing between diff statements int addDiffLagAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) throw (FrozenException); //! An Auxiliary variable for a unary op