3
$\begingroup$

I am using the ratio between two error probabilities in various functions. I want Mathematica to display this ratio in the most simple manner. How do I let Mathematica know that, in this case, the simplest manner is as the top line in the picture below? How do I let Mathematica factor the expression into (e1), (e2), (1 - e1) and (1 - e2)?

http://i.stack.imgur.com/89eol.png

$\endgroup$
  • 1
    $\begingroup$ Welcome to Mathematica.SE! Next time post the actual code instead of a picture, that makes it quicker for people to try it out and answer the question. $\endgroup$ – ssch Nov 7 '13 at 20:13
6
$\begingroup$

When Simiplify isn't doing what you want, always have a look at the FullForm to see why:

(1 - e1)/(1 - e2) // FullForm
(* Times[Plus[1, Times[-1, e1]], Power[Plus[1, Times[-1, e2]], -1]] *)

(-1 + e1)/(-1 + e2) // FullForm
(* Times[Plus[-1, e1], Power[Plus[-1, e2], -1]] *)

We see that it's related to -1 being very simple while -e2 is actually -1 * e2 we could use this to construct an appropriate ComplexityFunction but in many cases StringLength @ ToString @ # & is easier and gives good results:

StringLength@ToString[(1 - e1)/(1 - e2)]
(* 20 *)

StringLength@ToString[(-1 + e1)/(-1 + e2)]
(* 23 *)

Simplify[(-1 + e1)/(-1 + e2),
 ComplexityFunction :> (StringLength @ ToString @ # &)
 ]
(* (1 - e1)/(1 - e2) *)
$\endgroup$
3
$\begingroup$
(-1 + e1)/(-1 + e2) // TraditionalForm // StandardForm

(e1-1)/(e2-1)

Simplify[(-1 + e1)/(-1 + e2), 
 ComplexityFunction :> (LeafCount@# + 10 Count[#, -1 + _, -1] &)]

(1 - e1)/(1 - e2)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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