0
$\begingroup$

While massaging an expression in Mathematica I get terms of the form $(-((-1 + z) z))^{-1 + \epsilon}$. However, $z$ is between $0$ and $1$ and thus I would prefer $((1 - z) z)^{-1 + \epsilon}$. Just using simplify gives me the undesired result, so I tried defining a complexity function for Simplify:

   Simplify[
     (-((-1 + z) z))^(-1 + \[Epsilon]), ComplexityFunction -> (LeafCount[#] + 
       100 Count[#, -1 + z, {0, Infinity}]) &] 

This hower stll gives me $(-((-1 + z) z))^{-1 + \epsilon}$ so I tried to help Mathematica by telling it the transformation rule I want

tf[x_] := x /. -((-1 + z) z) :> z (1 - z);
 Simplify[(-((-1 + z) z))^(-1 + \[Epsilon]), 
   ComplexityFunction -> (LeafCount[#] + 100 Count[#, -1 + z, {0, Infinity}]) &, 
   TransformationFunctions -> {tf, Automatic}] 

,which however still yields $(-((-1 + z) z))^{-1 + \epsilon}$. Finally, I told Mathematica to only use my transformation

   Simplify[(-((-1 + z) z))^(-1 + \[Epsilon]), 
   ComplexityFunction -> (LeafCount[#] + 
       100 Count[#, -1 + z, {0, Infinity}]) &, 
   TransformationFunctions -> {tf}] 

, which finally yields $((1 - z) z)^{-1 + \epsilon}$. However, in general, I would like Mathematica to also check for other simplifications. I do not understand why Mathematica ends up with a worse complexity when using more possible simplifications.

Edit: Also adding assumptions as suggested by Mariusz Iwaniuk does not work and still yields the undesired result.

Simplify[(-((-1 + z) z))^(-1 + \[Epsilon]),   Assumptions -> {0 <= z <= 1, \[Epsilon] \[Element] Reals}]
$\endgroup$
3
  • 1
    $\begingroup$ To more simplified input: Simplify[(-((-1 + z) z))^(-1 + \[Epsilon]), Assumptions -> {0 <= z <= 1, \[Epsilon] \[Element] Reals}] $\endgroup$ Dec 21, 2022 at 9:41
  • $\begingroup$ Put the & inside the parentheses in your complexity function. $\endgroup$ Dec 21, 2022 at 19:38
  • $\begingroup$ Why not use your tf[x] directly to pre-process the expression and then use Simplify for further simplifications? Simplify is almost a blackbox to users and hard to control. $\endgroup$
    – Lacia
    Dec 24, 2022 at 8:08

1 Answer 1

-1
$\begingroup$

Let us try the following. First, let us introduce a function, factorMinus, which takes a sign minus out of the expression:

factorMinus[expr_, fun_ : Identity] := (-1)*
  HoldForm[Evaluate[fun[(-1)*expr]]]

Now one can apply this function to the term -1+z:

expr1 = MapAt[factorMinus, expr, {1, 2}] // ReleaseHold
(*  ((1 - z) z)^(-1 + \[Epsilon])   *)

Done. Have fun!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.