source: branches/Couenne/Couenne/src/simplify/simplify.cpp @ 531

Last change on this file since 531 was 340, checked in by pbelotti, 13 years ago

modified branch point, now solve ex3_1_1. Cut most of the output

File size: 1.2 KB
Line 
1/*
2 * Name:    simplify.cpp
3 * Author:  Pietro Belotti
4 * Purpose: symbolic expression simplifier
5 *
6 * (C) Pietro Belotti. This file is licensed under the Common Public License (CPL)
7 */
8
9#include <expression.h>
10#include <exprOp.h>
11#include <exprUnary.h>
12#include <exprConst.h>
13
14
15// simplify n-ary expression f (g_1(x), g_2(x)... g_n(x))
16
17expression *exprOp:: simplify () {
18
19  //  print (std::cout, "op", PRE); printf (" --> ");
20
21  //  Simplify arguments g_1(x), g_2(x)... g_n(x) first
22  for (register int i=0; i<nargs_; i++) {
23
24    register expression *subst;
25
26    if ((subst = (arglist_ [i]) -> simplify ())) {
27
28      delete arglist_ [i];
29      arglist_ [i] = subst;
30    }
31  }
32
33  //  print (std::cout, "op", PRE); printf ("\n");
34
35  return NULL;
36}
37
38
39// simplify unary operators
40
41expression *exprUnary:: simplify () {
42
43  register expression *subst;
44
45  // Simplify argument g(x) of this expression f(g(x))
46  if ((subst = argument_ -> simplify ())) {
47
48    delete argument_;
49    argument_ = subst;
50
51    // g(x) is a constant k, therefore return f (k)
52    if (subst -> Type () == CONST) {
53
54      expression *ret = new exprConst (operator () ());
55      argument_ = NULL;
56      delete subst;
57
58      return ret;
59    }
60    else return NULL;
61  }
62  else return NULL;
63}
Note: See TracBrowser for help on using the repository browser.