diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 54d0af452e9e96dd938ea2db31741d4df851af0a..435448888fe4429f91e228d2491f0b4f6fd228cb 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -5229,39 +5229,6 @@ DynamicModel::substituteLeadLagInternal(AuxVarType type, bool deterministic_mode equation = substeq; } - // Substitute in aux_equations - // Without this loop, the auxiliary equations in equations - // will diverge from those in aux_equations - for (auto & aux_equation : aux_equations) - { - expr_t subst; - switch (type) - { - case AuxVarType::endoLead: - subst = aux_equation->substituteEndoLeadGreaterThanTwo(subst_table, - neweqs, deterministic_model); - break; - case AuxVarType::endoLag: - subst = aux_equation->substituteEndoLagGreaterThanTwo(subst_table, neweqs); - break; - case AuxVarType::exoLead: - subst = aux_equation->substituteExoLead(subst_table, neweqs, deterministic_model); - break; - case AuxVarType::exoLag: - subst = aux_equation->substituteExoLag(subst_table, neweqs); - break; - case AuxVarType::diffForward: - subst = aux_equation->differentiateForwardVars(subset, subst_table, neweqs); - break; - default: - cerr << "DynamicModel::substituteLeadLagInternal: impossible case" << endl; - exit(EXIT_FAILURE); - } - auto *substeq = dynamic_cast<BinaryOpNode *>(subst); - assert(substeq != nullptr); - aux_equation = substeq; - } - // Add new equations for (auto & neweq : neweqs) addEquation(neweq, -1); diff --git a/src/ModelTree.hh b/src/ModelTree.hh index 682fe0e1ef51a42c066fc1c83a12b32abaa44dbb..bee2defd9843db13924e8eace7d0eb08c6599d20 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -59,6 +59,15 @@ protected: vector<int> equations_lineno; //! Only stores generated auxiliary equations, in an order meaningful for evaluation + /*! These equations only contain the definition of auxiliary variables, and + may diverge from those in the main model (equations), if other model + transformations applied subsequently. This is not a problem, since + aux_equations is only used for regenerating the values of auxiliaries + given the others. + + For example, such a divergence appears when there is an expectation + operator in a ramsey model, see + tests/optimal_policy/nk_ramsey_expectation.mod */ deque<BinaryOpNode *> aux_equations; //! Stores equation tags