You can also use my pkg Reduce.jl for that if you want symbolic optimized common sub-expressions
julia> using Reduce; load_package(:scope)
julia> Algebra.optimize(:(z = a^2*b^2+10*a^2*m^6+a^2*m^2+2*a*b*m^4+2*b^2*m^6+b^2*m^2))
quote
g40 = b * a
g44 = m * m
g41 = g44 * b * b
g42 = g44 * a * a
g43 = g44 * g44
z = g41 + g42 + g40 * (2g43 + g40) + g43 * (2g41 + 10g42)
end
or if you really want @pure
you can just locally define a new method for that like I described here