Talk:Common subexpression elimination

This problem seems much more complicated than the article suggests. For example,

takes 19 multiplications and 9 additions to evaluate, but it can be rewritten as

which only requires 3 multiplications and 3 additions. How does subexpression elimination know how to do this?