
# Tests of the ** operator and routines to collect exponents.

obj1:= sin(x) b sin(x) c sin(x)**3 d;
@collect_factors!(%);
tst1:= sin(x)**5 b c d - @(obj1);
@collect_terms!(%);
@assert(tst1);


obj2:= A_{m n} b A_{m n};
@collect_factors!(%);
tst2:= A_{m n} b A_{m n} - @(obj2);
@collect_terms!(%);
@assert(tst2);


obj3:= a**(2+3b) c a**(sin(x));
@collect_factors!(%);
tst3:= a**((2 + 3 * b) + sin(x)) * c - @(obj3);
@collect_terms!(%);
@assert(tst3);

tst4:= x**2;
@substitute!(%)( x-> 0);
@assert(tst4);

obj5:= p**2 p**{-1};
@collect_factors!(%);
tst5:= p - @(obj5);
@collect_terms!(%);
@assert(tst5);

obj6:= 3 p**2 p**{-2} * h_{m n} * h^{m n};
@collect_factors!(%);
tst6:= 3 h_{m n} h^{m n} - @(obj6);
@collect_terms!(%);
@assert(tst6);

obj7:= 3 p p**{-1} * h_{m n} * h^{m n};
@collect_factors!(%);
tst7:= 3 h_{m n} h^{m n} - @(obj7);
@collect_terms!(%);
@assert(tst7);

# Test 8: Catch powers <=1.
@reset.
obj8:= A**(-1);
@expand_power!(%);
tst8:= A**(-1) - @(obj8);
@collect_terms!(%);
@assert(tst8);

# Test 8b: Catch non-integer powers.
@reset.
obj8b:= A**(3/2);
@expand_power!(%);
tst8b:= A**(3/2) - @(obj8b);
@collect_terms!(%);
@assert(tst8b);


# Test 9: nested powers and so on
#
@reset.
obj9:= b**2 c**3 e;
@substitute!(%)(b -> 2*B*C, c -> (2*A*C + B**2), e -> A**2 );
# max9:= expand( @(obj9) );
@expand_power!(obj9);
@distribute!(%);
@prodsort!(%);
@collect_terms!(%);
@collect_factors!(%);
# @maxima(max9);
tst9:= 4 A**2 B**8 C**2 + 24 A**3 B**6 C**3 + 48 A**4 B**4 C**4 + 32 A**5 B**2 C**5 - @(obj9);
@collect_terms!(%);
@assert(tst9);

# Test 10: non-commuting factors
#
@reset.
{A,B,C,D,E}::NonCommuting.
obj10:= A B D q E B A q;
@collect_factors!(%);
tst10:= A B D q**2 E B A - @(obj10);
@collect_terms!(%);
@assert(tst10);

# Test 11: multipliers inside pow
#
@reset.
obj11a:= x**2;
@substitute!(%)( x -> -u );
@expand_power!(%);
@collect_factors!(%);
tst11a:= u**2 - @(obj11a);
@collect_terms!(%);
@assert(tst11a);

@reset.
obj11b:= x**3;
@substitute!(%)( x -> - 3 u );
@expand_power!(%);
@collect_factors!(%);
tst11b:= - 27 u**3 - @(obj11b);
@collect_terms!(%);
@assert(tst11b);

@reset.
obj11c:= x**{m} x**{-m};
@collect_factors!(%);
tst11c:= 1 - @(obj11c);
@collect_terms!(%);
@assert(tst11c);

@reset.
obj11d:= x**2 - x**{2};
@collect_terms!(%);
@assert(obj11d);

@reset.
obj11e:= x**{-2} - x**{(-2)};
@collect_terms!(%);
@assert(obj11e);

