Launch

Introduction

Farad (pronounced fair-ad) is a free web-based math environment for everyone. The language is natural and simple with no programming experience required.

Powerful things happen when you don’t worry about unit conversions:

  • You are more confident in your answers.
  • Critical inputs can stay in their source unit of measure for easier review.
  • You might learn more about how units relate across different disciplines.
  • Feedback is instant when a resultant unit does not match your expectation.
  • You might prevent another Hubble Telescope incident.

See Philosophy for more background information.

Demo

Hover over items to view the tooltip. The application consists of a script editor for persistent and sharable calculations, and a terminal for single-line calculations and other special features.

Loading...
Results will show up here.
NO ERRORS

Script editor

Scripts are evaluated on the server, ensuring shared calculations are consistent and untampered. The output will also include any errors as well as information about the server. The version is useful for troubleshooting when contacting support. See Privacy for more information.

Buttons

  • [ Title ] - Displayed when sharing links or printing reports.
  • [ Precision ] - Significant figures (1-15).
  • Share - Toggle creating a short link as part of the output.
  • Evaluate - Evaluate the script on the server and display the output.
  • Reset - Reset the script editor, title, and precision back to the values of the original link.

In the full screen editor, the following buttons are also available in the navigation bar:

  • > - Opens a terminal in a new window.
  • New - Opens a new IDE in a new tab.
  • Print - Prints a report of the output including the Share link and server info.
  • Tutorial - Opens a tutorial script in a new tab.

Keyboard shortcuts

WindowsMacShortcut
Ctrl + Enter + EnterEvaluate script
Ctrl + + + +Zoom in
Ctrl + - + -Zoom out
Ctrl + P + PPrint report

Terminal

The terminal runs locally. It accepts the same math syntax as a script with some additional commands:

> 1 + 1
2

> 3 ft + 4 in to mm
1016 mm

Commands

help

Type help for a list of commands.

import

Import and evaluate the contents of the script editor using import.

Script block:

x = 1
y = 5
x=1 => 1
y=5 => 5
NO ERRORS

Terminal:

> import
Importing...
Import complete.

> x + y
5

This feature is unavailable inside a fullscreen terminal.

clear

Clear the contents of the terminal and any imported scope with clear.

Keys

When in the terminal, all key strokes are captures. Script editor shortcuts will be disabled.

KeyAction
EnterEvaluate command.
Cycle back through history of commands.
Cycle forward through history of commands.

Syntax

Arithmetic

Perform basic addition, subtraction, multiplication, and division:

1+1 => 2
NO ERRORS
2*3-16/4 => 2
NO ERRORS

Variables

Assign numbers, units, strings, and arrays to variables:

a=4 => 4
10*a => 40
NO ERRORS

Hide output

End a line in a semi colon ; to hide it from the output. The expression is still rendered. Reports printed or exported to PDF will not show the original script.

1 + 2;
2 + 4
2+4 => 6
NO ERRORS

Functions

See Functions for a list.

abs(-20) => 20
mean([1,5,9,10,15]) => 8
NO ERRORS

Define custom functions:

f(a,b,c)=a+b*c => f(a, b, c)
f(1,2,3) => 7
NO ERRORS

Help

Use help() to get more information on a function, constant, or datatype inside a script or a terminal:

help(pi) => Name: pi Category: Constants Description: The number pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, and is approximately equal to 3.14159 Syntax: pi Examples: pi 3.1415926535898 sin(pi/2) 1 See also: tau
NO ERRORS

Data types

Numbers

Numbers and fractions are 64 bits in size with up to 15 digits of significant figures.

1+1e-14 => 1.00000000000001
NO ERRORS

Units

Most units of measure are accepted, plus abbreviations and common pluralities. Submit a request for additional units or abbreviations.

1in+1mm => 1.03937 in
NO ERRORS
1200N+1300lbftokip => 1.56977 kip
NO ERRORS
12g/40mLtokg/m^3 => 300 kg / m^3
NO ERRORS
3kg*9.81m/s^2tolbf => 6.61613 lbf
NO ERRORS
1yeartodays => 365.25 days
NO ERRORS
120V/15A => 8 ohm
NO ERRORS

Convert units with to or in. Do this at the end of any expression.

1ft+3intomm => 381 mm
NO ERRORS
1ft+3ininmm => 381 mm
NO ERRORS

Comments

Comments are prefixed with #. They do not appear in the output.

# At the beginning of a line
speed = 30 m/s to mph # At the end of a line
speed=30m/stomph => 67.1081 mph
NO ERRORS

Strings

Strings are defined on their own line with "double quotes". They will appear in the output in paragraph form.

"I show up in the output"
# But this doesn't
I show up in the output
NO ERRORS

Strings may be assigned to variables.

Matrices

Matrices are multi-dimensional list of other types. See matrix functions

oneD=[1,2,3,4] => [1, 2, 3, 4]
twoD=[[1mm,2mm],[3in,4in]] => [[1 mm, 2 mm], [3 in, 4 in]]
NO ERRORS

Dimensions

Definition

Dimensions (Dim) are a value with a tolerance. Length, volume, or any other type may be used. There are several ways to create a Dim, but the final data structure is normalized to center ± tolerance.

dim(nominal, tolerance)
dim(1gal,1cup) => 1 gal ± 1 cup
dim(3V) => 3 V ± 0 V
bilateral(nominal, deviation1, deviation2)
bilateral(10mm,0.5mm,-0.25mm) => 10.125 mm ± 0.375 mm
bilateral(10mm,-0.25mm,0.5mm) => 10.125 mm ± 0.375 mm
bilateral(10mm,2mm,4mm) => 13 mm ± 1 mm
limit(limit1, limit2):
limit(3,3.1) => 3.05 ± 0.05
NO ERRORS

Dim expressions

Add and subtract dimensions to get the cumulative uncertainty of the stack:

a=dim(1mm,0.01mm) => 1 mm ± 10 um
b=dim(2mm,0.1mm) => 2 mm ± 0.1 mm
a+b => 3 mm ± 0.11 mm
NO ERRORS

Multiplication of Dims is also supported:

a*b => 2 mm^2 ± 0.12 mm^2
3*b => 6 mm ± 0.3 mm
NO ERRORS

Division is currently only supported with scalars at this time:

a/2 => 0.5 mm ± 5 um
NO ERRORS
amps = dim(3 A, 30 mA);
volts = dim(120 V, 10 V);
amps / volts
Unexpected type of argument in function divide (expected: number or bigint or string or boolean or Array or Matrix, actual: Dim, index: 1)

Dim functions

There are several functions compatible with Dim types:

c=dim(1lbf,0.1lbf) => 1 lbf ± 0.1 lbf
Get the nominal (center) value:
nom(c) => 1 lbf
Get the plus/minus tolerance value:
tol(c) => 0.1 lbf
Get the upper service limit (max):
USL(c) => 1.1 lbf
Get the lower service limit (min):
LSL(c) => 0.9 lbf
NO ERRORS

Script Library

NameURL
TutorialURL
Inflation calculatorURL
Metric 6g6g thread profile tolerances per ISOURL

Units of Measure

Base Units

TypeUnits
Lengthmeter (m), inch (in), foot (ft), yard (yd), mile (mi), link (li), rod (rd), chain (ch), angstrom, mil
Surface aream², sqin, sqft, sqyd, sqmi, sqrd, sqch, sqmil, acre, hectare
Volumem³, liter (l, L, lt, liter), cc, cuin, cuft, cuyd, teaspoon, tablespoon
Liquid volumeminim, fluiddram (fldr), fluidounce (floz), gill (gi), cup (cp), pint (pt), quart (qt), gallon (gal), tsp, tbsp, beerbarrel (bbl), oilbarrel (obl), hogshead, drop (gtt)
Anglesrad (radian), deg (degree), grad (gradian), cycle, arcsec (arcsecond), arcmin (arcminute)
Timesecond (s, secs, seconds), minute (min, mins, minutes), hour (h, hr, hrs, hours), day (days), week (weeks), fortnight, month (months), year (years), decade (decades), century (centuries), millennium (millennia)
Frequencyhertz (Hz)
Massgram (g), tonne, ton, grain (gr), dram (dr), ounce (oz), poundmass (lbm, lb, lbs), hundredweight (cwt), slug (slugs), slinch (slinches, blob, blobs), stick, stone
Electric currentampere (A)
Temperaturekelvin (K), celsius (degC), fahrenheit (degF), rankine (degR)
Amount of substancemole (mol)
Luminous intensitycandela (cd)
Forcenewton (N), dyne (dyn), poundforce (lbf), kip
Energyjoule (J), erg, Wh, BTU, electronvolt (eV)
Powerwatt (W), hp
PressurePa, psi, ksi, atm, torr, bar, mmHg, mmH₂O, cmH₂O
Electromagnetismampere (A), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV)
Binarybits (b), bytes (B)
Surface Densitygsm
Speedmph

Prefixes

Add prefixes to base units:

3mm+40um => 3.04 mm
NO ERRORS
(1000Mb/s)/(56kb/s) => 17857.1
NO ERRORS

Metric Prefixes (Positive Powers)

NameAbbreviationValue
decada1e1
hectoh1e2
kilok1e3
megaM1e6
gigaG1e9
teraT1e12
petaP1e15
exaE1e18
zettaZ1e21
yottaY1e24
ronnaR1e27
quettaQ1e30

Metric Prefixes (Negative Powers)

NameAbbreviationValue
decid1e-1
centic1e-2
millim1e-3
microu1e-6
nanon1e-9
picop1e-12
femtof1e-15
attoa1e-18
zeptoz1e-21
yoctoy1e-24
rontor1e-27
quectoq1e-30

Binary Prefixes

NameAbbreviationValue
kibiKi1024
mebiMi1024²
gibiGi1024³
tebiTi1024⁴
pebiPi1024⁵
exiEi1024⁶
zebiZi1024⁷
yobiYi1024⁸

Decimal Prefixes for Binary Units

NameAbbreviationValue
kilok1e3
megaM1e6
gigaG1e9
teraT1e12
petaP1e15
exaE1e18
zettaZ1e21
yottaY1e24

Constants

Universal Constants

NameSymbolValueUnit
speedOfLightc299792458m · s⁻¹
gravitationConstantG6.6738480e-11m³ · kg⁻¹ · s⁻²
planckConstanth6.626069311e-34J · s
reducedPlanckConstantħ1.05457172647e-34J · s

Electromagnetic Constants

NameSymbolValueUnit
magneticConstantμ1.2566370614e-6N · A
electricConstantε8.854187817e-12F · m
vacuumImpedanceZ376.730313461Ω
coulombκ8.9875517873681764e9N · m · C
elementaryChargee1.60217656535e-19C
bohrMagnetonμ9.2740096820e-24J · T
conductanceQuantumG7.748091734625e-5S
inverseConductanceQuantumG12906.403721742Ω
magneticFluxQuantumf2.06783375846e-15Wb
nuclearMagnetonμ5.0507835311e-27J · T
klitzingR25812.807443484Ω

Atomic and Nuclear Constants

NameSymbolValueUnit
bohrRadiusa5.291772109217e-11m
classicalElectronRadiusr2.817940326727e-15m
electronMassm9.1093829140e-31kg
fermiCouplingG1.1663645e-5GeV
fineStructureα7.297352569824e-3-
hartreeEnergyE4.3597443419e-18J
protonMassm1.67262177774e-27kg
deuteronMassm3.3435830926e-27kg
neutronMassm1.6749271613e-27kg
quantumOfCirculationh / (2m)3.636947552024e-4m · s
rydbergR10973731.56853955m
thomsonCrossSection-6.65245873413e-29m
weakMixingAngle-0.222321-
efimovFactor-22.7-

Physico-Chemical Constants

NameSymbolValueUnit
atomicMassm1.66053892173e-27kg
avogadroN6.0221412927e23mol
boltzmannk1.380648813e-23J · K
faradayF96485.336521C · mol
firstRadiationc3.7417715317e-16W · m
loschmidt1n2.686780524e25m
gasConstantR8.314462175J · K · mol
molarPlanckConstantN · h3.990312717628e-10J · s · mol
molarVolume1V2.241396820e-10m · mol
sackurTetrode2--1.164870823-
secondRadiationc1.438777013e-2m · K
stefanBoltzmannσ5.67037321e-8W · m · K
wienDisplacementb2.897772126e-3m · K

Adopted Values

NameSymbolValueUnit
molarMassM1e-3kg · mol
molarMassC12M(C)1.2e-2kg · mol
gravityg9.80665m · s
atmatm101325Pa

Natural Units

NameSymbolValueUnit
planckLengthl1.61619997e-35m
planckMassm2.1765113e-8kg
planckTimet5.3910632e-44s
planckChargeq1.87554595641e-18C
planckTemperatureT1.41683385e+32K

Functions

Algebric functions

FunctionDescription
leafCount(expr)Gives the number of “leaf nodes” in the parse tree of the given expression.
lsolve(L, b)Finds one solution of a linear equation system by forwards substitution.
lsolveAll(L, b)Finds all solutions of a linear equation system by forwards substitution.
lup(A)Calculate the Matrix LU decomposition with partial pivoting.
lusolve(A, b)Solves the linear system A * x = b where A is an [n x n] matrix and b is a [n] column vector.
lyap(A, Q)Solves the Continuous-time Lyapunov equation A*P + P*A' + Q = 0 for P, where Q is an input matrix.
polynomialRoot(constant, linearCoeff, quadraticCoeff, cubicCoeff)Finds the numerical values of the distinct roots of a polynomial with real or complex coefficients.
qr(A)Calculate the Matrix QR decomposition.
rationalize(expr)Transform a rationalizable expression into a rational fraction.
resolve(expr, scope)Replaces variable nodes with their scoped values.
schur(A)Performs a real Schur decomposition of the real matrix A = U*T*U' where U is orthogonal and T is upper quasi-triangular.

Arithmetic functions

FunctionDescription
abs(x)Calculate the absolute value of a number.
add(x, y)Add two or more values, x + y.
cbrt(x [, allRoots])Calculate the cubic root of a value.
ceil(x)Round a value towards plus infinity. If x is complex, both real and imaginary parts are rounded towards plus infinity.
cube(x)Compute the cube of a value, x * x * x.
divide(x, y)Divide two values, x / y.
dotDivide(x, y)Divide two matrices element-wise.
dotMultiply(x, y)Multiply two matrices element-wise.
dotPow(x, y)Calculates the power of x to y element-wise.
exp(x)Calculate the exponential of a value.
expm1(x)Calculate the value of subtracting 1 from the exponential value.
fix(x)Round a value towards zero.
floor(x)Round a value towards minus infinity.
gcd(a, b)Calculate the greatest common divisor for two or more values or arrays.
hypot(a, b, …)Calculate the hypotenuse of a list with values.
invmod(a, b)Calculate the (modular) multiplicative inverse of a modulo b.
lcm(a, b)Calculate the least common multiple for two or more values or arrays.
log(x [, base])Calculate the logarithm of a value.
log10(x)Calculate the 10-base logarithm of a value.
log1p(x)Calculate the logarithm of a value + 1.
log2(x)Calculate the 2-base logarithm of a value.
mod(x, y)Calculates the modulus, the remainder of an integer division.
multiply(x, y)Multiply two or more values, x * y.
norm(x [, p])Calculate the norm of a number, vector, or matrix.
nthRoot(a)Calculate the nth root of a value.
nthRoots(x)Calculate the nth roots of a value.
pow(x, y)Calculates the power of x to y, x ^ y.
round(x [, n])Round a value towards the nearest rounded value.
sign(x)Compute the sign of a value.
sqrt(x)Calculate the square root of a value.
square(x)Compute the square of a value, x * x.
subtract(x, y)Subtract two values, x - y.
unaryMinus(x)Inverse the sign of a value, apply a unary minus operation.
unaryPlus(x)Unary plus operation.
xgcd(a, b)Calculate the extended greatest common divisor for two values.

Bitwise functions

FunctionDescription
bitAnd(x, y)Bitwise AND two values, x & y.
bitNot(x)Bitwise NOT value, ~x.
bitOr(x, y)Bitwise OR two values, x | y.
bitXor(x, y)Bitwise XOR two values, x ^ y.
leftShift(x, y)Bitwise left logical shift of a value x by y number of bits, x << y.
rightArithShift(x, y)Bitwise right arithmetic shift of a value x by y number of bits, x >> y.
rightLogShift(x, y)Bitwise right logical shift of a value x by y number of bits, x >>> y.

Calculus functions

FunctionDescription
derivative(expr, variable)Takes the derivative of an expression expressed in parser Nodes.
integrate(expr, a, b)Computes the definite integral of an expression from a to b.
limit(expr, variable, value)Computes the limit of an expression as the variable approaches value.
numericalDerivative(expr, h)Computes the numerical derivative of an expression with step size h.
numericalIntegrate(expr, a, b)Computes the numerical integral of an expression from a to b.

Combinatoric functions

FunctionDescription
bellNumbers(n)The Bell Numbers count the number of partitions of a set.
catalan(n)The Catalan Numbers enumerate combinatorial structures of many different types.
composition(n, k)The composition counts of n into k parts.
stirlingS2(n, k)The Stirling numbers of the second kind count the number of ways to partition a set of n labeled objects into k nonempty unlabeled subsets.

Complex functions

FunctionDescription
arg(x)Compute the argument of a complex value.
conj(x)Compute the complex conjugate of a complex value.
im(x)Get the imaginary part of a complex number.
re(x)Get the real part of a complex number.

Geometric functions

FunctionDescription
collinear(A, B, C)Tests if points A, B, C are collinear (i.e., lie on a straight line).
cross(A, B)Computes the cross product of two 3D vectors A and B.
distance(A, B)Computes the distance between two points A and B.
dot(A, B)Computes the dot product of two vectors A and B.
intersect(A, B)Computes the intersection point of two lines, if they exist.
midpoint(A, B)Computes the midpoint between two points A and B.
perpendicular(A, B)Computes the perpendicular of a vector B with respect to vector A.
reflect(A, B)Computes the reflection of a vector A across vector B.
rotate(A, theta)Rotates a vector A by an angle theta.
scale(A, factor)Scales a vector A by a given factor.
translate(A, dx, dy)Translates a point A by distances dx and dy.

Linear algebric functions

FunctionDescription
cholesky(A)Performs the Cholesky decomposition on matrix A.
eigen(A)Computes the eigenvalues and eigenvectors of matrix A.
inv(A)Computes the inverse of matrix A, if it exists.
lu(A)Computes the LU decomposition of matrix A.
rank(A)Computes the rank of matrix A.
svd(A)Computes the Singular Value Decomposition of matrix A.
trace(A)Computes the trace (sum of diagonal elements) of matrix A.
transpose(A)Computes the transpose of matrix A.
vecnorm(A)Computes the vector norm (Euclidean distance) of a vector A.
vander(x)Computes the Vandermonde matrix of a vector x.

Logical functions

FunctionDescription
and(x, y)Logical AND.
not(x)Logical NOT.
or(x, y)Logical OR.
xor(x, y)Logical XOR.

Matrix functions

See matrices.

FunctionDescription
add(A, B)Adds two matrices A and B.
subtract(A, B)Subtracts matrix B from matrix A.
multiply(A, B)Multiplies matrix A by matrix B.
elementwiseMultiply(A, B)Performs element-wise multiplication of two matrices A and B.
divide(A, B)Divides matrix A by matrix B element-wise.
determinant(A)Computes the determinant of matrix A.
inverse(A)Computes the inverse of matrix A.
adjoint(A)Computes the adjoint (or adjugate) matrix of A.
transpose(A)Computes the transpose of matrix A.
diagonal(A)Extracts the diagonal elements of matrix A as a vector.

Numeric functions

FunctionDescription
solveODE(func, tspan, y0)Numerical integration of Ordinary Differential Equations. See more

Probability functions

FunctionDescription
combinations(n, k)Compute the number of ways of picking k unordered outcomes from n possibilities.
combinationsWithRep(n, k)Compute the number of ways of picking k unordered outcomes from n possibilities, allowing individual outcomes to be repeated more than once.
factorial(n)Compute the factorial of a value. Factorial only supports an integer value as an argument.
gamma(n)Compute the gamma function of a value using Lanczos approximation for small values and an extended Stirling approximation for large values.
kldivergence(x, y)Calculate the Kullback-Leibler (KL) divergence between two distributions.
lgamma(n)Logarithm of the gamma function for real, positive numbers and complex numbers, using Lanczos approximation for numbers and Stirling series for complex numbers.
multinomial(a)Multinomial coefficients compute the number of ways of picking values a1, a2, …
permutations(n [, k])Compute the number of ways of obtaining an ordered subset of k elements from a set of n elements.
pickRandom(array)Randomly pick one or more values from a one-dimensional array.
random([min, max])Return a random number larger or equal to min and smaller than max using a uniform distribution.
randomInt([min, max])Return a random integer larger or equal to min and smaller than max using a uniform distribution.

Relational functions

FunctionDescription
compare(x, y)Compare two values.
compareNatural(x, y)Compare two values of any type in a deterministic, natural way.
compareText(x, y)Compare two strings lexically.
deepEqual(x, y)Test element-wise whether two matrices are equal.
equal(x, y)Test whether two values are equal.
equalText(x, y)Check equality of two strings.
larger(x, y)Test whether value x is larger than y.
largerEq(x, y)Test whether value x is larger or equal to y.
smaller(x, y)Test whether value x is smaller than y.
smallerEq(x, y)Test whether value x is smaller or equal to y.
unequal(x, y)Test whether two values are unequal.

Set functions

FunctionDescription
setCartesian(set1, set2)Create the cartesian product of two (multi)sets.
setDifference(set1, set2)Create the difference of two (multi)sets: every element of set1, that is not the element of set2.
setDistinct(set)Collect the distinct elements of a multiset.
setIntersect(set1, set2)Create the intersection of two (multi)sets.
setIsSubset(set1, set2)Check whether a (multi)set is a subset of another (multi)set.
setMultiplicity(element, set)Count the multiplicity of an element in a multiset.
setPowerset(set)Create the powerset of a (multi)set.
setSize(set)Count the number of elements of a (multi)set.
setSymDifference(set1, set2)Create the symmetric difference of two (multi)sets.
setUnion(set1, set2)Create the union of two (multi)sets.

Signal functions

FunctionDescription
freqz(b, a)Calculates the frequency response of a filter given its numerator (b) and denominator (a) coefficients.
zpk2tf(z, p, k)Compute the transfer function of a zero-pole-gain model with zero (z), pole (p), and gain (k).

Special functions

FunctionDescription
erf(x)Compute the erf function of a value using rational Chebyshev approximations for different intervals of x.
zeta(n)Compute the Riemann Zeta function of a value using an infinite series for all of the complex plane using Riemann’s Functional equation.

Statistics functions

FunctionDescription
mean(values)Computes the mean (average) of a list of values.
median(values)Computes the median of a list of values.
mode(values)Computes the mode (most frequent value) of a list of values.
variance(values)Computes the variance of a list of values.
stddev(values)Computes the standard deviation of a list of values.
covariance(values1, values2)Computes the covariance between two lists of values.
correlation(values1, values2)Computes the correlation coefficient between two lists of values.
regression(values1, values2)Computes the linear regression of two lists of values.
skewness(values)Computes the skewness (degree of asymmetry) of a list of values.
kurtosis(values)Computes the kurtosis (peakedness) of a list of values.

Trigonometry functions

FunctionDescription
acos(x)Calculate the inverse cosine of a value.
acosh(x)Calculate the hyperbolic arccos of a value, defined as acosh(x) = ln(sqrt(x^2 - 1) + x).
acot(x)Calculate the inverse cotangent of a value, defined as acot(x) = atan(1/x).
acoth(x)Calculate the inverse hyperbolic tangent of a value, defined as acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2.
acsc(x)Calculate the inverse cosecant of a value, defined as acsc(x) = asin(1/x).
acsch(x)Calculate the inverse hyperbolic cosecant of a value, defined as acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1)).
asec(x)Calculate the inverse secant of a value.
asech(x)Calculate the hyperbolic arcsecant of a value, defined as asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x).
asin(x)Calculate the inverse sine of a value.
asinh(x)Calculate the hyperbolic arcsine of a value, defined as asinh(x) = ln(x + sqrt(x^2 + 1)).
atan(x)Calculate the inverse tangent of a value.
atan2(y, x)Calculate the inverse tangent function with two arguments, y/x.
atanh(x)Calculate the hyperbolic arctangent of a value, defined as atanh(x) = ln((1 + x)/(1 - x)) / 2.
cos(x)Calculate the cosine of a value.
cosh(x)Calculate the hyperbolic cosine of a value, defined as cosh(x) = 1/2 * (exp(x) + exp(-x)).
cot(x)Calculate the cotangent of a value.
coth(x)Calculate the hyperbolic cotangent of a value, defined as coth(x) = 1 / tanh(x).
csc(x)Calculate the cosecant of a value, defined as csc(x) = 1/sin(x).
csch(x)Calculate the hyperbolic cosecant of a value, defined as csch(x) = 1 / sinh(x).
sec(x)Calculate the secant of a value, defined as sec(x) = 1/cos(x).
sech(x)Calculate the hyperbolic secant of a value, defined as sech(x) = 1 / cosh(x).
sin(x)Calculate the sine of a value.
sinh(x)Calculate the hyperbolic sine of a value, defined as sinh(x) = 1/2 * (exp(x) - exp(-x)).
tan(x)Calculate the tangent of a value.
tanh(x)Calculate the hyperbolic tangent of a value, defined as tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1).

Utility functions

FunctionDescription
clone(x)Clone an object.
hasNumericValue(x)Test whether a value is a numeric value.
isInteger(x)Test whether a value is an integer number.
isNaN(x)Test whether a value is NaN (not a number).
isNegative(x)Test whether a value is negative: smaller than zero.
isNumeric(x)Test whether a value is a numeric value.
isPositive(x)Test whether a value is positive: larger than zero.
isPrime(x)Test whether a value is prime: has no divisors other than itself and one.
isZero(x)Test whether a value is zero.
numeric(x)Convert a numeric input to a specific numeric type: number, BigNumber, bigint, or Fraction.
typeOf(x)Determine the type of an entity.

Philosophy

Introduction

Opinion as of November 2024

Units are an afterthought in most calculators, programming languages, and computer-aid engineering (CAE) tools. Web forms might have a drop-down that lets you set one of two units systems for the entire form. Programming languages have adopted libraries that add units support; however, the syntaxes are verbose, lack abbreviations and colloquial equivalents, all while having to deal with boiler plate and extra dependencies. CAE tools have come the closest to creating natural and native units-supported environments, but it comes at the cost of proprietary file formats and licensing costs.

We have learned to work with what we have though. You can apply dimensional analysis techniques from grade school, download a phone app that converts inches to millimeters with voice commands, enforce everyone in your organization to adhere to a strict units system, or hope that the Ti-83 is just right.

To make a parallel to programming, units are like types. Types are a system for making expectations. You flag variables, functions, etc. with a specific form, and when they are used incorrectly, you get errors. 1 fortnight + 100 miles would result in an error.

The biggest barrier to types is that they are verbose. To demonstrate the differences in syntax among common languages, let’s evaluate 1 mm + 1 inch then convert to feet:

AI Generated

The following code was created with assistance from Chat GPT. Please help me correct this here.

Language comparison

C++

#include <boost/units/systems/si/length.hpp>
#include <boost/units/systems/us/length.hpp>
#include <boost/units/conversion.hpp>

auto a = boost::units::quantity<boost::units::si::length>((1.0 * boost::units::si::millimeters) + (1.0 * boost::units::us::inches)).value() / boost::units::us::feet;

C#

using UnitsNet;
double a = (Length.FromMillimeters(1) + Length.FromInches(1)).Feet;

Excel

=CONVERT(1, "mm", "ft") + CONVERT(1, "in", "ft")

Fortran

use physunits
a = (1.0_mm + 1.0_inch) / 1.0_ft

Go

import ("gonum.org/v1/gonum/unit")
a := (1*unit.Millimeter + 1*unit.Inch).To(unit.Foot)

Julia

using Unitful
a = 1u"mm" + 1u"in" |> u"ft"

Maple

with(Units[Simple]):
a := Convert(1*Unit('mm') + 1*Unit('in'), 'ft');

MATLAB

u = symunit;
a = unitConvert(1*u.mm + 1*u.in, u.ft);

Mathematica

a = UnitConvert[Quantity[1, "Millimeters"] + Quantity[1, "Inches"], "Feet"]

Python

from pint import UnitRegistry
ureg = UnitRegistry()
a = (1 * ureg.mm + 1 * ureg.inch).to(ureg.ft)

R

library(units)
a <- set_units(1, mm) + set_units(1, inch)
a <- set_units(a, ft)

Rust

use uom::si::length::millimeter;
use uom::si::length::inch;
use uom::si::length::foot;

let a = (1.0 * millimeter::MILLIMETER + 1.0 * inch::INCH).get::<foot::FOOT>();

Swift

import SwiftUnits
let a = (1 * UnitLength.millimeters + 1 * UnitLength.inches).converted(to: .feet)

MathJS

Or you could do:

1mm+1inchinfeet => 0.0866 feet
NO ERRORS

Or maybe:

1mm+1inchestofeet => 0.0866 feet
1millimeters+1ininft => 0.0866 ft
NO ERRORS

MathJS began development in early 2013. The library features a simple language syntax and extensible core library.

In 2024, Apple launched several features across its devices that it calls Math Notes, which adds a math solver with units support to various parts of the operating systems. You’ll notice the syntax is essentially identical, and I think that’s to be embraced.

Units work for you when using them is as easy as 1 mm + 1 in. Simple syntax tooling is not always appropriate, but it’s worth investigating.

Privacy

All inputs are encrypted using Transport Layer Security (TLS) over HTTPS. Never send sensitive information. Radian R&D does not retain logs of usage but Cloudflare may for a period of time. Using the short link functionality subjects you to this additional privacy notice.

Disclosures

WARNING

This software is in an alpha release state and is provided as-is without warranty. Please report bugs here. The documentation lags functionality at the moment.

THANK YOU

Radian R&D proudly sponsors MathJS.

Footnotes

  1. The values of loschmidt and molarVolume are at T = 273.15 K and p = 101.325 kPa. 2

  2. The value of sackurTetrode is at T = 1 K and p = 101.325 kPa.

Table of Contents