- if (exponent.info(info_flags::integer)) {
- // Integer powers are distributed
- ex n = basis.bp->normal(sym_lst, repl_lst, level-1);
- ex num = n.numer(false);
- ex den = n.denom(false);
- return power(num, exponent) / power(den, exponent);
- } else {
- // Non-integer powers are replaced by temporary symbol (after normalizing basis)
- ex n = power(basis.bp->normal(sym_lst, repl_lst, level-1), exponent);
- return replace_with_symbol(n, sym_lst, repl_lst);
+ // Normalize basis
+ ex n = basis.bp->normal(sym_lst, repl_lst, level-1);
+
+ if (exponent.info(info_flags::integer)) {
+
+ if (exponent.info(info_flags::positive)) {
+
+ // (a/b)^n -> {a^n, b^n}
+ return (new lst(power(n.op(0), exponent), power(n.op(1), exponent)))->setflag(status_flags::dynallocated);
+
+ } else if (exponent.info(info_flags::negint)) {
+
+ // (a/b)^-n -> {b^n, a^n}
+ return (new lst(power(n.op(1), -exponent), power(n.op(0), -exponent)))->setflag(status_flags::dynallocated);
+ }
+
+ } else {
+ if (exponent.info(info_flags::positive)) {
+
+ // (a/b)^z -> {sym((a/b)^z), 1}
+ return (new lst(replace_with_symbol(power(n.op(0) / n.op(1), exponent), sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated);
+
+ } else {
+
+ if (n.op(1).is_equal(_ex1())) {
+
+ // a^-x -> {1, sym(a^x)}
+ return (new lst(_ex1(), replace_with_symbol(power(n.op(0), -exponent), sym_lst, repl_lst)))->setflag(status_flags::dynallocated);
+
+ } else {
+
+ // (a/b)^-x -> {(b/a)^x, 1}
+ return (new lst(replace_with_symbol(power(n.op(1) / n.op(0), -exponent), sym_lst, repl_lst), _ex1()))->setflag(status_flags::dynallocated);
+ }
+ }