Let #y = x-xe^(x-x^2/2)#.

Factor out #x#.

#y = x(1-e^(x-x^2/2))#

Take the derivative and use the #color(blue)("product rule")# :

#dy/dx = color(red)(d/dx(x))(1-e^(x-x^2/2)) + xcolor(red)(d/dx (1-e^(x-x^2))#

The #1# doesn't matter when differentiating.

Let #g(x) = e^(x-x^2/2)#

Using the property that #color(blue)(d/dx -f(x) = -d/dx f(x))#, we get :

#dy/dx = 1-e^(x-x^2/2)-x*color(red)(g'(x)#

We have to solve the for #color(red)(g'(x))#.

Take the natural logarithm of #g(x)# :

#ln(g(x)) = (x-x^2/2)ln e = x-x^2/2#

And now differentiate both sides :

#(g'(x))/(g(x)) = d/dx x-x^2/2 = d/dx x - d/dx x^2/2#

#(g'(x))/(g(x)) = 1 - x#

#g'(x) = (e^(x-x^2/2))(1-x)#

Substitute it in the #dy/dx# equation :

#dy/dx = 1 -e^(x-x^2/2) - x(e^(x-x^2/2))(1-x)#, so

#dy/dx = 1-e^(x-x^2/2)(1-x(1-x))#

#dy/dx = 1-e^(x-x^2/2)(1-x+x^2)#

And finally,

#color(blue)(f'(x) =1-e^(x-x^2/2)(x^2+x-1) #.