Trigonometry
The trigonometry library holds the constant pi, the conversions of
angles, the circular and hyperbolic functions with their inverses, the
cardinal sine and the trigonometric integrals, and three functions that
rewrite trigonometric expressions. This introduction gives the concepts you
need before you read the entries.
The functions
Each circular function has an inverse, a hyperbolic form, and an inverse
hyperbolic form. The inverse hyperbolic functions use the ISO 80000-2 names:
arsinh, not arcsinh. The prefix "ar" stands for "area".
| Function | Inverse | Hyperbolic | Inverse hyperbolic |
|---|---|---|---|
sin | arcsin | sinh | arsinh |
cos | arccos | cosh | arcosh |
tan | arctan, arctan2 | tanh | artanh |
cot | arccot | coth | arcoth |
sec | arcsec | sech | arsech |
csc | arccsc | csch | arcsch |
The functions apply to each element of a list:
sin([0, pi / 6, pi / 2])
// ➔ [0, 1/2, 1]
Angles
The argument of a circular function is an angle in radians. degrees(d)
converts an angle in degrees to radians, and dms(d, m, s) converts an angle
in degrees, minutes and seconds. Both conversions are exact when their
arguments are exact.
[degrees(180), degrees(45), dms(12, 30)]
// ➔ [pi, 1/4 * pi, 5/72 * pi]
sin(degrees(30))
// ➔ 1/2
Exact values and numeric values
When the argument is exact, the result is exact. If the value at the argument is known in closed form, the function returns that value. The closed form can contain square roots:
[sin(pi / 6), cos(5pi / 4), tan(pi / 12)]
// ➔ [1/2, -sqrt(2)/2, 2 - sqrt(3)]
If no closed form is known, the result stays symbolic. N gives a numeric
value:
[sin(1), N(sin(1))]
// ➔ [sin(1), 0.841470984807896506653]
When the argument is a floating-point number, the result is a floating-point number:
sin(1.2)
// ➔ 0.93203908596722634967
At a pole, the value is the complex infinity ~oo:
[tan(pi / 2), sec(pi / 2), cot(0)]
// ➔ [~oo, ~oo, ~oo]
The inverse functions and their ranges
An inverse function returns the principal value. The principal value is in the range that this table shows.
| Function | Range of the principal value |
|---|---|
arcsin | from -pi/2 to pi/2 |
arccos | from 0 to pi |
arctan | between -pi/2 and pi/2 |
arccot | between 0 and pi |
arcsec | from 0 to pi, not pi/2 |
arccsc | from -pi/2 to pi/2, not 0 |
arctan2(y, x) | between -pi and pi, pi included |
[arcsin(1), arccos(-1), arctan(-1), arcsec(-2), arccsc(-2)]
// ➔ [1/2 * pi, pi, -1/4 * pi, 2/3 * pi, -1/6 * pi]
The range of arccot is between 0 and pi. Thus a negative argument gives
an angle between pi/2 and pi:
N([arccot(1), arccot(-1)])
// ➔ [0.785398163397448309616, 2.35619449019234492885]
arctan2(y, x) is the angle of the point (x, y). The first argument is the
y coordinate. The function uses the signs of both coordinates to find the
quadrant:
[arctan2(1, 1), arctan2(1, -1), arctan2(-1, -1), arctan2(0, -1)]
// ➔ [1/4 * pi, 3/4 * pi, -3/4 * pi, pi]
When the argument is exact and no real value exists, the result stays
symbolic. N then gives the complex principal value:
[arcsin(2), N(arcsin(2))]
// ➔ [arcsin(2), (1.57079632679489661923 - 1.31695789692481670863i)]
inverseFunction returns the inverse of a function:
[inverseFunction(sin), inverseFunction(cosh)]
// ➔ [arcsin, arcosh]
Trigonometric transformations
Three functions rewrite a trigonometric or hyperbolic expression. They keep exact values exact.
trigExpand expands a function of a sum, or of an integer multiple of an
angle:
trigExpand(sin(a + b))
// ➔ sin(b) * cos(a) + sin(a) * cos(b)
trigExpand(cos(2x))
// ➔ -sin(x)^2 + cos(x)^2
trigReduce does the opposite operation. It changes products and integer
powers into a sum of functions of multiple angles:
trigReduce(cos(x)^3)
// ➔ 1/4 * cos(3x) + 3/4 * cos(x)
trigToExp writes the functions with the complex exponential:
trigToExp(cosh(x))
// ➔ 1/2 * (e^x + e^(-x))
simplify uses the trigonometric identities, for example the Pythagorean
identities and the double-angle formulas:
simplify(sin(x)^2 + cos(x)^2)
// ➔ 1
simplify(1 + tan(x)^2)
// ➔ sec(x)^2
Trigonometric functions
Complex values
With N, an inverse circular or inverse hyperbolic function returns its
complex principal value when no real value exists. A floating-point
argument gives the complex value without N. Complex arguments are also
accepted:
[arcsin(2), N(arcsin(2))]
// ➔ [arcsin(2),(1.57079632679489661923 - 1.31695789692481670863i)]
arcosh(0.5)
// ➔ 1.04719755119659774615i
N(arsinh(1 + i))
// ➔ (1.0612750619050357 + 0.6662394324925153i)
Hyperbolic functions of a logarithm
A hyperbolic function of ln(q), for a rational q, is a rational
number, since \cosh(\ln q) = \frac{1}{2}(q + q^{-1}):
[cosh(ln(2)), sinh(ln(3)), tanh(ln(2)), coth(ln(2))]
// ➔ [5/4,4/3,3/5,5/3]
A function of its inverse
A function of its own inverse is its argument, for each circular and
hyperbolic function. An inverse of its own function gives the principal
value when the argument is an exact real number. arcsin(sin(x)) stays,
because it is not x outside [-\pi/2, \pi/2].
[sin(arcsin(x)), cosh(arcosh(x)), tan(arctan(x))]
// ➔ [x,x,x]
[arcsin(sin(3)), arccos(cos(5)), arcsin(sin(x))]
// ➔ [-3 + pi,-5 + 2pi,arcsin(sin(x))]
simplify also rewrites a function of a different inverse, and an
inverse of a negated argument:
[simplify(cos(arcsin(x))), simplify(tan(arcsin(x)))]
// ➔ [sqrt(1 - x^2),x / sqrt(1 - x^2)]
[simplify(arccos(-x)), simplify(arccot(-x))]
// ➔ [-arccos(x) + pi,-arccot(x) + pi]
Trigonometric simplification
simplify applies the trigonometric identities that make an expression
shorter. trigExpand and trigReduce apply the identities that change
its form; Trigonometric transformations
describes them.
[simplify(sin(x)^2 + cos(x)^2), simplify(1 - sin(x)^2)]
// ➔ [1,cos(x)^2]
[simplify(1 + tan(x)^2), simplify(2sin(x) * cos(x))]
// ➔ [sec(x)^2,sin(2x)]
[simplify(sin(x) / cos(x)), simplify(cos(x) / sin(x))]
// ➔ [tan(x),cot(x)]
The JavaScript API also has the Fu algorithm, a systematic search for a
simpler equivalent form, as a strategy of its simplify method: see
Trigonometric simplification.
Supported identities
| Identity | Example | Epsil |
|---|---|---|
| Pythagorean | \sin^2 x + \cos^2 x = 1, 1 + \tan^2 x = \sec^2 x | simplify |
| Quotient | \sin x / \cos x = \tan x | simplify |
| Double angle | 2 \sin x \cos x = \sin 2x | simplify, trigReduce |
| Double angle | \cos^2 x - \sin^2 x = \cos 2x | trigReduce |
| Sum of angles | \sin(a + b) = \sin a \cos b + \cos a \sin b | trigExpand |
| Product to sum | \sin x \cos y = \frac{1}{2}(\sin(x + y) + \sin(x - y)) | trigReduce |
| Exponential form | \cos x = \frac{1}{2}(e^{ix} + e^{-ix}) | trigToExp |
trigReduce(cos(x)^2 - sin(x)^2)
// ➔ cos(2x)
trigReduce(sin(x) * cos(y))
// ➔ 1/2 * sin(x + y) + 1/2 * sin(x - y)
simplify and the transformation functions do not apply the reciprocal
identities, such as \csc x \sin x = 1, nor the sum-to-product identities,
such as \sin x + \sin y = 2 \sin \frac{x+y}{2} \cos \frac{x-y}{2}. The
Fu algorithm of the JavaScript API applies the reciprocal identities and
Morrie's law, for products of cosines of doubled angles.
[simplify(csc(x) * sin(x)), trigReduce(sin(x) + sin(y))]
// ➔ [sin(x) * csc(x),sin(x) + sin(y)]
Definitions
Each definition is listed under its Epsil spelling (the MathJSON name when it has none), with its signature in the engine's type syntax. The Standard Library page is the one-page index of every category.
arccos
(broadcastable<complex | quantity>) -> number
- argument 1 — The cosine of the angle; outside [-1, 1] the result is complex. Sample:
1 / 2.
Arccosine, the inverse cosine function.
arccos(1/2)
// ➔ 1/3 * pi
N(arccos(1/3))
// ➔ 1.23095941734077468213
MathJSON: Arccos • LaTeX: \arccos
arccot
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The cotangent of the angle; the result is in (0, π) in radians (in the angular unit of the engine), with 0 at +∞ and π at −∞. Sample:
1.
Arccotangent, the inverse cotangent function.
N(arccot(1))
// ➔ 0.785398163397448309616
N(arccot(-1))
// ➔ 2.35619449019234492885
On the real line, arccot takes its values between 0 and pi. For a
complex argument,
\operatorname{arccot}(z) = \frac{\pi}{2} -
\operatorname{arctan}(z)
[arccot(-1), arccot(0)]
// ➔ [3/4 * pi,1/2 * pi]
chop(N(arccot(1 + i) - (pi/2 - arctan(1 + i))))
// ➔ 0
arccot is continuous across the real line: next to -3, its value is
next to arccot(-3). Its branch cuts are those of arctan: the imaginary
axis above i and below -i.
N(arccot(-3 + 10^(-12) * i))
// ➔ (2.819842099193151 - 9.999999999999999e-14 * i)
N(arccot(-3))
// ➔ 2.81984209919315104506
N([arccot(2i), arccot(-2i)])
// ➔ [-0.5493061443340549i,(3.141592653589793 + 0.5493061443340549i)]
Some systems (Mathematica, mpmath) define the arccotangent as
\operatorname{arctan}(1/z) instead. That is an odd function, and it
differs from this one by \pi when \operatorname{Re} z < 0.
MathJSON: Arccot • LaTeX: arcctg
["Arccot", z].
["Arccot", -1]
// ➔ ["Multiply", ["Rational", 3, 4], "Pi"]
arccsc
(broadcastable<complex | infinity | quantity>) -> number
- argument 1 — The cosecant of the angle; inside (-1, 1) the result is complex, and 0 has no value (an exact 0 stays unevaluated, a numeric 0 gives NaN). Sample:
2.
Arccosecant, the inverse cosecant function.
arccsc(2)
// ➔ 1/6 * pi
N(arccsc(3))
// ➔ 0.339836909454121937096
MathJSON: Arccsc • LaTeX: arccsc
arcosh
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The hyperbolic cosine of the result; below 1 the result is complex. Sample:
2.
Inverse hyperbolic cosine (area hyperbolic cosine).
arcosh(1)
// ➔ 0
N(arcosh(2))
// ➔ 1.31695789692481670863
MathJSON: Arcosh • LaTeX: arcosh
arcoth
(broadcastable<complex | infinity | quantity>) -> number
- argument 1 — The hyperbolic cotangent of the result; ±1 gives ±∞, and inside (-1, 1) the result is complex. Sample:
2.
Inverse hyperbolic cotangent (area hyperbolic cotangent).
N(arcoth(2))
// ➔ 0.549306144334054845698
MathJSON: Arcoth • LaTeX: arcoth
arcsch
(broadcastable<complex | infinity | quantity>) -> number
- argument 1 — The hyperbolic cosecant of the result; 0 gives complex infinity. Sample:
1.
Inverse hyperbolic cosecant (area hyperbolic cosecant).
N(arcsch(1))
// ➔ 0.881373587019543025232
MathJSON: Arcsch • LaTeX: arcsch
arcsec
(broadcastable<complex | infinity | quantity>) -> number
- argument 1 — The secant of the angle; inside (-1, 1) the result is complex, and 0 has no value (an exact 0 stays unevaluated, a numeric 0 gives NaN). Sample:
2.
Arcsecant, the inverse secant function.
arcsec(2)
// ➔ 1/3 * pi
N(arcsec(3))
// ➔ 1.23095941734077468214
MathJSON: Arcsec • LaTeX: arcsec
arcsin
(broadcastable<complex | quantity>) -> number
- argument 1 — The sine of the angle; outside [-1, 1] the result is complex. Sample:
1 / 2.
Arcsine, the inverse sine function.
arcsin(1/2)
// ➔ 1/6 * pi
N(arcsin(2))
// ➔ (1.57079632679489661923 - 1.31695789692481670863i)
MathJSON: Arcsin • LaTeX: \arcsin
arctan
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The tangent of the angle; ±∞ gives ±π/2 (in radians; the result is in the angular unit of the engine). Sample:
1.
Inverse tangent.
arctan(1)
// ➔ 1/4 * pi
N(arctan(2))
// ➔ 1.10714871779409050302
MathJSON: Arctan • LaTeX: \arctan
arctan2
MathJSON Arctan2 · (y: broadcastable<real | signed_infinity>, x: broadcastable<real | signed_infinity>) -> real
y— The y coordinate of the point. Sample:1.x— The x coordinate of the point; the result is the angle from the positive x axis, in (−π, π] in radians (in the angular unit of the engine), and 0 at the origin. Sample:-1.
Two-argument arctangent giving the angle of a vector.
arctan2(1, -1)
// ➔ 3/4 * pi
arctan2(-1, -1)
// ➔ -3/4 * pi
arsech
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The hyperbolic secant of the result; 0 gives +∞, and outside [0, 1] the result is complex. Sample:
1 / 2.
Inverse hyperbolic secant (area hyperbolic secant).
arsech(1)
// ➔ 0
N(arsech(1/2))
// ➔ 1.31695789692481670863
MathJSON: Arsech • LaTeX: arsech
arsinh
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The hyperbolic sine of the result; ±∞ gives ±∞. Sample:
1.
Inverse hyperbolic sine (area hyperbolic sine).
arsinh(0)
// ➔ 0
N(arsinh(1))
// ➔ 0.881373587019543025232
MathJSON: Arsinh • LaTeX: arsinh
artanh
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The hyperbolic tangent of the result; ±1 gives ±∞, and outside [-1, 1] the result is complex. Sample:
1 / 2.
Inverse hyperbolic tangent (area hyperbolic tangent).
artanh(0)
// ➔ 0
N(artanh(1/2))
// ➔ 0.549306144334054845698
MathJSON: Artanh • LaTeX: artanh
cos
(broadcastable<complex | quantity>) -> number
- argument 1 — The angle, in radians (or in the angular unit of the engine). Sample:
pi / 3.
Cosine of an angle.
cos(pi / 3)
// ➔ 1/2
N(cos(1))
// ➔ 0.540302305868139717401
MathJSON: Cos • LaTeX: \cos
cosIntegral
MathJSON CosIntegral · (broadcastable<complex | infinity>) -> number
- argument 1 — The number; 0 gives −∞, +∞ gives 0, and a negative real number gives a complex value. Sample:
1.
Cosine integral: γ + ln(x) + ∫₀ˣ (cos(t)−1)/t dt.
N(cosIntegral(1))
// ➔ 0.337403922900968134663
cosh
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The number; a real number gives a result of at least 1, and ±∞ gives +∞. Sample:
1.
Hyperbolic cosine.
cosh(0)
// ➔ 1
N(cosh(1))
// ➔ 1.54308063481524377848
MathJSON: Cosh • LaTeX: \cosh
coshIntegral
MathJSON CoshIntegral · (broadcastable<complex | infinity>) -> number
- argument 1 — The number; 0 gives −∞, ±∞ gives +∞, and a negative real number gives a complex value. Sample:
1.
Hyperbolic cosine integral: γ + ln|x| + ∫₀ˣ (cosh(t)−1)/t dt.
N(coshIntegral(1))
// ➔ 0.837866940980208240895
cot
(broadcastable<complex | quantity>) -> number
- argument 1 — The angle, in radians (or in the angular unit of the engine); a multiple of π gives complex infinity. Sample:
pi / 6.
Cotangent, the reciprocal of tangent.
cot(pi / 6)
// ➔ sqrt(3)
N(cot(1))
// ➔ 0.642092615934330703005
MathJSON: Cot • LaTeX: \cot
coth
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The number; 0 gives complex infinity, and ±∞ gives ±1. Sample:
1.
Hyperbolic cotangent, the reciprocal of hyperbolic tangent.
N(coth(1))
// ➔ 1.31303528549933130364
MathJSON: Coth • LaTeX: \coth
csc
(broadcastable<complex | quantity>) -> number
- argument 1 — The angle, in radians (or in the angular unit of the engine); a multiple of π gives complex infinity. Sample:
pi / 6.
Cosecant, the reciprocal of sine.
csc(pi / 6)
// ➔ 2
N(csc(1))
// ➔ 1.18839510577812121626
MathJSON: Csc • LaTeX: \csc
csch
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The number; 0 gives complex infinity, and ±∞ gives 0. Sample:
1.
Hyperbolic cosecant, the reciprocal of hyperbolic sine.
N(csch(1))
// ➔ 0.850918128239321545136
MathJSON: Csch • LaTeX: \csch
dms
MathJSON DMS · (degrees: broadcastable<number>, minutes: broadcastable<number>?, seconds: broadcastable<number>?) -> number
degrees— The whole degrees of the angle; the minutes and seconds are added to it, also when it is negative. Sample:30.minutes— The minutes of arc, 1/60 of a degree each; 0 by default. Sample:15.seconds— The seconds of arc, 1/3600 of a degree each; 0 by default. Sample:30.
Construct an angle from degrees, minutes, and seconds.
dms(30, 15)
// ➔ 121/720 * pi
N(dms(30, 15))
// ➔ 0.527962098728284697019
degrees
(broadcastable<real>) -> real
- argument 1 — The angle in degrees; it is not reduced modulo 360. Sample:
30.
Convert an angle in degrees.
degrees(30)
// ➔ 1/6 * pi
sin(degrees(30))
// ➔ 1/2
MathJSON: Degrees • LaTeX: \degree
fresnelC
(broadcastable<complex | signed_infinity>) -> complex
- argument 1 — The upper limit of the integral from 0; ±∞ gives ±1/2. Sample:
1.
Fresnel cosine integral.
fresnelC(+oo)
// ➔ 1/2
N(fresnelC(1))
// ➔ 0.779893400376822829474
C(x) = \int_0^x \cos\!\left(\frac{\pi t^2}{2}\right) dt
It is an odd function, C(-x) = -C(x), which simplify applies, and
C(\infty) = \tfrac{1}{2}. Its derivative is the integrand:
[simplify(fresnelC(-x)), fresnelC(-oo)]
// ➔ [-FresnelC(x),-1/2]
D(fresnelC(x), x)
// ➔ cos(1/2 * pi * x^2)
See also: Fresnel integral, DLMF 7.2.
MathJSON: FresnelC • LaTeX: FresnelC
["FresnelC", x]. In LaTeX: \operatorname{FresnelC}(x).
["N", ["FresnelC", 1]]
// ➔ 0.779893400376822829474
fresnelS
(broadcastable<complex | signed_infinity>) -> complex
- argument 1 — The upper limit of the integral from 0; ±∞ gives ±1/2. Sample:
1.
Fresnel sine integral.
fresnelS(+oo)
// ➔ 1/2
N(fresnelS(1))
// ➔ 0.438259147390354766077
S(x) = \int_0^x \sin\!\left(\frac{\pi t^2}{2}\right) dt
It is an odd function, S(-x) = -S(x), which simplify applies, and
S(\infty) = \tfrac{1}{2}. Its derivative is the integrand:
[simplify(fresnelS(-x)), N(fresnelS(-1)), fresnelS(0)]
// ➔ [-FresnelS(x),-0.438259147390354766077,0]
D(fresnelS(x), x)
// ➔ sin(1/2 * pi * x^2)
N(fresnelS(1 + i))
// ➔ (-2.0618882191948398 + 2.0618882191948398i)
Fresnel integrals
The Fresnel integrals arise in the description of near-field diffraction and in the geometry of the Cornu spiral (Euler spiral).
See also: DLMF 7.2.
MathJSON: FresnelS • LaTeX: FresnelS
["FresnelS", x]. In LaTeX: \operatorname{FresnelS}(x).
["N", ["FresnelS", 1]]
// ➔ 0.438259147390354766077
haversine
(broadcastable<real>) -> number
- argument 1 — The angle, in radians (or in the angular unit of the engine); the result is (1 − cos(x))/2, in [0, 1]. Sample:
pi / 3.
Haversine function.
haversine(pi / 3)
// ➔ 1/4
haversine(x)
// ➔ 1/2 * (1 - cos(x))
\operatorname{hav}(z) = \sin^2 \frac{z}{2} = \frac{1 - \cos z}{2}
The haversine was
important in navigation: it appears in the haversine formula, which
computes the distance between two points on a sphere from their
latitudes and longitudes. inverseHaversine(z) is
2 \arcsin \sqrt{z}.
[haversine(pi), inverseHaversine(1)]
// ➔ [1,pi]
MathJSON: Haversine
["Haversine", z], ["InverseHaversine", z].
["Haversine", ["Divide", "Pi", 2]]
// ➔ ["Rational", 1, 2]
hypot
MathJSON Hypot · (broadcastable<infinity | real>, broadcastable<infinity | real>) -> +oo | nan | real
- argument 1 — One leg; an infinite leg makes the result +∞. Sample:
3. - argument 2 — The other leg. Sample:
4.
Hypotenuse length: sqrt(x^2 + y^2).
hypot(3, 4)
// ➔ 5
hypot(1, 1)
// ➔ sqrt(2)
inverseFunction
(function) -> function
- argument 1 — The function to invert; a function with no known inverse leaves the call unevaluated. Sample:
sin.
Inverse of a function.
inverseFunction(sin)
// ➔ arcsin
inverseFunction(tan)(1)
// ➔ 1/4 * pi
inverseFunction(f) is the inverse of the function f, such as arcsin for
sin. It is an operator: it takes a function and gives a function.
inverseFunction(sin)(x)
// ➔ arcsin(x)
MathJSON: InverseFunction • LaTeX: ^{-1
["InverseFunction", f]. In LaTeX: \sin^{-1}(x).
[["InverseFunction", "Sin"], "x"]
inverseHaversine
MathJSON InverseHaversine · (broadcastable<real>) -> number
- argument 1 — The haversine of the angle; inside [0, 1] the result is in [0, π] in radians (in the angular unit of the engine), and outside it the result is complex. Sample:
1 / 2.
Inverse haversine function.
inverseHaversine(1/2)
// ➔ 1/2 * pi
N(inverseHaversine(1/4))
// ➔ 1.04719755119659774615
pi
constant real<3.141592653589793..3.141592653589794> = 3.14159265358979323846
The constant π ≈ 3.14159, the ratio of a circle's circumference to its diameter.
N(pi)
// ➔ 3.14159265358979323846
cos(pi)
// ➔ -1
MathJSON: Pi • LaTeX: \pi
sec
(broadcastable<complex | quantity>) -> number
- argument 1 — The angle, in radians (or in the angular unit of the engine); an odd multiple of π/2 gives complex infinity. Sample:
pi / 3.
Secant, the reciprocal of cosine.
sec(pi / 3)
// ➔ 2
N(sec(1))
// ➔ 1.85081571768092561791
MathJSON: Sec • LaTeX: \sec
sech
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The number; a real number gives a result in (0, 1], and ±∞ gives 0. Sample:
1.
Hyperbolic secant, the reciprocal of hyperbolic cosine.
sech(0)
// ➔ 1
N(sech(1))
// ➔ 0.648054273663885399574
MathJSON: Sech • LaTeX: sech
sin
(broadcastable<complex | quantity>) -> number
- argument 1 — The angle, in radians (or in the angular unit of the engine). Sample:
pi / 6.
Sine of an angle.
sin(pi / 6)
// ➔ 1/2
sin(1)
// ➔ sin(1)
N(sin(1))
// ➔ 0.841470984807896506653
MathJSON: Sin • LaTeX: \sin
sinIntegral
MathJSON SinIntegral · (broadcastable<complex | infinity>) -> number
- argument 1 — The upper limit of the integral from 0; ±∞ gives ±π/2. Sample:
1.
Sine integral: ∫₀ˣ sin(t)/t dt.
sinIntegral(+oo)
// ➔ 1/2 * pi
N(sinIntegral(1))
// ➔ 0.946083070367183014941
sinc
(broadcastable<complex | signed_infinity>) -> complex
- argument 1 — The number; 0 gives 1, and ±∞ gives 0. Sample:
pi / 2.
Unnormalized sinc function: sin(x)/x with sinc(0)=1.
sinc(0)
// ➔ 1
N(sinc(1))
// ➔ 0.841470984807896506653
MathJSON: Sinc • LaTeX: sinc
sinh
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The number; ±∞ gives ±∞. Sample:
1.
Hyperbolic sine.
sinh(0)
// ➔ 0
N(sinh(1))
// ➔ 1.17520119364380145688
MathJSON: Sinh • LaTeX: \sinh
sinhIntegral
MathJSON SinhIntegral · (broadcastable<complex | infinity>) -> number
- argument 1 — The upper limit of the integral from 0; ±∞ gives ±∞. Sample:
1.
Hyperbolic sine integral: ∫₀ˣ sinh(t)/t dt.
sinhIntegral(0)
// ➔ 0
N(sinhIntegral(1))
// ➔ 1.05725087537572851457
tan
(broadcastable<complex | quantity>) -> number
- argument 1 — The angle, in radians (or in the angular unit of the engine); an odd multiple of π/2 gives complex infinity. Sample:
pi / 4.
Tangent of an angle.
tan(pi / 3)
// ➔ sqrt(3)
N(tan(1))
// ➔ 1.55740772465490223051
MathJSON: Tan • LaTeX: \tan
tanh
(broadcastable<complex | quantity | signed_infinity>) -> number
- argument 1 — The number; a real number gives a result in (-1, 1), and ±∞ gives ±1. Sample:
1.
Hyperbolic tangent.
tanh(0)
// ➔ 0
N(tanh(1))
// ➔ 0.761594155955764888119
MathJSON: Tanh • LaTeX: \tanh
trigExpand
(value) -> value
- argument 1 — The expression whose trigonometric and hyperbolic functions are expanded. Sample:
sin(2x).
Expand trigonometric and hyperbolic functions of sums and integer multiples of angles.
trigExpand(sin(a + b))
// ➔ sin(b) * cos(a) + sin(a) * cos(b)
trigExpand(sin(2x))
// ➔ 2sin(x) * cos(x)
trigExpand(cos(2 * x))
// ➔ -sin(x)^2 + cos(x)^2
trigExpand is the trigonometric analog of expand. Hyperbolic functions
are expanded with their own addition formulas. sec, csc and cot are
expanded as the reciprocals of the expanded cos, sin and tan.
trigExpand(sinh(a + b))
// ➔ sinh(b) * cosh(a) + sinh(a) * cosh(b)
trigExpand(sin(3x))
// ➔ -sin(x)^3 + 3sin(x) * cos(x)^2
trigExpand(tan(a + b))
// ➔ (tan(a) + tan(b)) / (1 - tan(a) * tan(b))
trigExpand(sec(a + b))
// ➔ 1 / (cos(a) * cos(b) - sin(a) * sin(b))
Only sums and integer multiples are expanded. An exact value stays exact:
[trigExpand(sin(x / 2)), trigExpand(sin(2.5 * x))]
// ➔ [sin(1/2 * x),sin(2.5 * x)]
trigExpand(sin(pi/6 + x))
// ➔ 1/2 * cos(x) + sqrt(3)/2 * sin(x)
MathJSON: TrigExpand
["TrigExpand", expr].
["TrigExpand", ["Sin", ["Add", "a", "b"]]]
// ➔ ["Add", ["Multiply", ["Sin", "b"], ["Cos", "a"]], ["Multiply", ["Sin", "a"], ["Cos", "b"]]]
["TrigExpand", ["Cos", ["Multiply", 2, "x"]]]
// ➔ ["Add", ["Negate", ["Power", ["Sin", "x"], 2]], ["Power", ["Cos", "x"], 2]]
trigReduce
(value) -> value
- argument 1 — The expression whose products and powers are reduced. Sample:
sin(x)^2.
Rewrite products and integer powers of trigonometric and hyperbolic functions as a linear combination of functions of multiple angles (the inverse of TrigExpand).
trigReduce(sin(x)^2)
// ➔ -1/2 * cos(2x) + 1/2
trigReduce(sin(x) * cos(x))
// ➔ 1/2 * sin(2x)
trigReduce is the inverse of trigExpand, and the trigonometric analog
of factor. A product of functions of different angles becomes a sum,
and hyperbolic functions are reduced with their own formulas:
trigReduce(-sin(x)^3 + 3sin(x) * cos(x)^2)
// ➔ sin(3x)
trigReduce(cos(x)^4)
// ➔ 1/8 * cos(4x) + 1/2 * cos(2x) + 3/8
trigReduce(sinh(x)^2)
// ➔ 1/2 * cosh(2x) - 1/2
trigReduce(cos(x) * cos(2x) * cos(4x))
// ➔ 1/4 * cos(x) + 1/4 * cos(3x) + 1/4 * cos(5x) + 1/4 * cos(7x)
trigExpand, trigReduce and trigToExp rewrite the formula that a
variable holds, and the result of another rewrite:
let f = sin(3x)
let g = trigExpand(f)
[g, trigReduce(g), trigToExp(f)]
// ➔ [-sin(x)^3 + 3sin(x) * cos(x)^2,sin(3x),-1/2 * i * e^(3i * x) + 1/2 * i * e^(-3i * x)]
MathJSON: TrigReduce
["TrigReduce", expr].
["TrigReduce", ["Power", ["Sin", "x"], 2]]
// ➔ ["Add", ["Multiply", ["Rational", -1, 2], ["Cos", ["Multiply", 2, "x"]]], ["Rational", 1, 2]]
["TrigReduce", ["Multiply", ["Sin", "x"], ["Cos", "x"]]]
// ➔ ["Multiply", ["Rational", 1, 2], ["Sin", ["Multiply", 2, "x"]]]
trigToExp
(value) -> value
- argument 1 — The expression to rewrite. Sample:
cos(x).
Rewrite trigonometric and hyperbolic functions in terms of the complex exponential, exactly.
trigToExp(sin(x))
// ➔ -1/2 * i * e^(i * x) + 1/2 * i * e^(-i * x)
trigToExp(cos(x))
// ➔ 1/2 * (e^(i * x) + e^(-i * x))
trigToExp exposes the exponential structure of an expression, which can
make it easier to manipulate algebraically. A hyperbolic function becomes
a real exponential:
trigToExp(sinh(x))
// ➔ 1/2 * (-e^(-x) + e^x)
trigToExp(tan(x))
// ➔ -i * (-e^(-i * x) + e^(i * x)) / (e^(i * x) + e^(-i * x))
MathJSON: TrigToExp
["TrigToExp", expr].
["TrigToExp", ["Cos", "x"]]
// ➔ ["Multiply", ["Rational", 1, 2], ["Add", ["Power", "ExponentialE", ["Multiply", ["Complex", 0, 1], "x"]], ["Power", "ExponentialE", ["Multiply", ["Complex", 0, -1], "x"]]]]