Isaak B. answered 06/18/19
Engineering Physics Grad Experienced with using MATLAB
You don't need to expand a function to use its result.
The fact that its result is being used multiple places in the derivative doesn't change that.
e.g. when we write that two things are equal, they are literally exactly equivalent. So use what f(x) works out to or the expression that explains how it gets worked out --- wherever, and as many times as you want.