/home/coin/SVN-release/OS-2.1.0/Couenne/src/expression/simplify/simplify.cpp

Go to the documentation of this file.
00001 /* $Id: simplify.cpp 268 2009-10-22 03:41:03Z pbelotti $
00002  *
00003  * Name:    simplify.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: symbolic expression simplifier
00006  *
00007  * (C) Carnegie-Mellon University, 2006. 
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include "expression.hpp"
00012 #include "exprOp.hpp"
00013 #include "exprUnary.hpp"
00014 #include "exprConst.hpp"
00015 
00016 
00017 // simplify n-ary expression f (g_1(x), g_2(x)... g_n(x))
00018 
00019 expression *exprOp:: simplify () {
00020 
00021   //  Simplify arguments g_1(x), g_2(x)... g_n(x) first
00022   for (int i=0; i<nargs_; i++) {
00023 
00024     expression *subst;
00025 
00026     if ((subst = (arglist_ [i]) -> simplify ())) {
00027 
00028       delete arglist_ [i];
00029       arglist_ [i] = subst;
00030     }
00031   }
00032 
00033   return NULL;
00034 }
00035 
00036 
00037 // simplify unary operators
00038 
00039 expression *exprUnary:: simplify () {
00040 
00041   register expression *subst;
00042 
00043   // Simplify argument g(x) of this expression f(g(x))
00044   if ((subst = argument_ -> simplify ())) {
00045 
00046     delete argument_;
00047     argument_ = subst;
00048 
00049     // g(x) is a constant k, therefore return f (k)
00050     if (subst -> Type () == CONST) {
00051 
00052       expression *ret = new exprConst (operator () ());
00053       argument_ = NULL;
00054       delete subst;
00055 
00056       return ret;
00057     } else return NULL;
00058   } else return NULL;
00059 }

Generated on Tue Mar 30 03:04:37 2010 by  doxygen 1.4.7