Skip to content

Commit b5e6af0

Browse files
authored
Add complex number support to atanh (#524)
1 parent 57d60ce commit b5e6af0

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

Diff for: spec/API_specification/array_api/elementwise_functions.py

+40-5
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ def atan2(x1: array, x2: array, /) -> array:
265265
"""
266266

267267
def atanh(x: array, /) -> array:
268-
"""
269-
Calculates an implementation-dependent approximation to the inverse hyperbolic tangent, having domain ``[-1, +1]`` and codomain ``[-infinity, +infinity]``, for each element ``x_i`` of the input array ``x``.
268+
r"""
269+
Calculates an implementation-dependent approximation to the inverse hyperbolic tangent for each element ``x_i`` of the input array ``x``.
270270
271271
**Special cases**
272272
273-
For floating-point operands,
273+
For real-valued floating-point operands,
274274
275275
- If ``x_i`` is ``NaN``, the result is ``NaN``.
276276
- If ``x_i`` is less than ``-1``, the result is ``NaN``.
@@ -280,15 +280,50 @@ def atanh(x: array, /) -> array:
280280
- If ``x_i`` is ``+0``, the result is ``+0``.
281281
- If ``x_i`` is ``-0``, the result is ``-0``.
282282
283+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
284+
285+
- If ``a`` is ``+0`` and ``b`` is ``+0``, the result is ``+0 + 0j``.
286+
- If ``a`` is ``+0`` and ``b`` is ``NaN``, the result is ``+0 + NaN j``.
287+
- If ``a`` is ``1`` and ``b`` is ``+0``, the result is ``+infinity + 0j``.
288+
- If ``a`` is a positive (i.e., greater than ``0``) finite number and ``b`` is ``+infinity``, the result is ``+0 + πj/2``.
289+
- If ``a`` is a nonzero finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
290+
- If ``a`` is ``+infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``+0 + πj/2``.
291+
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``+0 + πj/2``.
292+
- If ``a`` is ``+infinity`` and ``b`` is ``NaN``, the result is ``+0 + NaN j``.
293+
- If ``a`` is ``NaN`` and ``b`` is a finite number, the result is ``NaN + NaN j``.
294+
- If ``a`` is ``NaN`` and ``b`` is ``+infinity``, the result is ``±0 + πj/2`` (sign of the real component is unspecified).
295+
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
296+
297+
.. note::
298+
The principal value of the inverse hyperbolic tangent of a complex number :math:`z` is
299+
300+
.. math::
301+
\operatorname{atanh}(z) = \frac{\ln(1+z)-\ln(z-1)}{2}
302+
303+
For any :math:`z`,
304+
305+
.. math::
306+
\operatorname{atanh}(z) = \frac{\operatorname{atan}(zj)}{j}
307+
308+
.. note::
309+
For complex floating-point operands, ``atanh(conj(x))`` must equal ``conj(atanh(x))`` and ``atanh(-x)`` must equal ``-atanh(x)``.
310+
311+
.. note::
312+
The inverse hyperbolic tangent is a multi-valued function and requires a branch cut on the complex plane. By convention, a branch cut is placed at the line segments :math:`(-\infty, 1]` and :math:`[1, \infty)` of the real axis.
313+
314+
Accordingly, for complex arguments, the function returns the inverse hyperbolic tangent in the range of a half-strip unbounded along the real axis and in the interval :math:`[-\pi j/2, +\pi j/2]` along the imaginary axis.
315+
316+
*Note: branch cuts have provisional status* (see :ref:`branch-cuts`).
317+
283318
Parameters
284319
----------
285320
x: array
286-
input array whose elements each represent the area of a hyperbolic sector. Should have a real-valued floating-point data type.
321+
input array whose elements each represent the area of a hyperbolic sector. Should have a floating-point data type.
287322
288323
Returns
289324
-------
290325
out: array
291-
an array containing the inverse hyperbolic tangent of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
326+
an array containing the inverse hyperbolic tangent of each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
292327
"""
293328

294329
def bitwise_and(x1: array, x2: array, /) -> array:

0 commit comments

Comments
 (0)