PS And if you want to recurse down the whole expression, you can either use
scanmap(separate_roots, ...)
or
separate_roots(ex):=
if mapatom(ex)
then ex
elseif inpart(ex,0)="^"
then block([b:inpart(ex,1),e:inpart(ex,2)],
if numberp(b) and numberp(e)
then b^truncate(e)*box(b^(e-truncate(e)))
else map('separate_roots,ex))
else map('separate_roots,ex)$
-s
On Sun, Feb 5, 2012 at 14:07, Stavros Macrakis <macrakis at alum.mit.edu>wrote:
> 5^(3/2) is Maxima's standard way of expressing sqrt(5)^3 = 5*sqrt(5). It
> is important in Maxima to have standard ways of expressing such things,
> otherwise it risks not simplifying e.g. 5*sqrt(5) - 5^(3/2).
>
> Since Maxima is programmable, you can of course generate whatever form you
> want -- though you shouldn't use the standard sqrt function, since Maxima
> "knows" about it and will simplify it.
>
> Here is one simple trick:
>
> (%i1) display2d:false$
> (%i2) 5^(3/2);
> (%o2) 5^(3/2)
> (%i3) ratsubst(sqr(5),sqrt(5),%o2);
> (%o3) sqr(5)^3
> (%i4) ratsubst(5,sqr(5)^2,%o3);
> (%o4) 5*sqr(5)
>
> Of course, subsequent calculations won't know that sqr(5)^2 = 5.
>
> You could also do something like this:
>
> separate_roots(ex):=
> if mapatom(ex)
> then ex
> elseif inpart(ex,0)="^"
> then block([b:inpart(ex,1),e:inpart(ex,2)],
> if numberp(b) and numberp(e)
> then b^truncate(e)*box(b^(e-truncate(e))) <<< box "protects" from
> simplification
> else ex)
> else ex$
>
> This produces ugly results (with box), especially for negative powers, but
> you should be able to customize this to something more of your liking.
>
> -s
>
> On Sat, Feb 4, 2012 at 10:41, zxl <zhaxiaolei at gmail.com> wrote:
>
>> hello:
>>
>> I hope expand (a+b sqrt(5))^n to the form A+B sqrt(5), but expand
>> ((1+sqrt(5))) give me 5^(3/2)+ 3 sqrt(5) + 16. How can I convert 5^(3/2) to
>> 5 5^(1/2) ?
>>
>> thanks
>>
>> z.x.l
>>
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>
>>
>