10000 BUG: arccos inaccurate for small complex numbers · Issue #6081 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
BUG: arccos inaccurate for small complex numbers #6081
Open
@pbrod

Description

@pbrod

Consider the following examples:
The first few terms of taylor-series for arccos is given by

>>> import numpy as np
>>> def arccos_3(x):
...     return np.pi/2-x-x**3/6-3*x**5/40

Then we compare the taylor-series with numpy.arccos for small complex number:

>>> x =  1je-14
>>> v1 = np.arccos(x); v1
(1.5707963267948966-9.9920072216263584e-15j)

>>> v2 = arccos_3(x); v2
(1.5707963267948966-1e-14j)

>>> (v2-v1).imag/v2.imag
0.00079927783736416112

Lets compute the complex step derivative of arcos

>>> y = 0
>>> h = 1e-14
>>> np.arccos(y+1j*h).imag/h
-0.99920072216263589

The exact value is -1:

>>> arccos_3(1j*h).imag/h
-1.0

In both the examples the relative error of the complex part of numpy.arccos function is around 1e-3.

It should be relatively easy to fix this as the complex part of arccos function is proportional to x when x is small.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0