- ExprNode::maxLag() and ExprNode::maxLead() now take into account exogenous
deterministic variables, for consistency with M_.maximum_{lead,lag}
- ExprNode::maxLag() no longer behaves as if diff() operators were
expanded (i.e. it now returns 1 on diff(x(-1))), for consistency with
maxEndoLag() and maxExoLag()
- New ExprNode::maxLagWithDiffsExpanded() method, that behaves as maxLag() used
to behave (except that it also takes exogenous deterministic into account)
Previously, this function was counting the total number of diff() operators in
an expression. But this is not very useful, and is potentially misleading,
because in practice we use this function to compute the maximum lag on
variables in levels.
This function now returns the maximum number of nested diffs.
For example, on diff(x)+diff(diff(y)), this function was returning 3, and it
now returns 2.
The engine is now more robust and should reject any expression that does not
conform to the expected form. It is also able to deal with more cases, such as
terms appearing with a minus sign, or variables in the middle of a
three-factors product.
BTW, use a std::tuple for storing the result of the matching inside
PacExpectationNode, and change the order of components within the
structure (variable first, scalar last).
This facilitates switching variable types on the fly. In particular, this
allows removing the hack in DynamicModel::updateAfterVariableChange() that way
basically recreating all the nodes after the type change.
This was not conceptually an enum, but rather a collection of unrelated
constants:
- two constants for use as placeholder for symbol IDs at different places
- one constant for the default number of arguments
This mimicks the structure of M-functions (though the logic for filling the
temporary terms vector is a bit different).
This change implied a modification in the way we compute the checksum in case
of block decomposition (the temporary terms for the C output are not correctly
computed in that case).
- BTW, store them in a std::vector rather than std::list
- incidentally, fix issue in VariableNode::removeTrendLeadLag where expression
sharing was possibly violated when creating a new VariableNode
Given a previously declared var_model, the var_expectation_model statement is
used to declare a way of forming expectations with this VAR (possibly using a
finite or infinite discounted sum). The var_expectation operator now takes a
single argument, the name of the var_expectation_model.
For the moment, this only works when the var_model is using equations
explicitly declared in the model block.
In the absence of this option, if a var_model statement(s) is present, then aux vars/eqs are created for the same types of unary operators but only for equations specified in the var_model statement
In the absence of both this option and var_model statements, no unary op auxiliary variables are created
diffs continue to be substituted everywhere; for the moment auxiliary variables are created for diffs of expressions. A forthcoming change will allow auxiliary variables created for diffs of expressions to be linked with their lagged expressions as is currently the case for diffs of variables
Given that temporary terms are separated in several functions (residuals,
jacobian, …), we must make sure that all temporary terms derived from a given
external function call are assigned just after that call, and not in an other
function.
More precisely, remove those variants where temporary_terms can be specified
without temporary_terms_idxs, in order to make clear that the latter is
expected. For situations where the tt_idxs are not needed (C, block MATLAB), an
empty map has to be explicitly given.
Incidentally fix bug when a trinary operator becomes a temporary term with
block decomposition (without bytecode).
Also add a safety check to ensure that, if a temporary term is detected, its
index is indeed present in temporary_terms_idxs.
The version with no temporary_terms_idxs argument needs not be virtual, since
it is the same implementation in all derived classes. Rather move it at the
level of the base ExprNode class.
In the presence of MLVs, the temporary terms indexing was corrupted. The code
was using the implicit assumption that the ExprNodeLess ordering was giving the
same ordering as the temporary terms indexes ordering. But MLVs can be higher
in ExprNodeLess ordering than some other temporary terms, while they have the
lowest temporary terms index, hence the bug.
Fix this by no longer relying on the ExprNodeLess ordering, and rather use a
full map<ExprNode *, int> for ModelTree::temporary_terms_idxs. By the way,
simplify the code by removing a few useless data structures (e.g.
ModelTree::temporary_terms_idxs_*).