bugGNU Octave - Bugs: bug #60055, regarding to bug #15872: atanh...

 
 

bug #60055: regarding to bug #15872: atanh branch cut strangeness

Submitter:  None
Submitted:  Sun 14 Feb 2021 05:50:34 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Wont Fix Assigned to:  None
Originator Name:  Francisco Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 6.1.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 15 Feb 2021 05:47:10 PM UTC, comment #6: 

"What I expect about atanh(3) is the principal value (ppv) of it.
As in sqrt(4) = 2 (is the ppv)."

This is just a choice.  One could return the principal value or not return the principal value.  There is nothing that says +2 is a better answer than -2 for sqrt(4).

atanh in Octave is mapped to the C/C++ math library.  That library changes very slowly so I'm surprised that you don't replicate a zero error.  tanh is mapped to ::tanh which throws it to the linker to make a decision about which tanh implementation to use.  It's possible that you have more than one math library present on your system and that mixing atanh from one library with tanh from a different library results in incomplete cancellation.  But that does seem low probability.  I suppose you could also look at the change history for the C/C++ math library and see if there have been any updates touching on the hyperbolic functions.


Rik <rik5>
Group administrator
Mon 15 Feb 2021 05:28:18 PM UTC, comment #5: 

AFAIU, there is no "one principal value" of atanh. But it's possible to define a principal value that best fits ones needs. See e.g. [1].

While Wikipedia is no standardization source, they do describe the principal value that Octave chose to use (to be compatible with Matlab) first. The definition you propose is described second as being used by "some authors".

[1]: https://en.wikipedia.org/wiki/Inverse_hyperbolic_functions#Principal_values_of_the_inverse_hyperbolic_tangent_and_cotangent

Markus Mützel <mmuetzel>
Group administrator
Mon 15 Feb 2021 04:21:20 PM UTC, comment #4: 

Regarding to precision.

The numerical error is also present in using
0.5*log((1+z)/(1-z)) to define atanh.

By the way in the version I am running tanh(atanh(z)) present the same numerical errors and zobs - z is not zero.

I think that your version is more recient and the atanh functions is coded taking into account the case when the imaginary part is zero. But if you compute with z=1e6 +1.1*i you will see the numerica errors.

Francisco <fco_p>
Mon 15 Feb 2021 03:32:54 PM UTC, comment #3: 

What I expect about atanh(3) is the principal value (ppv) of it.
As in sqrt(4) = 2 (is the ppv).

The extension to values outside -1<x<1 is in the context of complex variables. And this is why log a/b does not not give the ppv when using to define atanh.

The real explanations is that octave seeks to be Matlab-compatible.



Francisco <fco_p>
Mon 15 Feb 2021 06:19:21 AM UTC, comment #2: 

Choices about which phase factor to use are exactly that: choices.  Fortran and Mathematica may have made one choice, but Octave seeks to be Matlab-compatible so we need to follow whatever choice The Mathworks made.  In this case, Matlab gives


atanh (3)
ans = .3466 + 1.5708i


You can see below that the difference in choosing the phase results in an error term that is on the order of machine precision, so that's as good as numerical methods, as opposed to pure math, can get.


octave:4> tanh (.3466 + pi/2i)
ans =  2.9998e+00 - 4.8978e-16i
octave:5> tanh (.3466 - pi/2i)
ans =  2.9998e+00 + 4.8978e-16i


In either case the value is an appropriate inverse of the tanh function because x - tanh(atanh(x)) is approximately zero.

Another way to think about this is to consider the sqrt function.  The sqrt function is the inverse of the squaring function.  So if I define


fsqr = @(x) x.^2;


then there is an inverse function finv such that x = finv (fsqr (x)).  For fsqr(), that inverse function is sqrt().  But, sqrt() can return two possible values.  For example, sqrt(25) = -5 is correct because -5^2 = 25.  Likewise, sqrt(25) = 5 is correct because 5^2 = 25.  Either answer is acceptable, and it is simply a choice that most mathematical programs make to return the answer with the positive phase factor.

One further point, the Mathematica calculation uses the identity log (x + y) = log (x) - log (y).  This is true for pure math, but only approximately true when using a computer where there is finite precision and round-off error.  One thing that helps reduce errors is to use similarly sized numbers.  The value (1 + z) / (1 - z) will be calculated more accurately because the numerator and the denominator are of near equal magnitude.  You can check this with the following calculation


octave:15> z = 1e6;
octave:16> zobs = abs (tanh (0.5*(log (1+z) - log (1-z))))
zobs = 1.0000e+06
octave:17> zobs - z
ans = -1.3944e-04


But Octave's version of the atanh function reproduces the original Z value more accurately.


octave:18> zobs = abs (tanh (atanh (z)))
zobs = 1000000
octave:19> zobs - z
ans = 0


Marking as "Won't Fix" and closing report.





Rik <rik5>
Group administrator
Sun 14 Feb 2021 10:20:27 PM UTC, comment #1: 
Anonymous
Sun 14 Feb 2021 05:50:34 PM UTC, original submission:  



I think the principal value (ppv) of atanh is
atanh(z)= 0.5*(log(1+z) -log(1-z)). This is the value used in fortran and Mathematica.

We cannot use
atanh(z) = 0.5*log((1+z)/(1-z)) this won't give the ppv.

Octave reports for instance, atanh (3) = 0.34 + i pi/2
Which is not the ppv.


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by fco_p (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-02-15 rik5 StatusNone Wont Fix
        Open/ClosedOpen Closed
        Operating SystemMicrosoft Windows Any

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code