Skip to content

Commit 733f27c

Browse files
authored
Add complex number support to tan (#459)
* Add complex number support to `tan` * Fix linebreak * Fix equation * Update equation
1 parent 9dc714e commit 733f27c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

spec/API_specification/array_api/elementwise_functions.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -1442,27 +1442,42 @@ def subtract(x1: array, x2: array, /) -> array:
14421442
"""
14431443

14441444
def tan(x: array, /) -> array:
1445-
"""
1446-
Calculates an implementation-dependent approximation to the tangent, having domain ``(-infinity, +infinity)`` and codomain ``(-infinity, +infinity)``, for each element ``x_i`` of the input array ``x``. Each element ``x_i`` is assumed to be expressed in radians.
1445+
r"""
1446+
Calculates an implementation-dependent approximation to the tangent for each element ``x_i`` of the input array ``x``.
1447+
1448+
Each element ``x_i`` is assumed to be expressed in radians.
14471449
14481450
**Special cases**
14491451
1450-
For floating-point operands,
1452+
For real-valued floating-point operands,
14511453
14521454
- If ``x_i`` is ``NaN``, the result is ``NaN``.
14531455
- If ``x_i`` is ``+0``, the result is ``+0``.
14541456
- If ``x_i`` is ``-0``, the result is ``-0``.
14551457
- If ``x_i`` is either ``+infinity`` or ``-infinity``, the result is ``NaN``.
14561458
1459+
For complex floating-point operands, special cases must be handled as if the operation is implemented as ``-1j * tanh(x*1j)``.
1460+
1461+
.. note::
1462+
Tangent is an analytical function on the complex plane and has no branch cuts. The function is periodic, with period :math:`\pi j`, with respect to the real component and has first order poles along the real line at coordinates :math:`(\pi (\frac{1}{2} + n), 0)`. However, IEEE 754 binary floating-point representation cannot represent the value :math:`\pi / 2` exactly, and, thus, no argument value is possible for which a pole error occurs.
1463+
1464+
.. note::
1465+
For complex arguments, the mathematical definition of tangent is
1466+
1467+
.. math::
1468+
\begin{align} \operatorname{tan}(x) &= \frac{j(e^{-jx} - e^{jx})}{e^{-jx} + e^{jx}} \\ &= (-1) \frac{j(e^{jx} - e^{-jx})}{e^{jx} + e^{-jx}} \\ &= -j \cdot \operatorname{tanh}(jx) \end{align}
1469+
1470+
where :math:`\operatorname{tanh}` is the hyperbolic tangent.
1471+
14571472
Parameters
14581473
----------
14591474
x: array
1460-
input array whose elements are expressed in radians. Should have a real-valued floating-point data type.
1475+
input array whose elements are expressed in radians. Should have a floating-point data type.
14611476
14621477
Returns
14631478
-------
14641479
out: array
1465-
an array containing the tangent of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
1480+
an array containing the tangent of each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
14661481
"""
14671482

14681483
def tanh(x: array, /) -> array:

0 commit comments

Comments
 (0)