Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# SymOps.cpp

    00001 /*
    00002  *             Copyright (C) 2005 Maarten Keijzer
    00003  *
    00004  *          This program is free software; you can redistribute it and/or modify
    00005  *          it under the terms of version 2 of the GNU General Public License as
    00006  *          published by the Free Software Foundation.
    00007  *
    00008  *          This program is distributed in the hope that it will be useful,
    00009  *          but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010  *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00011  *          GNU General Public License for more details.
    00012  *
    00013  *          You should have received a copy of the GNU General Public License
    00014  *          along with this program; if not, write to the Free Software
    00015  *          Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00016  */
    00017
    00018 #include "FunDef.h"
    00019 #include "SymOps.h"
    00020 #include "Sym.h"
    00021
    00022 using namespace std;
    00023
    00024 void collect(token_t t, Sym a, SymVec& args) {
    00025
    00026     if (a.token() == t) {
    00027         const SymVec& a_args = a.args();
    00028         for (unsigned i = 0; i < a_args.size(); ++i) {
    00029             collect(t, a_args[i], args);
    00030         }
    00031         return;
    00032     }
    00033
    00034     args.push_back(a);
    00035 }
    00036
    00037 Sym operator+(Sym a, Sym b) {
    00038
    00039     SymVec args;
    00040
    00041     collect(sum_token, a, args);
    00042     collect(sum_token, b, args);
    00043
    00044     return Sym(sum_token, args);
    00045 }
    00046
    00047 Sym operator*(Sym a, Sym b) {
    00048
    00049     SymVec args;
    00050
    00051     collect(prod_token, a, args);
    00052     collect(prod_token, b, args);
    00053
    00054     return Sym(prod_token, args);
    00055 }
    00056
    00057 Sym operator/(Sym a, Sym b) {
    00058
    00059     SymVec args;
    00060
    00061     collect(prod_token, a, args);
    00062
    00063     SymVec args2;
    00064     collect(prod_token, b, args2);
    00065
    00066     SymVec inv;
    00067     inv.push_back(Sym(prod_token, args2));
    00068
    00069     args.push_back( Sym(inv_token, inv) );
    00070
    00071     return Sym(prod_token, args);
    00072 }
    00073
    00074 Sym operator-(Sym a, Sym b) {
    00075
    00076     SymVec args;
    00077
    00078     collect(sum_token, a, args);
    00079
    00080     SymVec args2;
    00081     collect(sum_token, b, args2);
    00082
    00083     SymVec min;
    00084     min.push_back(Sym(sum_token, args2));
    00085
    00086     args.push_back( Sym(min_token, min) );
    00087
    00088     return Sym(sum_token, args);
    00089 }
    00090
    00091 Sym operator-(Sym a) {
    00092     return Sym(min_token, a);
    00093 }
    00094
    00095 Sym pow(Sym a, Sym b) {
    00096     SymVec args;
    00097     args.push_back(a);
    00098     args.push_back(b);
    00099     return Sym(pow_token, args);
    00100 }
    00101
    00102 Sym ifltz(Sym a, Sym b, Sym c) {
    00103     SymVec args;
    00104     args.push_back(a);
    00105     args.push_back(b);
    00106     args.push_back(c);
    00107     return Sym(ifltz_token, args);
    00108 }
    00109