]> www.ginac.de Git - ginac.git/blobdiff - check/exam_powerlaws.cpp
Finalize 1.7.6 release.
[ginac.git] / check / exam_powerlaws.cpp
index b7f2815fdfdb96342d136e88155bf872673a83dc..fb7328f55dfdc09e39764b25976391ece772cdcc 100644 (file)
@@ -4,7 +4,7 @@
  *  this code, it is a sanity check rather deeply rooted in GiNaC's classes. */
 
 /*
- *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2019 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "exams.h"
+#include "ginac.h"
+using namespace GiNaC;
 
-static unsigned exam_powerlaws1(void)
+#include <iostream>
+using namespace std;
+
+static unsigned exam_powerlaws1()
 {
        // (x^a)^b = x^(a*b)
        
@@ -65,19 +69,19 @@ static unsigned exam_powerlaws1(void)
                return 1;
        }
        
-       ex e4 = e1.subs(lst(a==-1, b==2.5));
+       ex e4 = e1.subs(lst{a==-1, b==-2.5});
        if (!(is_exactly_a<power>(e4) &&
              is_exactly_a<power>(e4.op(0)) &&
              is_exactly_a<symbol>(e4.op(0).op(0)) &&
              is_exactly_a<numeric>(e4.op(0).op(1)) &&
              is_exactly_a<numeric>(e4.op(1)) &&
-             e4.is_equal(power(power(x,-1),2.5)) )) {
-               clog << "(x^a)^b, x symbolic, a==-1, b==2.5 wrong" << endl;
+             e4.is_equal(power(power(x,-1),-2.5)) )) {
+               clog << "(x^a)^b, x symbolic, a==-1, b==-2.5 wrong" << endl;
                clog << "returned: " << e4 << endl;
                return 1;
        }
        
-       ex e5 = e1.subs(lst(a==-0.9, b==2.5));
+       ex e5 = e1.subs(lst{a==-0.9, b==2.5});
        if (!(is_exactly_a<power>(e5) &&
              is_exactly_a<symbol>(e5.op(0)) &&
              is_exactly_a<numeric>(e5.op(1)) &&
@@ -87,7 +91,7 @@ static unsigned exam_powerlaws1(void)
                return 1;
        }
        
-       ex e6 = e1.subs(lst(a==numeric(3)+numeric(5.3)*I, b==-5));
+       ex e6 = e1.subs(lst{a==numeric(3)+numeric(5.3)*I, b==-5});
        if (!(is_exactly_a<power>(e6) &&
              is_exactly_a<symbol>(e6.op(0)) &&
              is_exactly_a<numeric>(e6.op(1)) &&
@@ -100,7 +104,7 @@ static unsigned exam_powerlaws1(void)
        return 0;
 }
 
-static unsigned exam_powerlaws2(void)
+static unsigned exam_powerlaws2()
 {
        // (a*x)^b = a^b * x^b
        
@@ -158,7 +162,7 @@ static unsigned exam_powerlaws2(void)
                return 1;
        }
        
-       ex e5 = e1.subs(lst(a==3.2, b==3+numeric(5)*I));
+       ex e5 = e1.subs(lst{a==3.2, b==3+numeric(5)*I});
        if (!(is_exactly_a<mul>(e5) &&
              (e5.nops()==2) &&
              is_exactly_a<power>(e5.op(0)) &&
@@ -170,7 +174,7 @@ static unsigned exam_powerlaws2(void)
                return 1;
        }
        
-       ex e6 = e1.subs(lst(a==-3.2, b==3+numeric(5)*I));
+       ex e6 = e1.subs(lst{a==-3.2, b==3+numeric(5)*I});
        if (!(is_exactly_a<mul>(e6) &&
              (e6.nops()==2) &&
              is_exactly_a<power>(e6.op(0)) &&
@@ -182,7 +186,7 @@ static unsigned exam_powerlaws2(void)
                return 1;
        }
        
-       ex e7 = e1.subs(lst(a==3+numeric(5)*I, b==3.2));
+       ex e7 = e1.subs(lst{a==3+numeric(5)*I, b==3.2});
        if (!(is_exactly_a<power>(e7) &&
              is_exactly_a<mul>(e7.op(0)) &&
              (e7.op(0).nops()==2) &&
@@ -198,7 +202,7 @@ static unsigned exam_powerlaws2(void)
        return 0;
 }
 
-static unsigned exam_powerlaws3(void)
+static unsigned exam_powerlaws3()
 {
        // numeric evaluation
 
@@ -237,7 +241,7 @@ static unsigned exam_powerlaws3(void)
        return 0;
 }
 
-static unsigned exam_powerlaws4(void)
+static unsigned exam_powerlaws4()
 {
        // test for mul::eval()
        
@@ -262,7 +266,7 @@ static unsigned exam_powerlaws4(void)
        return 0;
 }
 
-static unsigned exam_powerlaws5(void)
+static unsigned exam_powerlaws5()
 {
        // cabinet of slightly pathological cases
        
@@ -284,25 +288,54 @@ static unsigned exam_powerlaws5(void)
        return 0;
 }
 
-unsigned exam_powerlaws(void)
+static unsigned exam_powerlaws6()
+{
+       // check expansion rules for positive symbols
+
+       symbol a("a");
+       symbol b("b");
+       symbol c("c");
+       realsymbol x("x");
+       realsymbol y("y");
+       possymbol p("p");
+       possymbol q("q");
+       numeric half=numeric(1,2);
+
+       ex e1 = pow(5*pow(3*a*b*x*y*p*q,2),7*half*c).expand();
+       ex e2 = pow(p,7*c)*pow(q,7*c)*pow(pow(a*b*x*y,2),numeric(7,2)*c)*pow(45,numeric(7,2)*c);
+       if (!e1.is_equal(e2)) {
+               clog << "Could not expand exponents with positive bases in " << e1 << endl;
+               return 1;
+       }
+
+       ex e3 = pow(-pow(-a*x*p,3)*pow(b*y*p,3),half*c).expand().normal();
+       ex e4 = pow(p,3*c)*pow(pow(a*b*x*y,3),half*c);
+
+       if (!e3.is_equal(e4)) {
+               clog << "Could not expand exponents with positive bases in " << e3 << endl;
+               return 1;
+       }
+
+       return 0;
+}
+
+unsigned exam_powerlaws()
 {
        unsigned result = 0;
        
        cout << "examining power laws" << flush;
-       clog << "----------power laws:" << endl;
        
        result += exam_powerlaws1();  cout << '.' << flush;
        result += exam_powerlaws2();  cout << '.' << flush;
        result += exam_powerlaws3();  cout << '.' << flush;
        result += exam_powerlaws4();  cout << '.' << flush;
        result += exam_powerlaws5();  cout << '.' << flush;
-       
-       if (!result) {
-               cout << " passed " << endl;
-               clog << "(no output)" << endl;
-       } else {
-               cout << " failed " << endl;
-       }
+       result += exam_powerlaws6();  cout << '.' << flush;
        
        return result;
 }
+
+int main(int argc, char** argv)
+{
+       return exam_powerlaws();
+}