Suppose I have formula like the following:
(1 - x) (1 - y) + ((1 - x) (1 - y))/(z + 2)
Obviously, (1 - x) (1 - y) is found a couple of places in the formula.
How do I denote (1 - x) (1 - y) by z and thereby simplify my formula?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityIf you are looking for an automated process you may find Experimental`OptimizeExpression
useful:
$Context = "Compile`"; (* improve formatting for copy *)
Experimental`OptimizeExpression[(1 - x) (1 - y) + ((1 - x) (1 - y))/(z + 2)]
Experimental`OptimizedExpression[ Block[{$1, $2, $3, $4}, $1 = -x; $2 = 1 + $1; $3 = -y; $4 = 1 + $3; $2 $4 + ($2 $4)/(2 + z) ] ]
Or perhaps a simple replacement can suit your needs:
(1 - x) (1 - y) + ((1 - x) (1 - y))/(z + 2) /. ((1 - x) (1 - y)) :> zz
zz + zz/(2 + z)
I used zz
instead of z
for clarity.
Simplify[(1 - x) (1 - y) + ((1 - x) (1 - y))/(z + 2), z == (1 - x) (1 - y)]
$$\frac{z (z+3)}{z+2}$$
PolynomialReduce
is a good function for computations of this type. $\endgroup$