Changing signs of terms like (x-1) after factor or simplification



How about something like this:

pullsign(ex) :=
   if member(sign(ex), '[neg, nz])
   then [-1, -ex]
   else [1, ex]$

postrans(ex):=
  block([inflag:true,pull],
    if mapatom(ex) then ex
    elseif op(ex)="*" then
       (pull:maplist(pullsign,ex),
        apply("*",map('first,pull))*apply("*",map('second,pull)))
    elseif op(ex)="^" then
       (pull:pullsign(part(ex,1)),
        pull[1]^part(ex,2)*pull[2]^part(ex,2))
    else map(postrans,ex))$

Example:

     assume(x>0,x<1)$

     postrans((1-x)*(x-1)^3)  =>  -(1-x)^4

Note that this won't work for a single term:

     postrans(-(1-x)) => x-1

Is this what you had in mind?

           -s


On Sat, Mar 26, 2011 at 11:47, Sebastian Kranz <skranz at uni-bonn.de> wrote:

> Hi,
>
>  I use Maxima often to simplify terms or equations that have a lot terms of
> the form (1-x) with variables x in [0,1]. The simplifying functions of
> Maxima tend to transform the terms (1-x) in the less intuitive form -(x-1)
> and I have to convert them back manually. For example,
>
> (%i231) factor(a-x*a);
> (%o231) - a (x - 1)
>
> Does anybody know an automatic way to tell Maxima that it shall tranform
> terms like (x-1) into -(1-x) and multiply the minus sign with all other
> minus signs in the product? E.g. I would like
>
> factor(a-x*a);
> a (1-x)
>
> or
>
> factor(-a+x*a);
> - a (1-x)
>
> Alternatively, is it complicated to write a general function that does this
> transformation? E.g. a function nicesign(expr), yielding:
>
> nicesign(factor(a-x*a));
> a (1-x)
>
> Perhaps creating such a function is not too complciated, but I really have
> no knowledge of maxima programming.
>
> Thanks for any help,
> Sebastian
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>