- // (a*x)^b = a^b * x^b
-
- symbol x("x");
- symbol a("a");
- symbol b("b");
-
- ex e1=power(a*x,b);
- if (!(is_ex_exactly_of_type(e1,power) &&
- is_ex_exactly_of_type(e1.op(0),mul) &&
- (e1.op(0).nops()==2) &&
- is_ex_exactly_of_type(e1.op(0).op(0),symbol) &&
- is_ex_exactly_of_type(e1.op(0).op(1),symbol) &&
- is_ex_exactly_of_type(e1.op(1),symbol) &&
- e1.is_equal(power(a*x,b)) )) {
- clog << "(a*x)^b, x,a,b symbolic wrong" << endl;
- clog << "returned: " << e1 << endl;
- return 1;
- }
-
- ex e2=e1.subs(a==3);
- if (!(is_ex_exactly_of_type(e2,power) &&
- is_ex_exactly_of_type(e2.op(0),mul) &&
- (e2.op(0).nops()==2) &&
- is_ex_exactly_of_type(e2.op(0).op(0),symbol) &&
- is_ex_exactly_of_type(e2.op(0).op(1),numeric) &&
- is_ex_exactly_of_type(e2.op(1),symbol) &&
- e2.is_equal(power(3*x,b)) )) {
- clog << "(a*x)^b, x,b symbolic, a==3 wrong" << endl;
- clog << "returned: " << e2 << endl;
- return 1;
- }
-
- ex e3=e1.subs(b==-3);
- if (!(is_ex_exactly_of_type(e3,mul) &&
- (e3.nops()==2) &&
- is_ex_exactly_of_type(e3.op(0),power) &&
- is_ex_exactly_of_type(e3.op(1),power) &&
- e3.is_equal(power(a,-3)*power(x,-3)) )) {
- clog << "(a*x)^b, x,a symbolic, b==-3 wrong" << endl;
- clog << "returned: " << e3 << endl;
- return 1;
- }
-
- ex e4=e1.subs(b==4.5);
- if (!(is_ex_exactly_of_type(e4,power) &&
- is_ex_exactly_of_type(e4.op(0),mul) &&
- (e4.op(0).nops()==2) &&
- is_ex_exactly_of_type(e4.op(0).op(0),symbol) &&
- is_ex_exactly_of_type(e4.op(0).op(1),symbol) &&
- is_ex_exactly_of_type(e4.op(1),numeric) &&
- e4.is_equal(power(a*x,4.5)) )) {
- clog << "(a*x)^b, x,a symbolic, b==4.5 wrong" << endl;
- clog << "returned: " << e4 << endl;
- return 1;
- }
-
- ex e5=e1.subs(lst(a==3.2,b==3+numeric(5)*I));
- if (!(is_ex_exactly_of_type(e5,mul) &&
- (e5.nops()==2) &&
- is_ex_exactly_of_type(e5.op(0),power) &&
- is_ex_exactly_of_type(e5.op(1),numeric) &&
- e5.is_equal(power(x,3+numeric(5)*I)*
- power(numeric(3.2),3+numeric(5)*I)) )) {
- clog << "(a*x)^b, x symbolic, a==3.2, b==3+5*I wrong" << endl;
- clog << "returned: " << e5 << endl;
- return 1;
- }
-
- ex e6=e1.subs(lst(a==-3.2,b==3+numeric(5)*I));
- if (!(is_ex_exactly_of_type(e6,mul) &&
- (e6.nops()==2) &&
- is_ex_exactly_of_type(e6.op(0),power) &&
- is_ex_exactly_of_type(e6.op(1),numeric) &&
- e6.is_equal(power(-x,3+numeric(5)*I)*
- power(numeric(3.2),3+numeric(5)*I)) )) {
- clog << "(a*x)^b, x symbolic, a==-3.2, b==3+5*I wrong" << endl;
- clog << "returned: " << e6 << endl;
- return 1;
- }
-
- ex e7=e1.subs(lst(a==3+numeric(5)*I,b==3.2));
- if (!(is_ex_exactly_of_type(e7,power) &&
- is_ex_exactly_of_type(e7.op(0),mul) &&
- (e7.op(0).nops()==2) &&
- is_ex_exactly_of_type(e7.op(0).op(0),symbol) &&
- is_ex_exactly_of_type(e7.op(0).op(1),numeric) &&
- is_ex_exactly_of_type(e7.op(1),numeric) &&
- e7.is_equal(power((3+numeric(5)*I)*x,3.2)) )) {
- clog << "(a*x)^b, x symbolic, a==3+5*I, b==3.2 wrong" << endl;
- clog << "returned: " << e7 << endl;
- return 1;
- }
-
- return 0;
+ // (a*x)^b = a^b * x^b
+
+ symbol x("x");
+ symbol a("a");
+ symbol b("b");
+
+ ex e1 = power(a*x,b);
+ if (!(is_exactly_a<power>(e1) &&
+ is_exactly_a<mul>(e1.op(0)) &&
+ (e1.op(0).nops()==2) &&
+ is_exactly_a<symbol>(e1.op(0).op(0)) &&
+ is_exactly_a<symbol>(e1.op(0).op(1)) &&
+ is_exactly_a<symbol>(e1.op(1)) &&
+ e1.is_equal(power(a*x,b)) )) {
+ clog << "(a*x)^b, x,a,b symbolic wrong" << endl;
+ clog << "returned: " << e1 << endl;
+ return 1;
+ }
+
+ ex e2 = e1.subs(a==3);
+ if (!(is_exactly_a<power>(e2) &&
+ is_exactly_a<mul>(e2.op(0)) &&
+ (e2.op(0).nops()==2) &&
+ is_exactly_a<symbol>(e2.op(0).op(0)) &&
+ is_exactly_a<numeric>(e2.op(0).op(1)) &&
+ is_exactly_a<symbol>(e2.op(1)) &&
+ e2.is_equal(power(3*x,b)) )) {
+ clog << "(a*x)^b, x,b symbolic, a==3 wrong" << endl;
+ clog << "returned: " << e2 << endl;
+ return 1;
+ }
+
+ ex e3 = e1.subs(b==-3);
+ if (!(is_exactly_a<mul>(e3) &&
+ (e3.nops()==2) &&
+ is_exactly_a<power>(e3.op(0)) &&
+ is_exactly_a<power>(e3.op(1)) &&
+ e3.is_equal(power(a,-3)*power(x,-3)) )) {
+ clog << "(a*x)^b, x,a symbolic, b==-3 wrong" << endl;
+ clog << "returned: " << e3 << endl;
+ return 1;
+ }
+
+ ex e4 = e1.subs(b==4.5);
+ if (!(is_exactly_a<power>(e4) &&
+ is_exactly_a<mul>(e4.op(0)) &&
+ (e4.op(0).nops()==2) &&
+ is_exactly_a<symbol>(e4.op(0).op(0)) &&
+ is_exactly_a<symbol>(e4.op(0).op(1)) &&
+ is_exactly_a<numeric>(e4.op(1)) &&
+ e4.is_equal(power(a*x,4.5)) )) {
+ clog << "(a*x)^b, x,a symbolic, b==4.5 wrong" << endl;
+ clog << "returned: " << e4 << endl;
+ return 1;
+ }
+
+ 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)) &&
+ is_exactly_a<numeric>(e5.op(1)) &&
+ e5.is_equal(power(x,3+numeric(5)*I)*
+ power(numeric(3.2),3+numeric(5)*I)) )) {
+ clog << "(a*x)^b, x symbolic, a==3.2, b==3+5*I wrong" << endl;
+ clog << "returned: " << e5 << endl;
+ return 1;
+ }
+
+ 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)) &&
+ is_exactly_a<numeric>(e6.op(1)) &&
+ e6.is_equal(power(-x,3+numeric(5)*I)*
+ power(numeric(3.2),3+numeric(5)*I)) )) {
+ clog << "(a*x)^b, x symbolic, a==-3.2, b==3+5*I wrong" << endl;
+ clog << "returned: " << e6 << endl;
+ return 1;
+ }
+
+ 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) &&
+ is_exactly_a<symbol>(e7.op(0).op(0)) &&
+ is_exactly_a<numeric>(e7.op(0).op(1)) &&
+ is_exactly_a<numeric>(e7.op(1)) &&
+ e7.is_equal(power((3+numeric(5)*I)*x,3.2)) )) {
+ clog << "(a*x)^b, x symbolic, a==3+5*I, b==3.2 wrong" << endl;
+ clog << "returned: " << e7 << endl;
+ return 1;
+ }
+
+ return 0;