SyFi  0.3
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 /* Simplification strategy during form creation:
00009  *      - Count symbols
00010  *      - Take the X % most used symbols, and create a sqrfree factorization
00011  *      OR SIMPLY:
00012  *      - Create a sqrfree factorization wrt (x,y,z)
00013  */
00014 
00015 /* Simplification strategy after integration:
00016  *      - Count symbols
00017  *      - Count flops
00018  *      - Take the P % most used symbols with degree > D, and create a sqrfree factorization
00019  *      - Count flops
00020  *      - Undo if flop count increases!
00021  *      - Register single variable powers
00022  *      - Simplify with ExpressionSimplifier
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                 //cout << "        " << it->first << ": " << it->second << endl;
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         cout << "sqrfree in x,y,z of expanded form:" << endl;
00068         print(sqrfree(expand(e),lst(x,y,z)));
00069 */
00070 
00071 /*
00072         cout << "collect_common_factors:" << endl;
00073         print(collect_common_factors(e));
00074 
00075         cout << "collect_common_factors o expand:" << endl;
00076         print(collect_common_factors(expand(e)));
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         list<symexpair>::iterator it = sel.begin();
00101         for(;it!=sel.end();it++)
00102         {
00103                 cout << it->first << ", " << it->second << endl;
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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator