### math

#### sage math: how to combine or expand exponents in a symbolic expression?

How can I combine or expand the exponents in an expression in sage? In other words, how can I have sage rewrite an expression from (a**b)**c to a**(b*c), or vise versa? Examples: sage: var('x y') (x, y) sage: assume(x, 'rational') sage: assume(y, 'rational') sage: combine_exponents( (x^2)^y ) x^(2*y) sage: assume(x > 0) sage: expand_exponents( x^(1/3*y) ) (x^y)^(1/3) What I have already tried: sage: b = x^(2*y) sage: a = (x^2)^y sage: bool(a == b) True sage: a (x^2)^y sage: simplify(a) (x^2)^y sage: expand(a) (x^2)^y sage: b x^(2*y) sage: expand(b) x^(2*y) Update: simplify_exp (codelion's answer) works to convert from (a**b)**c to a**(b*c), but not the other way around. Is it possible to get sage to expand exponents as well?

Starting from Sage 6.5, to transform a into b, use the method canonicalize_radical. sage: a.canonicalize_radical() x^(2*y) Note that the four methods simplify_exp, exp_simplify, simplify_radical, radical_simplify, which had the same effect, are being deprecated in favour of canonicalize_radical. See Sage trac ticket #11912. I don't know if there is a built-in function to transform b into a. You could define your own function like this: def power_step(expr, step=None): a, b = SR.var('a'), SR.var('b') if str(expr.operator()) == str((a^b).operator()): aa, mm = expr.operands() if step is None: if str(mm.operator()) == str((a*b).operator()): bb = mm.operands().pop() return (aa^bb)^(mm/bb) else: return expr return (aa^step)^(mm/step) else: if step is None: return expr else: return (expr^step)^(1/step) Then you can decompose the powering into steps: sage: x, y = var('x y') sage: power_step(x^(2*y),y) (x^y)^2 sage: power_step(x^(2*y),2) (x^2)^y Note that if you don't specify the step, it won't always pick the first one that is displayed. sage: power_step(2^(x*y)) (2^y)^x sage: power_step(x^(2*y)) (x^2)^y

You can use the simplify_exp() function. So for your example do the following: sage: a.simplify_exp() x^(2*y)

### Related Links

how to find the shortest distance in geomatry route?

how to reduce dimensionality of vector

Direction from a normalized vector

matrix norm that is invariant through a change of basis

Convert Cartesian point to point on rotated plane (pic)

Spot light cone direction rotation and orientation inversion

Adding two params of a predicate that aren't static

undefined reference to `tan' but math.h has been included

Computing which side of a line a point is [closed]

Solving the recurrence relation for number of nodes in an AVL tree?

how to cluster curve with kmeans?

Mathematical formula for inverse distance in a range [closed]

Drawing a star - what is sine and cosine actually in reference to?

Type-level arithmetics in OCaml

Determining the big Oh for (n-1)+(n-1)

How to store three small numbers into one double?