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



Dear Stavros,

thanks a lot, I was indeed looking for such a function. It worked very 
nice on example factorizations that I tested. E.g.

assume(x>=0,x<=1)$
postrans(factor(a*x-a));

yields as desired
                             - a (1 - x)

even though I just have weak inequalities in assume(...). Interestingly, 
however, I could not replicate your example.  This means

assume(x>0,x<1)$
postrans((1-x)*(x-1)^3);

yields on my Computer without any change

(1-x)*(x-1)^3

and

assume(x>0,x<1)$
postrans(5*factor((1-x)*(x-1)^3));

yields

- 5 (x - 1)^4

Maybe some of my global settings are different than yours (I have got  
Maxima 5.18.1 for Windows). Still the function will be very helpful, as 
it works in a lot of cases.

Many thanks,
Sebastian



Am 26.3.2011 21:23, schrieb Stavros Macrakis:
> 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 
> <mailto: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 <mailto:Maxima at math.utexas.edu>
>     http://www.math.utexas.edu/mailman/listinfo/maxima
>
>