Changing signs of terms like (x-1) after factor or simplification
Subject: Changing signs of terms like (x-1) after factor or simplification
From: Sebastian Kranz
Date: Sun, 27 Mar 2011 04:31:31 +0200
Great! The new function works perfectly so far on all my examples.
Thanks for the hint that there is a new Maxima version. The "News" on
the Maxima website: http://maxima.sourceforge.net/ seem to be a bit
outdatet as it currently states version 5.18.1 from 2009 to be the
newest version. (I was already wondering a bit whether development of
Maxima had stopped). Is there some website that lists the changes in the
new versions?
(In particular, I wonder whether with a new version, it is possible to
have an external program send input to Maxima via a named pipe in
Windows. I have actually started to write a, very unelegant, interface
that allows to copy math into the clipboard from Lyx, press on a button
in a Tcl/Tk window created by an R program that reads these Latex
strings, does a lot of string replacements and writes the resulting
Maxima code into a file, starts a new instance of Maxima to run this
file, reads the resulting file, transforms it back to nice Latex math
readable by Lyx and copies it back to the clipboard so that the user can
paste the modified mathematical expression whereever he likes in Lyx.
Sounds completely inrobust, but it actually seems to work surprisingly
decent in a very raw first version. It just takes some time to restart
Maxima every time one wants to perform some math operation in Lyx, as I
could not figure out how to pipe to a running instance of Maxima...)
Best wishes,
Sebastian
Am 27.3.2011 03:30, schrieb Stavros Macrakis:
> Sorry! I sent you the wrong version of my code.
>
> Try:
>
> pullsign(ex) :=
> (ex: postrans(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))$
>
> By the way, you may want to update to the current version of Maxima --
> I am testing on 5.23.2.
>
> -s
>
> On Sat, Mar 26, 2011 at 21:07, Sebastian Kranz <skranz at uni-bonn.de
> <mailto:skranz at uni-bonn.de>> wrote:
>
> 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
>>
>>
>
>