From cb78300e954b9851333c3db92d818094cf582e99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Thu, 17 Feb 2022 12:57:54 +0100
Subject: [PATCH] Transform predetermined variables before simplifying
 equations

Equation simplification takes leads/lags into account, so those need to be
correct upon entry of the procedure.
---
 src/ModFile.cc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/ModFile.cc b/src/ModFile.cc
index a033be96..e41cd2f6 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -376,20 +376,21 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, bool
                        const string &exclude_eqs, const string &include_eqs)
 {
   /* Save the original model (must be done before any model transformations by preprocessor)
+     — except predetermined variables (which must be handled before the call to
+       setLeadsLagsOrig(), see #47, and also before equation simplification,
+       since the latter uses leads/lags, see #83)
      — except substituting out variables which we know are constant (they
        appear in an equation of the form: X = constant)
      — except adl operators which we always want expanded
-     — except predetermined variables (which must be handled before the call to
-       setLeadsLagsOrig(), see preprocessor#47)
      — except diff operators with a lead which have been expanded by
        DataTree:AddDiff()
   */
   dynamic_model.includeExcludeEquations(exclude_eqs, true);
   dynamic_model.includeExcludeEquations(include_eqs, false);
-  dynamic_model.simplifyEquations();
-  dynamic_model.substituteAdl();
   if (symbol_table.predeterminedNbr() > 0)
     dynamic_model.transformPredeterminedVariables();
+  dynamic_model.simplifyEquations();
+  dynamic_model.substituteAdl();
   dynamic_model.setLeadsLagsOrig();
   original_model = dynamic_model;
   dynamic_model.expandEqTags();
-- 
GitLab