2

What I need are the power-series for sinh and cosh that are faster to calculate. For example, here is the standard sin(x) power series: $$\sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} - \cdots $$ And now the modified power series: $$\sin(x)=x\left(1-\frac{x^2}{3 \cdot 2}\left(1-\frac{x^2}{5 \cdot 4}\left(1-\frac{x^2}{7 \cdot 6}\left(\phantom{\frac{}{}}\cdots\right.\right.\right.\right.$$

Also, for example, here is the standard cos(x) power series: $$\cos x =1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}\cdots $$ And now the modified power series: $$\cos x =1-\frac{x^2}{2\cdot 1}\left(1-\frac{x^2}{4 \cdot 3}\left(1-\frac{x^2}{6 \cdot 5}\left(1-\frac{x^2}{8 \cdot 7}\left(\phantom{\frac{}{}}\cdots\right.\right.\right.\right.$$

The modified power series are much faster to calculate because the denominators are much smaller numbers than the Factorials, after (or about) 15! or the 7th iteration. There is a huge difference in time spent calculating $$\frac{x^7}{7!} $$ and calculating $$ 1-\frac{x^2}{7 \cdot 6}$$ I just wonder why if it can be done for the sin() and cos(), why can't it be done for sinh() and cosh() also. sin() and sinh() do not look that different, and the same for cos() and cosh().

!-------------------------------------------------------------

Below is my original post

I also look at the sinh and cosh

I am using $$\sinh x = x + \tfrac{x^3}{3!}+ \tfrac{x^5}{5!} + \tfrac{x^7}{7!}+ \cdots $$ and $$\cosh x = 1 + \tfrac{x^2}{2!}+ \tfrac{x^4}{4!} + \tfrac{x^6}{6!}+ \cdots $$

And I do get correct results. BUT the results are very slow to produce. Using Is there a way to get trig functions without a calculator? , then to the "Tailored Taylor" section, as my primary example and as the greatest "speed-up" given, then the calculation was very fast. Due to "x**11/11!" (and all other calculations of this type) was exchanged for an easier division calculation. I can not re-work or re-design Infinite Series. I do not have that level of Math. Would or could anybody please show me the way. Thank you very much. Also, using "e" does not help. Thank you.

See also my previous questions (and the answers and comments I've received) in this area:


[Answering the 1st reply And Yes, there must be a better way to answer, but I don't know that method.] I knew this question was close at hand. I can only give "short answers". I am a computer programmer. I am using a different kind of number system that uses an Integer-array to contain a number, rather than just using one (1) 16 bit to a 64 bit memory place. I do add, subtract, multiply, and divide an array with an integer (array/integer) or another array (array/array). But dividing an array with another array is very slow. I want to divide using only an integer which is much faster. So, I know this sounds very odd but this is the basic "short" reason or answer.

[Answering the 2nd reply] No, no floating, or doubles, or decimals. These types of numbers and the algorithms used to make the calculations, have a degree of inaccuracy. Using only integers, power-series and continued-fractions, then any degree of accuracy or precision can be achieved. Yes this does sound odd, but it is my little project.

[Answering the 3rd reply] I rather not use GNU C library. I believe they use polynomials and tables. Which is fine for 6 to 12 decimals of accuracy. But I rather not. Thank you very much.

[To everybody] So far, this site has been the only site that has provided help to me. I want to Thank everybody for their help. And yes, my spelling and grammar is a little off also. Sorry.

  • 3
    You have now asked three questions about "fast ways to calculate" trigonometric and hyperbolic functions. If you can [edit] the question to tell us why you need a fast algorithm and what tools you permit we might be able to help. – Ethan Bolker Mar 22 '19 at 21:22
  • It sounds like maybe what you want to achieve is arbitrary-precision floating point arithmetic? In which case, could you just reuse an existing library such as mpfr? – Daniel Schepler Mar 22 '19 at 22:44
  • Have you thought about downloading the source code for the GNU C library (glibc)? I think it includes C code to calculate all those functions, although I have not checked it out myself. https://www.gnu.org/software/libc/sources.html – awkward Mar 22 '19 at 23:41
  • Your "faster" evaluation is very similar to Horner's scheme to evaluate polynomials. The straight Taylor formula is never used. –  Mar 23 '19 at 21:54
  • For large $x$, use the exponential representation. Then compute the exponential of the fractional part by Taylor, and the exponential of the integer part by successive squarings of $e$. –  Mar 23 '19 at 21:56
  • If the "modified" versions of the $\sin$ and $\cos$ series satisfy you, then just changing all "$-$"s to "$+$"s give you corresponding versions of the $\sinh$ and $\cosh$ series. Easy-peasy. – Blue Mar 24 '19 at 04:57
  • Thank you very much. I will try this. – Bill Bollinger Mar 24 '19 at 14:03
  • My approach, rather than trying to use a Horner's type method, would be to evaluate each term sequentially. Then for example, to get from the $x^7/7!$ term to the $x^9/9!$ term I would multiply by $x^2$ (which you could precompute once if you want) and divide by $8\cdot 9$. – Daniel Schepler Mar 25 '19 at 17:09

2 Answers2

1

First off, I would use $\sinh(x) = \frac12(e^x-e^{-x}) $ and $\cosh(x) = \frac12(e^x+e^{-x}) $ so you need to be able to calculate $e^{\pm x}$.

Since you are writing about arrays of numbers, it seems to me that you have some kind of multiple-precision representation.

Since $e^{x+y} =e^xe^y $, to compute $e^x$ for multiple-precision $x$, we can compute (or precompute) $x^a$ for each component of $x$ and multiply these.

If the components are 16 bits long, then each component needs a table 65536 long. I don't know how much have storage you have available, so I don't know if this is feasible.

If you have gigabytes, probably yes. If a lot less, probably not. But then you could do 8 bits at a time so the tables would have 256 entries.

Any, those are my suggestions: use the definitions with $e^x$ and precompute tables of components of the numbers.

marty cohen
  • 107,799
0

Many such functions are calculated using "Cordic", also known as "Volder's algorithm". https://en.wikipedia.org/wiki/CORDIC

user247327
  • 18,710