From af1e4837b89cccfbb7d2d63d82bb022a82523995 Mon Sep 17 00:00:00 2001 From: Ferhat Mihoubi Date: Fri, 10 Jun 2011 11:59:34 +0200 Subject: [PATCH] - correction of the bug in normalization process for expressions of the form a^x (Ticket #186) - If a case is not handled, the equation is supposed to be impossible to normalize. - comments added to describe the normalization process --- ExprNode.cc | 109 ++++++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/ExprNode.cc b/ExprNode.cc index b9d4ae8e..9acb5c18 100644 --- a/ExprNode.cc +++ b/ExprNode.cc @@ -135,6 +135,7 @@ ExprNode::computeTemporaryTerms(map &reference_count, pair ExprNode::normalizeEquation(int var_endo, vector > > &List_of_Op_RHS) const { + /* nothing to do */ return (make_pair(0, (expr_t) NULL)); } @@ -335,6 +336,7 @@ NumConstNode::collectVariables(SymbolType type_arg, set > &result pair NumConstNode::normalizeEquation(int var_endo, vector > > &List_of_Op_RHS) const { + /* return the numercial constant */ return (make_pair(0, datatree.AddNonNegativeConstant(datatree.num_constants.get(id)))); } @@ -843,9 +845,22 @@ VariableNode::collectVariables(SymbolType type_arg, set > &result pair VariableNode::normalizeEquation(int var_endo, vector > > &List_of_Op_RHS) const { + /* The equation has to be normalized with respect to the current endogenous variable ascribed to it. + The two input arguments are : + - The ID of the endogenous variable associated to the equation. + - The list of operators and operands needed to normalize the equation* + + The pair returned by NormalizeEquation is composed of + - a flag indicating if the expression returned contains (flag = 1) or not (flag = 0) + the endogenous variable related to the equation. + If the expression contains more than one occurence of the associated endogenous variable, + the flag is equal to 2. + - an expression equal to the RHS if flag = 0 and equal to NULL elsewhere + */ if (type == eEndogenous) { if (datatree.symbol_table.getTypeSpecificID(symb_id) == var_endo && lag == 0) + /* the endogenous variable */ return (make_pair(1, (expr_t) NULL)); else return (make_pair(0, datatree.AddVariableInternal(symb_id, lag))); @@ -1812,10 +1827,12 @@ UnaryOpNode::normalizeEquation(int var_endo, vector res = arg->normalizeEquation(var_endo, List_of_Op_RHS); int is_endogenous_present = res.first; expr_t New_expr_t = res.second; - /*if(res.second.second)*/ - if (is_endogenous_present == 2) + + if (is_endogenous_present == 2) /* The equation could not be normalized and the process is given-up*/ return (make_pair(2, (expr_t) NULL)); - else if (is_endogenous_present) + else if (is_endogenous_present) /* The argument of the function contains the current values of + the endogenous variable associated to the equation. + In order to normalized, we have to apply the invert function to the RHS.*/ { switch (op_code) { @@ -1831,50 +1848,21 @@ UnaryOpNode::normalizeEquation(int var_endo, vector BinaryOpNode::normalizeEquation(int var_endo, vector > > &List_of_Op_RHS) const { + /* Checks if the current value of the endogenous variable related to the equation + is present in the arguments of the binary operator. */ vector > > List_of_Op_RHS1, List_of_Op_RHS2; int is_endogenous_present_1, is_endogenous_present_2; pair res; @@ -2923,13 +2914,18 @@ BinaryOpNode::normalizeEquation(int var_endo, vectornormalizeEquation(var_endo, List_of_Op_RHS2); is_endogenous_present_2 = res.first; expr_t_2 = res.second; + + /* If the two expressions contains the current value of the endogenous variable associated to the equation + the equation could not be normalized and the process is given-up.*/ if (is_endogenous_present_1 == 2 || is_endogenous_present_2 == 2) return (make_pair(2, (expr_t) NULL)); else if (is_endogenous_present_1 && is_endogenous_present_2) return (make_pair(2, (expr_t) NULL)); - else if (is_endogenous_present_1) + else if (is_endogenous_present_1) /*If the current values of the endogenous variable associated to the equation + is present only in the first operand of the expression, we try to normalize the equation*/ { - if (op_code == oEqual) + if (op_code == oEqual) /* The end of the normalization process : + All the operations needed to normalize the equation are applied. */ { pair > it; int oo = List_of_Op_RHS1.size(); @@ -3054,9 +3050,16 @@ BinaryOpNode::normalizeEquation(int var_endo, vector