# Trigonometric functions¶

Except where otherwise noted, the trigonometric functions take a radian angle as input and the inverse trigonometric functions return radian angles.

The ordinary trigonometric functions are single-valued functions defined everywhere in the complex plane (except at the poles of tan, sec, csc, and cot). They are defined generally via the exponential function, e.g.

The inverse trigonometric functions are multivalued, thus requiring branch cuts, and are generally real-valued only on a part of the real line. Definitions and branch cuts are given in the documentation of each function. The branch cut conventions used by mpmath are essentially the same as those found in most standard mathematical software, such as Mathematica and Python’s own cmath libary (as of Python 2.6; earlier Python versions implement some functions erroneously).

### degrees()¶

mpmath.degrees(x)

Converts the radian angle to a degree angle:

>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> degrees(pi/3)
60.0

Converts the degree angle to radians:

>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
1.0471975511966

## Trigonometric functions¶

### cos()¶

mpmath.cos(x, **kwargs)

Computes the cosine of , .

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> cos(pi/3)
0.5
>>> cos(100000001)
-0.9802850113244713353133243
>>> cos(2+3j)
(-4.189625690968807230132555 - 9.109227893755336597979197j)
>>> cos(inf)
nan
>>> nprint(chop(taylor(cos, 0, 6)))
[1.0, 0.0, -0.5, 0.0, 0.0416667, 0.0, -0.00138889]

Intervals are supported via mpmath.iv.cos():

>>> iv.dps = 25; iv.pretty = True
>>> iv.cos([0,1])
[0.540302305868139717400936602301, 1.0]
>>> iv.cos([0,2])
[-0.41614683654714238699756823214, 1.0]

### sin()¶

mpmath.sin(x, **kwargs)

Computes the sine of , .

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> sin(pi/3)
0.8660254037844386467637232
>>> sin(100000001)
0.1975887055794968911438743
>>> sin(2+3j)
(9.1544991469114295734673 - 4.168906959966564350754813j)
>>> sin(inf)
nan
>>> nprint(chop(taylor(sin, 0, 6)))
[0.0, 1.0, 0.0, -0.166667, 0.0, 0.00833333, 0.0]

Intervals are supported via mpmath.iv.sin():

>>> iv.dps = 25; iv.pretty = True
>>> iv.sin([0,1])
[0.0, 0.841470984807896506652502331201]
>>> iv.sin([0,2])
[0.0, 1.0]

### tan()¶

mpmath.tan(x, **kwargs)

Computes the tangent of , . The tangent function is singular at , but tan(x) always returns a finite result since cannot be represented exactly using floating-point arithmetic.

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> tan(pi/3)
1.732050807568877293527446
>>> tan(100000001)
-0.2015625081449864533091058
>>> tan(2+3j)
(-0.003764025641504248292751221 + 1.003238627353609801446359j)
>>> tan(inf)
nan
>>> nprint(chop(taylor(tan, 0, 6)))
[0.0, 1.0, 0.0, 0.333333, 0.0, 0.133333, 0.0]

Intervals are supported via mpmath.iv.tan():

>>> iv.dps = 25; iv.pretty = True
>>> iv.tan([0,1])
[0.0, 1.55740772465490223050697482944]
>>> iv.tan([0,2])  # Interval includes a singularity
[-inf, +inf]

### sec()¶

mpmath.sec(x)

Computes the secant of , . The secant function is singular at , but sec(x) always returns a finite result since cannot be represented exactly using floating-point arithmetic.

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> sec(pi/3)
2.0
>>> sec(10000001)
-1.184723164360392819100265
>>> sec(2+3j)
(-0.04167496441114427004834991 + 0.0906111371962375965296612j)
>>> sec(inf)
nan
>>> nprint(chop(taylor(sec, 0, 6)))
[1.0, 0.0, 0.5, 0.0, 0.208333, 0.0, 0.0847222]

Intervals are supported via mpmath.iv.sec():

>>> iv.dps = 25; iv.pretty = True
>>> iv.sec([0,1])
[1.0, 1.85081571768092561791175326276]
>>> iv.sec([0,2])  # Interval includes a singularity
[-inf, +inf]

### csc()¶

mpmath.csc(x)

Computes the cosecant of , . This cosecant function is singular at , but with the exception of the point , csc(x) returns a finite result since cannot be represented exactly using floating-point arithmetic.

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> csc(pi/3)
1.154700538379251529018298
>>> csc(10000001)
-1.864910497503629858938891
>>> csc(2+3j)
(0.09047320975320743980579048 + 0.04120098628857412646300981j)
>>> csc(inf)
nan

Intervals are supported via mpmath.iv.csc():

>>> iv.dps = 25; iv.pretty = True
>>> iv.csc([0,1])  # Interval includes a singularity
[1.18839510577812121626159943988, +inf]
>>> iv.csc([0,2])
[1.0, +inf]

### cot()¶

mpmath.cot(x)

Computes the cotangent of , . This cotangent function is singular at , but with the exception of the point , cot(x) returns a finite result since cannot be represented exactly using floating-point arithmetic.

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> cot(pi/3)
0.5773502691896257645091488
>>> cot(10000001)
1.574131876209625656003562
>>> cot(2+3j)
(-0.003739710376336956660117409 - 0.9967577965693583104609688j)
>>> cot(inf)
nan

Intervals are supported via mpmath.iv.cot():

>>> iv.dps = 25; iv.pretty = True
>>> iv.cot([0,1])  # Interval includes a singularity
[0.642092615934330703006419974862, +inf]
>>> iv.cot([1,2])
[-inf, +inf]

## Trigonometric functions with modified argument¶

### cospi()¶

mpmath.cospi(x, **kwargs)

Computes , more accurately than the expression cos(pi*x):

>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> cospi(10**10), cos(pi*(10**10))
(1.0, 0.999999999997493)
>>> cospi(10**10+0.5), cos(pi*(10**10+0.5))
(0.0, 1.59960492420134e-6)

### sinpi()¶

mpmath.sinpi(x, **kwargs)

Computes , more accurately than the expression sin(pi*x):

>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> sinpi(10**10), sin(pi*(10**10))
(0.0, -2.23936276195592e-6)
>>> sinpi(10**10+0.5), sin(pi*(10**10+0.5))
(1.0, 0.999999999998721)

## Inverse trigonometric functions¶

### acos()¶

mpmath.acos(x, **kwargs)

Computes the inverse cosine or arccosine of , . Since for real , the inverse cosine is real-valued only for . On this interval, acos() is defined to be a monotonically decreasing function assuming values between and .

Basic values are:

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> acos(-1)
3.141592653589793238462643
>>> acos(0)
1.570796326794896619231322
>>> acos(1)
0.0
>>> nprint(chop(taylor(acos, 0, 6)))
[1.5708, -1.0, 0.0, -0.166667, 0.0, -0.075, 0.0]

acos() is defined so as to be a proper inverse function of for . We have for all , but only for :

>>> for x in [1, 10, -1, 2+3j, 10+3j]:
...     print cos(acos(x)), acos(cos(x))
...
1.0 1.0
(10.0 + 0.0j) 2.566370614359172953850574
-1.0 1.0
(2.0 + 3.0j) (2.0 + 3.0j)
(10.0 + 3.0j) (2.566370614359172953850574 - 3.0j)

The inverse cosine has two branch points: . acos() places the branch cuts along the line segments and . In general,

where the principal-branch log and square root are implied.

### asin()¶

mpmath.asin(x, **kwargs)

Computes the inverse sine or arcsine of , . Since for real , the inverse sine is real-valued only for . On this interval, it is defined to be a monotonically increasing function assuming values between and .

Basic values are:

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> asin(-1)
-1.570796326794896619231322
>>> asin(0)
0.0
>>> asin(1)
1.570796326794896619231322
>>> nprint(chop(taylor(asin, 0, 6)))
[0.0, 1.0, 0.0, 0.166667, 0.0, 0.075, 0.0]

asin() is defined so as to be a proper inverse function of for . We have for all , but only for :

>>> for x in [1, 10, -1, 1+3j, -2+3j]:
...     print chop(sin(asin(x))), asin(sin(x))
...
1.0 1.0
10.0 -0.5752220392306202846120698
-1.0 -1.0
(1.0 + 3.0j) (1.0 + 3.0j)
(-2.0 + 3.0j) (-1.141592653589793238462643 - 3.0j)

The inverse sine has two branch points: . asin() places the branch cuts along the line segments and . In general,

where the principal-branch log and square root are implied.

### atan()¶

mpmath.atan(x, **kwargs)

Computes the inverse tangent or arctangent of , . This is a real-valued function for all real , with range .

Basic values are:

>>> from mpmath import *
>>> mp.dps = 25; mp.pretty = True
>>> atan(-inf)
-1.570796326794896619231322
>>> atan(-1)
-0.7853981633974483096156609
>>> atan(0)
0.0
>>> atan(1)
0.7853981633974483096156609
>>> atan(inf)
1.570796326794896619231322
>>> nprint(chop(taylor(atan, 0, 6)))
[0.0, 1.0, 0.0, -0.333333, 0.0, 0.2, 0.0]

The inverse tangent is often used to compute angles. However, the atan2 function is often better for this as it preserves sign (see atan2()).

atan() is defined so as to be a proper inverse function of for . We have for all , but only for :

>>> mp.dps = 25
>>> for x in [1, 10, -1, 1+3j, -2+3j]:
...     print tan(atan(x)), atan(tan(x))
...
1.0 1.0
10.0 0.5752220392306202846120698
-1.0 -1.0
(1.0 + 3.0j) (1.000000000000000000000001 + 3.0j)
(-2.0 + 3.0j) (1.141592653589793238462644 + 3.0j)

The inverse tangent has two branch points: . atan() places the branch cuts along the line segments and . In general,

where the principal-branch log is implied.

### asec()¶

mpmath.asec(x)
Computes the inverse secant of , .

### acsc()¶

mpmath.acsc(x)
Computes the inverse cosecant of , .

### acot()¶

mpmath.acot(x)
Computes the inverse cotangent of , .

## Sinc function¶

### sinc()¶

mpmath.sinc(x)

sinc(x) computes the unnormalized sinc function, defined as

See sincpi() for the normalized sinc function.

Simple values and limits include:

>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> sinc(0)
1.0
>>> sinc(1)
0.841470984807897
>>> sinc(inf)
0.0

The integral of the sinc function is the sine integral Si:

0.946083070367183
>>> si(1)
0.946083070367183

### sincpi()¶

mpmath.sincpi(x)

sincpi(x) computes the normalized sinc function, defined as

Equivalently, we have .

The normalization entails that the function integrates to unity over the entire real line:

>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
1.0

Like, sinpi(), sincpi() is evaluated accurately at its roots:

>>> sincpi(10)
0.0