Trigonometric functions - Functions

Skip to content
Back to top
View this page
Edit this page

# Trigonometric functions

class sage.functions.trig.Function_arccos

  Bases: `GinacFunction`

  The arccosine function.

  EXAMPLES:

  Sage

      sage: arccos(0.5)                                                           # needs sage.rings.real_mpfr
      1.04719755119660
      sage: arccos(1/2)                                                           # needs sage.symbolic
      1/3*pi
      sage: arccos(1 + 1.0*I)                                                     # needs sage.symbolic
      0.904556894302381 - 1.06127506190504*I
      sage: arccos(3/4).n(100)                                                    # needs sage.symbolic
      0.72273424781341561117837735264

  Python

      >>> from sage.all import *
      >>> arccos(RealNumber('0.5'))                                                           # needs sage.rings.real_mpfr
      1.04719755119660
      >>> arccos(Integer(1)/Integer(2))                                                           # needs sage.symbolic
      1/3*pi
      >>> arccos(Integer(1) + RealNumber('1.0')*I)                                                     # needs sage.symbolic
      0.904556894302381 - 1.06127506190504*I
      >>> arccos(Integer(3)/Integer(4)).n(Integer(100))                                                    # needs sage.symbolic
      0.72273424781341561117837735264

  We can delay evaluation using the `hold` parameter:

  Sage

      sage: arccos(0, hold=True)                                                  # needs sage.symbolic
      arccos(0)

  [Python]

      >>> from sage.all import *
      >>> arccos(Integer(0), hold=True)                                                  # needs sage.symbolic
      arccos(0)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = arccos(0, hold=True); a.simplify()                                # needs sage.symbolic
      1/2*pi

  Python

      >>> from sage.all import *
      >>> a = arccos(Integer(0), hold=True); a.simplify()                                # needs sage.symbolic
      1/2*pi

  `conjugate(arccos(x))==arccos(conjugate(x))`, unless on the branch cuts, which run along the real axis outside the interval [-1, +1].:

  Sage

      sage: # needs sage.symbolic
      sage: conjugate(arccos(x))
      conjugate(arccos(x))
      sage: var('y', domain='positive')
      y
      sage: conjugate(arccos(y))
      conjugate(arccos(y))
      sage: conjugate(arccos(y+I))
      conjugate(arccos(y + I))
      sage: conjugate(arccos(1/16))
      arccos(1/16)
      sage: conjugate(arccos(2))
      conjugate(arccos(2))
      sage: conjugate(arccos(-2))
      pi - conjugate(arccos(2))

  [Python]

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> conjugate(arccos(x))
      conjugate(arccos(x))
      >>> var('y', domain='positive')
      y
      >>> conjugate(arccos(y))
      conjugate(arccos(y))
      >>> conjugate(arccos(y+I))
      conjugate(arccos(y + I))
      >>> conjugate(arccos(Integer(1)/Integer(16)))
      arccos(1/16)
      >>> conjugate(arccos(Integer(2)))
      conjugate(arccos(2))
      >>> conjugate(arccos(-Integer(2)))
      pi - conjugate(arccos(2))

class sage.functions.trig.Function_arccot

  Bases: `GinacFunction`

  The arccotangent function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: arccot(1/2)
      arccot(1/2)
      sage: RDF(arccot(1/2))  # abs tol 2e-16
      1.1071487177940906
      sage: arccot(1 + I)
      arccot(I + 1)
      sage: arccot(1/2).n(100)
      1.1071487177940905030170654602
      sage: float(arccot(1/2))  # abs tol 2e-16
      1.1071487177940906
      sage: bool(diff(acot(x), x) == -diff(atan(x), x))
      True
      sage: diff(acot(x), x)
      -1/(x^2 + 1)

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> arccot(Integer(1)/Integer(2))
      arccot(1/2)
      >>> RDF(arccot(Integer(1)/Integer(2)))  # abs tol 2e-16
      1.1071487177940906
      >>> arccot(Integer(1) + I)
      arccot(I + 1)
      >>> arccot(Integer(1)/Integer(2)).n(Integer(100))
      1.1071487177940905030170654602
      >>> float(arccot(Integer(1)/Integer(2)))  # abs tol 2e-16
      1.1071487177940906
      >>> bool(diff(acot(x), x) == -diff(atan(x), x))
      True
      >>> diff(acot(x), x)
      -1/(x^2 + 1)

  We can delay evaluation using the `hold` parameter:

  Sage

      sage: arccot(1, hold=True)                                                  # needs sage.symbolic
      arccot(1)

  [Python]

      >>> from sage.all import *
      >>> arccot(Integer(1), hold=True)                                                  # needs sage.symbolic
      arccot(1)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = arccot(1, hold=True); a.simplify()                                # needs sage.symbolic
      1/4*pi

  Python

      >>> from sage.all import *
      >>> a = arccot(Integer(1), hold=True); a.simplify()                                # needs sage.symbolic
      1/4*pi

class sage.functions.trig.Function_arccsc

  Bases: `GinacFunction`

  The arccosecant function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: arccsc(2)
      arccsc(2)
      sage: RDF(arccsc(2))  # rel tol 1e-15
      0.5235987755982988
      sage: arccsc(2).n(100)
      0.52359877559829887307710723055
      sage: float(arccsc(2))
      0.52359877559829...
      sage: arccsc(1 + I)
      arccsc(I + 1)
      sage: diff(acsc(x), x)
      -1/(sqrt(x^2 - 1)*x)
      sage: arccsc(x)._sympy_()                                                   # needs sympy
      acsc(x)

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> arccsc(Integer(2))
      arccsc(2)
      >>> RDF(arccsc(Integer(2)))  # rel tol 1e-15
      0.5235987755982988
      >>> arccsc(Integer(2)).n(Integer(100))
      0.52359877559829887307710723055
      >>> float(arccsc(Integer(2)))
      0.52359877559829...
      >>> arccsc(Integer(1) + I)
      arccsc(I + 1)
      >>> diff(acsc(x), x)
      -1/(sqrt(x^2 - 1)*x)
      >>> arccsc(x)._sympy_()                                                   # needs sympy
      acsc(x)

  We can delay evaluation using the `hold` parameter:

  Sage

      sage: arccsc(1, hold=True)                                                  # needs sage.symbolic
      arccsc(1)

  [Python]

      >>> from sage.all import *
      >>> arccsc(Integer(1), hold=True)                                                  # needs sage.symbolic
      arccsc(1)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = arccsc(1, hold=True); a.simplify()                                # needs sage.symbolic
      1/2*pi

  Python

      >>> from sage.all import *
      >>> a = arccsc(Integer(1), hold=True); a.simplify()                                # needs sage.symbolic
      1/2*pi

class sage.functions.trig.Function_arcsec

  Bases: `GinacFunction`

  The arcsecant function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: arcsec(2)
      arcsec(2)
      sage: arcsec(2.0)
      1.04719755119660
      sage: arcsec(2).n(100)
      1.0471975511965977461542144611
      sage: arcsec(1/2).n(100)
      1.3169578969248167086250463473*I
      sage: RDF(arcsec(2))  # abs tol 1e-15
      1.0471975511965976
      sage: arcsec(1 + I)
      arcsec(I + 1)
      sage: diff(asec(x), x)
      1/(sqrt(x^2 - 1)*x)
      sage: arcsec(x)._sympy_()                                                   # needs sympy
      asec(x)

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> arcsec(Integer(2))
      arcsec(2)
      >>> arcsec(RealNumber('2.0'))
      1.04719755119660
      >>> arcsec(Integer(2)).n(Integer(100))
      1.0471975511965977461542144611
      >>> arcsec(Integer(1)/Integer(2)).n(Integer(100))
      1.3169578969248167086250463473*I
      >>> RDF(arcsec(Integer(2)))  # abs tol 1e-15
      1.0471975511965976
      >>> arcsec(Integer(1) + I)
      arcsec(I + 1)
      >>> diff(asec(x), x)
      1/(sqrt(x^2 - 1)*x)
      >>> arcsec(x)._sympy_()                                                   # needs sympy
      asec(x)

  We can delay evaluation using the `hold` parameter:

  Sage

      sage: arcsec(1, hold=True)                                                  # needs sage.symbolic
      arcsec(1)

  [Python]

      >>> from sage.all import *
      >>> arcsec(Integer(1), hold=True)                                                  # needs sage.symbolic
      arcsec(1)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = arcsec(1, hold=True); a.simplify()                                # needs sage.symbolic
      0

  Python

      >>> from sage.all import *
      >>> a = arcsec(Integer(1), hold=True); a.simplify()                                # needs sage.symbolic
      0

class sage.functions.trig.Function_arcsin

  Bases: `GinacFunction`

  The arcsine function.

  EXAMPLES:

  Sage

      sage: arcsin(0.5)                                                           # needs sage.rings.real_mpfr
      0.523598775598299
      sage: arcsin(1/2)                                                           # needs sage.symbolic
      1/6*pi
      sage: arcsin(1 + 1.0*I)                                                     # needs sage.symbolic
      0.666239432492515 + 1.06127506190504*I

  Python

      >>> from sage.all import *
      >>> arcsin(RealNumber('0.5'))                                                           # needs sage.rings.real_mpfr
      0.523598775598299
      >>> arcsin(Integer(1)/Integer(2))                                                           # needs sage.symbolic
      1/6*pi
      >>> arcsin(Integer(1) + RealNumber('1.0')*I)                                                     # needs sage.symbolic
      0.666239432492515 + 1.06127506190504*I

  We can delay evaluation using the `hold` parameter:

  Sage

      sage: arcsin(0, hold=True)                                                  # needs sage.symbolic
      arcsin(0)

  [Python]

      >>> from sage.all import *
      >>> arcsin(Integer(0), hold=True)                                                  # needs sage.symbolic
      arcsin(0)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = arcsin(0, hold=True); a.simplify()                                # needs sage.symbolic
      0

  Python

      >>> from sage.all import *
      >>> a = arcsin(Integer(0), hold=True); a.simplify()                                # needs sage.symbolic
      0

  `conjugate(arcsin(x))==arcsin(conjugate(x))`, unless on the branch cuts which run along the real axis outside the interval [-1, +1].:

  Sage

      sage: # needs sage.symbolic
      sage: conjugate(arcsin(x))
      conjugate(arcsin(x))
      sage: var('y', domain='positive')
      y
      sage: conjugate(arcsin(y))
      conjugate(arcsin(y))
      sage: conjugate(arcsin(y+I))
      conjugate(arcsin(y + I))
      sage: conjugate(arcsin(1/16))
      arcsin(1/16)
      sage: conjugate(arcsin(2))
      conjugate(arcsin(2))
      sage: conjugate(arcsin(-2))
      -conjugate(arcsin(2))

  [Python]

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> conjugate(arcsin(x))
      conjugate(arcsin(x))
      >>> var('y', domain='positive')
      y
      >>> conjugate(arcsin(y))
      conjugate(arcsin(y))
      >>> conjugate(arcsin(y+I))
      conjugate(arcsin(y + I))
      >>> conjugate(arcsin(Integer(1)/Integer(16)))
      arcsin(1/16)
      >>> conjugate(arcsin(Integer(2)))
      conjugate(arcsin(2))
      >>> conjugate(arcsin(-Integer(2)))
      -conjugate(arcsin(2))

class sage.functions.trig.Function_arctan

  Bases: `GinacFunction`

  The arctangent function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: arctan(1/2)
      arctan(1/2)
      sage: RDF(arctan(1/2))  # rel tol 1e-15
      0.46364760900080615
      sage: arctan(1 + I)
      arctan(I + 1)
      sage: arctan(1/2).n(100)
      0.46364760900080611621425623146

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> arctan(Integer(1)/Integer(2))
      arctan(1/2)
      >>> RDF(arctan(Integer(1)/Integer(2)))  # rel tol 1e-15
      0.46364760900080615
      >>> arctan(Integer(1) + I)
      arctan(I + 1)
      >>> arctan(Integer(1)/Integer(2)).n(Integer(100))
      0.46364760900080611621425623146

  We can delay evaluation using the `hold` parameter:

  Sage

      sage: arctan(0, hold=True)                                                  # needs sage.symbolic
      arctan(0)

  [Python]

      >>> from sage.all import *
      >>> arctan(Integer(0), hold=True)                                                  # needs sage.symbolic
      arctan(0)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = arctan(0, hold=True); a.simplify()                                # needs sage.symbolic
      0

  Python

      >>> from sage.all import *
      >>> a = arctan(Integer(0), hold=True); a.simplify()                                # needs sage.symbolic
      0

  `conjugate(arctan(x))==arctan(conjugate(x))`, unless on the branch cuts which run along the imaginary axis outside the interval [-I, +I].:

  Sage

      sage: # needs sage.symbolic
      sage: conjugate(arctan(x))
      conjugate(arctan(x))
      sage: var('y', domain='positive')
      y
      sage: conjugate(arctan(y))
      arctan(y)
      sage: conjugate(arctan(y+I))
      conjugate(arctan(y + I))
      sage: conjugate(arctan(1/16))
      arctan(1/16)
      sage: conjugate(arctan(-2*I))
      conjugate(arctan(-2*I))
      sage: conjugate(arctan(2*I))
      conjugate(arctan(2*I))
      sage: conjugate(arctan(I/2))
      arctan(-1/2*I)

  [Python]

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> conjugate(arctan(x))
      conjugate(arctan(x))
      >>> var('y', domain='positive')
      y
      >>> conjugate(arctan(y))
      arctan(y)
      >>> conjugate(arctan(y+I))
      conjugate(arctan(y + I))
      >>> conjugate(arctan(Integer(1)/Integer(16)))
      arctan(1/16)
      >>> conjugate(arctan(-Integer(2)*I))
      conjugate(arctan(-2*I))
      >>> conjugate(arctan(Integer(2)*I))
      conjugate(arctan(2*I))
      >>> conjugate(arctan(I/Integer(2)))
      arctan(-1/2*I)

class sage.functions.trig.Function_arctan2

  Bases: `GinacFunction`

  The modified arctangent function.

  Returns the arc tangent (measured in radians) of \(y/x\), where unlike `arctan(y/x)`, the signs of both `x` and `y` are considered. In particular, this function measures the angle of a ray through the origin and \((x,y)\), with the positive \(x\)-axis the zero mark, and with output angle \(\theta\) being between \(-\pi<\theta<=\pi\).

  Hence, `arctan2(y,x) = arctan(y/x)` only for \(x>0\). One may consider the usual arctan to measure angles of lines through the origin, while the modified function measures rays through the origin.

  Note that the \(y\)-coordinate is by convention the first input.

  EXAMPLES:

  Note the difference between the two functions:

  Sage

      sage: arctan2(1, -1)                                                        # needs sage.symbolic
      3/4*pi
      sage: arctan(1/-1)                                                          # needs sage.symbolic
      -1/4*pi

  Python

      >>> from sage.all import *
      >>> arctan2(Integer(1), -Integer(1))                                                        # needs sage.symbolic
      3/4*pi
      >>> arctan(Integer(1)/-Integer(1))                                                          # needs sage.symbolic
      -1/4*pi

  This is consistent with Python and Maxima:

  Sage

      sage: maxima.atan2(1, -1)                                                   # needs sage.symbolic
      (3*%pi)/4
      sage: math.atan2(1, -1)
      2.356194490192345

  [Python]

      >>> from sage.all import *
      >>> maxima.atan2(Integer(1), -Integer(1))                                                   # needs sage.symbolic
      (3*%pi)/4
      >>> math.atan2(Integer(1), -Integer(1))
      2.356194490192345

  More examples:

  Sage

      sage: arctan2(1, 0)                                                         # needs sage.symbolic
      1/2*pi
      sage: arctan2(2, 3)                                                         # needs sage.symbolic
      arctan(2/3)
      sage: arctan2(-1, -1)                                                       # needs sage.symbolic
      -3/4*pi

  Python

      >>> from sage.all import *
      >>> arctan2(Integer(1), Integer(0))                                                         # needs sage.symbolic
      1/2*pi
      >>> arctan2(Integer(2), Integer(3))                                                         # needs sage.symbolic
      arctan(2/3)
      >>> arctan2(-Integer(1), -Integer(1))                                                       # needs sage.symbolic
      -3/4*pi

  Of course we can approximate as well:

  Sage

      sage: arctan2(-1/2, 1).n(100)                                               # needs sage.symbolic
      -0.46364760900080611621425623146
      sage: arctan2(2, 3).n(100)                                                  # needs sage.symbolic
      0.58800260354756755124561108063

  [Python]

      >>> from sage.all import *
      >>> arctan2(-Integer(1)/Integer(2), Integer(1)).n(Integer(100))                                               # needs sage.symbolic
      -0.46364760900080611621425623146
      >>> arctan2(Integer(2), Integer(3)).n(Integer(100))                                                  # needs sage.symbolic
      0.58800260354756755124561108063

  We can delay evaluation using the `hold` parameter:

  Sage

      sage: arctan2(-1/2, 1, hold=True)                                           # needs sage.symbolic
      arctan2(-1/2, 1)

  Python

      >>> from sage.all import *
      >>> arctan2(-Integer(1)/Integer(2), Integer(1), hold=True)                                           # needs sage.symbolic
      arctan2(-1/2, 1)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: arctan2(-1/2, 1, hold=True).simplify()                                # needs sage.symbolic
      -arctan(1/2)

  [Python]

      >>> from sage.all import *
      >>> arctan2(-Integer(1)/Integer(2), Integer(1), hold=True).simplify()                                # needs sage.symbolic
      -arctan(1/2)

  The function also works with numpy arrays as input:

  Sage

      sage: # needs numpy
      sage: import numpy
      sage: a = numpy.linspace(1, 3, 3)
      sage: b = numpy.linspace(3, 6, 3)
      sage: atan2(a, b)
      array([0.32175055, 0.41822433, 0.46364761])

      sage: atan2(1,a)                                                            # needs numpy
      array([0.78539816, 0.46364761, 0.32175055])

      sage: atan2(a, 1)                                                           # needs numpy
      array([0.78539816, 1.10714872, 1.24904577])

  Python

      >>> from sage.all import *
      >>> # needs numpy
      >>> import numpy
      >>> a = numpy.linspace(Integer(1), Integer(3), Integer(3))
      >>> b = numpy.linspace(Integer(3), Integer(6), Integer(3))
      >>> atan2(a, b)
      array([0.32175055, 0.41822433, 0.46364761])

      >>> atan2(Integer(1),a)                                                            # needs numpy
      array([0.78539816, 0.46364761, 0.32175055])

      >>> atan2(a, Integer(1))                                                           # needs numpy
      array([0.78539816, 1.10714872, 1.24904577])

class sage.functions.trig.Function_cos

  Bases: `GinacFunction`

  The cosine function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: cos(pi)
      -1
      sage: cos(x).subs(x==pi)
      -1
      sage: cos(2).n(100)
      -0.41614683654714238699756822950
      sage: cos(x)._sympy_()                                                      # needs sympy
      cos(x)

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> cos(pi)
      -1
      >>> cos(x).subs(x==pi)
      -1
      >>> cos(Integer(2)).n(Integer(100))
      -0.41614683654714238699756822950
      >>> cos(x)._sympy_()                                                      # needs sympy
      cos(x)

  We can prevent evaluation using the `hold` parameter:

  Sage

      sage: cos(0, hold=True)                                                     # needs sage.symbolic
      cos(0)

  [Python]

      >>> from sage.all import *
      >>> cos(Integer(0), hold=True)                                                     # needs sage.symbolic
      cos(0)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = cos(0, hold=True); a.simplify()                                   # needs sage.symbolic
      1

  Python

      >>> from sage.all import *
      >>> a = cos(Integer(0), hold=True); a.simplify()                                   # needs sage.symbolic
      1

  If possible, the argument is also reduced modulo the period length \(2\pi\), and well-known identities are directly evaluated:

  Sage

      sage: # needs sage.symbolic
      sage: k = var('k', domain='integer')
      sage: cos(1 + 2*k*pi)
      cos(1)
      sage: cos(k*pi)
      cos(pi*k)
      sage: cos(pi/3 + 2*k*pi)
      1/2

  [Python]

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> k = var('k', domain='integer')
      >>> cos(Integer(1) + Integer(2)*k*pi)
      cos(1)
      >>> cos(k*pi)
      cos(pi*k)
      >>> cos(pi/Integer(3) + Integer(2)*k*pi)
      1/2

class sage.functions.trig.Function_cot

  Bases: `GinacFunction`

  The cotangent function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: cot(pi/4)
      1
      sage: RR(cot(pi/4))
      1.00000000000000
      sage: cot(1/2)
      cot(1/2)
      sage: cot(0.5)
      1.83048772171245

      sage: latex(cot(x))                                                         # needs sage.symbolic
      \cot\left(x\right)
      sage: cot(x)._sympy_()                                                      # needs sympy sage.symbolic
      cot(x)

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> cot(pi/Integer(4))
      1
      >>> RR(cot(pi/Integer(4)))
      1.00000000000000
      >>> cot(Integer(1)/Integer(2))
      cot(1/2)
      >>> cot(RealNumber('0.5'))
      1.83048772171245

      >>> latex(cot(x))                                                         # needs sage.symbolic
      \cot\left(x\right)
      >>> cot(x)._sympy_()                                                      # needs sympy sage.symbolic
      cot(x)

  We can prevent evaluation using the `hold` parameter:

  Sage

      sage: cot(pi/4, hold=True)                                                  # needs sage.symbolic
      cot(1/4*pi)

  [Python]

      >>> from sage.all import *
      >>> cot(pi/Integer(4), hold=True)                                                  # needs sage.symbolic
      cot(1/4*pi)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = cot(pi/4, hold=True); a.simplify()                                # needs sage.symbolic
      1

  Python

      >>> from sage.all import *
      >>> a = cot(pi/Integer(4), hold=True); a.simplify()                                # needs sage.symbolic
      1

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: cot(pi/4)
      1
      sage: cot(x).subs(x==pi/4)
      1
      sage: cot(pi/7)
      cot(1/7*pi)
      sage: cot(x)
      cot(x)

      sage: # needs sage.symbolic
      sage: n(cot(pi/4), 100)
      1.0000000000000000000000000000
      sage: float(cot(1))
      0.64209261593433...
      sage: bool(diff(cot(x), x) == diff(1/tan(x), x))
      True
      sage: diff(cot(x), x)
      -cot(x)^2 - 1

  [Python]

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> cot(pi/Integer(4))
      1
      >>> cot(x).subs(x==pi/Integer(4))
      1
      >>> cot(pi/Integer(7))
      cot(1/7*pi)
      >>> cot(x)
      cot(x)

      >>> # needs sage.symbolic
      >>> n(cot(pi/Integer(4)), Integer(100))
      1.0000000000000000000000000000
      >>> float(cot(Integer(1)))
      0.64209261593433...
      >>> bool(diff(cot(x), x) == diff(Integer(1)/tan(x), x))
      True
      >>> diff(cot(x), x)
      -cot(x)^2 - 1

class sage.functions.trig.Function_csc

  Bases: `GinacFunction`

  The cosecant function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: csc(pi/4)
      sqrt(2)
      sage: csc(x).subs(x==pi/4)
      sqrt(2)
      sage: csc(pi/7)
      csc(1/7*pi)
      sage: csc(x)
      csc(x)
      sage: RR(csc(pi/4))
      1.41421356237310
      sage: n(csc(pi/4), 100)
      1.4142135623730950488016887242
      sage: float(csc(pi/4))
      1.4142135623730951
      sage: csc(1/2)
      csc(1/2)
      sage: csc(0.5)
      2.08582964293349

      sage: # needs sage.symbolic
      sage: bool(diff(csc(x), x) == diff(1/sin(x), x))
      True
      sage: diff(csc(x), x)
      -cot(x)*csc(x)
      sage: latex(csc(x))
      \csc\left(x\right)
      sage: csc(x)._sympy_()                                                      # needs sympy
      csc(x)

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> csc(pi/Integer(4))
      sqrt(2)
      >>> csc(x).subs(x==pi/Integer(4))
      sqrt(2)
      >>> csc(pi/Integer(7))
      csc(1/7*pi)
      >>> csc(x)
      csc(x)
      >>> RR(csc(pi/Integer(4)))
      1.41421356237310
      >>> n(csc(pi/Integer(4)), Integer(100))
      1.4142135623730950488016887242
      >>> float(csc(pi/Integer(4)))
      1.4142135623730951
      >>> csc(Integer(1)/Integer(2))
      csc(1/2)
      >>> csc(RealNumber('0.5'))
      2.08582964293349

      >>> # needs sage.symbolic
      >>> bool(diff(csc(x), x) == diff(Integer(1)/sin(x), x))
      True
      >>> diff(csc(x), x)
      -cot(x)*csc(x)
      >>> latex(csc(x))
      \csc\left(x\right)
      >>> csc(x)._sympy_()                                                      # needs sympy
      csc(x)

  We can prevent evaluation using the `hold` parameter:

  Sage

      sage: csc(pi/4, hold=True)                                                  # needs sage.symbolic
      csc(1/4*pi)

  [Python]

      >>> from sage.all import *
      >>> csc(pi/Integer(4), hold=True)                                                  # needs sage.symbolic
      csc(1/4*pi)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = csc(pi/4,hold=True); a.simplify()                                 # needs sage.symbolic
      sqrt(2)

  Python

      >>> from sage.all import *
      >>> a = csc(pi/Integer(4),hold=True); a.simplify()                                 # needs sage.symbolic
      sqrt(2)

class sage.functions.trig.Function_sec

  Bases: `GinacFunction`

  The secant function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: sec(pi/4)
      sqrt(2)
      sage: sec(x).subs(x==pi/4)
      sqrt(2)
      sage: sec(pi/7)
      sec(1/7*pi)
      sage: sec(x)
      sec(x)
      sage: RR(sec(pi/4))
      1.41421356237310
      sage: n(sec(pi/4),100)
      1.4142135623730950488016887242
      sage: float(sec(pi/4))
      1.4142135623730951
      sage: sec(1/2)
      sec(1/2)
      sage: sec(0.5)
      1.13949392732455

      sage: # needs sage.symbolic
      sage: bool(diff(sec(x), x) == diff(1/cos(x), x))
      True
      sage: diff(sec(x), x)
      sec(x)*tan(x)
      sage: latex(sec(x))
      \sec\left(x\right)
      sage: sec(x)._sympy_()                                                      # needs sympy
      sec(x)

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> sec(pi/Integer(4))
      sqrt(2)
      >>> sec(x).subs(x==pi/Integer(4))
      sqrt(2)
      >>> sec(pi/Integer(7))
      sec(1/7*pi)
      >>> sec(x)
      sec(x)
      >>> RR(sec(pi/Integer(4)))
      1.41421356237310
      >>> n(sec(pi/Integer(4)),Integer(100))
      1.4142135623730950488016887242
      >>> float(sec(pi/Integer(4)))
      1.4142135623730951
      >>> sec(Integer(1)/Integer(2))
      sec(1/2)
      >>> sec(RealNumber('0.5'))
      1.13949392732455

      >>> # needs sage.symbolic
      >>> bool(diff(sec(x), x) == diff(Integer(1)/cos(x), x))
      True
      >>> diff(sec(x), x)
      sec(x)*tan(x)
      >>> latex(sec(x))
      \sec\left(x\right)
      >>> sec(x)._sympy_()                                                      # needs sympy
      sec(x)

  We can prevent evaluation using the `hold` parameter:

  Sage

      sage: sec(pi/4, hold=True)                                                  # needs sage.symbolic
      sec(1/4*pi)

  [Python]

      >>> from sage.all import *
      >>> sec(pi/Integer(4), hold=True)                                                  # needs sage.symbolic
      sec(1/4*pi)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = sec(pi/4, hold=True); a.simplify()                                # needs sage.symbolic
      sqrt(2)

  Python

      >>> from sage.all import *
      >>> a = sec(pi/Integer(4), hold=True); a.simplify()                                # needs sage.symbolic
      sqrt(2)

class sage.functions.trig.Function_sin

  Bases: `GinacFunction`

  The sine function.

  EXAMPLES:

  Sage

      sage: # needs sage.symbolic
      sage: sin(0)
      0
      sage: sin(x).subs(x==0)
      0
      sage: sin(2).n(100)
      0.90929742682568169539601986591
      sage: sin(x)._sympy_()                                                      # needs sympy
      sin(x)

  Python

      >>> from sage.all import *
      >>> # needs sage.symbolic
      >>> sin(Integer(0))
      0
      >>> sin(x).subs(x==Integer(0))
      0
      >>> sin(Integer(2)).n(Integer(100))
      0.90929742682568169539601986591
      >>> sin(x)._sympy_()                                                      # needs sympy
      sin(x)

  We can prevent evaluation using the `hold` parameter:

  Sage

      sage: sin(0, hold=True)                                                     # needs sage.symbolic
      sin(0)

  [Python]

      >>> from sage.all import *
      >>> sin(Integer(0), hold=True)                                                     # needs sage.symbolic
      sin(0)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = sin(0, hold=True); a.simplify()                                   # needs sage.symbolic
      0

  Python

      >>> from sage.all import *
      >>> a = sin(Integer(0), hold=True); a.simplify()                                   # needs sage.symbolic
      0

  If possible, the argument is also reduced modulo the period length \(2\pi\), and well-known identities are directly evaluated:

  Sage

      sage: k = var('k', domain='integer')                                        # needs sage.symbolic
      sage: sin(1 + 2*k*pi)                                                       # needs sage.symbolic
      sin(1)
      sage: sin(k*pi)                                                             # needs sage.symbolic
      0

  [Python]

      >>> from sage.all import *
      >>> k = var('k', domain='integer')                                        # needs sage.symbolic
      >>> sin(Integer(1) + Integer(2)*k*pi)                                                       # needs sage.symbolic
      sin(1)
      >>> sin(k*pi)                                                             # needs sage.symbolic
      0

class sage.functions.trig.Function_tan

  Bases: `GinacFunction`

  The tangent function.

  EXAMPLES:

  Sage

      sage: # needs sage.rings.real_mpfr
      sage: tan(3.1415)
      -0.0000926535900581913
      sage: tan(3.1415/4)
      0.999953674278156

      sage: # needs sage.symbolic
      sage: tan(pi)
      0
      sage: tan(pi/4)
      1
      sage: tan(1/2)
      tan(1/2)
      sage: RR(tan(1/2))
      0.546302489843790

  Python

      >>> from sage.all import *
      >>> # needs sage.rings.real_mpfr
      >>> tan(RealNumber('3.1415'))
      -0.0000926535900581913
      >>> tan(RealNumber('3.1415')/Integer(4))
      0.999953674278156

      >>> # needs sage.symbolic
      >>> tan(pi)
      0
      >>> tan(pi/Integer(4))
      1
      >>> tan(Integer(1)/Integer(2))
      tan(1/2)
      >>> RR(tan(Integer(1)/Integer(2)))
      0.546302489843790

  We can prevent evaluation using the `hold` parameter:

  Sage

      sage: tan(pi/4, hold=True)                                                  # needs sage.symbolic
      tan(1/4*pi)

  [Python]

      >>> from sage.all import *
      >>> tan(pi/Integer(4), hold=True)                                                  # needs sage.symbolic
      tan(1/4*pi)

  To then evaluate again, we currently must use Maxima via `sage.symbolic.expression.Expression.simplify()`:

  Sage

      sage: a = tan(pi/4, hold=True); a.simplify()                                # needs sage.symbolic
      1

  Python

      >>> from sage.all import *
      >>> a = tan(pi/Integer(4), hold=True); a.simplify()                                # needs sage.symbolic
      1

  If possible, the argument is also reduced modulo the period length \(\pi\), and well-known identities are directly evaluated:

  Sage

      sage: k = var('k', domain='integer')                                        # needs sage.symbolic
      sage: tan(1 + 2*k*pi)                                                       # needs sage.symbolic
      tan(1)
      sage: tan(k*pi)                                                             # needs sage.symbolic
      0

  [Python]

      >>> from sage.all import *
      >>> k = var('k', domain='integer')                                        # needs sage.symbolic
      >>> tan(Integer(1) + Integer(2)*k*pi)                                                       # needs sage.symbolic
      tan(1)
      >>> tan(k*pi)                                                             # needs sage.symbolic
      0