Based on the fundamental trigonometric identity:
#sin^2 alpha + cos^2 alpha = 1#
we have that:
#int (sin^2(x/2)+cos^2(x/2))/(sin(x/2) - cos(x/2))dx = int dx/(sin(x/2)- cos(x/2))#
Use now the parametric fomulas:
#sin(x/2) = (2tan(x/4))/(1+tan^2(x/4))#
#cos(x/2) = (1-tan^2(x/4))/(1+tan^2(x/4))#
substituting:
#t= tan(x/4)#
#x = 4arctan(t)#
#dx = (4dt)/(1+t^2)#
we have:
# int dx/(sin(x/2)- cos(x/2)) = int 1/( (2t)/(1+t^2) - (1-t^2)/(1+t^2)) (4dt)/(1+t^2)#
# int dx/(sin(x/2)- cos(x/2)) = 4 int (dt)/(t^2+2t-1)#
Complete the square at the denominator:
# int dx/(sin(x/2)- cos(x/2)) = 4 int (dt)/((t+1)^2-2) = 2int (dt)/(((t+1)/sqrt2)^2 -1)#
Substitute again:
#u = (t+1)/sqrt2#
#dt =sqrt2 du#
so:
# int dx/(sin(x/2)- cos(x/2)) = 2sqrt2 int (du)/(u^2-1)#
factorize the denominator and perform partial fractions decompositions:
#1/(u^2-1) = 1/((u-1)(u+1)) = 1/2(1/(u-1) - 1/(u+1))#
Then:
# int dx/(sin(x/2)- cos(x/2)) = sqrt2 (int (du)/(u-1) -int (du)/(u+1))#
# int dx/(sin(x/2)- cos(x/2)) = sqrt2(ln abs (u-1) - ln abs (u+1)) +C#
using the properties of logarithms:
# int dx/(sin(x/2)- cos(x/2)) = sqrt2 ln abs ((u-1)/(u+1))+C #
undoing the substitutions:
#u = (tan(x/4)+1)/sqrt2#
#(u-1)/(u+1) = ( ( tan(x/4)+1)/sqrt2 -1)/((tan(x/4)+1)/sqrt2+1) = (tan(x/4) +1 -sqrt(2))/(tan(x/4) +1 +sqrt2)#
Finally:
# int dx/(sin(x/2)- cos(x/2)) = sqrt2 ln abs ((tan(x/4) +1-sqrt(2))/(tan(x/4) +1 +sqrt2)) + C#