Skip to content

Add complex support to acosh #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions spec/API_specification/array_api/elementwise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,70 @@ def acos(x: array, /) -> array:
"""

def acosh(x: array, /) -> array:
"""
Calculates an implementation-dependent approximation to the inverse hyperbolic cosine, having domain ``[+1, +infinity]`` and codomain ``[+0, +infinity]``, for each element ``x_i`` of the input array ``x``.
r"""
Calculates an implementation-dependent approximation to the inverse hyperbolic cosine for each element ``x_i`` of the input array ``x``.

**Special cases**

For floating-point operands,
For real-valued floating-point operands,

- If ``x_i`` is ``NaN``, the result is ``NaN``.
- If ``x_i`` is less than ``1``, the result is ``NaN``.
- If ``x_i`` is ``1``, the result is ``+0``.
- If ``x_i`` is ``+infinity``, the result is ``+infinity``.

For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and

- If ``a`` is either ``+0`` or ``-0`` and ``b`` is ``+0``, the result is ``+0 + πj/2``.
- If ``a`` is a finite number and ``b`` is ``+infinity``, the result is ``+infinity + πj/2``.
- If ``a`` is a nonzero finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
- If ``a`` is ``+0`` and ``b`` is ``NaN``, the result is ``NaN ± πj/2`` (sign of imaginary component is unspecified).
- If ``a`` is ``-infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``+infinity + πj``.
- If ``a`` is ``+infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``+infinity + 0j``.
- If ``a`` is ``-infinity`` and ``b`` is ``+infinity``, the result is ``+infinity + 3πj/4``.
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``+infinity + πj/4``.
- If ``a`` is either ``+infinity`` or ``-infinity`` and ``b`` is ``NaN``, the result is ``+infinity + NaN j``.
- If ``a`` is ``NaN`` and ``b`` is a finite number, the result is ``NaN + NaN j``.
- If ``a`` is ``NaN`` and ``b`` is ``+infinity``, the result is ``+infinity + NaN j``.
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.

.. note::
The principal value of the inverse hyperbolic cosine of a complex number :math:`z` is

.. math::
\operatorname{acosh}(z) = \ln(z + \sqrt{z+1}\sqrt{z-1})

For any :math:`z`,

.. math::
\operatorname{acosh}(z) = \frac{\sqrt{z-1}}{\sqrt{1-z}}\operatorname{acos}(z)

or simply

.. math::
\operatorname{acosh}(z) = j\ \operatorname{acos}(z)

in the upper half of the complex plane.

.. note::
For complex floating-point operands, ``acosh(conj(x))`` must equal ``conj(acosh(x))``.

.. note::
The inverse hyperbolic cosine is a multi-valued function and requires a branch cut on the complex plane. By convention, a branch cut is placed at the line segment :math:`(-\infty, 1)` of the real axis.

Accordingly, for complex arguments, the function returns the inverse hyperbolic cosine in the interval :math:`[0, \infty)` along the real axis and in the interval :math:`[-\pi j, +\pi j]` along the imaginary axis.

*Note: branch cuts have provisional status* (see :ref:`branch-cuts`).

Parameters
----------
x: array
input array whose elements each represent the area of a hyperbolic sector. Should have a real-valued floating-point data type.
input array whose elements each represent the area of a hyperbolic sector. Should have a floating-point data type.

Returns
-------
out: array
an array containing the inverse hyperbolic cosine of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
an array containing the inverse hyperbolic cosine of each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
"""

def add(x1: array, x2: array, /) -> array:
Expand Down