Mathematica often writes simplied expressions with -1
first followed by any variables (eg. -1+x
).
However I want to write it as -(1-x)
i.e. retaining 1-x
form everywhere.
The reason is two fold: first is of course beautification. Secondly sometimes when multiplying a number of expressions containing some parts in the numerator and denominator differ by overall negative sign do not simplify unless I use FullSimplify
. Now sometimes using FullSimplify
at a later stage of simplification could be considerably inefficient in terms of performance.
Some naive custom simplification rules to cure this problem could be dangerous as the following toy example:
t1=(-((-1+u) /(1+u (-1+v))))^(-(1/2))//PowerExpand
Now this is not nice looking. A naive delayed substitution could be fatal.
t2 = (( t1 /. Plus[-1,x_] :> (1-x)*$g ) //PowerExpand)/. {$g->-1}
This is of course wrong.
How should one safely do such simplification to force (1-x)
form correctly?
Edit: The desired form of the input (restricting in a unit hypercube) will look like following:
t0=(-((-1+u) /(1+u (-1+v))))^(-(1/2))
t3=Assuming[{0<=u<=1,0<=v<=1},t0 /. Power[x_,y_] :> Simplify[Expand[x]]^y /. {Plus[-1,x_] :> (1-x)*$g} /. {$g->-1}]//PowerExpand
Note that t0
and t1
differ by PowerExpand
. So the results differ if I first do Simplification within brackets and then PowerExpand or first do PowerExpand and then do simplification.
TraditionalForm
for display:(t1 = (-((-1 + u)/(1 + u (-1 + v))))^(-(1/2)) // PowerExpand) // TraditionalForm
$\endgroup$x-1
is not I am after rather(1-x)
form. $\endgroup$Sqrt
, which must be done manually anyway. It also only uses the form1-x
. Is it nonetheless still problematic somehow? $\endgroup$PowerExpand
being, well...questionably implemented! The "Possible issues" section ofPowerExpand
notes that it will sometimes do weird things under automatic assumptions. If you know thatu,v > 0
, you can doPowerExpand[t0, Assumptions -> {u > 0, v > 0}]
and get the right answer. You can also doPowerExpand[t0, Assumptions -> {}]
for maximum safety and generality, but you get an ugly sign factor in front. In general idk...but either wayPowerExpand
seems responsible for your woes here! I wonder ifSimplify
by itself could be made to work... $\endgroup$