flop_counter.cpp
Go to the documentation of this file.00001 #include <iostream>
00002 #include <ginac/ginac.h>
00003
00004 #include "SyFi.h"
00005 #include "ginac_tools.h"
00006
00007 using namespace std;
00008 using namespace GiNaC;
00009 using namespace SyFi;
00010
00011
00012
00013
00014
00015
00016 ex pickExpression(int i)
00017 {
00018 ex x = get_symbol("x");
00019 ex y = get_symbol("y");
00020 ex z = get_symbol("z");
00021
00022 ex e;
00023 switch(i)
00024 {
00025 case 0: e = 1; break;
00026 case 1: e = x; break;
00027 case 2: e = x+y; break;
00028 case 3: e = x+y+z; break;
00029 case 4: e = x*y; break;
00030 case 5: e = x*y*z; break;
00031 case 6: e = x*x*y*y*z*z; break;
00032 case 7: e = x*x*x*y*y*y*z*z*z; break;
00033 case 8:
00034 e = power(x,3)*power(y,2) + power(x,2) + x*y*y;
00035 break;
00036 case 9:
00037 e = power(x,3)*power(y,2) + power(x,2) + x*y*y;
00038 e = power(e, e) + e;
00039 break;
00040
00041 default:
00042 e = 0;
00043 }
00044 return e;
00045 }
00046
00047
00048 int main(int argc, char **argv)
00049 {
00050 bool verbose = false;
00051 if(argc>1 && argv[1][0] == 'v') verbose = true;
00052
00053 int from = 0;
00054 int to = 10;
00055 for(int i=from; i<to; i++)
00056 {
00057
00058 ex e = pickExpression(i);
00059 ex f = e*e;
00060
00061 ExStats es = count_ops(e);
00062 ExStats fs = count_ops(f);
00063
00064 if(verbose) cout << "Flops in e = " << e << endl;
00065 else cout << "Flops in e " << endl;
00066 cout << " adds: " << es.adds << endl;
00067 cout << " muls: " << es.muls << endl;
00068 cout << " pows: " << es.pows << endl;
00069 cout << " funs: " << es.functions << endl;
00070 cout << " flops: " << es.flops << endl;
00071 cout << endl;
00072 if(verbose) cout << "Flops in f = " << f << endl;
00073 else cout << "Flops in f " << endl;
00074 cout << " adds: " << fs.adds << endl;
00075 cout << " muls: " << fs.muls << endl;
00076 cout << " pows: " << fs.pows << endl;
00077 cout << " funs: " << fs.functions << endl;
00078 cout << " flops: " << fs.flops << endl;
00079 cout << endl;
00080 }
00081
00082 return 0;
00083 }
00084