Use of subexpression caching in Dynare++ evaluator can lead to wrong results
Consider the following MOD file:
var y;
varexo e;
parameters beta rbar rebar lambdae t1 t2;
beta = 1/1.02^0.25;
rbar = 1.02^0.25;
rebar = (1.065-rbar^4+1)^0.25;
lambdae = 0.2;
lambdae = 1-lambdae;
t1 = (1-lambdae)/beta;
t2 = lambdae/beta;
model;
y = t2*y(-1)+e;
end;
initval;
y = 0;
end;
vcov = [1];
order = 1;
The value computed for t1
will be wrong, and will be equal to that of t2
. Here is what happens step-by-step:
-
lambdae = 0.2;
=> Dynare++ registers thatlambdae=0.2
-
lambdae=1-lambdae;
=> Dynare++ computes1-lambdae=0.8
and caches that identity; then it updateslambdae=0.8
-
t1 = (1-lambdae)/beta;
=> Dynare++ (wrongly) uses the cached value1-lambdae=0.8
-
t2 = lambdae/beta;
=> Dynare++ (rightly) uses the valuelambdae=0.8
It seems that the only sensible solution to this problem is to disable subexpression caching during the evaluation phase.