00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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