2008-02-03 11:28:36 +01:00
/*
2018-01-30 10:06:56 +01:00
* Copyright ( C ) 2007 - 2018 Dynare Team
2008-02-03 11:28:36 +01:00
*
* This file is part of Dynare .
*
* Dynare is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* Dynare is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with Dynare . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef _EXPR_NODE_HH
# define _EXPR_NODE_HH
# include <set>
# include <map>
# include <vector>
2009-07-06 12:36:36 +02:00
# include <ostream>
2018-05-29 17:07:18 +02:00
# include <functional>
2008-02-03 11:28:36 +01:00
2013-12-30 14:45:17 +01:00
using namespace std ;
2008-02-03 11:28:36 +01:00
# include "SymbolTable.hh"
# include "CodeInterpreter.hh"
2010-02-22 17:33:38 +01:00
# include "ExternalFunctionsTable.hh"
2016-11-18 16:52:13 +01:00
# include "SymbolList.hh"
2008-02-03 11:28:36 +01:00
class DataTree ;
2009-09-30 17:10:31 +02:00
class VariableNode ;
2018-03-02 12:32:01 +01:00
class UnaryOpNode ;
2009-09-30 17:10:31 +02:00
class BinaryOpNode ;
2018-02-07 10:05:32 +01:00
class PacExpectationNode ;
2008-02-03 11:28:36 +01:00
2018-06-04 14:07:13 +02:00
using expr_t = class ExprNode * ;
2008-02-03 11:28:36 +01:00
struct ExprNodeLess ;
//! Type for set of temporary terms
2018-05-28 15:50:29 +02:00
/*! The ExprNodeLess ordering is important for the temporary terms algorithm,
see the definition of ExprNodeLess */
2018-06-04 14:31:26 +02:00
using temporary_terms_t = set < expr_t , ExprNodeLess > ;
2018-03-27 17:14:30 +02:00
/*! Keeps track of array indices of temporary_terms for writing */
2018-06-04 14:31:26 +02:00
using temporary_terms_idxs_t = map < expr_t , int > ;
2009-04-17 18:26:23 +02:00
2009-12-16 14:21:31 +01:00
//! set of temporary terms used in a block
2018-06-04 14:07:13 +02:00
using temporary_terms_inuse_t = set < int > ;
2009-12-16 14:21:31 +01:00
2018-06-04 14:31:26 +02:00
using map_idx_t = map < int , int > ;
2008-02-03 11:28:36 +01:00
2009-04-30 15:14:33 +02:00
//! Type for evaluation contexts
/*! The key is a symbol id. Lags are assumed to be null */
2018-06-04 14:31:26 +02:00
using eval_context_t = map < int , double > ;
2009-04-30 15:14:33 +02:00
2010-03-04 16:40:07 +01:00
//! Type for tracking first/second derivative functions that have already been written as temporary terms
2018-06-04 14:31:26 +02:00
using deriv_node_temp_terms_t = map < pair < int , vector < expr_t > > , int > ;
2010-03-04 16:40:07 +01:00
2018-02-28 17:33:00 +01:00
//! Type for the substitution map used in the process of substitutitng diff expressions
2018-05-15 14:18:42 +02:00
//! diff_table[static_expr_t][lag] -> [dynamic_expr_t]
2018-06-04 14:31:26 +02:00
using diff_table_t = map < expr_t , map < int , expr_t > > ;
2018-02-28 17:33:00 +01:00
2008-02-03 11:28:36 +01:00
//! Possible types of output when writing ExprNode(s)
enum ExprNodeOutputType
{
2010-09-20 17:04:38 +02:00
oMatlabStaticModel , //!< Matlab code, static model
oMatlabDynamicModel , //!< Matlab code, dynamic model
oMatlabStaticModelSparse , //!< Matlab code, static block decomposed model
oMatlabDynamicModelSparse , //!< Matlab code, dynamic block decomposed model
oCDynamicModel , //!< C code, dynamic model
2011-08-18 12:44:11 +02:00
oCStaticModel , //!< C code, static model
2015-07-27 15:33:38 +02:00
oJuliaStaticModel , //!< Julia code, static model
2015-07-27 17:02:51 +02:00
oJuliaDynamicModel , //!< Julia code, dynamic model
2010-03-09 16:40:52 +01:00
oMatlabOutsideModel , //!< Matlab code, outside model block (for example in initval)
2010-09-20 17:04:38 +02:00
oLatexStaticModel , //!< LaTeX code, static model
oLatexDynamicModel , //!< LaTeX code, dynamic model
oLatexDynamicSteadyStateOperator , //!< LaTeX code, dynamic model, inside a steady state operator
oMatlabDynamicSteadyStateOperator , //!< Matlab code, dynamic model, inside a steady state operator
oMatlabDynamicSparseSteadyStateOperator , //!< Matlab code, dynamic block decomposed model, inside a steady state operator
oCDynamicSteadyStateOperator , //!< C code, dynamic model, inside a steady state operator
2015-07-27 17:02:51 +02:00
oJuliaDynamicSteadyStateOperator , //!< Julia code, dynamic model, inside a steady state operator
2015-07-28 17:27:56 +02:00
oSteadyStateFile , //!< Matlab code, in the generated steady state file
2018-03-02 17:50:35 +01:00
oJuliaSteadyStateFile , //!< Julia code, in the generated steady state file
oMatlabDseries //!< Matlab code for dseries
2008-02-03 11:28:36 +01:00
} ;
2009-04-30 15:14:33 +02:00
# define IS_MATLAB(output_type) ((output_type) == oMatlabStaticModel \
| | ( output_type ) = = oMatlabDynamicModel \
| | ( output_type ) = = oMatlabOutsideModel \
| | ( output_type ) = = oMatlabStaticModelSparse \
2009-09-10 22:09:16 +02:00
| | ( output_type ) = = oMatlabDynamicModelSparse \
2009-12-16 18:13:23 +01:00
| | ( output_type ) = = oMatlabDynamicSteadyStateOperator \
2010-09-20 17:04:38 +02:00
| | ( output_type ) = = oMatlabDynamicSparseSteadyStateOperator \
2018-03-02 17:50:35 +01:00
| | ( output_type ) = = oSteadyStateFile \
| | ( output_type ) = = oMatlabDseries )
2009-04-30 15:14:33 +02:00
2017-06-01 19:58:32 +02:00
# define IS_JULIA(output_type) ((output_type) == oJuliaStaticModel \
| | ( output_type ) = = oJuliaDynamicModel \
2016-05-19 21:32:19 +02:00
| | ( output_type ) = = oJuliaDynamicSteadyStateOperator \
| | ( output_type ) = = oJuliaSteadyStateFile )
2015-07-27 17:02:51 +02:00
2017-06-01 19:58:32 +02:00
# define IS_C(output_type) ((output_type) == oCDynamicModel \
| | ( output_type ) = = oCStaticModel \
2018-07-17 16:52:11 +02:00
| | ( output_type ) = = oCDynamicSteadyStateOperator )
2009-04-30 15:14:33 +02:00
# define IS_LATEX(output_type) ((output_type) == oLatexStaticModel \
2009-12-16 18:13:23 +01:00
| | ( output_type ) = = oLatexDynamicModel \
| | ( output_type ) = = oLatexDynamicSteadyStateOperator )
2008-02-03 11:28:36 +01:00
2015-08-21 16:44:55 +02:00
/* Equal to 1 for Matlab langage or Julia, or to 0 for C language. Not defined for LaTeX.
In Matlab and Julia , array indexes begin at 1 , while they begin at 0 in C */
# define ARRAY_SUBSCRIPT_OFFSET(output_type) ((int) (IS_MATLAB(output_type) || IS_JULIA(output_type)))
2008-02-03 11:28:36 +01:00
2009-04-30 15:14:33 +02:00
// Left and right array subscript delimiters: '(' and ')' for Matlab, '[' and ']' for C
# define LEFT_ARRAY_SUBSCRIPT(output_type) (IS_MATLAB(output_type) ? '(' : '[')
# define RIGHT_ARRAY_SUBSCRIPT(output_type) (IS_MATLAB(output_type) ? ')' : ']')
2008-02-03 11:28:36 +01:00
2009-04-30 15:14:33 +02:00
// Left and right parentheses
# define LEFT_PAR(output_type) (IS_LATEX(output_type) ? "\\left(" : "(")
# define RIGHT_PAR(output_type) (IS_LATEX(output_type) ? "\\right)" : ")")
2008-02-03 11:28:36 +01:00
//! Base class for expression nodes
2018-02-07 10:05:32 +01:00
class ExprNode
2017-06-01 19:58:32 +02:00
{
friend class DataTree ;
friend class DynamicModel ;
friend class StaticModel ;
friend class ModelTree ;
friend struct ExprNodeLess ;
friend class NumConstNode ;
friend class VariableNode ;
friend class UnaryOpNode ;
friend class BinaryOpNode ;
friend class TrinaryOpNode ;
friend class AbstractExternalFunctionNode ;
friend class VarExpectationNode ;
2018-01-30 16:33:16 +01:00
friend class PacExpectationNode ;
2017-06-01 19:58:32 +02:00
private :
//! Computes derivative w.r. to a derivation ID (but doesn't store it in derivatives map)
/*! You shoud use getDerivative() to get the benefit of symbolic a priori and of caching */
virtual expr_t computeDerivative ( int deriv_id ) = 0 ;
protected :
//! Reference to the enclosing DataTree
DataTree & datatree ;
//! Index number
int idx ;
//! Is the data member non_null_derivatives initialized ?
bool preparedForDerivation ;
//! Set of derivation IDs with respect to which the derivative is potentially non-null
set < int > non_null_derivatives ;
//! Used for caching of first order derivatives (when non-null)
map < int , expr_t > derivatives ;
2018-07-17 16:32:00 +02:00
const static int min_cost_matlab { 40 * 90 } ;
const static int min_cost_c { 40 * 4 } ;
inline static int min_cost ( bool is_matlab ) { return ( is_matlab ? min_cost_matlab : min_cost_c ) ; } ;
2017-06-01 19:58:32 +02:00
//! Cost of computing current node
/*! Nodes included in temporary_terms are considered having a null cost */
virtual int cost ( int cost , bool is_matlab ) const ;
virtual int cost ( const temporary_terms_t & temporary_terms , bool is_matlab ) const ;
virtual int cost ( const map < NodeTreeReference , temporary_terms_t > & temp_terms_map , bool is_matlab ) const ;
//! For creating equation cross references
struct EquationInfo
{
2018-06-04 14:17:36 +02:00
set < pair < int , int > > param ;
set < pair < int , int > > endo ;
set < pair < int , int > > exo ;
set < pair < int , int > > exo_det ;
2017-06-01 19:58:32 +02:00
} ;
2018-05-25 14:50:08 +02:00
//! If this node is a temporary term, writes its temporary term representation
/*! Returns true if node is a temporary term and has therefore been
written to output */
bool checkIfTemporaryTermThenWrite ( ostream & output , ExprNodeOutputType output_type ,
const temporary_terms_t & temporary_terms ,
const temporary_terms_idxs_t & temporary_terms_idxs ) const ;
2017-06-01 19:58:32 +02:00
public :
ExprNode ( DataTree & datatree_arg ) ;
virtual
~ ExprNode ( ) ;
//! Initializes data member non_null_derivatives
virtual void prepareForDerivation ( ) = 0 ;
//! Returns derivative w.r. to derivation ID
/*! Uses a symbolic a priori to pre-detect null derivatives, and caches the result for other derivatives (to avoid computing it several times)
For an equal node , returns the derivative of lhs minus rhs */
expr_t getDerivative ( int deriv_id ) ;
//! Computes derivatives by applying the chain rule for some variables
/*!
\ param deriv_id The derivation ID with respect to which we are derivating
\ param recursive_variables Contains the derivation ID for which chain rules must be applied . Keys are derivation IDs , values are equations of the form x = f ( y ) where x is the key variable and x doesn ' t appear in y
*/
virtual expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) = 0 ;
//! Returns precedence of node
/*! Equals 100 for constants, variables, unary ops, and temporary terms */
virtual int precedence ( ExprNodeOutputType output_t , const temporary_terms_t & temporary_terms ) const ;
//! Fills temporary_terms set, using reference counts
/*! A node will be marked as a temporary term if it is referenced at least two times (i.e. has at least two parents), and has a computing cost (multiplied by reference count) greater to datatree.min_cost */
2018-06-04 14:17:36 +02:00
virtual void computeTemporaryTerms ( map < expr_t , pair < int , NodeTreeReference > > & reference_count ,
2017-06-01 19:58:32 +02:00
map < NodeTreeReference , temporary_terms_t > & temp_terms_map ,
bool is_matlab , NodeTreeReference tr ) const ;
//! Writes output of node, using a Txxx notation for nodes in temporary_terms, and specifiying the set of already written external functions
/*!
\ param [ in ] output the output stream
\ param [ in ] output_type the type of output ( MATLAB , C , LaTeX . . . )
\ param [ in ] temporary_terms the nodes that are marked as temporary terms
2018-05-29 11:12:22 +02:00
\ param [ in ] a map from temporary_terms to integers indexes ( in the
MATLAB or Julia vector of temporary terms ) ; can be empty
when writing C or MATLAB with block decomposition )
2018-05-29 11:59:42 +02:00
\ param [ in ] tef_terms the set of already written external function nodes
2017-06-01 19:58:32 +02:00
*/
2018-05-29 11:59:42 +02:00
virtual void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const = 0 ;
2017-06-01 19:58:32 +02:00
//! returns true if the expr node contains an external function
virtual bool containsExternalFunction ( ) const = 0 ;
//! Writes output of node (with no temporary terms and with "outside model" output type)
void writeOutput ( ostream & output ) const ;
//! Writes output of node (with no temporary terms)
void writeOutput ( ostream & output , ExprNodeOutputType output_type ) const ;
//! Writes output of node, using a Txxx notation for nodes in temporary_terms
2018-03-27 17:14:30 +02:00
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs ) const ;
2017-06-01 19:58:32 +02:00
2017-06-14 07:01:31 +02:00
//! Writes output of node in JSON syntax
2018-05-29 11:59:42 +02:00
virtual void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic = true ) const = 0 ;
2017-06-14 07:01:31 +02:00
virtual int precedenceJson ( const temporary_terms_t & temporary_terms ) const ;
2017-06-01 19:58:32 +02:00
//! Writes the output for an external function, ensuring that the external function is called as few times as possible using temporary terms
virtual void writeExternalFunctionOutput ( ostream & output , ExprNodeOutputType output_type ,
const temporary_terms_t & temporary_terms ,
2018-03-27 17:14:30 +02:00
const temporary_terms_idxs_t & temporary_terms_idxs ,
2017-06-01 19:58:32 +02:00
deriv_node_temp_terms_t & tef_terms ) const ;
2017-06-14 07:01:31 +02:00
//! Write the JSON output of an external function in a string vector
//! Allows the insertion of commas if necessary
virtual void writeJsonExternalFunctionOutput ( vector < string > & efout ,
const temporary_terms_t & temporary_terms ,
2017-10-16 17:24:55 +02:00
deriv_node_temp_terms_t & tef_terms ,
const bool isdynamic = true ) const ;
2017-06-14 07:01:31 +02:00
2017-06-01 19:58:32 +02:00
virtual void compileExternalFunctionOutput ( ostream & CompileCode , unsigned int & instruction_number ,
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
deriv_node_temp_terms_t & tef_terms ) const ;
//! Computes the set of all variables of a given symbol type in the expression (with information on lags)
/*!
Variables are stored as integer pairs of the form ( symb_id , lag ) .
They are added to the set given in argument .
Note that model local variables are substituted by their expression in the computation
( and added if type_arg = ModelLocalVariable ) .
*/
2018-06-04 14:17:36 +02:00
virtual void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const = 0 ;
2017-06-01 19:58:32 +02:00
2018-05-16 12:17:06 +02:00
//! Find lowest lag for VAR
virtual int VarMinLag ( ) const = 0 ;
2018-04-16 13:50:31 +02:00
//! Find the maximum lag in a VAR: handles case where LHS is diff
2018-06-11 10:40:00 +02:00
virtual int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const = 0 ;
2018-04-16 13:50:31 +02:00
//! Finds LHS variable in a VAR equation
virtual void collectVARLHSVariable ( set < expr_t > & result ) const = 0 ;
2017-06-01 19:58:32 +02:00
//! Computes the set of all variables of a given symbol type in the expression (without information on lags)
/*!
Variables are stored as symb_id .
They are added to the set given in argument .
Note that model local variables are substituted by their expression in the computation
( and added if type_arg = ModelLocalVariable ) .
*/
void collectVariables ( SymbolType type_arg , set < int > & result ) const ;
//! Computes the set of endogenous variables in the expression
/*!
Endogenous are stored as integer pairs of the form ( type_specific_id , lag ) .
They are added to the set given in argument .
Note that model local variables are substituted by their expression in the computation .
*/
2018-06-04 14:17:36 +02:00
virtual void collectEndogenous ( set < pair < int , int > > & result ) const ;
2017-06-01 19:58:32 +02:00
//! Computes the set of exogenous variables in the expression
/*!
Exogenous are stored as integer pairs of the form ( type_specific_id , lag ) .
They are added to the set given in argument .
Note that model local variables are substituted by their expression in the computation .
*/
2018-06-04 14:17:36 +02:00
virtual void collectExogenous ( set < pair < int , int > > & result ) const ;
2017-06-01 19:58:32 +02:00
virtual void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const = 0 ;
virtual void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2017-06-01 19:58:32 +02:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2017-06-01 19:58:32 +02:00
int equation ) const ;
class EvalException
{
} ;
class EvalExternalFunctionException : public EvalException
{
} ;
2018-06-04 12:50:53 +02:00
virtual double eval ( const eval_context_t & eval_context ) const noexcept ( false ) = 0 ;
2018-05-29 11:59:42 +02:00
virtual void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic , const deriv_node_temp_terms_t & tef_terms ) const = 0 ;
2017-06-01 19:58:32 +02:00
void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ) const ;
//! Creates a static version of this node
/*!
This method duplicates the current node by creating a similar node from which all leads / lags have been stripped ,
adds the result in the static_datatree argument ( and not in the original datatree ) , and returns it .
*/
virtual expr_t toStatic ( DataTree & static_datatree ) const = 0 ;
/*!
Compute cross references for equations
*/
// virtual void computeXrefs(set<int> ¶m, set<int> &endo, set<int> &exo, set<int> &exo_det) const = 0;
virtual void computeXrefs ( EquationInfo & ei ) const = 0 ;
//! Try to normalize an equation linear in its endogenous variable
2018-06-04 14:17:36 +02:00
virtual pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const = 0 ;
2017-06-01 19:58:32 +02:00
//! Returns the maximum lead of endogenous in this expression
/*! Always returns a non-negative value */
virtual int maxEndoLead ( ) const = 0 ;
//! Returns the maximum lead of exogenous in this expression
/*! Always returns a non-negative value */
virtual int maxExoLead ( ) const = 0 ;
//! Returns the maximum lag of endogenous in this expression
/*! Always returns a non-negative value */
virtual int maxEndoLag ( ) const = 0 ;
//! Returns the maximum lag of exogenous in this expression
/*! Always returns a non-negative value */
virtual int maxExoLag ( ) const = 0 ;
//! Returns the relative period of the most forward term in this expression
/*! A negative value means that the expression contains only lagged variables */
virtual int maxLead ( ) const = 0 ;
2018-02-28 17:33:00 +01:00
//! Returns the relative period of the most backward term in this expression
/*! A negative value means that the expression contains only leaded variables */
virtual int maxLag ( ) const = 0 ;
2018-03-28 18:46:15 +02:00
//! Get Max lag of var associated with Pac model
//! Takes account of undiffed LHS variables in calculating the max lag
2018-08-13 12:12:20 +02:00
virtual int PacMaxLag ( int lhs_symb_id ) const = 0 ;
2018-03-28 18:46:15 +02:00
2018-04-17 15:17:28 +02:00
virtual expr_t undiff ( ) const = 0 ;
2017-06-01 19:58:32 +02:00
//! Returns a new expression where all the leads/lags have been shifted backwards by the same amount
/*!
Only acts on endogenous , exogenous , exogenous det
\ param [ in ] n The number of lags by which to shift
\ return The same expression except that leads / lags have been shifted backwards
*/
virtual expr_t decreaseLeadsLags ( int n ) const = 0 ;
//! Type for the substitution map used in the process of creating auxiliary vars for leads >= 2
2018-06-04 14:31:26 +02:00
using subst_table_t = map < const ExprNode * , const VariableNode * > ;
2017-06-01 19:58:32 +02:00
2018-02-28 17:33:00 +01:00
//! Type for the substitution map used in the process of substituting adl expressions
2018-06-04 14:31:26 +02:00
using subst_table_adl_t = map < const ExprNode * , const expr_t > ;
2017-06-12 14:56:44 +02:00
2017-06-01 19:58:32 +02:00
//! Creates auxiliary endo lead variables corresponding to this expression
/*!
If maximum endogenous lead > = 3 , this method will also create intermediary auxiliary var , and will add the equations of the form aux1 = aux2 ( + 1 ) to the substitution table .
\ pre This expression is assumed to have maximum endogenous lead > = 2
\ param [ in , out ] subst_table The table to which new auxiliary variables and their correspondance will be added
\ param [ out ] neweqs Equations to be added to the model to match the creation of auxiliary variables .
\ return The new variable node corresponding to the current expression
*/
VariableNode * createEndoLeadAuxiliaryVarForMyself ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const ;
//! Creates auxiliary exo lead variables corresponding to this expression
/*!
If maximum exogenous lead > = 2 , this method will also create intermediary auxiliary var , and will add the equations of the form aux1 = aux2 ( + 1 ) to the substitution table .
\ pre This expression is assumed to have maximum exogenous lead > = 1
\ param [ in , out ] subst_table The table to which new auxiliary variables and their correspondance will be added
\ param [ out ] neweqs Equations to be added to the model to match the creation of auxiliary variables .
\ return The new variable node corresponding to the current expression
*/
VariableNode * createExoLeadAuxiliaryVarForMyself ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const ;
//! Constructs a new expression where sub-expressions with max endo lead >= 2 have been replaced by auxiliary variables
/*!
\ param [ in , out ] subst_table Map used to store expressions that have already be substituted and their corresponding variable , in order to avoid creating two auxiliary variables for the same sub - expr .
\ param [ out ] neweqs Equations to be added to the model to match the creation of auxiliary variables .
If the method detects a sub - expr which needs to be substituted , two cases are possible :
- if this expr is in the table , then it will use the corresponding variable and return the substituted expression
- if this expr is not in the table , then it will create an auxiliary endogenous variable , add the substitution in the table and return the substituted expression
\ return A new equivalent expression where sub - expressions with max endo lead > = 2 have been replaced by auxiliary variables
*/
virtual expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const = 0 ;
//! Constructs a new expression where endo variables with max endo lag >= 2 have been replaced by auxiliary variables
/*!
\ param [ in , out ] subst_table Map used to store expressions that have already be substituted and their corresponding variable , in order to avoid creating two auxiliary variables for the same sub - expr .
\ param [ out ] neweqs Equations to be added to the model to match the creation of auxiliary variables .
*/
virtual expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const = 0 ;
//! Constructs a new expression where exogenous variables with a lead have been replaced by auxiliary variables
/*!
\ param [ in , out ] subst_table Map used to store expressions that have already be substituted and their corresponding variable , in order to avoid creating two auxiliary variables for the same sub - expr .
\ param [ out ] neweqs Equations to be added to the model to match the creation of auxiliary variables .
*/
virtual expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const = 0 ;
//! Constructs a new expression where exogenous variables with a lag have been replaced by auxiliary variables
/*!
\ param [ in , out ] subst_table Map used to store expressions that have already be substituted and their corresponding variable , in order to avoid creating two auxiliary variables for the same sub - expr .
\ param [ out ] neweqs Equations to be added to the model to match the creation of auxiliary variables .
*/
virtual expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const = 0 ;
//! Constructs a new expression where the expectation operator has been replaced by auxiliary variables
/*!
\ param [ in , out ] subst_table Map used to store expressions that have already be substituted and their corresponding variable , in order to avoid creating two auxiliary variables for the same sub - expr .
\ param [ out ] neweqs Equations to be added to the model to match the creation of auxiliary variables .
\ param [ in ] partial_information_model Are we substituting in a partial information model ?
*/
virtual expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const = 0 ;
virtual expr_t decreaseLeadsLagsPredeterminedVariables ( ) const = 0 ;
//! Constructs a new expression where forward variables (supposed to be at most in t+1) have been replaced by themselves at t, plus a new aux var representing their (time) differentiate
/*!
\ param [ in ] subset variables to which to limit the transformation ; transform
all fwrd vars if empty
\ param [ in , out ] subst_table Map used to store mapping between a given
forward variable and the aux var that contains its differentiate
\ param [ out ] neweqs Equations to be added to the model to match the creation of auxiliary variables .
*/
virtual expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const = 0 ;
//! Return true if the nodeID is a numerical constant equal to value and false otherwise
/*!
\ param [ in ] value of the numerical constante
\ param [ out ] the boolean equal to true if NodeId is a constant equal to value
*/
virtual bool isNumConstNodeEqualTo ( double value ) const = 0 ;
//! Returns true if the expression contains one or several endogenous variable
2018-06-04 12:40:37 +02:00
virtual bool containsEndogenous ( ) const = 0 ;
2017-06-01 19:58:32 +02:00
//! Returns true if the expression contains one or several exogenous variable
virtual bool containsExogenous ( ) const = 0 ;
2018-05-31 15:34:25 +02:00
//! Returns the number of diffs present
virtual int countDiffs ( ) const = 0 ;
2018-02-08 13:07:15 +01:00
2017-06-01 19:58:32 +02:00
//! Return true if the nodeID is a variable withe a type equal to type_arg, a specific variable id aqual to varfiable_id and a lag equal to lag_arg and false otherwise
/*!
\ param [ in ] the type ( type_arg ) , specifique variable id ( variable_id and the lag ( lag_arg )
\ param [ out ] the boolean equal to true if NodeId is the variable
*/
virtual bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const = 0 ;
//! Replaces the Trend var with datatree.One
virtual expr_t replaceTrendVar ( ) const = 0 ;
//! Constructs a new expression where the variable indicated by symb_id has been detrended
/*!
\ param [ in ] symb_id indicating the variable to be detrended
\ param [ in ] log_trend indicates if the trend is in log
\ param [ in ] trend indicating the trend
\ return the new binary op pointing to a detrended variable
*/
virtual expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const = 0 ;
2018-01-30 10:06:56 +01:00
//! Substitute adl operator
virtual expr_t substituteAdl ( ) const = 0 ;
2018-08-01 19:41:44 +02:00
//! Substitute VarExpectation nodes
virtual expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const = 0 ;
2018-01-30 10:06:56 +01:00
//! Substitute diff operator
2018-03-02 12:32:01 +01:00
virtual void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const = 0 ;
2018-05-30 16:48:08 +02:00
virtual void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const = 0 ;
2018-04-17 15:17:28 +02:00
virtual expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const = 0 ;
2018-05-30 16:48:08 +02:00
virtual expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const = 0 ;
2017-06-12 14:56:44 +02:00
2018-01-30 16:33:16 +01:00
//! Substitute pac_expectation operator
2018-02-07 13:49:57 +01:00
virtual expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) = 0 ;
2018-01-30 16:33:16 +01:00
2017-06-01 19:58:32 +02:00
//! Add ExprNodes to the provided datatree
virtual expr_t cloneDynamic ( DataTree & dynamic_datatree ) const = 0 ;
//! Move a trend variable with lag/lead to time t by dividing/multiplying by its growth factor
virtual expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const = 0 ;
//! Returns true if the expression is in static form (no lead, no lag, no expectation, no STEADY_STATE)
virtual bool isInStaticForm ( ) const = 0 ;
//! Substitute auxiliary variables by their expression in static model
virtual expr_t substituteStaticAuxiliaryVariable ( ) const = 0 ;
//! Returns true if model_info_name is referenced by a VarExpectationNode
virtual bool isVarModelReferenced ( const string & model_info_name ) const = 0 ;
2018-02-12 17:37:53 +01:00
//! Fills parameter information related to PAC equation
2018-08-09 16:14:40 +02:00
virtual void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const = 0 ;
//! Fills info for non optimizing part of PAC equation
virtual void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const = 0 ;
//! Returns true if expression is of the form:
//! param * (endog op endog op ...) + param * (endog op endog op ...) + ...
virtual bool isParamTimesEndogExpr ( ) const = 0 ;
//! Finds the share of optimizing agents in the PAC equation,
//! the expr node associated with it,
//! and the expr node associated with the non-optimizing part
virtual void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const = 0 ;
2018-02-12 17:37:53 +01:00
//! Adds PAC equation param info to pac_expectation
2018-08-13 17:00:47 +02:00
virtual void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) = 0 ;
2018-02-12 17:37:53 +01:00
2018-01-30 16:33:16 +01:00
//! Fills var_model info for pac_expectation node
2018-08-13 12:12:20 +02:00
virtual void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) = 0 ;
2018-01-30 16:33:16 +01:00
2018-06-05 18:38:53 +02:00
//! Returns true if PacExpectationNode encountered
2018-08-13 12:12:20 +02:00
virtual bool containsPacExpectation ( const string & pac_model_name = " " ) const = 0 ;
2018-06-05 18:38:53 +02:00
2017-06-01 19:58:32 +02:00
//! Fills map
virtual void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const = 0 ;
} ;
2008-02-03 11:28:36 +01:00
//! Object used to compare two nodes (using their indexes)
2018-05-28 15:50:29 +02:00
/*! Note that in this ordering, a subexpression is always less than the
expression from which it is extracted . This property is used extensively in
the temporary terms computations . */
2008-02-03 11:28:36 +01:00
struct ExprNodeLess
{
2009-12-16 18:13:23 +01:00
bool
2010-09-16 19:18:45 +02:00
operator ( ) ( expr_t arg1 , expr_t arg2 ) const
2008-02-03 11:28:36 +01:00
{
return arg1 - > idx < arg2 - > idx ;
}
} ;
//! Numerical constant node
/*! The constant is necessarily non-negative (this is enforced at the NumericalConstants class level) */
class NumConstNode : public ExprNode
{
private :
//! Id from numerical constants table
const int id ;
2018-06-04 12:53:26 +02:00
expr_t computeDerivative ( int deriv_id ) override ;
2008-02-03 11:28:36 +01:00
public :
NumConstNode ( DataTree & datatree_arg , int id_arg ) ;
2009-12-16 18:13:23 +01:00
int
get_id ( ) const
{
return id ;
} ;
2018-06-04 12:53:26 +02:00
void prepareForDerivation ( ) override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
bool containsExternalFunction ( ) const override ;
void collectVARLHSVariable ( set < expr_t > & result ) const override ;
2018-06-04 14:17:36 +02:00
void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const override ;
2018-06-04 12:53:26 +02:00
void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const override ;
double eval ( const eval_context_t & eval_context ) const noexcept ( false ) override ;
void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic , const deriv_node_temp_terms_t & tef_terms ) const override ;
expr_t toStatic ( DataTree & static_datatree ) const override ;
void computeXrefs ( EquationInfo & ei ) const override ;
2018-06-04 14:17:36 +02:00
pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const override ;
2018-06-04 12:53:26 +02:00
expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) override ;
int maxEndoLead ( ) const override ;
int maxExoLead ( ) const override ;
int maxEndoLag ( ) const override ;
int maxExoLag ( ) const override ;
int maxLead ( ) const override ;
int maxLag ( ) const override ;
int VarMinLag ( ) const override ;
2018-06-11 10:40:00 +02:00
int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const override ;
2018-08-13 12:12:20 +02:00
int PacMaxLag ( int lhs_symb_id ) const override ;
2018-06-04 12:53:26 +02:00
expr_t undiff ( ) const override ;
expr_t decreaseLeadsLags ( int n ) const override ;
expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const override ;
expr_t substituteAdl ( ) const override ;
2018-08-01 19:41:44 +02:00
expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const override ;
2018-06-04 12:53:26 +02:00
void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const override ;
void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const override ;
expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) override ;
expr_t decreaseLeadsLagsPredeterminedVariables ( ) const override ;
expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
bool isNumConstNodeEqualTo ( double value ) const override ;
bool containsEndogenous ( ) const override ;
bool containsExogenous ( ) const override ;
int countDiffs ( ) const override ;
bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const override ;
expr_t replaceTrendVar ( ) const override ;
expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const override ;
bool isInStaticForm ( ) const override ;
2018-08-13 17:00:47 +02:00
void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) override ;
2018-08-13 12:12:20 +02:00
void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) override ;
2018-08-09 16:14:40 +02:00
bool containsPacExpectation ( const string & pac_model_name = " " ) const override ;
void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const override ;
void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const override ;
void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const override ;
bool isParamTimesEndogExpr ( ) const override ;
2018-06-04 12:53:26 +02:00
bool isVarModelReferenced ( const string & model_info_name ) const override ;
void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const override ;
expr_t substituteStaticAuxiliaryVariable ( ) const override ;
2008-02-03 11:28:36 +01:00
} ;
//! Symbol or variable node
class VariableNode : public ExprNode
{
2011-01-13 18:08:26 +01:00
friend class UnaryOpNode ;
2008-02-03 11:28:36 +01:00
private :
//! Id from the symbol table
const int symb_id ;
2008-10-17 12:20:19 +02:00
const SymbolType type ;
2010-08-19 15:20:54 +02:00
//! A positive value is a lead, a negative is a lag
2008-02-03 11:28:36 +01:00
const int lag ;
2018-06-04 12:53:26 +02:00
expr_t computeDerivative ( int deriv_id ) override ;
2008-02-03 11:28:36 +01:00
public :
2009-09-30 17:10:31 +02:00
VariableNode ( DataTree & datatree_arg , int symb_id_arg , int lag_arg ) ;
2018-06-04 12:53:26 +02:00
void prepareForDerivation ( ) override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
bool containsExternalFunction ( ) const override ;
void collectVARLHSVariable ( set < expr_t > & result ) const override ;
2018-06-04 14:17:36 +02:00
void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const override ;
2018-06-04 12:53:26 +02:00
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2010-09-16 19:00:48 +02:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2009-01-23 11:59:37 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const override ;
double eval ( const eval_context_t & eval_context ) const noexcept ( false ) override ;
void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic , const deriv_node_temp_terms_t & tef_terms ) const override ;
expr_t toStatic ( DataTree & static_datatree ) const override ;
void computeXrefs ( EquationInfo & ei ) const override ;
2010-07-23 11:20:24 +02:00
SymbolType
get_type ( ) const
{
return type ;
} ;
2009-12-16 18:13:23 +01:00
int
get_symb_id ( ) const
{
return symb_id ;
} ;
2017-06-01 19:58:32 +02:00
int
get_lag ( ) const
{
return lag ;
} ;
2018-06-04 14:17:36 +02:00
pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const override ;
2018-06-04 12:53:26 +02:00
expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) override ;
int maxEndoLead ( ) const override ;
int maxExoLead ( ) const override ;
int maxEndoLag ( ) const override ;
int maxExoLag ( ) const override ;
int maxLead ( ) const override ;
int maxLag ( ) const override ;
int VarMinLag ( ) const override ;
2018-06-11 10:40:00 +02:00
int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const override ;
2018-08-13 12:12:20 +02:00
int PacMaxLag ( int lhs_symb_id ) const override ;
2018-06-04 12:53:26 +02:00
expr_t undiff ( ) const override ;
expr_t decreaseLeadsLags ( int n ) const override ;
expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const override ;
expr_t substituteAdl ( ) const override ;
2018-08-01 19:41:44 +02:00
expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const override ;
2018-06-04 12:53:26 +02:00
void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const override ;
void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const override ;
expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) override ;
expr_t decreaseLeadsLagsPredeterminedVariables ( ) const override ;
expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
bool isNumConstNodeEqualTo ( double value ) const override ;
bool containsEndogenous ( ) const override ;
bool containsExogenous ( ) const override ;
int countDiffs ( ) const override ;
bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const override ;
expr_t replaceTrendVar ( ) const override ;
expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const override ;
bool isInStaticForm ( ) const override ;
2018-08-13 17:00:47 +02:00
void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) override ;
2018-08-13 12:12:20 +02:00
void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) override ;
bool containsPacExpectation ( const string & pac_model_name = " " ) const override ;
2018-08-09 16:14:40 +02:00
void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const override ;
void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const override ;
void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const override ;
bool isParamTimesEndogExpr ( ) const override ;
2018-06-04 12:53:26 +02:00
bool isVarModelReferenced ( const string & model_info_name ) const override ;
void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const override ;
2016-03-18 14:55:14 +01:00
//! Substitute auxiliary variables by their expression in static model
2018-06-04 12:53:26 +02:00
expr_t substituteStaticAuxiliaryVariable ( ) const override ;
2008-02-03 11:28:36 +01:00
} ;
//! Unary operator node
class UnaryOpNode : public ExprNode
{
private :
2010-09-16 19:18:45 +02:00
const expr_t arg ;
2009-11-06 19:19:52 +01:00
//! Stores the information set. Only used for expectation operator
const int expectation_information_set ;
2018-07-18 16:18:26 +02:00
//! Only used for UnaryOpcode::steadyStateParamDeriv and UnaryOpcode::steadyStateParam2ndDeriv
2011-01-13 18:08:26 +01:00
const int param1_symb_id , param2_symb_id ;
2008-02-03 11:28:36 +01:00
const UnaryOpcode op_code ;
2017-07-03 16:38:44 +02:00
const string adl_param_name ;
2017-07-03 17:21:11 +02:00
const vector < int > adl_lags ;
2018-06-04 12:53:26 +02:00
expr_t computeDerivative ( int deriv_id ) override ;
int cost ( int cost , bool is_matlab ) const override ;
int cost ( const temporary_terms_t & temporary_terms , bool is_matlab ) const override ;
int cost ( const map < NodeTreeReference , temporary_terms_t > & temp_terms_map , bool is_matlab ) const override ;
2009-07-06 11:34:21 +02:00
//! Returns the derivative of this node if darg is the derivative of the argument
2011-01-13 18:08:26 +01:00
expr_t composeDerivatives ( expr_t darg , int deriv_id ) ;
2008-02-03 11:28:36 +01:00
public :
2018-06-04 12:31:07 +02:00
UnaryOpNode ( DataTree & datatree_arg , UnaryOpcode op_code_arg , const expr_t arg_arg , int expectation_information_set_arg , int param1_symb_id_arg , int param2_symb_id_arg , string adl_param_name_arg , vector < int > adl_lags_arg ) ;
2018-06-04 12:53:26 +02:00
void prepareForDerivation ( ) override ;
2018-06-04 14:17:36 +02:00
void computeTemporaryTerms ( map < expr_t , pair < int , NodeTreeReference > > & reference_count ,
2015-09-03 13:50:02 +02:00
map < NodeTreeReference , temporary_terms_t > & temp_terms_map ,
2018-06-04 12:53:26 +02:00
bool is_matlab , NodeTreeReference tr ) const override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
bool containsExternalFunction ( ) const override ;
void writeExternalFunctionOutput ( ostream & output , ExprNodeOutputType output_type ,
2010-09-16 19:00:48 +02:00
const temporary_terms_t & temporary_terms ,
2018-03-27 17:14:30 +02:00
const temporary_terms_idxs_t & temporary_terms_idxs ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonExternalFunctionOutput ( vector < string > & efout ,
2017-02-20 12:18:11 +01:00
const temporary_terms_t & temporary_terms ,
2017-10-16 17:24:55 +02:00
deriv_node_temp_terms_t & tef_terms ,
2018-06-04 12:53:26 +02:00
const bool isdynamic ) const override ;
void compileExternalFunctionOutput ( ostream & CompileCode , unsigned int & instruction_number ,
2010-12-10 11:50:27 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2010-09-16 19:00:48 +02:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2008-02-03 11:28:36 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
void collectVARLHSVariable ( set < expr_t > & result ) const override ;
2018-06-04 14:17:36 +02:00
void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const override ;
2018-06-04 12:53:26 +02:00
void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const override ;
2018-06-04 12:50:53 +02:00
static double eval_opcode ( UnaryOpcode op_code , double v ) noexcept ( false ) ;
2018-06-04 12:53:26 +02:00
double eval ( const eval_context_t & eval_context ) const noexcept ( false ) override ;
void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic , const deriv_node_temp_terms_t & tef_terms ) const override ;
2009-04-14 16:39:53 +02:00
//! Returns operand
2010-09-16 19:18:45 +02:00
expr_t
2009-12-16 18:13:23 +01:00
get_arg ( ) const
{
return ( arg ) ;
} ;
2009-04-14 16:39:53 +02:00
//! Returns op code
2009-12-16 18:13:23 +01:00
UnaryOpcode
get_op_code ( ) const
{
return ( op_code ) ;
} ;
2018-06-04 12:53:26 +02:00
expr_t toStatic ( DataTree & static_datatree ) const override ;
void computeXrefs ( EquationInfo & ei ) const override ;
2018-06-04 14:17:36 +02:00
pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const override ;
2018-06-04 12:53:26 +02:00
expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) override ;
int maxEndoLead ( ) const override ;
int maxExoLead ( ) const override ;
int maxEndoLag ( ) const override ;
int maxExoLag ( ) const override ;
int maxLead ( ) const override ;
int maxLag ( ) const override ;
int VarMinLag ( ) const override ;
2018-06-11 10:40:00 +02:00
int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const override ;
2018-08-13 12:12:20 +02:00
int PacMaxLag ( int lhs_symb_id ) const override ;
2018-06-04 12:53:26 +02:00
expr_t undiff ( ) const override ;
expr_t decreaseLeadsLags ( int n ) const override ;
expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
2009-09-30 17:10:31 +02:00
//! Creates another UnaryOpNode with the same opcode, but with a possibly different datatree and argument
2010-09-16 19:18:45 +02:00
expr_t buildSimilarUnaryOpNode ( expr_t alt_arg , DataTree & alt_datatree ) const ;
2018-06-04 12:53:26 +02:00
expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const override ;
expr_t substituteAdl ( ) const override ;
2018-08-01 19:41:44 +02:00
expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const override ;
2018-06-04 12:53:26 +02:00
void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const override ;
2018-06-07 12:53:00 +02:00
bool createAuxVarForUnaryOpNode ( ) const ;
2018-06-04 12:53:26 +02:00
void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const override ;
expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) override ;
expr_t decreaseLeadsLagsPredeterminedVariables ( ) const override ;
expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
bool isNumConstNodeEqualTo ( double value ) const override ;
bool containsEndogenous ( ) const override ;
bool containsExogenous ( ) const override ;
int countDiffs ( ) const override ;
bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const override ;
expr_t replaceTrendVar ( ) const override ;
expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const override ;
bool isInStaticForm ( ) const override ;
2018-08-13 17:00:47 +02:00
void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) override ;
2018-08-13 12:12:20 +02:00
void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) override ;
bool containsPacExpectation ( const string & pac_model_name = " " ) const override ;
2018-08-09 16:14:40 +02:00
void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const override ;
void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const override ;
void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const override ;
bool isParamTimesEndogExpr ( ) const override ;
2018-06-04 12:53:26 +02:00
bool isVarModelReferenced ( const string & model_info_name ) const override ;
void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const override ;
2016-03-18 14:55:14 +01:00
//! Substitute auxiliary variables by their expression in static model
2018-06-04 12:53:26 +02:00
expr_t substituteStaticAuxiliaryVariable ( ) const override ;
2008-02-03 11:28:36 +01:00
} ;
//! Binary operator node
class BinaryOpNode : public ExprNode
{
private :
2010-09-16 19:18:45 +02:00
const expr_t arg1 , arg2 ;
2008-02-03 11:28:36 +01:00
const BinaryOpcode op_code ;
2018-06-04 12:53:26 +02:00
expr_t computeDerivative ( int deriv_id ) override ;
int cost ( int cost , bool is_matlab ) const override ;
int cost ( const temporary_terms_t & temporary_terms , bool is_matlab ) const override ;
int cost ( const map < NodeTreeReference , temporary_terms_t > & temp_terms_map , bool is_matlab ) const override ;
2009-07-06 11:34:21 +02:00
//! Returns the derivative of this node if darg1 and darg2 are the derivatives of the arguments
2010-09-16 19:18:45 +02:00
expr_t composeDerivatives ( expr_t darg1 , expr_t darg2 ) ;
2010-12-13 14:07:05 +01:00
const int powerDerivOrder ;
2017-06-23 18:01:07 +02:00
const string adlparam ;
2008-02-03 11:28:36 +01:00
public :
2010-09-16 19:18:45 +02:00
BinaryOpNode ( DataTree & datatree_arg , const expr_t arg1_arg ,
BinaryOpcode op_code_arg , const expr_t arg2_arg ) ;
2010-12-13 14:07:05 +01:00
BinaryOpNode ( DataTree & datatree_arg , const expr_t arg1_arg ,
BinaryOpcode op_code_arg , const expr_t arg2_arg , int powerDerivOrder ) ;
2018-06-04 12:53:26 +02:00
void prepareForDerivation ( ) override ;
int precedenceJson ( const temporary_terms_t & temporary_terms ) const override ;
int precedence ( ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms ) const override ;
2018-06-04 14:17:36 +02:00
void computeTemporaryTerms ( map < expr_t , pair < int , NodeTreeReference > > & reference_count ,
2015-09-03 13:50:02 +02:00
map < NodeTreeReference , temporary_terms_t > & temp_terms_map ,
2018-06-04 12:53:26 +02:00
bool is_matlab , NodeTreeReference tr ) const override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
bool containsExternalFunction ( ) const override ;
void writeExternalFunctionOutput ( ostream & output , ExprNodeOutputType output_type ,
2010-09-16 19:00:48 +02:00
const temporary_terms_t & temporary_terms ,
2018-03-27 17:14:30 +02:00
const temporary_terms_idxs_t & temporary_terms_idxs ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonExternalFunctionOutput ( vector < string > & efout ,
2017-02-20 12:18:11 +01:00
const temporary_terms_t & temporary_terms ,
2017-10-16 17:24:55 +02:00
deriv_node_temp_terms_t & tef_terms ,
2018-06-04 12:53:26 +02:00
const bool isdynamic ) const override ;
void compileExternalFunctionOutput ( ostream & CompileCode , unsigned int & instruction_number ,
2010-12-10 11:50:27 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2010-09-16 19:00:48 +02:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2008-02-03 11:28:36 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
void collectVARLHSVariable ( set < expr_t > & result ) const override ;
2018-06-04 14:17:36 +02:00
void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const override ;
2018-06-04 12:53:26 +02:00
void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const override ;
2018-06-04 12:50:53 +02:00
static double eval_opcode ( double v1 , BinaryOpcode op_code , double v2 , int derivOrder ) noexcept ( false ) ;
2018-06-04 12:53:26 +02:00
double eval ( const eval_context_t & eval_context ) const noexcept ( false ) override ;
void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic , const deriv_node_temp_terms_t & tef_terms ) const override ;
2010-09-16 19:18:45 +02:00
virtual expr_t Compute_RHS ( expr_t arg1 , expr_t arg2 , int op , int op_type ) const ;
2009-04-14 16:39:53 +02:00
//! Returns first operand
2010-09-16 19:18:45 +02:00
expr_t
2009-12-16 18:13:23 +01:00
get_arg1 ( ) const
{
return ( arg1 ) ;
} ;
2009-04-14 16:39:53 +02:00
//! Returns second operand
2010-09-16 19:18:45 +02:00
expr_t
2009-12-16 18:13:23 +01:00
get_arg2 ( ) const
{
return ( arg2 ) ;
} ;
2009-04-14 16:39:53 +02:00
//! Returns op code
2009-12-16 18:13:23 +01:00
BinaryOpcode
get_op_code ( ) const
{
return ( op_code ) ;
} ;
2010-12-13 14:07:05 +01:00
int
get_power_deriv_order ( ) const
{
return powerDerivOrder ;
}
2018-08-09 16:14:40 +02:00
void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const override ;
void getPacNonOptimizingPartHelper ( const expr_t arg1 , const expr_t arg2 ,
set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const ;
void getPacOptimizingPartHelper ( const expr_t arg1 , const expr_t arg2 ,
set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & ar_params_and_vars ) const ;
void getPacLHS ( pair < int , int > & lhs ) ;
2018-06-04 12:53:26 +02:00
expr_t toStatic ( DataTree & static_datatree ) const override ;
void computeXrefs ( EquationInfo & ei ) const override ;
2018-06-04 14:17:36 +02:00
pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const override ;
2018-06-04 12:53:26 +02:00
expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) override ;
int maxEndoLead ( ) const override ;
int maxExoLead ( ) const override ;
int maxEndoLag ( ) const override ;
int maxExoLag ( ) const override ;
int maxLead ( ) const override ;
int maxLag ( ) const override ;
int VarMinLag ( ) const override ;
2018-06-11 10:40:00 +02:00
int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const override ;
2018-08-13 12:12:20 +02:00
int PacMaxLag ( int lhs_symb_id ) const override ;
2018-06-04 12:53:26 +02:00
expr_t undiff ( ) const override ;
expr_t decreaseLeadsLags ( int n ) const override ;
expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
2009-09-30 17:10:31 +02:00
//! Creates another BinaryOpNode with the same opcode, but with a possibly different datatree and arguments
2010-09-16 19:18:45 +02:00
expr_t buildSimilarBinaryOpNode ( expr_t alt_arg1 , expr_t alt_arg2 , DataTree & alt_datatree ) const ;
2018-06-04 12:53:26 +02:00
expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const override ;
expr_t substituteAdl ( ) const override ;
2018-08-01 19:41:44 +02:00
expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const override ;
2018-06-04 12:53:26 +02:00
void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const override ;
void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const override ;
expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) override ;
expr_t decreaseLeadsLagsPredeterminedVariables ( ) const override ;
expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
bool isNumConstNodeEqualTo ( double value ) const override ;
bool containsEndogenous ( ) const override ;
bool containsExogenous ( ) const override ;
int countDiffs ( ) const override ;
bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const override ;
expr_t replaceTrendVar ( ) const override ;
expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const override ;
2010-12-13 14:07:05 +01:00
//! Function to write out the oPowerNode in expr_t terms as opposed to writing out the function itself
expr_t unpackPowerDeriv ( ) const ;
2011-03-28 11:19:10 +02:00
//! Returns MULT_i*(lhs-rhs) = 0, creating multiplier MULT_i
2011-03-21 18:40:57 +01:00
expr_t addMultipliersToConstraints ( int i ) ;
//! Returns the non-zero hand-side of an equation (that must have a hand side equal to zero)
expr_t getNonZeroPartofEquation ( ) const ;
2018-06-04 12:53:26 +02:00
bool isInStaticForm ( ) const override ;
2018-08-13 17:00:47 +02:00
void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & ar_params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) override ;
2018-08-13 12:12:20 +02:00
void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) override ;
bool containsPacExpectation ( const string & pac_model_name = " " ) const override ;
2018-08-09 16:14:40 +02:00
void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const override ;
void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const override ;
bool isParamTimesEndogExpr ( ) const override ;
2018-06-04 12:53:26 +02:00
bool isVarModelReferenced ( const string & model_info_name ) const override ;
void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const override ;
2016-03-18 14:55:14 +01:00
//! Substitute auxiliary variables by their expression in static model
2018-06-04 12:53:26 +02:00
expr_t substituteStaticAuxiliaryVariable ( ) const override ;
2016-03-18 14:55:14 +01:00
//! Substitute auxiliary variables by their expression in static model auxiliary variable definition
virtual expr_t substituteStaticAuxiliaryDefinition ( ) const ;
2008-02-03 11:28:36 +01:00
} ;
//! Trinary operator node
class TrinaryOpNode : public ExprNode
{
friend class ModelTree ;
private :
2010-09-16 19:18:45 +02:00
const expr_t arg1 , arg2 , arg3 ;
2008-02-03 11:28:36 +01:00
const TrinaryOpcode op_code ;
2018-06-04 12:53:26 +02:00
expr_t computeDerivative ( int deriv_id ) override ;
int cost ( int cost , bool is_matlab ) const override ;
int cost ( const temporary_terms_t & temporary_terms , bool is_matlab ) const override ;
int cost ( const map < NodeTreeReference , temporary_terms_t > & temp_terms_map , bool is_matlab ) const override ;
2009-07-06 11:34:21 +02:00
//! Returns the derivative of this node if darg1, darg2 and darg3 are the derivatives of the arguments
2010-09-16 19:18:45 +02:00
expr_t composeDerivatives ( expr_t darg1 , expr_t darg2 , expr_t darg3 ) ;
2008-02-03 11:28:36 +01:00
public :
2010-09-16 19:18:45 +02:00
TrinaryOpNode ( DataTree & datatree_arg , const expr_t arg1_arg ,
TrinaryOpcode op_code_arg , const expr_t arg2_arg , const expr_t arg3_arg ) ;
2018-06-04 12:53:26 +02:00
void prepareForDerivation ( ) override ;
int precedence ( ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms ) const override ;
2018-06-04 14:17:36 +02:00
void computeTemporaryTerms ( map < expr_t , pair < int , NodeTreeReference > > & reference_count ,
2015-09-03 13:50:02 +02:00
map < NodeTreeReference , temporary_terms_t > & temp_terms_map ,
2018-06-04 12:53:26 +02:00
bool is_matlab , NodeTreeReference tr ) const override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
bool containsExternalFunction ( ) const override ;
void writeExternalFunctionOutput ( ostream & output , ExprNodeOutputType output_type ,
2010-09-16 19:00:48 +02:00
const temporary_terms_t & temporary_terms ,
2018-03-27 17:14:30 +02:00
const temporary_terms_idxs_t & temporary_terms_idxs ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonExternalFunctionOutput ( vector < string > & efout ,
2017-02-20 12:18:11 +01:00
const temporary_terms_t & temporary_terms ,
2017-10-16 17:24:55 +02:00
deriv_node_temp_terms_t & tef_terms ,
2018-06-04 12:53:26 +02:00
const bool isdynamic ) const override ;
void compileExternalFunctionOutput ( ostream & CompileCode , unsigned int & instruction_number ,
2010-12-10 11:50:27 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2010-09-16 19:00:48 +02:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2008-02-03 11:28:36 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
void collectVARLHSVariable ( set < expr_t > & result ) const override ;
2018-06-04 14:17:36 +02:00
void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const override ;
2018-06-04 12:53:26 +02:00
void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const override ;
2018-06-04 12:50:53 +02:00
static double eval_opcode ( double v1 , TrinaryOpcode op_code , double v2 , double v3 ) noexcept ( false ) ;
2018-06-04 12:53:26 +02:00
double eval ( const eval_context_t & eval_context ) const noexcept ( false ) override ;
void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic , const deriv_node_temp_terms_t & tef_terms ) const override ;
expr_t toStatic ( DataTree & static_datatree ) const override ;
void computeXrefs ( EquationInfo & ei ) const override ;
2018-06-04 14:17:36 +02:00
pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const override ;
2018-06-04 12:53:26 +02:00
expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) override ;
int maxEndoLead ( ) const override ;
int maxExoLead ( ) const override ;
int maxEndoLag ( ) const override ;
int maxExoLag ( ) const override ;
int maxLead ( ) const override ;
int maxLag ( ) const override ;
int VarMinLag ( ) const override ;
2018-06-11 10:40:00 +02:00
int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const override ;
2018-08-13 12:12:20 +02:00
int PacMaxLag ( int lhs_symb_id ) const override ;
2018-06-04 12:53:26 +02:00
expr_t undiff ( ) const override ;
expr_t decreaseLeadsLags ( int n ) const override ;
expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
2009-09-30 17:10:31 +02:00
//! Creates another TrinaryOpNode with the same opcode, but with a possibly different datatree and arguments
2010-09-16 19:18:45 +02:00
expr_t buildSimilarTrinaryOpNode ( expr_t alt_arg1 , expr_t alt_arg2 , expr_t alt_arg3 , DataTree & alt_datatree ) const ;
2018-06-04 12:53:26 +02:00
expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const override ;
expr_t substituteAdl ( ) const override ;
2018-08-01 19:41:44 +02:00
expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const override ;
2018-06-04 12:53:26 +02:00
void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const override ;
void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const override ;
expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) override ;
expr_t decreaseLeadsLagsPredeterminedVariables ( ) const override ;
expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
bool isNumConstNodeEqualTo ( double value ) const override ;
bool containsEndogenous ( ) const override ;
bool containsExogenous ( ) const override ;
int countDiffs ( ) const override ;
bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const override ;
expr_t replaceTrendVar ( ) const override ;
expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const override ;
bool isInStaticForm ( ) const override ;
2018-08-13 17:00:47 +02:00
void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) override ;
2018-08-13 12:12:20 +02:00
void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) override ;
bool containsPacExpectation ( const string & pac_model_name = " " ) const override ;
2018-08-09 16:14:40 +02:00
void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const override ;
void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const override ;
void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const override ;
bool isParamTimesEndogExpr ( ) const override ;
2018-06-04 12:53:26 +02:00
bool isVarModelReferenced ( const string & model_info_name ) const override ;
void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const override ;
2016-03-18 14:55:14 +01:00
//! Substitute auxiliary variables by their expression in static model
2018-06-04 12:53:26 +02:00
expr_t substituteStaticAuxiliaryVariable ( ) const override ;
2008-02-03 11:28:36 +01:00
} ;
2010-02-22 17:33:38 +01:00
//! External function node
2014-03-13 11:22:00 +01:00
class AbstractExternalFunctionNode : public ExprNode
2008-02-03 11:28:36 +01:00
{
private :
2018-06-04 12:53:26 +02:00
expr_t computeDerivative ( int deriv_id ) override ;
2014-03-13 11:22:00 +01:00
virtual expr_t composeDerivatives ( const vector < expr_t > & dargs ) = 0 ;
2010-02-22 17:33:38 +01:00
protected :
2010-03-04 16:40:07 +01:00
//! Thrown when trying to access an unknown entry in external_function_node_map
class UnknownFunctionNameAndArgs
{
} ;
2008-02-03 11:28:36 +01:00
const int symb_id ;
2010-09-16 19:18:45 +02:00
const vector < expr_t > arguments ;
2010-03-04 16:40:07 +01:00
//! Returns true if the given external function has been written as a temporary term
2018-05-29 11:59:42 +02:00
bool alreadyWrittenAsTefTerm ( int the_symb_id , const deriv_node_temp_terms_t & tef_terms ) const ;
2010-03-04 16:40:07 +01:00
//! Returns the index in the tef_terms map of this external function
2018-06-04 12:50:53 +02:00
int getIndxInTefTerms ( int the_symb_id , const deriv_node_temp_terms_t & tef_terms ) const noexcept ( false ) ;
2010-03-04 16:40:07 +01:00
//! Helper function to write output arguments of any given external function
2018-05-29 11:59:42 +02:00
void writeExternalFunctionArguments ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const ;
void writeJsonExternalFunctionArguments ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const ;
2018-05-29 17:07:18 +02:00
/*! Returns a predicate that tests whether an other ExprNode is an external
function which is computed by the same external function call ( i . e . it has
the same so - called " Tef " index ) */
virtual function < bool ( expr_t ) > sameTefTermPredicate ( ) const = 0 ;
2008-02-03 11:28:36 +01:00
public :
2014-03-13 11:22:00 +01:00
AbstractExternalFunctionNode ( DataTree & datatree_arg , int symb_id_arg ,
2018-06-04 12:31:07 +02:00
vector < expr_t > arguments_arg ) ;
2018-06-04 12:53:26 +02:00
void prepareForDerivation ( ) override ;
2018-06-04 14:17:36 +02:00
void computeTemporaryTerms ( map < expr_t , pair < int , NodeTreeReference > > & reference_count ,
2015-09-03 13:50:02 +02:00
map < NodeTreeReference , temporary_terms_t > & temp_terms_map ,
2018-06-04 12:53:26 +02:00
bool is_matlab , NodeTreeReference tr ) const override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override = 0 ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic = true ) const override = 0 ;
bool containsExternalFunction ( ) const override ;
void writeExternalFunctionOutput ( ostream & output , ExprNodeOutputType output_type ,
2010-09-16 19:00:48 +02:00
const temporary_terms_t & temporary_terms ,
2018-03-27 17:14:30 +02:00
const temporary_terms_idxs_t & temporary_terms_idxs ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override = 0 ;
void writeJsonExternalFunctionOutput ( vector < string > & efout ,
2017-02-20 12:18:11 +01:00
const temporary_terms_t & temporary_terms ,
2017-10-16 17:24:55 +02:00
deriv_node_temp_terms_t & tef_terms ,
2018-06-04 12:53:26 +02:00
const bool isdynamic = true ) const override = 0 ;
void compileExternalFunctionOutput ( ostream & CompileCode , unsigned int & instruction_number ,
2011-02-04 16:25:38 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override = 0 ;
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2010-09-16 19:00:48 +02:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2008-02-03 11:28:36 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override = 0 ;
void collectVARLHSVariable ( set < expr_t > & result ) const override ;
2018-06-04 14:17:36 +02:00
void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const override ;
2018-06-04 12:53:26 +02:00
void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const override ;
double eval ( const eval_context_t & eval_context ) const noexcept ( false ) override ;
2010-12-10 11:50:27 +01:00
unsigned int compileExternalFunctionArguments ( ostream & CompileCode , unsigned int & instruction_number ,
2011-02-04 16:25:38 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-05-29 11:59:42 +02:00
const deriv_node_temp_terms_t & tef_terms ) const ;
2010-12-10 11:50:27 +01:00
2018-06-04 12:53:26 +02:00
void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic , const deriv_node_temp_terms_t & tef_terms ) const override = 0 ;
expr_t toStatic ( DataTree & static_datatree ) const override = 0 ;
void computeXrefs ( EquationInfo & ei ) const override = 0 ;
2018-06-04 14:17:36 +02:00
pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const override ;
2018-06-04 12:53:26 +02:00
expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) override ;
int maxEndoLead ( ) const override ;
int maxExoLead ( ) const override ;
int maxEndoLag ( ) const override ;
int maxExoLag ( ) const override ;
int maxLead ( ) const override ;
int maxLag ( ) const override ;
int VarMinLag ( ) const override ;
2018-06-11 10:40:00 +02:00
int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const override ;
2018-08-13 12:12:20 +02:00
int PacMaxLag ( int lhs_symb_id ) const override ;
2018-06-04 12:53:26 +02:00
expr_t undiff ( ) const override ;
expr_t decreaseLeadsLags ( int n ) const override ;
expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const override ;
expr_t substituteAdl ( ) const override ;
2018-08-01 19:41:44 +02:00
expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const override ;
2018-06-04 12:53:26 +02:00
void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const override ;
void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const override ;
expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) override ;
2014-03-13 11:22:00 +01:00
virtual expr_t buildSimilarExternalFunctionNode ( vector < expr_t > & alt_args , DataTree & alt_datatree ) const = 0 ;
2018-06-04 12:53:26 +02:00
expr_t decreaseLeadsLagsPredeterminedVariables ( ) const override ;
expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
bool isNumConstNodeEqualTo ( double value ) const override ;
bool containsEndogenous ( ) const override ;
bool containsExogenous ( ) const override ;
int countDiffs ( ) const override ;
bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const override ;
2018-05-29 11:59:42 +02:00
virtual void writePrhs ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms , const string & ending ) const ;
2018-06-04 12:53:26 +02:00
expr_t replaceTrendVar ( ) const override ;
expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override = 0 ;
expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const override ;
bool isInStaticForm ( ) const override ;
2018-08-13 17:00:47 +02:00
void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) override ;
2018-08-13 12:12:20 +02:00
void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) override ;
bool containsPacExpectation ( const string & pac_model_name = " " ) const override ;
2018-08-09 16:14:40 +02:00
void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const override ;
void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const override ;
void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const override ;
bool isParamTimesEndogExpr ( ) const override ;
2018-06-04 12:53:26 +02:00
bool isVarModelReferenced ( const string & model_info_name ) const override ;
void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const override ;
2016-03-18 14:55:14 +01:00
//! Substitute auxiliary variables by their expression in static model
2018-06-04 12:53:26 +02:00
expr_t substituteStaticAuxiliaryVariable ( ) const override ;
2008-02-03 11:28:36 +01:00
} ;
2014-03-13 11:22:00 +01:00
class ExternalFunctionNode : public AbstractExternalFunctionNode
{
2018-05-29 17:07:18 +02:00
friend class FirstDerivExternalFunctionNode ;
friend class SecondDerivExternalFunctionNode ;
2014-03-13 11:22:00 +01:00
private :
2018-06-04 12:53:26 +02:00
expr_t composeDerivatives ( const vector < expr_t > & dargs ) override ;
2018-05-29 17:07:18 +02:00
protected :
function < bool ( expr_t ) > sameTefTermPredicate ( ) const override ;
2014-03-13 11:22:00 +01:00
public :
ExternalFunctionNode ( DataTree & datatree_arg , int symb_id_arg ,
const vector < expr_t > & arguments_arg ) ;
2018-06-04 12:53:26 +02:00
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
void writeExternalFunctionOutput ( ostream & output , ExprNodeOutputType output_type ,
2014-03-13 11:22:00 +01:00
const temporary_terms_t & temporary_terms ,
2018-03-27 17:14:30 +02:00
const temporary_terms_idxs_t & temporary_terms_idxs ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonExternalFunctionOutput ( vector < string > & efout ,
2017-02-20 12:18:11 +01:00
const temporary_terms_t & temporary_terms ,
2017-10-16 17:24:55 +02:00
deriv_node_temp_terms_t & tef_terms ,
2018-06-04 12:53:26 +02:00
const bool isdynamic ) const override ;
void compileExternalFunctionOutput ( ostream & CompileCode , unsigned int & instruction_number ,
2014-03-13 11:22:00 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2014-03-13 11:22:00 +01:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2014-03-13 11:22:00 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
void compile ( ostream & CompileCode , unsigned int & instruction_number , bool lhs_rhs , const temporary_terms_t & temporary_terms , const map_idx_t & map_idx , bool dynamic , bool steady_dynamic , const deriv_node_temp_terms_t & tef_terms ) const override ;
expr_t toStatic ( DataTree & static_datatree ) const override ;
void computeXrefs ( EquationInfo & ei ) const override ;
expr_t buildSimilarExternalFunctionNode ( vector < expr_t > & alt_args , DataTree & alt_datatree ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
2014-03-13 11:22:00 +01:00
} ;
class FirstDerivExternalFunctionNode : public AbstractExternalFunctionNode
2010-02-22 17:33:38 +01:00
{
private :
const int inputIndex ;
2018-06-04 12:53:26 +02:00
expr_t composeDerivatives ( const vector < expr_t > & dargs ) override ;
2018-05-29 17:07:18 +02:00
protected :
function < bool ( expr_t ) > sameTefTermPredicate ( ) const override ;
2010-02-22 17:33:38 +01:00
public :
FirstDerivExternalFunctionNode ( DataTree & datatree_arg ,
int top_level_symb_id_arg ,
2010-09-16 19:18:45 +02:00
const vector < expr_t > & arguments_arg ,
2010-02-22 17:33:38 +01:00
int inputIndex_arg ) ;
2018-06-04 12:53:26 +02:00
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2010-09-16 19:00:48 +02:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2010-03-04 16:40:07 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
void compile ( ostream & CompileCode , unsigned int & instruction_number ,
2011-02-04 16:25:38 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeExternalFunctionOutput ( ostream & output , ExprNodeOutputType output_type ,
2010-09-16 19:00:48 +02:00
const temporary_terms_t & temporary_terms ,
2018-03-27 17:14:30 +02:00
const temporary_terms_idxs_t & temporary_terms_idxs ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonExternalFunctionOutput ( vector < string > & efout ,
2017-02-20 12:18:11 +01:00
const temporary_terms_t & temporary_terms ,
2017-10-16 17:24:55 +02:00
deriv_node_temp_terms_t & tef_terms ,
2018-06-04 12:53:26 +02:00
const bool isdynamic ) const override ;
void compileExternalFunctionOutput ( ostream & CompileCode , unsigned int & instruction_number ,
2011-02-04 16:25:38 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
expr_t toStatic ( DataTree & static_datatree ) const override ;
void computeXrefs ( EquationInfo & ei ) const override ;
expr_t buildSimilarExternalFunctionNode ( vector < expr_t > & alt_args , DataTree & alt_datatree ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
2010-02-22 17:33:38 +01:00
} ;
2014-03-13 11:22:00 +01:00
class SecondDerivExternalFunctionNode : public AbstractExternalFunctionNode
2010-02-22 17:33:38 +01:00
{
private :
const int inputIndex1 ;
const int inputIndex2 ;
2018-06-04 12:53:26 +02:00
expr_t composeDerivatives ( const vector < expr_t > & dargs ) override ;
2018-05-29 17:07:18 +02:00
protected :
function < bool ( expr_t ) > sameTefTermPredicate ( ) const override ;
2010-02-22 17:33:38 +01:00
public :
SecondDerivExternalFunctionNode ( DataTree & datatree_arg ,
int top_level_symb_id_arg ,
2010-09-16 19:18:45 +02:00
const vector < expr_t > & arguments_arg ,
2010-02-22 17:33:38 +01:00
int inputIndex1_arg ,
int inputIndex2_arg ) ;
2018-06-04 12:53:26 +02:00
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2010-09-16 19:00:48 +02:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2010-03-04 16:40:07 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
void compile ( ostream & CompileCode , unsigned int & instruction_number ,
2014-03-13 11:22:00 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
const deriv_node_temp_terms_t & tef_terms ) const override ;
void writeExternalFunctionOutput ( ostream & output , ExprNodeOutputType output_type ,
2010-09-16 19:00:48 +02:00
const temporary_terms_t & temporary_terms ,
2018-03-27 17:14:30 +02:00
const temporary_terms_idxs_t & temporary_terms_idxs ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
void writeJsonExternalFunctionOutput ( vector < string > & efout ,
2017-02-20 12:18:11 +01:00
const temporary_terms_t & temporary_terms ,
2017-10-16 17:24:55 +02:00
deriv_node_temp_terms_t & tef_terms ,
2018-06-04 12:53:26 +02:00
const bool isdynamic ) const override ;
void compileExternalFunctionOutput ( ostream & CompileCode , unsigned int & instruction_number ,
2014-03-13 11:22:00 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
deriv_node_temp_terms_t & tef_terms ) const override ;
expr_t toStatic ( DataTree & static_datatree ) const override ;
void computeXrefs ( EquationInfo & ei ) const override ;
expr_t buildSimilarExternalFunctionNode ( vector < expr_t > & alt_args , DataTree & alt_datatree ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
2010-02-22 17:33:38 +01:00
} ;
2016-11-18 16:52:13 +01:00
class VarExpectationNode : public ExprNode
{
private :
2018-08-01 19:41:44 +02:00
const string model_name ;
2016-11-18 16:52:13 +01:00
public :
2018-08-01 19:41:44 +02:00
VarExpectationNode ( DataTree & datatree_arg , string model_name_arg ) ;
2018-06-04 14:17:36 +02:00
void computeTemporaryTerms ( map < expr_t , pair < int , NodeTreeReference > > & reference_count ,
2016-11-18 16:52:13 +01:00
map < NodeTreeReference , temporary_terms_t > & temp_terms_map ,
2018-06-04 12:53:26 +02:00
bool is_matlab , NodeTreeReference tr ) const override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2016-11-18 16:52:13 +01:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2016-11-18 16:52:13 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
expr_t toStatic ( DataTree & static_datatree ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
int maxEndoLead ( ) const override ;
int maxExoLead ( ) const override ;
int maxEndoLag ( ) const override ;
int maxExoLag ( ) const override ;
int maxLead ( ) const override ;
int maxLag ( ) const override ;
int VarMinLag ( ) const override ;
2018-06-11 10:40:00 +02:00
int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const override ;
2018-08-13 12:12:20 +02:00
int PacMaxLag ( int lhs_symb_id ) const override ;
2018-06-04 12:53:26 +02:00
expr_t undiff ( ) const override ;
expr_t decreaseLeadsLags ( int n ) const override ;
void prepareForDerivation ( ) override ;
expr_t computeDerivative ( int deriv_id ) override ;
expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) override ;
bool containsExternalFunction ( ) const override ;
double eval ( const eval_context_t & eval_context ) const noexcept ( false ) override ;
void computeXrefs ( EquationInfo & ei ) const override ;
expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const override ;
expr_t substituteAdl ( ) const override ;
2018-08-01 19:41:44 +02:00
expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const override ;
2018-06-04 12:53:26 +02:00
void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const override ;
void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const override ;
expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) override ;
2018-06-04 14:17:36 +02:00
pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const override ;
2018-06-04 12:53:26 +02:00
void compile ( ostream & CompileCode , unsigned int & instruction_number ,
2018-01-30 16:33:16 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
const deriv_node_temp_terms_t & tef_terms ) const override ;
void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const override ;
void collectVARLHSVariable ( set < expr_t > & result ) const override ;
2018-06-04 14:17:36 +02:00
void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const override ;
2018-06-04 12:53:26 +02:00
bool containsEndogenous ( ) const override ;
bool containsExogenous ( ) const override ;
int countDiffs ( ) const override ;
bool isNumConstNodeEqualTo ( double value ) const override ;
expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t decreaseLeadsLagsPredeterminedVariables ( ) const override ;
bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const override ;
expr_t replaceTrendVar ( ) const override ;
expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const override ;
expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const override ;
bool isInStaticForm ( ) const override ;
2018-08-13 17:00:47 +02:00
void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) override ;
2018-08-13 12:12:20 +02:00
void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) override ;
bool containsPacExpectation ( const string & pac_model_name = " " ) const override ;
2018-08-09 16:14:40 +02:00
void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const override ;
void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const override ;
void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const override ;
bool isParamTimesEndogExpr ( ) const override ;
2018-06-04 12:53:26 +02:00
bool isVarModelReferenced ( const string & model_info_name ) const override ;
void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const override ;
expr_t substituteStaticAuxiliaryVariable ( ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
2018-01-30 16:33:16 +01:00
} ;
class PacExpectationNode : public ExprNode
{
private :
2018-03-28 18:46:15 +02:00
const string model_name ;
string var_model_name ;
int growth_symb_id ;
2018-02-07 13:49:57 +01:00
bool stationary_vars_present , nonstationary_vars_present ;
2018-02-09 16:57:12 +01:00
vector < int > lhs ;
2018-02-15 16:10:01 +01:00
pair < int , int > lhs_pac_var ;
2018-08-13 12:12:20 +02:00
int max_lag , pac_max_lag ;
2018-02-07 13:49:57 +01:00
vector < int > h0_indices , h1_indices ;
2018-02-12 15:21:36 +01:00
int growth_param_index , equation_number ;
2018-08-13 17:00:47 +02:00
int optim_share_index ;
2018-06-04 14:17:36 +02:00
set < pair < int , pair < int , int > > > ec_params_and_vars ;
set < pair < int , pair < int , int > > > ar_params_and_vars ;
2018-08-09 16:14:40 +02:00
set < pair < int , pair < pair < int , int > , double > > > params_vars_and_scaling_factor ;
2018-01-30 16:33:16 +01:00
public :
2018-06-04 12:31:07 +02:00
PacExpectationNode ( DataTree & datatree_arg , string model_name ) ;
2018-06-04 14:17:36 +02:00
void computeTemporaryTerms ( map < expr_t , pair < int , NodeTreeReference > > & reference_count ,
2018-01-30 16:33:16 +01:00
map < NodeTreeReference , temporary_terms_t > & temp_terms_map ,
2018-06-04 12:53:26 +02:00
bool is_matlab , NodeTreeReference tr ) const override ;
void writeOutput ( ostream & output , ExprNodeOutputType output_type , const temporary_terms_t & temporary_terms , const temporary_terms_idxs_t & temporary_terms_idxs , const deriv_node_temp_terms_t & tef_terms ) const override ;
void computeTemporaryTerms ( map < expr_t , int > & reference_count ,
2018-01-30 16:33:16 +01:00
temporary_terms_t & temporary_terms ,
2018-06-04 14:17:36 +02:00
map < expr_t , pair < int , int > > & first_occurence ,
2018-01-30 16:33:16 +01:00
int Curr_block ,
2018-06-04 14:17:36 +02:00
vector < vector < temporary_terms_t > > & v_temporary_terms ,
2018-06-04 12:53:26 +02:00
int equation ) const override ;
expr_t toStatic ( DataTree & static_datatree ) const override ;
expr_t cloneDynamic ( DataTree & dynamic_datatree ) const override ;
int maxEndoLead ( ) const override ;
int maxExoLead ( ) const override ;
int maxEndoLag ( ) const override ;
int maxExoLag ( ) const override ;
int maxLead ( ) const override ;
int maxLag ( ) const override ;
int VarMinLag ( ) const override ;
2018-06-11 10:40:00 +02:00
int VarMaxLag ( DataTree & static_datatree , set < expr_t > & static_lhs ) const override ;
2018-08-13 12:12:20 +02:00
int PacMaxLag ( int lhs_symb_id ) const override ;
2018-06-04 12:53:26 +02:00
expr_t undiff ( ) const override ;
expr_t decreaseLeadsLags ( int n ) const override ;
void prepareForDerivation ( ) override ;
expr_t computeDerivative ( int deriv_id ) override ;
expr_t getChainRuleDerivative ( int deriv_id , const map < int , expr_t > & recursive_variables ) override ;
bool containsExternalFunction ( ) const override ;
double eval ( const eval_context_t & eval_context ) const noexcept ( false ) override ;
void computeXrefs ( EquationInfo & ei ) const override ;
expr_t substituteEndoLeadGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteEndoLagGreaterThanTwo ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExoLead ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool deterministic_model ) const override ;
expr_t substituteExoLag ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteExpectation ( subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs , bool partial_information_model ) const override ;
expr_t substituteAdl ( ) const override ;
2018-08-01 19:41:44 +02:00
expr_t substituteVarExpectation ( const map < string , expr_t > & subst_table ) const override ;
2018-06-04 12:53:26 +02:00
void findDiffNodes ( DataTree & static_datatree , diff_table_t & diff_table ) const override ;
void findUnaryOpNodesForAuxVarCreation ( DataTree & static_datatree , diff_table_t & nodes ) const override ;
expr_t substituteDiff ( DataTree & static_datatree , diff_table_t & diff_table , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substituteUnaryOpNodes ( DataTree & static_datatree , diff_table_t & nodes , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t substitutePacExpectation ( map < const PacExpectationNode * , const BinaryOpNode * > & subst_table ) override ;
2018-06-04 14:17:36 +02:00
pair < int , expr_t > normalizeEquation ( int symb_id_endo , vector < pair < int , pair < expr_t , expr_t > > > & List_of_Op_RHS ) const override ;
2018-06-04 12:53:26 +02:00
void compile ( ostream & CompileCode , unsigned int & instruction_number ,
2016-11-18 16:52:13 +01:00
bool lhs_rhs , const temporary_terms_t & temporary_terms ,
const map_idx_t & map_idx , bool dynamic , bool steady_dynamic ,
2018-06-04 12:53:26 +02:00
const deriv_node_temp_terms_t & tef_terms ) const override ;
void collectTemporary_terms ( const temporary_terms_t & temporary_terms , temporary_terms_inuse_t & temporary_terms_inuse , int Curr_Block ) const override ;
void collectVARLHSVariable ( set < expr_t > & result ) const override ;
2018-06-04 14:17:36 +02:00
void collectDynamicVariables ( SymbolType type_arg , set < pair < int , int > > & result ) const override ;
2018-06-04 12:53:26 +02:00
bool containsEndogenous ( ) const override ;
bool containsExogenous ( ) const override ;
int countDiffs ( ) const override ;
bool isNumConstNodeEqualTo ( double value ) const override ;
expr_t differentiateForwardVars ( const vector < string > & subset , subst_table_t & subst_table , vector < BinaryOpNode * > & neweqs ) const override ;
expr_t decreaseLeadsLagsPredeterminedVariables ( ) const override ;
bool isVariableNodeEqualTo ( SymbolType type_arg , int variable_id , int lag_arg ) const override ;
expr_t replaceTrendVar ( ) const override ;
expr_t detrend ( int symb_id , bool log_trend , expr_t trend ) const override ;
expr_t removeTrendLeadLag ( map < int , expr_t > trend_symbols_map ) const override ;
bool isInStaticForm ( ) const override ;
2018-08-13 17:00:47 +02:00
void addParamInfoToPac ( pair < int , int > & lhs_arg , int optim_share_arg , set < pair < int , pair < int , int > > > & ec_params_and_vars_arg , set < pair < int , pair < int , int > > > & params_and_vars_arg , set < pair < int , pair < pair < int , int > , double > > > & params_vars_and_scaling_factor_arg ) override ;
2018-08-13 12:12:20 +02:00
void fillPacExpectationVarInfo ( string & model_name_arg , vector < int > & lhs_arg , int max_lag_arg , int pac_max_lag_arg , vector < bool > & nonstationary_arg , int growth_symb_id_arg , int equation_number_arg ) override ;
bool containsPacExpectation ( const string & pac_model_name = " " ) const override ;
2018-08-09 16:14:40 +02:00
void getPacNonOptimizingPart ( set < pair < int , pair < pair < int , int > , double > > >
& params_vars_and_scaling_factor ) const override ;
void getPacOptimizingPart ( set < pair < int , pair < int , int > > > & ec_params_and_vars ,
set < pair < int , pair < int , int > > > & params_and_vars ) const override ;
void getPacOptimizingShareAndExprNodes ( set < int > & optim_share ,
expr_t & optim_part ,
expr_t & non_optim_part ) const override ;
bool isParamTimesEndogExpr ( ) const override ;
2018-06-04 12:53:26 +02:00
bool isVarModelReferenced ( const string & model_info_name ) const override ;
void getEndosAndMaxLags ( map < string , int > & model_endos_and_lags ) const override ;
expr_t substituteStaticAuxiliaryVariable ( ) const override ;
void writeJsonOutput ( ostream & output , const temporary_terms_t & temporary_terms , const deriv_node_temp_terms_t & tef_terms , const bool isdynamic ) const override ;
2016-11-18 16:52:13 +01:00
} ;
2008-02-03 11:28:36 +01:00
# endif