ex_inspection.cpp
Go to the documentation of this file.00001 #include <iostream>
00002 using namespace std;
00003
00004 #include <tools.h>
00005 using namespace GiNaC;
00006 using namespace SyFi;
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 void print(ex e)
00027 {
00028 cout << " e = " << e << endl;
00029
00030 exhashmap<int> sc = count_symbols(e);
00031 exhashmap<int>::iterator it;
00032 int count = 0;
00033 int maxcount = 0;
00034 for(it = sc.begin(); it != sc.end(); it++)
00035 {
00036 if(it->second > maxcount)
00037 maxcount = it->second;
00038 count += it->second;
00039
00040 }
00041 cout << " number of symbols / total symbol count = " << sc.size() << ", " << count << endl;
00042
00043 ExStats es = count_ops(e);
00044 cout << " m,a,p,f,flops = "
00045 << es.muls << ", "
00046 << es.adds << ", "
00047 << es.pows << ", "
00048 << es.functions << ", "
00049 << es.flops << endl;
00050 }
00051
00052 void variants(ex e)
00053 {
00054 cout << "====================" << endl;
00055 cout << "original:" << endl;
00056 print(e);
00057
00058 cout << "expand:" << endl;
00059 print(expand(e));
00060
00061 cout << "normal:" << endl;
00062 print(normal(e));
00063
00064 cout << "sqrfree in x,y,z:" << endl;
00065 print(sqrfree(e,lst(x,y,z)));
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 cout << "----------------------------------------" << endl;
00079
00080 list<symexpair> sel;
00081 list<symbol> sl;
00082 sl.push_back(x);
00083 sl.push_back(y);
00084 sl.push_back(z);
00085
00086 cout << "replace_powers:" << endl;
00087 print( replace_powers(e, sl, sel) );
00088
00089 cout << "replace_powers(expand):" << endl;
00090 print( replace_powers(expand(e), sl, sel) );
00091
00092 cout << "replace_powers(sqrfree):" << endl;
00093 print( replace_powers(sqrfree(e, lst(x,y,z)), sl, sel) );
00094
00095 cout << "replace_powers(sqrfree(expand)):" << endl;
00096 print( replace_powers(sqrfree(expand(e), lst(x,y,z)), sl, sel) );
00097 cout << "====================" << endl;
00098
00099
00100
00101
00102
00103
00104
00105
00106 }
00107
00108 int main() {
00109 initSyFi(3);
00110
00111 ex e;
00112
00113 e = x*y+y*z+z*x;
00114 variants(e);
00115
00116 e = pow(x*y+y*z+z*x,5);
00117 variants(e);
00118
00119 e = (x*y*z)*(x*y*z)+(x*y*z)+(x*y*z);
00120 variants(e);
00121
00122 e = pow(2-2*y,3) * pow(1+x*y,2) * pow(x-2*y,2) * (x+y);
00123 variants(e);
00124
00125 e = 1;
00126 for(int i=0; i<10; i++)
00127 {
00128 e = e*isymb("x",i) + isymb("y",i);
00129 }
00130 variants(e);
00131
00132 return 0;
00133 }