Return the absolute value of x, commonly written as |x|. When given a real number, it returns a non-negative real value. When given a complex number, it returns the modulus of the number.
The argument can have a dimension.
Example:
abs(-3 meter)
= 3 meter
abs(4 + 3j)
= 5
Return the square root of x. Any complex number may be specified, yielding the complex root in the upper half plane.
Alias: √(x).
Added in version 1.0.
The argument may have a dimension.
Compute the third (cubic) root of x. Negative real numbers yield a negative real cubic root:
cbrt(-27)
= -3
This function accepts any complex input. The result will generally be the first complex root, i.e. the one with a phase between 0 and π/3. Real negative arguments however will still yield a real (negative) result. Use x^(1/3) to get the first complex root.
Alias: ∛(x).
Added in version 1.0.
Compute the natural exponential function.
The argument must be dimensionless.
See also
ln() (natural logarithm)Compute the natural logarithm.
Any non-zero number may be given. The result will be the principal value. The branch cut runs across the negative real axis. Nevertheless, in SpeedCrunch ln() is defined for negative real numbers as ln(-x) = ln(|x|)) + πj, extending the branch from the upper half-plane.
Return the numerical value of quantity x.
For unitless values, this returns the value unchanged. For quantities with units, it returns the numerical value in SI/base units by default.
If x includes an explicit conversion target (-> [unit]), it returns
the numerical value in that target unit.
Example:
numval(3)
= 3
numval(3 [m/s])
= 3
numval(3 [km/s])
= 3000
numval(3 [km/s] -> [cm/s])
= 300000
Added in version 1.0.
Convert a Unix timestamp (seconds since 1970-01-01 00:00:00 UTC) into a
numeric date/time value formatted as YYYYMMDD.HHMMSS.
If offset is omitted, the timestamp is converted using the local system
timezone. If offset is provided, it is interpreted as hours offset to
GMT/UTC (fractional offsets are supported), and conversion is performed in
UTC after applying that offset.
This function is the inverse of epoch() when using the same offset.
Example:
datetime(1514761200; 1)
= 20180101.000000
datetime(1551464695; -3.5)
= 20190301.145455
Added in version 1.0.
Convert a numeric date/time value in YYYYMMDD.HHMMSS format to a Unix
timestamp (seconds since 1970-01-01 00:00:00 UTC).
If offset is omitted, the value is interpreted in the local system
timezone. If offset is provided, it is interpreted as hours offset to
GMT/UTC (fractional offsets are supported).
This function is the inverse of datetime() when using the same offset.
Example:
epoch(20180101.000000; 1)
= 1514761200
epoch(20190301.145455; -3.5)
= 1551464695
Compute the molar mass of a chemical formula and return the result with
dimension g/mol.
The formula argument is case-sensitive and supports either plain digits
(for example C6H12O6) or subscript digits (for example C₆H₁₂O₆).
Parsing fails for invalid formulas.
Advanced chemical notation is not supported yet. For example, grouped or
hydrated formulas such as K4[Fe(CN)6]·3H2O currently fail to parse.
The element table follows the official IUPAC CIAAW 2021 abridged standard atomic weights.
Example:
molmass(C6H12O6)
= 180.156 g/mol
Compute the mass of a substance amount and return the result with dimension
g.
This function reuses molmass() internally and is equivalent to:
mol * molmass(formula).
The formula argument follows the same parsing rules as molmass().
Example:
mass(1; C6H12O6)
= 180.156 g
Compute molarity as amount of substance divided by solution volume and
return the result with dimension mol/L.
This function is equivalent to: n / V.
If n or V is dimensionless, SpeedCrunch interprets them as mol
and L, respectively.
Example:
molarity(0.50; 1.00)
= 0.5 mol/L
Added in version 1.0.
Lists are written with braces and semicolon-separated elements. Matrices are written as a list of row lists. Only one-dimensional lists and two-dimensional matrices are supported:
mylist = {1; 2; 3; 4; 5}
mat = {{1; 2; 3}; {4; 5; 6}}
The function-style notation list(...) is also accepted on input, for
example list(1; 2; 3) is equivalent to {1; 2; 3}.
List and matrix results use the same spacing, for example {1; 2; 3} and
{{1; 2}; {3; 4}}.
List and matrix elements must be dimensionless. Units cannot be attached to individual elements or to a list or matrix as a whole.
Supported arithmetic operations are addition and subtraction between same-shaped lists or matrices, multiplication by a scalar on either side, division by a scalar on the right-hand side, and matrix multiplication for compatible matrices. In matrix multiplication, a list can be used as a row vector on the left when the right operand is a matrix. A list can also be used as a row vector on the right when the left operand is a one-column matrix. List-by-list multiplication is not supported. Matrix products with a single result element return that scalar directly. Scalar addition/subtraction, scalar divided by a list or matrix, elementwise multiplication, and elementwise division are not supported:
{1; 2; 3} + {4; 5; 6}
= {5; 7; 9}
2 * {{1; 2}; {3; 4}}
= {{2; 4}; {6; 8}}
{1; 2; 3} / 2
= {0.5; 1; 1.5}
{{1; 2}; {3; 4}} * {{5; 6}; {7; 8}}
= {{19; 22}; {43; 50}}
{1; 2; 3} * {{1}; {2}; {3}}
= 14
{{1}; {2}; {3}} * {4; 5; 6}
= {{4; 5; 6}; {8; 10; 12}; {12; 15; 18}}
The aggregation and statistics functions count(), sum(),
min(), max(), average(), mean(), median(),
varp(), vars(), stdevp(), and stdevs() accept a list or
matrix as a single argument. Matrix inputs are flattened for these scalar
statistics. The p variants use population normalization (n); the s
variants use sample normalization (n-1).
covp(), covs(), corrp(), and corrs() treat matrices
column-wise: rows are observations and columns are variables.
Added in version 1.0.
Return the dot product of two equal-length lists.
Added in version 1.0.
Return the cross product of two three-element lists.
Added in version 1.0.
Return the Euclidean norm of a list, or the Frobenius norm of a matrix.
Added in version 1.0.
Return the transposed matrix.
Added in version 1.0.
Return the determinant of a square matrix.
Added in version 1.0.
Return the inverse of a square matrix.
Added in version 1.0.
Return the sum of the diagonal of a square matrix.
Added in version 1.0.
Return the matrix rank.
Added in version 1.0.
Return the population covariance matrix. Rows are observations and columns
are variables. This uses population normalization (n).
Added in version 1.0.
Return the sample covariance matrix. Rows are observations and columns are
variables. This uses sample normalization (n-1).
Added in version 1.0.
Return the population Pearson correlation matrix. Rows are observations and
columns are variables. This is derived from covp().
Added in version 1.0.
Return the sample Pearson correlation matrix. Rows are observations and
columns are variables. This is derived from covs().
Added in version 1.0.
Return all matrix elements as a single list in row-major order.
Added in version 1.0.
Return the row count.
Added in version 1.0.
Return the column count.
Added in version 1.0.
Return {n} for a list and {rows; cols} for a matrix.
For direct trigonometric input (sin(), cos(), tan(),
cot(), sec(), csc()), explicit angle units
(rad, degree, gradian/grad/gon, turn, arcminute,
arcsecond) override the global angle mode. Unitless values follow the
current angle mode.
Returns the sine of x. The behavior depends on both the angle mode setting and on whether complex numbers are enabled.
In degrees, gradians, or turns modes, the argument is assumed to be expressed in such that sin() is periodic with a period of 360 degrees, 400 gradians, or 1 turn, respectively: sin(x) = sin(x+360), sin(x) = sin(x+400), or sin(x) = sin(x+1). Complex arguments are allowed only in radians mode, regardless of the corresponding setting.
When radians are set as the angle mode, sin() will be 2π-periodic. The argument may be complex.
For real arguments beyond approx. |x|>1077, SpeedCrunch no longer recognizes the periodicity of the function and issues an error.
The argument of sin() must be dimensionless.
The inverse function is arcsin().
Returns the cosine of x. The behavior depends on both the angle mode setting and on whether complex numbers are enabled.
In degrees, gradians, or turns modes, the argument is assumed to be expressed in such that cos() is periodic with a period of 360 degrees, 400 gradians, or 1 turn, respectively: cos(x) = cos(x+360), cos(x) = cos(x+400), or cos(x) = cos(x+1). Complex arguments are allowed only in radians mode, regardless of the corresponding setting.
When radians are set as the angle mode, cos() will be 2π-periodic. The argument may be complex.
For real arguments beyond approx. |x|>1077, SpeedCrunch no longer recognizes the periodicity of the function and issues an error.
The argument of cos() must be dimensionless.
The inverse function is arccos().
Return cos(x) + i·sin(x).
Like sin() and cos(), explicit angle units
(rad, degree, gradian/grad/gon, turn,
arcminute, arcsecond) override the global angle mode. Unitless
values follow the current angle mode.
Complex arguments are allowed only in radians mode. The argument must be dimensionless.
Returns the tangent of x. The behavior depends on both the angle mode setting and on whether complex numbers are enabled.
In degrees, gradians, or turns modes, the argument is assumed to be expressed in such that tan() is periodic with a period of 360 degrees, 400 gradians, or 1 turn, respectively: tan(x) = tan(x+360), tan(x) = tan(x+400), or tan(x) = tan(x+1). Complex arguments are allowed only in radians mode, regardless of the corresponding setting.
When radians are set as the angle mode, tan() will be π-periodic. The argument may be complex.
The argument of tan() must be dimensionless.
The inverse function is arctan().
Returns the cotangent of x. The behavior depends on both the angle mode setting and on whether complex numbers are enabled.
In degrees, gradians, or turns modes, the argument is assumed to be expressed in such that cot() is periodic with a period of 360 degrees, 400 gradians, or 1 turn, respectively: cot(x) = cot(x+360), cot(x) = cot(x+400), or cot(x) = cot(x+1). Complex arguments are allowed only in radians mode, regardless of the corresponding setting.
When radians are set as the angle mode, cot() will be π-periodic. The argument may be complex.
The argument of cot() must be dimensionless.
Returns the secant of x, defined as the reciprocal cosine of x: sec(x) = 1/cos(x). The behavior depends on both the angle mode setting and on whether complex numbers are enabled.
In degrees, gradians, or turns modes, the argument is assumed to be expressed in such that sec() is periodic with a period of 360 degrees, 400 gradians, or 1 turn, respectively: sec(x) = sec(x+360), sec(x) = sec(x+400), or sec(x) = sec(x+1). Complex arguments are allowed only in radians mode, regardless of the corresponding setting.
When radians are set as the angle mode, sec() will be 2π-periodic. The argument may be complex.
For real arguments beyond approx. |x|>1077, SpeedCrunch no longer recognizes the periodicity of the function and issues an error.
The argument of sec() must be dimensionless.
Returns the cosecant of x, defined as the reciprocal sine of x: csc(x) = 1/sin(x). The behavior depends on both the angle mode setting and on whether complex numbers are enabled.
In degrees, gradians, or turns modes, the argument is assumed to be expressed in such that csc() is periodic with a period of 360 degrees, 400 gradians, or 1 turn, respectively: csc(x) = csc(x+360), csc(x) = csc(x+400), or csc(x) = csc(x+1). Complex arguments are allowed only in radians mode, regardless of the corresponding setting.
When radians are set as the angle mode, csc() will be 2π-periodic. The argument may be complex.
For real arguments beyond approx. |x|>1077, SpeedCrunch no longer recognizes the periodicity of the function and issues an error.
The argument of csc() must be dimensionless.
Returns the inverse cosine of x, such that cos(arccos(x)) = x. The behavior of the function depends on the angle mode setting.
In degrees, gradians, or turns modes, arccos() takes a real argument from [-1, 1], and the return value is in the range [0, 180], [0, 200], or [0, 0.5], respectively. Real arguments outside [-1, 1] and complex numbers are allowed only in radians mode.
When radians are set as the angle mode, arccos() maps an element from [-1, 1] to a value in [0, π] and may take any argument from the complex plane. arccos(-1) = π and arccos(1) = 0 match the real-valued results.
The argument of arccos() must be dimensionless.
The inverse function is cos().
Returns the inverse sine of x, such that sin(arcsin(x)) = x. The behavior of the function depends on the angle mode setting.
In degrees, gradians, or turns modes, arcsin() takes a real argument from [-1, 1], and the return value is in the range [-90, 90], [-100, 100], or [-0.25, 0.25], respectively. Real arguments outside [-1, 1] and complex numbers are allowed only in radians mode.
When radians are set as the angle mode, arcsin() maps an element from [-1, 1] to a value in [-π/2, π/2] and may take any argument from the complex plane. arcsin(-1) = π/2 and arcsin(1) = π/2 match the real-valued results.
The argument of arccos() must be dimensionless.
The inverse function is sin().
Returns the inverse tangent of x, such that tan(arctan(x)) = x. The behavior of the function depends on the angle mode setting.
In degrees, gradians, or turns modes, arctan() takes a real argument from [-1, 1], and the return value is in the range [-90, 90], [-100, 100], or [-0.25, 0.25], respectively. Real arguments outside [-1, 1] and complex numbers are allowed only in radians mode.
When radians are set as the angle mode, arctan() maps a real number to a value in [-π/2, π/2] and may take any argument from the complex plane, except for +j and -j.
The argument of arctan() must be dimensionless.
The inverse function is tan().
Returns the angle formed by the vector (x, y) and the X axis. If the point (x, y) lies in the first quadrant (i.e. both x > 0 and y > 0 are true), it is given by arctan(y/x). However, the function handles vectors in other quadrants as well.
The behavior of the function depends on the angle mode setting. In degrees, gradians, or turns modes, this function returns a value in the range ]-180, 180], ]-200, 200], or ]-0.5, 0.5], respectively. When radians are set as the angle mode, the return value lies in the range ]-π, π].
Unlike arctan() this function only accepts real arguments.
The argument values must be dimensionless.
Return the hyperbolic sine of x. Any complex number may be used as the argument.
The argument must be dimensionless.
The inverse function is arsinh().
Return the hyperbolic cosine of x. Any complex number may be used as the argument.
The argument must be dimensionless.
The inverse function is arcosh().
Return the hyperbolic tangent of x. Any complex number may be used as the argument.
The argument must be dimensionless.
For sufficiently large positive or negative real arguments, the result rounds
to 1 or -1, respectively, without a range error.
The inverse function is artanh().
Compute the area hyperbolic sine of x, the inverse function to sinh(). arsinh(x) is the only solution to cosh(y) = x.
The function is defined for any complex z as arsinh(z) = ln[z + (z 2 +1) 1/2 ].
The function only accepts dimensionless arguments.
Compute the area hyperbolic cosine of x, the inverse function to cosh(). arcosh(x) is the positive solution to cosh(y) = x. Except for x=1, the second solution to this equation will be given by -arcosh(x).
The function is defined for any complex z as arcosh(z) = ln[z + (z 2 -1) 2 ].
The function only accepts dimensionless arguments.
Compute the area hyperbolic tangent of x, the inverse function to tanh(). artanh(x) is the only solution to tanh(y) = x.
This function accepts any argument except for -1 and +1. In the complex plane, it is defined as artanh(z) = 1/2 * ln[(z+1)/(z-1)].
The function only accepts dimensionless arguments.
Compute the error function, evaluated in x. The error function is closely related to the Gaussian cumulative density function.
Note that currently only real arguments are allowed. Furthermore, the function only accepts dimensionless arguments.
Compute the complementary error function, evaluated in x. The complementary error function is defined by erfc(x) = 1 - erf(x).
Note that currently only real arguments are allowed. Furthermore, the function only accepts dimensionless arguments.
Evaluates the gamma function (frequently denoted by the Greek letter Γ). The gamma function is an analytic extension to the factorial operation which is defined on real numbers as well. The relation between factorial and the gamma function is given by Γ(n) = (n - 1)!.
Note that currently only real arguments are allowed. Furthermore, the function only accepts dimensionless arguments.
The computation of the factorial operation is in fact implemented via gamma(). This means that in SpeedCrunch, factorials of non-integer numbers are allowed.
Computes ln(abs(gamma(x))). As the gamma function grows extremely quickly, it is sometimes easier to work with its logarithm instead. lngamma() allows much larger arguments that would otherwise overflow gamma().
Note that currently only real arguments are allowed. Furthermore, the function only accepts dimensionless arguments.
The complex-form functions in this section format one result in a specific complex representation. They override the global setting for that result only.
Complex numbers can also be entered in phasor notation as r ∠ θ. This is
equivalent to r * cis(θ): the left operand is the magnitude, and the right
operand is the phase angle. Unitless phases follow the global angle mode, while
explicit angle units override it.
When the angle mode is radians, complex forms display simple phase multiples
of pi symbolically, for example cis(pi / 2), exp(i · pi / 2), or
1 ∠ (pi / 2). Other angle modes display numeric phase values; exponential
form continues to use radians.
Return the real part of a complex number x.
The argument may have a dimension.
Return the imaginary part of a complex number x.
The argument may have a dimension.
Added in version 1.0.
Return the complex conjugate of a complex number x.
This function accepts any real or complex input.
Returns the phase (angle) of a complex number x. The unit of the angle corresponds to the current angle mode.
The argument may have a dimension.
See also
abs() (absolute value)Format the complex number x in rectangular form, i.e. the form
a + b u, where u is the currently selected imaginary-unit symbol
(i or j).
This corresponds to .
Format the complex number x in trigonometric form, shown as
r(cos ɸ + u sin ɸ), where u is the selected imaginary-unit symbol
(i or j). The angle ɸ follows the global angle mode.
This corresponds to .
Format the complex number x in exponential form, shown as
r e uɸ, where u is the selected imaginary-unit symbol
(i or j), and ɸ is in radians.
This corresponds to .
Format the complex number x in cis form, shown as r cis(ɸ). The
angle ɸ follows the global angle mode.
This corresponds to .
Format the complex number x in phasor form, shown as r ∠ ɸ. The
angle ɸ follows the global angle mode.
This output format is related to phasor input notation: r ∠ θ enters a
complex number from magnitude r and phase θ.
This corresponds to .
For x >= 0, return +1. For x < 0, return -1.
Convert the angle x into radians. Independently of the angle mode setting, this function will assume that x is given in degrees and return pi*x/180.
The function accepts real arguments that are either dimensionless (interpreted
as degrees) or explicitly tagged with an angle unit in [] (for example
[rad], [degree], [gradian], [turn], [arcminute],
[arcsecond]).
With explicit unit blocks, the equivalent conversion is x[deg] -> [rad].
Convert the angle x into degrees. Independently of the angle mode setting, this function will assume that x is given in radians and return 180*x/pi.
The function accepts real arguments that are either dimensionless (interpreted
as radians) or explicitly tagged with an angle unit in [].
With explicit unit blocks, the equivalent conversion is x[rad] -> [deg].
Added in version 1.0.
Convert the angle x into gradians. Independently of the angle mode setting, this function will assume that x is given in radians and return 200*x/pi.
The function accepts real arguments that are either dimensionless (interpreted
as radians) or explicitly tagged with an angle unit in [].
With explicit unit blocks, the equivalent conversion is x[rad] -> [grad].
Added in version 1.0.
Convert the angle x into turns. Independently of the angle mode setting, this function will assume that x is given in radians and return x/(2*pi).
The function accepts real arguments that are either dimensionless (interpreted
as radians) or explicitly tagged with an angle unit in [].
With explicit unit blocks, the equivalent conversion is x[rad] -> [turn].
Returns the integer part of x, effectively rounding it towards zero.
The function only accepts real, dimensionless arguments.
Returns the fractional (non-integer) part of x, given by frac(x) = x - int(x).
The function only accepts real, dimensionless arguments.