\(\int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx\) [118]

   Optimal result
   Rubi [A] (verified)
   Mathematica [A] (verified)
   Maple [A] (verified)
   Fricas [B] (verification not implemented)
   Sympy [B] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [A] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 11, antiderivative size = 19 \[ \int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx=-\frac {x}{2}+\log (\cosh (x))-\frac {1}{2 (1+\tanh (x))} \]

[Out]

-1/2*x+ln(cosh(x))-1/2/(1+tanh(x))

Rubi [A] (verified)

Time = 0.03 (sec) , antiderivative size = 19, normalized size of antiderivative = 1.00, number of steps used = 3, number of rules used = 2, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.182, Rules used = {3621, 3556} \[ \int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx=-\frac {x}{2}-\frac {1}{2 (\tanh (x)+1)}+\log (\cosh (x)) \]

[In]

Int[Tanh[x]^2/(1 + Tanh[x]),x]

[Out]

-1/2*x + Log[Cosh[x]] - 1/(2*(1 + Tanh[x]))

Rule 3556

Int[tan[(c_.) + (d_.)*(x_)], x_Symbol] :> Simp[-Log[RemoveContent[Cos[c + d*x], x]]/d, x] /; FreeQ[{c, d}, x]

Rule 3621

Int[((a_) + (b_.)*tan[(e_.) + (f_.)*(x_)])^(m_)*((c_.) + (d_.)*tan[(e_.) + (f_.)*(x_)])^2, x_Symbol] :> Simp[(
-b)*(a*c + b*d)^2*((a + b*Tan[e + f*x])^m/(2*a^3*f*m)), x] + Dist[1/(2*a^2), Int[(a + b*Tan[e + f*x])^(m + 1)*
Simp[a*c^2 - 2*b*c*d + a*d^2 - 2*b*d^2*Tan[e + f*x], x], x], x] /; FreeQ[{a, b, c, d, e, f}, x] && NeQ[b*c - a
*d, 0] && LeQ[m, -1] && EqQ[a^2 + b^2, 0]

Rubi steps \begin{align*} \text {integral}& = -\frac {1}{2 (1+\tanh (x))}-\frac {1}{2} \int (1-2 \tanh (x)) \, dx \\ & = -\frac {x}{2}-\frac {1}{2 (1+\tanh (x))}+\int \tanh (x) \, dx \\ & = -\frac {x}{2}+\log (\cosh (x))-\frac {1}{2 (1+\tanh (x))} \\ \end{align*}

Mathematica [A] (verified)

Time = 0.07 (sec) , antiderivative size = 34, normalized size of antiderivative = 1.79 \[ \int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx=\frac {2 \log (\cosh (x))+\tanh (x)+2 \log (\cosh (x)) \tanh (x)-\text {arctanh}(\tanh (x)) (1+\tanh (x))}{2 (1+\tanh (x))} \]

[In]

Integrate[Tanh[x]^2/(1 + Tanh[x]),x]

[Out]

(2*Log[Cosh[x]] + Tanh[x] + 2*Log[Cosh[x]]*Tanh[x] - ArcTanh[Tanh[x]]*(1 + Tanh[x]))/(2*(1 + Tanh[x]))

Maple [A] (verified)

Time = 0.04 (sec) , antiderivative size = 18, normalized size of antiderivative = 0.95

method result size
risch \(-\frac {3 x}{2}-\frac {{\mathrm e}^{-2 x}}{4}+\ln \left (1+{\mathrm e}^{2 x}\right )\) \(18\)
derivativedivides \(-\frac {1}{2 \left (1+\tanh \left (x \right )\right )}-\frac {3 \ln \left (1+\tanh \left (x \right )\right )}{4}-\frac {\ln \left (\tanh \left (x \right )-1\right )}{4}\) \(24\)
default \(-\frac {1}{2 \left (1+\tanh \left (x \right )\right )}-\frac {3 \ln \left (1+\tanh \left (x \right )\right )}{4}-\frac {\ln \left (\tanh \left (x \right )-1\right )}{4}\) \(24\)
parallelrisch \(-\frac {1+2 \ln \left (1-\tanh \left (x \right )\right ) \tanh \left (x \right )+3 \tanh \left (x \right ) x +2 \ln \left (1-\tanh \left (x \right )\right )+3 x}{2 \left (1+\tanh \left (x \right )\right )}\) \(39\)

[In]

int(tanh(x)^2/(1+tanh(x)),x,method=_RETURNVERBOSE)

[Out]

-3/2*x-1/4*exp(-2*x)+ln(1+exp(2*x))

Fricas [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 73 vs. \(2 (15) = 30\).

Time = 0.25 (sec) , antiderivative size = 73, normalized size of antiderivative = 3.84 \[ \int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx=-\frac {6 \, x \cosh \left (x\right )^{2} + 12 \, x \cosh \left (x\right ) \sinh \left (x\right ) + 6 \, x \sinh \left (x\right )^{2} - 4 \, {\left (\cosh \left (x\right )^{2} + 2 \, \cosh \left (x\right ) \sinh \left (x\right ) + \sinh \left (x\right )^{2}\right )} \log \left (\frac {2 \, \cosh \left (x\right )}{\cosh \left (x\right ) - \sinh \left (x\right )}\right ) + 1}{4 \, {\left (\cosh \left (x\right )^{2} + 2 \, \cosh \left (x\right ) \sinh \left (x\right ) + \sinh \left (x\right )^{2}\right )}} \]

[In]

integrate(tanh(x)^2/(1+tanh(x)),x, algorithm="fricas")

[Out]

-1/4*(6*x*cosh(x)^2 + 12*x*cosh(x)*sinh(x) + 6*x*sinh(x)^2 - 4*(cosh(x)^2 + 2*cosh(x)*sinh(x) + sinh(x)^2)*log
(2*cosh(x)/(cosh(x) - sinh(x))) + 1)/(cosh(x)^2 + 2*cosh(x)*sinh(x) + sinh(x)^2)

Sympy [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 61 vs. \(2 (15) = 30\).

Time = 0.17 (sec) , antiderivative size = 61, normalized size of antiderivative = 3.21 \[ \int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx=\frac {x \tanh {\left (x \right )}}{2 \tanh {\left (x \right )} + 2} + \frac {x}{2 \tanh {\left (x \right )} + 2} - \frac {2 \log {\left (\tanh {\left (x \right )} + 1 \right )} \tanh {\left (x \right )}}{2 \tanh {\left (x \right )} + 2} - \frac {2 \log {\left (\tanh {\left (x \right )} + 1 \right )}}{2 \tanh {\left (x \right )} + 2} - \frac {1}{2 \tanh {\left (x \right )} + 2} \]

[In]

integrate(tanh(x)**2/(1+tanh(x)),x)

[Out]

x*tanh(x)/(2*tanh(x) + 2) + x/(2*tanh(x) + 2) - 2*log(tanh(x) + 1)*tanh(x)/(2*tanh(x) + 2) - 2*log(tanh(x) + 1
)/(2*tanh(x) + 2) - 1/(2*tanh(x) + 2)

Maxima [A] (verification not implemented)

none

Time = 0.28 (sec) , antiderivative size = 17, normalized size of antiderivative = 0.89 \[ \int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx=\frac {1}{2} \, x - \frac {1}{4} \, e^{\left (-2 \, x\right )} + \log \left (e^{\left (-2 \, x\right )} + 1\right ) \]

[In]

integrate(tanh(x)^2/(1+tanh(x)),x, algorithm="maxima")

[Out]

1/2*x - 1/4*e^(-2*x) + log(e^(-2*x) + 1)

Giac [A] (verification not implemented)

none

Time = 0.26 (sec) , antiderivative size = 17, normalized size of antiderivative = 0.89 \[ \int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx=-\frac {3}{2} \, x - \frac {1}{4} \, e^{\left (-2 \, x\right )} + \log \left (e^{\left (2 \, x\right )} + 1\right ) \]

[In]

integrate(tanh(x)^2/(1+tanh(x)),x, algorithm="giac")

[Out]

-3/2*x - 1/4*e^(-2*x) + log(e^(2*x) + 1)

Mupad [B] (verification not implemented)

Time = 0.07 (sec) , antiderivative size = 21, normalized size of antiderivative = 1.11 \[ \int \frac {\tanh ^2(x)}{1+\tanh (x)} \, dx=\frac {x}{2}-\ln \left (\mathrm {tanh}\left (x\right )+1\right )-\frac {1}{2\,\left (\mathrm {tanh}\left (x\right )+1\right )} \]

[In]

int(tanh(x)^2/(tanh(x) + 1),x)

[Out]

x/2 - log(tanh(x) + 1) - 1/(2*(tanh(x) + 1))