Does $\int\frac{1}{2}\tanh\left(\frac{1}{x^{2}}\right)\,dx$ have a closed form?

101 Views Asked by At

Context: I am looking for an activation function that is linear in the area surrounding $x=0$, while also staying within the range of -1 to 1. While I was messing around in Desmos, I stumbled across the function $f(x)=\frac{1}{2}\tanh\left(\frac{1}{x^{2}}\right)$.

$\int\frac{1}{2}\tanh\left(\frac{1}{x^{2}}\right)\,dx$ produces the exact shape I am looking for, but I cannot figure out how to find the closed form for it.

Am I missing something obvious, or does this function not have a closed form antiderivative?

2

There are 2 best solutions below

1
On

Simplest one I can think of is $\dfrac{x}{1+|x|} $.

There are also $\tanh(x) $ and $\arctan(x) $ scaled as $(2/\pi)\arctan(\pi x/2) $.

0
On

Unfortunately I do not know of any closed form, but here is a solution, out of a few possibilities, that has an interval of convergence with $|x|<\infty$ which uses geometric series and the error and dawson integral function. This used Wolfram Alpha aid. Notice the n=0 term gives the partial sum of 0:

$$\mathrm{\frac12 \int tanh\left(\frac1{x^2}\right)dx=\frac12\int \frac{2}{e^{-\frac{2}{x^2}}+1}-1dx=\int \frac{1}{1- -e^{-\frac{2}{x^2}}}dx-\frac{x}{2}=-\frac{x}{2}+\sum_{n=0}^\infty\int \left(-e^{-\frac{2}{x^2}}\right)^n dx=C-\frac x2+\sum_{n=0}^\infty (-1)^n e^{-\frac{2 n}{x^2}} x + \sqrt{2\pi} \sum_{n=0}^\infty (-1)^n \sqrt n \,erf\left(\frac {\sqrt{2n}}x\right)\mathop =^{x\in\Bbb R} C-\frac x2 + \frac{x\,e^\frac2 {x^2}}{e^\frac2 {x^2} +1}+ \sqrt{2\pi} \sum_{n=1}^\infty (-1)^n \sqrt n \,erf\left(\frac {\sqrt{2n}}x\right)}$$

Another way which converges better is using this sum representation if the hyperbolic tangent converging for |x|>$\sqrt \frac 2\pi$ Which uses the Bernoulli Numbers $$\mathrm{\frac12 \int tanh\left(\frac1{x^2}\right)dx=\frac12\int\sum_{n=1}^\infty \frac{2^{2n}\left(2^{2n}-1\right)B_{2n} \left(\frac1{x^2}\right)^{2n-1}}{(2n)!}= C+\frac12\sum_{n=1}^\infty \frac{2^{2n}\left(2^{2n}-1\right)B_{2n}x^3\left(\frac 1 {x^2}\right)^{2n}}{(3-4n)(2n)!}\mathop=^{0<x\in \Bbb R}=C-\frac12\sum_{n=1}^\infty \frac{2^{2n}\left(2^{2n}-1\right)B_{2n}x^{3-4n}}{(4n-3)(2n)!}}$$

Please correct me and give me feedback!