TITLE: Derivative of max function
QUESTION [42 upvotes]: I was just wondering what the derivative of $f(x) = \max(0,1-x)^{2}$ would be. What technique do you use to determine this derivative?

REPLY [4 votes]: I would generalize this as follows:
Let
f(x) = max(0, g(x))^2

Then
f'(x) = [2*g(x)*g'(x)] if g(x) is > 0 else [0]

Does it make sense?