10000 Add complex number support to `sin` (#457) · data-apis/array-api@3c7395c · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c7395c

Browse files
authored
Add complex number support to sin (#457)
* Add complex number support to `sin` * Update equation
1 parent 39911e8 commit 3c7395c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

spec/API_specification/array_api/elementwise_functions.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,27 +1290,42 @@ def sign(x: array, /) -> array:
12901290
"""
12911291

12921292
def sin(x: array, /) -> array:
1293-
"""
1294-
Calculates an implementation-dependent approximation to the sine, having domain ``(-infinity, +infinity)`` and codomain ``[-1, +1]``, for each element ``x_i`` of the input array ``x``. Each element ``x_i`` is assumed to be expressed in radians.
1293+
r"""
1294+
Calculates an implementation-dependent approximation to the sine for each element ``x_i`` of the input array ``x``.
1295+
1296+
Each element ``x_i`` is assumed to be expressed in radians.
12951297
12961298
**Special cases**
12971299
1298-
For floating-point operands,
1300+
For real-valued floating-point operands,
12991301
13001302
- If ``x_i`` is ``NaN``, the result is ``NaN``.
13011303
- If ``x_i`` is ``+0``, the result is ``+0``.
13021304
- If ``x_i`` is ``-0``, the result is ``-0``.
13031305
- If ``x_i`` is either ``+infinity`` or ``-infinity``, the result is ``NaN``.
13041306
1307+
For complex floating-point operands, special cases must be handled as if the operation is implemented as ``-1j * sinh(x*1j)``.
1308+
1309+
.. note::
1310+
The sine is an entire function on the complex plane and has no branch cuts.
1311+
1312+
.. note::
1313+
For complex arguments, the mathematical definition of sine is
1314+
1315+
.. math::
1316+
\begin{align} \operatorname{sin}(x) &= \frac{e^{jx} - e^{-jx}}{2j} \\ &= \frac{\operatorname{sinh}(jx)}{j} \\ &= \frac{\operatorname{sinh}(jx)}{j} \cdot \frac{j}{j} \\ &= -j \cdot \operatorname{sinh}(jx) \end{align}
1317+
1318+
where :math:`\operatorname{sinh}` is the hyperbolic sine.
1319+
13051320
Parameters
13061321
----------
13071322
x: array
1308-
input array whose elements are each expressed in radians. Should have a real-valued floating-point data type.
1323+
input array whose elements are each expressed in radians. Should have a floating-point data type.
13091324
13101325
Returns
13111326
-------
13121327
out: array
1313-
an array containing the sine of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
1328+
an array containing the sine of each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
13141329
"""
13151330

13161331
def sinh(x: array, /) -> array:

0 commit comments

Comments
 (0)
0