integrate (e^x-x)^2 dx

I would expand it first

∫ (e^x - x)^2 dx
= ∫ e^(2x) - 2xe^x + x^2 dx

let's concentrate on the middle term, since the other two terms are easy to integrate

∫ 2xe^x dx

let u = 2x , let dv = e^x dx
du = 2dx and v = e^x

then ∫ 2xe^x dx = (2x)(e^x) - ∫ 2e^x dx
= 2xe^x - 2e^x

finally ...
∫ (e^x-x)^2 dx
= ∫ e^(2x) - 2xe^x + x^2 dx
= (1/2e^(2x) - (2xe^x - 2e^x) + (1/3)x^3 + c

= (1/2)e^(2x) - 2xe^x + 2e^x + (1/3)x^3 + c

To integrate the function (e^x - x)^2, we can expand the expression and then perform the integration term by term.

Let's start by expanding the expression (e^x - x)^2:
(e^x - x)^2 = (e^x - x)(e^x - x)
= e^x(e^x - x) - x(e^x - x)
= e^x * e^x - e^x * x - x * e^x + x^2
= e^(2x) - 2xe^x + x^2

Now, we will integrate each term separately:

∫ (e^(2x) - 2xe^x + x^2) dx

Integrating e^(2x) with respect to x gives us:
∫ e^(2x) dx = (1/2) * e^(2x) + C1

Integrating -2xe^x with respect to x requires integration by parts. Using integration by parts formula ∫ u * v dx = u * ∫ v dx - ∫ (u' * ∫ v dx) dx, we consider:
u = -2x (differentiate to get u' = -2)
v = e^x (integrate to get ∫ v dx = e^x)

Using the formula, we have:
∫ -2xe^x dx = u * ∫ v dx - ∫ (u' * ∫ v dx) dx
= (-2x) * e^x - ∫ (-2 * e^x) dx
= -2xe^x + 2∫ e^x dx
= -2xe^x + 2e^x + C2

Finally, integrating x^2 with respect to x gives us:
∫ x^2 dx = (1/3) * x^3 + C3

Now, we can add up the individual integrals to get the solution for the entire expression:

∫ (e^(2x) - 2xe^x + x^2) dx = (1/2) * e^(2x) + (-2xe^x + 2e^x) + (1/3) * x^3 + C

Simplifying this result:
= (1/2) * e^(2x) - 2xe^x + 2e^x + (1/3) * x^3 + C
= (1/2) * e^(2x) + (2e^x - 2xe^x) + (1/3) * x^3 + C

Hence, the integral of (e^x - x)^2 is given by:
(1/2) * e^(2x) + (2e^x - 2xe^x) + (1/3) * x^3 + C, where C is the constant of integration.