HP 35S: Hyperbolics Bug? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: HP 35S: Hyperbolics Bug? (/thread-4420.html) HP 35S: Hyperbolics Bug? - Gerald H - 07-24-2015 10:45 AM Do the hyperbolic functions suffer from similar inaccuracy near certain critical values as do the trig functions? RE: HP 35S: Hyperbolics Bug? - Marcio - 07-24-2015 11:14 AM (07-24-2015 10:45 AM)Gerald H Wrote:  Do the hyperbolic functions suffer from similar inaccuracy near certain critical values as do the trig functions? Could you provide some examples? RE: HP 35S: Hyperbolics Bug? - Paul Dale - 07-24-2015 11:27 AM It would be surprising. The hyperbolics don't have the same nasty cases as the circular trigonometric functions. There are still concerns but they aren't so insidious as with the circular functions. The näive formula for $$cosh(x) = \frac{e^x + e^{-x}}{2}$$ is stable across the entire domain. The näive formula for $$sinh(x) = \frac{e^x - e^{-x}}{2}$$ isn't. It encounters cancellation issues as x -> 0. This would be the place I'd go hunting for accuracy loss both for sinh and tanh. The 34S uses $$sinh(x) = \frac{(e^x - 1)(e^x + 1)}{2 e^x}, |x| < \frac{1}{2}$$ which is stable so long as the accurate builtin function for $$e^x - 1$$ is used. Outside of this domain, the näive formula works fine. Tanh can be expressed as $$\frac{sinh}{cosh}$$, however the 34S uses the alternative $$tanh(x) = \frac{e^{2x}-1}{e^{2x}+1} = \frac{e^{2x}-1}{e^{2x}-1 + 2}$$ which is more stable but does risk overflow for large x. For the inverse hyperbolic functions, $$cosh^{-1}(x) = log \left( x + \sqrt{x^2+1} \right)$$ is straightforward again. Arcsinh and arctanh require some care for x near zero. They can be stably calculated with the use of the $$ln1p(x) = ln(1 + x)$$ function: $\\sinh^{-1}(x) = ln1p \left( x \left(1 + \frac{x}{\sqrt{x^2+1}+1} \right) \right)\\ \\tanh^{-1}(x) = \frac{ln1p \left( \frac{2x}{1-x} \right)}{2}$ Assuming I got all of the formulas correct - Pauli RE: HP 35S: Hyperbolics Bug? - Marcio - 07-24-2015 12:14 PM (07-24-2015 11:27 AM)Paul Dale Wrote:  It would be surprising. The hyperbolics don't have the same nasty cases as the circular trigonometric functions. There are still concerns but they aren't so insidious as with the circular functions. The näive formula for $$cosh(x) = \frac{e^x + e^{-x}}{2}$$ is stable across the entire domain. The näive formula for $$sinh(x) = \frac{e^x - e^{-x}}{2}$$ isn't. It encounters cancellation issues as x -> 0. This would be the place I'd go hunting for accuracy loss both for sinh and tanh. If I remember correctly, I played with these functions quite a bit a while ago and couldn't find any loss of accuracy inside the working limits of the 35s. It seems the loss of precision pops up when you use complex numbers to calculate SIN or COS:. $cos(x) = \frac{e^{ix} + e^{-ix}}{2}$ Even so, in order for this problem to appear, the argument must be really small (for example, 1E-7) and the result multiplied by its inverse (1E7). Marcio RE: HP 35S: Hyperbolics Bug? - Thomas Klemm - 07-24-2015 01:22 PM (07-24-2015 10:45 AM)Gerald H Wrote:  Do the hyperbolic functions suffer from similar inaccuracy near certain critical values as do the trig functions? TANH(x) for 30000 <= x produces an OVERFLOW but gives 1 as a result. Cheers Thomas RE: HP 35S: Hyperbolics Bug? - Marcio - 07-24-2015 01:33 PM The overflow message is wrong but the result is right, that is bug 13, which also mentions that SINH and COSH will return incorrect results for large values. Would anybody be kind enough as to provide some examples? Thanks Marcio RE: HP 35S: Hyperbolics Bug? - Thomas Klemm - 07-24-2015 03:57 PM (07-24-2015 01:33 PM)Marcio Wrote:  Would anybody be kind enough as to provide some examples? SINH 25000 = OVERFLOW --> 1E500 SINH 30000 = OVERFLOW -- >3E499 Quote:What seems to happen when the argument is greater than 29999.999... is that the the mantissa is kept and the characteristic is changed to 499. RE: HP 35S: Hyperbolics Bug? - Marcio - 07-24-2015 04:49 PM (07-24-2015 03:57 PM)Thomas Klemm Wrote:   (07-24-2015 01:33 PM)Marcio Wrote:  Would anybody be kind enough as to provide some examples? SINH 25000 = OVERFLOW --> 1E500 SINH 30000 = OVERFLOW -- >3E499 Quote:What seems to happen when the argument is greater than 29999.999... is that the the mantissa is kept and the characteristic is changed to 499. I think this one is a bit common. The Prime will output similar results. Powerful computing environments such as MATLAB and others will return 'infinity' as a result, which might be what the 35s is trying to do here. RE: HP 35S: Hyperbolics Bug? - Marcio - 07-25-2015 04:22 AM (07-24-2015 10:45 AM)Gerald H Wrote:  Do the hyperbolic functions suffer from similar inaccuracy near certain critical values as do the trig functions? I would say no! I played a bit with SINH and COSH with both the 35s and 50g and all results were exactly the same. Marcio