Skip to content

Commit b43dcb1

Browse files
authored
Add complex number support to cosh (#453)
* Add complex number support to `cosh` * Add missing comma * Move notes and fix special cases
1 parent 19b830d commit b43dcb1

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

spec/API_specification/array_api/elementwise_functions.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,28 +427,59 @@ def cos(x: array, /) -> array:
427427
"""
428428

429429
def cosh(x: array, /) -> array:
430-
"""
431-
Calculates an implementation-dependent approximation to the hyperbolic cosine, having domain ``[-infinity, +infinity]`` and codomain ``[-infinity, +infinity]``, for each element ``x_i`` in the input array ``x``.
430+
r"""
431+
Calculates an implementation-dependent approximation to the hyperbolic cosine for each element ``x_i`` in the input array ``x``.
432+
433+
The mathematical definition of the hyperbolic cosine is
434+
435+
.. math::
436+
\operatorname{cosh}(x) = \frac{e^x + e^{-x}}{2}
432437
433438
**Special cases**
434439
435-
For floating-point operands,
440+
.. note::
441+
For all operands, ``cosh(x)`` must equal ``cosh(-x)``.
442+
443+
For real-valued floating-point operands,
436444
437445
- If ``x_i`` is ``NaN``, the result is ``NaN``.
438446
- If ``x_i`` is ``+0``, the result is ``1``.
439447
- If ``x_i`` is ``-0``, the result is ``1``.
440448
- If ``x_i`` is ``+infinity``, the result is ``+infinity``.
441449
- If ``x_i`` is ``-infinity``, the result is ``+infinity``.
442450
451+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
452+
453+
.. note::
454+
For complex floating-point operands, ``cosh(conj(x))`` must equal ``conj(cosh(x))``.
455+
456+
- If ``a`` is ``+0`` and ``b`` is ``+0``, the result is ``1 + 0j``.
457+
- If ``a`` is ``+0`` and ``b`` is ``+infinity``, the result is ``NaN + 0j`` (sign of the imaginary component is unspecified).
458+
- If ``a`` is ``+0`` and ``b`` is ``NaN``, the result is ``NaN + 0j`` (sign of the imaginary component is unspecified).
459+
- If ``a`` is a nonzero finite number and ``b`` is ``+infinity``, the result is ``NaN + NaN j``.
460+
- If ``a`` is a nonzero finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
461+
- If ``a`` is ``+infinity`` and ``b`` is ``+0``, the result is ``+infinity + 0j``.
462+
- If ``a`` is ``+infinity`` and ``b`` is a nonzero finite number, the result is ``+infinity * cis(b)``.
463+
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``+infinity + NaN j`` (sign of the real component is unspecified).
464+
- If ``a`` is ``+infinity`` and ``b`` is ``NaN``, the result is ``+infinity + NaN j``.
465+
- If ``a`` is ``NaN`` and ``b`` is either ``+0`` or ``-0``, the result is ``NaN + 0j`` (sign of the imaginary component is unspecified).
466+
- If ``a`` is ``NaN`` and ``b`` is a nonzero finite number, the result is ``NaN + NaN j``.
467+
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
468+
469+
where ``cis(v)`` is ``cos(v) + sin(v)*1j``.
470+
471+
.. note::
472+
The hyperbolic cosine is an entire function in the complex plane and has no branch cuts. The function is periodic, with period :math:`2\pi j`, with respect to the imaginary component.
473+
443474
Parameters
444475
----------
445476
x: array
446-
input array whose elements each represent a hyperbolic angle. Should have a real-valued floating-point data type.
477+
input array whose elements each represent a hyperbolic angle. Should have a floating-point data type.
447478
448479
Returns
449480
-------
450481
out: array
451-
an array containing the hyperbolic cosine of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
482+
an array containing the hyperbolic cosine of each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
452483
"""
453484

454485
def divide(x1: array, x2: array, /) -> array:

0 commit comments

Comments
 (0)