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)
?
$\begingroup$
$\endgroup$
1
-
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$– sschCommented Nov 7, 2013 at 20:13
Add a comment
|
2 Answers
$\begingroup$
$\endgroup$
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) *)
$\begingroup$
$\endgroup$
(-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)