I think you only use this in one place, so just write u.diff(f(x)) and eliminate the extra variable