In the “Optimization with gradients: An example” lecture, somehow this equation:

was converted to

Could someone please explain what math method was used to do this?

In the “Optimization with gradients: An example” lecture, somehow this equation:

was converted to

Could someone please explain what math method was used to do this?

Hi @kopachevsky!

Sure, we ommited this step because it would be quite messy and would take some time to just explain a tiny part. It is not hard, but a bit lengthy.

So let’s begin. Note that we can factor out a xy^2 from each term:

-\frac{1}{30} x^2 y^3 + \frac{1}{5}x^2 y^2 + \frac{2}{15} x y^3 - \frac{4}{5} x y^2 = xy \left( -\frac{1}{30} x y + \frac{1}{5}x + \frac{2}{15} y - \frac{4}{5} \right)

Let’s make the denominators all the same to simplify our calculations:

xy \left( -\frac{1}{30} x y + \frac{1}{5}x + \frac{2}{15} y - \frac{4}{5} \right) = xy \left( \frac{- x y + 6x + 4y -24}{30} \right) = \frac{xy}{30} \left( - x y + 6x + 4y -24\right)

Inside the parenthesis, we can factor one y (*):

\frac{xy}{30} \left( - x y + 6x + 4y -24\right) = \frac{xy}{30} \left( y(-x + 4) + 6x-24\right). Note also that 6x - 24 = 6(x-4). So:

\frac{xy}{30} \left( y(-x + 4) + 6x-24\right) = \frac{xy}{30} \left( y(-x + 4) + 6(x-4)\right).

Finally, note that -x+4 = -(x-4), so:

\frac{xy}{30} \left( y(-x + 4) + 6(x-4)\right) = \frac{xy}{30} \left( -y(x -4) + 6(x-4)\right) = \frac{xy^2}{30} (x-4)\left(6 - y\right) .

And this is essentialy the same as the image you have added. If you want to get exactly this, I think you can get it by factoring out x instead of y in (*). However, you can just see it by writing x - 4 = \frac{3x - 12}{3}.

I hope that helps!

Lucas

@lucas.coutinho This is the perfect explanation, I had this gues as one of possible options, but had also thought maybe there are some other tricks. Thanks!