3

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)?

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
LBogaardt
  • 1,595
  • 1
  • 11
  • 21
  • 1
    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. – ssch Nov 07 '13 at 20:13

2 Answers2

6

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) *)
ssch
  • 16,590
  • 2
  • 53
  • 88
3
(-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)

chyanog
  • 15,542
  • 3
  • 40
  • 78