Suppose you have an expression like this:

`sqrt(x) * 6 + sqrt(x + 1) * 6 + sqrt(x + 2) * 6 `

Are there any well-known or published algorithms that can find the repeated partial expressions and extract a function like this?

`let f(x) = sqrt(x) * 6 in f(x) + f(x + 1) + f(x + 2) `

I imagine there are some clever schemes in either the automatic vectorization literature or in automatically finding duplicate code. This is also somewhat similar to common subexpression elimination.