PAC: correctly handle log() and diff() operators in the equation defining the target

By default, the preprocessor substitutes logs and diffs by auxiliary variables
only in equations of auxiliary models (VAR, PAC). Hence they are not
substituted in the equation defining the target, since it is outside the
auxiliary model.

The fix consists in doing the substitution in that equation as well, when we
parse the linear combination within that equation.

Ref. dynare#1837
last-simulation-period
Sébastien Villemot 2022-01-17 12:57:37 +01:00
parent 8c528f4f9a
commit f05b552f31
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 14 additions and 0 deletions

View File

@ -991,6 +991,20 @@ PacModelTable::transformPass(const lag_equivalence_table_t &unary_ops_nodes,
exit(EXIT_FAILURE);
}
// Substitute unary ops and diffs in that equation, before parsing (see dynare#1837)
target_expr = target_expr->substituteUnaryOpNodes(unary_ops_nodes, unary_ops_subst_table, neweqs);
if (neweqs.size() > 0)
{
cerr << "ERROR: the equation defining the target of 'pac_target_info(" << name << ")' contains a variable with a unary operator that is not present in the model" << endl;
exit(EXIT_FAILURE);
}
target_expr = target_expr->substituteDiff(diff_nodes, diff_subst_table, neweqs);
if (neweqs.size() > 0)
{
cerr << "ERROR: the equation defining the target of 'pac_target_info(" << name << ")' contains a diff'd variable that is not present in the model" << endl;
exit(EXIT_FAILURE);
}
// Parse that model equation
vector<pair<int, expr_t>> terms;
expr_t constant;