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

Move point in cartesian coordinate through distance in the given direction
LU-Decomposition factorization error
How to find polygons in a given set of points and edges?
Calculate how much a point is worth based on played games
LibGDX: How to keep an Object at same visual screen position while rotating the camera
Setting the magnitude of a 2D Vector
Convert Lat/Long to X,Y position within a Bounding Box
d3js Cluster Force Layout IV block by Mike
Maximum number of points that lie on the same straight straight line in a 2D plane
How to draw a gps marker on a rotated custom image map
Conversion coordinates from a bound rectangle, to the coordinates of rotated rectangle contained by it
Why isn't this Math.random method working?
Calculate radius of curve/arc formed by line segments (approximate)
The Probability of … After n Trials
Finding minima of a function using genetic algorithm
Number of triangles with N points inside

Categories

HOME
validation
common-lisp
music
opencl
lua
auth0
openshift-origin
path
cql3
stripe-payments
intel-xdk
openvpn
payment-processing
sony
py.test
windows-10-desktop
sql-server-express
frequency
lighttpd
partitioning
android-dialogfragment
oracle11gr2
silk-performer
textmatebundles
similarity
many-to-many
datamatrix
bitcode
parallax
yii1.x
sumifs
debugview
bluebird
udid
angular2-databinding
magento2.0.2
swipe
stackexchange.exceptional
subtotal
jackrabbit
perl-module
sourcetree
jupyter-irkernel
message-hub
internet-explorer-10
consistency
project-centennial
mergesort
wp-api
httpexception
spring-form
smartbanner
jquery-masonry
xbrl
recurrence
stroke
okular
derbyjs
masm32
playback
jahia
itertools
jvm-arguments
tastypie
nuget-package-restore
mapr
olingo
tealeaf
xmllint
vlc-android
geneos
selenium2library
winobjc
target-platform
rabbitvcs
okuma
linq2db
spl
tabbar
xerces
google-swiffy
abort
data-science-studio
odoo
theorem-proving
isql
setattribute
disk-io
modalpopupextender
data-dictionary
android-lru-cache
simpleaudioengine
prudentia
glulookat
floating-point-conversion
jmdns
locomotivejs
rc-shell
cocosbuilder
timestamp-with-timezone
android-actionbar-compat
nsinvocation
jammit
mate
closest
eye-detection
staging
machine.config
indextank
program-transformation
executescalar
resharper-4.5
crc-cards
docking

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App