Calculating Arc Hyperbolic CoTangent faster than using a standard power series

56 Views Asked by At

I have used the standard Power-Series to calculate Arc Hyperbolic Co-Tangent trig function. But as with my other posts before, it is very slow. Here is the standard Power-Series, taken from https://en.wikipedia.org/wiki/Inverse_hyperbolic_functions#Series_expansions

$$ \operatorname{arcoth} x = \operatorname{artanh} \frac1x = x^{-1} + \frac {x^{-3}} {3} + \frac {x^{-5}} {5} + \frac {x^{-7}} {7} +\frac {x^{-9}} {9} + \frac {x^{-11}} {11} + \frac {x^{-13}} {13} \cdots \\ = \sum_{n=0}^\infty \frac {x^{-(2n+1)}} {2n+1} , \qquad \left| x \right| > 1 $$

I have used a different form to speed it up, which it did not. $$ \operatorname{arcoth} x = \frac {1}{x} + \left ( \frac{1}{3}*\frac{1}{x^{3}} \right ) + \left ( \frac{1}{5}*\frac{1}{x^{5}} \right ) + \left ( \frac{1}{7}*\frac{1}{x^{7}} \right ) \\ + \left ( \frac{1}{9}*\frac{1}{x^{9}} \right ) + \left ( \frac{1}{11}*\frac{1}{x^{11}} \right ) + \left ( \frac{1}{13}*\frac{1}{x^{13}} \right )+\cdots $$

But it is easier to reproduce in my calculator program. The part that is taking so long are terms $$ \left ( \frac{1}{x^{7}} \right ) $$ and higher. The time spent dividing $$ {x^{7}} $$ into $$ {1} $$ is huge. At this iteration, it takes about 15 seconds. The next ones just keep growing, using more time. My question is , Is there another way? Another Power Series? Redefine or rewrite $$ \left ( \frac{1}{7}*\frac{1}{x^{7}} \right ) $$ ? Any suggestions are welcomed. Thank you very much for your time.

1

There are 1 best solutions below

6
On BEST ANSWER

At each iteration I suggest that you compute the new values for $a_{n+1}=a_{n}*yy$ and $b_{n+1}=b_{n}+2$, with $a_1=1/x$, $b_1=1$ and $yy = 1/(x*x)$, following the suggestion by Blue. Then the new sum is $s_{n+1} = s_{n}+a_{n+1}/b_{n+1}$.

The code could be something like:

a = 1/x;
b = 1;
yy = a * a;

s = a;

j = 1;
max_iterations = 7;

while(j < max_iterations)
{
    j = j + 1;
    a = a * yy;
    b = b + 2;
    s = s + a/b;
}

In general, the sums are faster than the products, which in turn are faster than the quotients and the powers.