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.
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 theShare
link and server info.Tutorial
- Opens a tutorial script in a new tab.
Keyboard shortcuts
Windows | Mac | Shortcut |
---|---|---|
Ctrl + Enter | ⌘ + Enter | Evaluate script |
Ctrl + + | ⌘ + + | Zoom in |
Ctrl + - | ⌘ + - | Zoom out |
Ctrl + P | ⌘ + P | Print 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:
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.
Key | Action |
---|---|
Enter | Evaluate command. |
↑ | Cycle back through history of commands. |
↓ | Cycle forward through history of commands. |
Syntax
Arithmetic
Perform basic addition, subtraction, multiplication, and division:
Variables
Assign numbers, units, strings, and arrays to variables:
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.
Functions
See Functions for a list.
Define custom functions:
Help
Use help()
to get more information on a function, constant, or datatype inside
a script or a terminal:
Data types
Numbers
Numbers and fractions are 64 bits in size with up to 15 digits of significant figures.
Units
Most units of measure are accepted, plus abbreviations and common pluralities. Submit a request for additional units or abbreviations.
Convert units with to
or in
. Do this at the end of any expression.
Comments
Comments are prefixed with #
. They do not appear in the output.
Strings
Strings are defined on their own line with "double quotes"
. They will appear
in the output in paragraph form.
Strings may be assigned to variables.
Matrices
Matrices are multi-dimensional list of other types. See matrix functions
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 expressions
Add and subtract dimensions to get the cumulative uncertainty of the stack:
Multiplication of Dims is also supported:
Division is currently only supported with scalars at this time:
Dim functions
There are several functions compatible with Dim types:
Units of Measure
Base Units
Type | Units |
---|---|
Length | meter (m), inch (in), foot (ft), yard (yd), mile (mi), link (li), rod (rd), chain (ch), angstrom, mil |
Surface area | m^2 (m2), sqin, sqft, sqyd, sqmi, sqrd, sqch, sqmil, acre, hectare |
Volume | m^3 (m3), liter (l, L, lt, liter), cc, cuin, cuft, cuyd, teaspoon, tablespoon |
Liquid volume | minim, fluiddram (fldr), fluidounce (floz), gill (gi), cup (cp), pint (pt), quart (qt), gallon (gal), tsp, tbsp, tad, dash, pinch, beerbarrel (bbl), oilbarrel (obl), hogshead, drop (gtt) |
Angles | rad (radian), deg (degree), grad (gradian), cycle, arcsec (arcsecond), arcmin (arcminute) |
Time | second (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) |
Frequency | hertz (Hz) |
Mass | gram (g), tonne, ton, grain (gr), dram (dr), ounce (oz), poundmass (lbm, lb, lbs), hundredweight (cwt), slug (slugs), slinch (slinches, blob, blobs), stick, stone |
Electric current | ampere (A) |
Temperature | kelvin (K), celsius (degC), fahrenheit (degF), rankine (degR) |
Amount of substance | mole (mol) |
Luminous intensity | candela (cd) |
Force | newton (N), dyne (dyn), poundforce (lbf), kip |
Energy | joule (J), erg, Wh, BTU, electronvolt (eV) |
Power | watt (W), hp |
Pressure | Pa, psi, ksi, atm, torr, bar, mmHg, mmH2O, cmH2O |
Electromagnetism | ampere (A), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV) |
Binary | bits (b), bytes (B) |
Surface Density | gsm |
Speed | mph |
Prefixes
Add prefixes to base units:
Metric Prefixes (Positive Powers)
Name | Abbreviation | Value |
---|---|---|
deca | da | 1e1 |
hecto | h | 1e2 |
kilo | k | 1e3 |
mega | M | 1e6 |
giga | G | 1e9 |
tera | T | 1e12 |
peta | P | 1e15 |
exa | E | 1e18 |
zetta | Z | 1e21 |
yotta | Y | 1e24 |
ronna | R | 1e27 |
quetta | Q | 1e30 |
Metric Prefixes (Negative Powers)
Name | Abbreviation | Value |
---|---|---|
deci | d | 1e-1 |
centi | c | 1e-2 |
milli | m | 1e-3 |
micro | u | 1e-6 |
nano | n | 1e-9 |
pico | p | 1e-12 |
femto | f | 1e-15 |
atto | a | 1e-18 |
zepto | z | 1e-21 |
yocto | y | 1e-24 |
ronto | r | 1e-27 |
quecto | q | 1e-30 |
Binary Prefixes
Name | Abbreviation | Value |
---|---|---|
kibi | Ki | 1024 |
mebi | Mi | 1024² |
gibi | Gi | 1024³ |
tebi | Ti | 1024⁴ |
pebi | Pi | 1024⁵ |
exi | Ei | 1024⁶ |
zebi | Zi | 1024⁷ |
yobi | Yi | 1024⁸ |
Decimal Prefixes for Binary Units
Name | Abbreviation | Value |
---|---|---|
kilo | k | 1e3 |
mega | M | 1e6 |
giga | G | 1e9 |
tera | T | 1e12 |
peta | P | 1e15 |
exa | E | 1e18 |
zetta | Z | 1e21 |
yotta | Y | 1e24 |
Constants
Universal Constants
Name | Symbol | Value | Unit |
---|---|---|---|
speedOfLight | c | 299792458 | m · s⁻¹ |
gravitationConstant | G | 6.6738480e-11 | m³ · kg⁻¹ · s⁻² |
planckConstant | h | 6.626069311e-34 | J · s |
reducedPlanckConstant | ħ | 1.05457172647e-34 | J · s |
Electromagnetic Constants
Name | Symbol | Value | Unit |
---|---|---|---|
magneticConstant | μ | 1.2566370614e-6 | N · A |
electricConstant | ε | 8.854187817e-12 | F · m |
vacuumImpedance | Z | 376.730313461 | Ω |
coulomb | κ | 8.9875517873681764e9 | N · m |
elementaryCharge | e | 1.60217656535e-19 | C |
bohrMagneton | μ | 9.2740096820e-24 | J · T |
conductanceQuantum | G | 7.748091734625e-5 | S |
inverseConductanceQuantum | G | 12906.403721742 | Ω |
magneticFluxQuantum | f | 2.06783375846e-15 | Wb |
nuclearMagneton | μ | 5.0507835311e-27 | J · T |
klitzing | R | 25812.807443484 | Ω |
Atomic and Nuclear Constants
Name | Symbol | Value | Unit |
---|---|---|---|
bohrRadius | a | 5.291772109217e-11 | m |
classicalElectronRadius | r | 2.817940326727e-15 | m |
electronMass | m | 9.1093829140e-31 | kg |
fermiCoupling | G | 1.1663645e-5 | GeV |
fineStructure | α | 7.297352569824e-3 | - |
hartreeEnergy | E | 4.3597443419e-18 | J |
protonMass | m | 1.67262177774e-27 | kg |
deuteronMass | m | 3.3435830926e-27 | kg |
neutronMass | m | 1.6749271613e-27 | kg |
quantumOfCirculation | h / (2m | 3.636947552024e-4 | m |
rydberg | R | 10973731.56853955 | m |
thomsonCrossSection | - | 6.65245873413e-29 | m |
weakMixingAngle | - | 0.222321 | - |
efimovFactor | - | 22.7 | - |
Physico-Chemical Constants
Name | Symbol | Value | Unit |
---|---|---|---|
atomicMass | m | 1.66053892173e-27 | kg |
avogadro | N | 6.0221412927e23 | mol |
boltzmann | k | 1.380648813e-23 | J · K |
faraday | F | 96485.336521 | C · mol |
firstRadiation | c | 3.7417715317e-16 | W · m |
loschmidt1 | n | 2.686780524e25 | m |
gasConstant | R | 8.314462175 | J · K |
molarPlanckConstant | N | 3.990312717628e-10 | J · s · mol |
molarVolume1 | V | 2.241396820e-10 | m |
sackurTetrode2 | - | -1.164870823 | - |
secondRadiation | c | 1.438777013e-2 | m · K |
stefanBoltzmann | σ | 5.67037321e-8 | W · m |
wienDisplacement | b | 2.897772126e-3 | m · K |
Adopted Values
Name | Symbol | Value | Unit |
---|---|---|---|
molarMass | M | 1e-3 | kg · mol |
molarMassC12 | M( | 1.2e-2 | kg · mol |
gravity | g | 9.80665 | m · s |
atm | atm | 101325 | Pa |
Natural Units
Name | Symbol | Value | Unit |
---|---|---|---|
planckLength | l | 1.61619997e-35 | m |
planckMass | m | 2.1765113e-8 | kg |
planckTime | t | 5.3910632e-44 | s |
planckCharge | q | 1.87554595641e-18 | C |
planckTemperature | T | 1.41683385e+32 | K |
Functions
Algebric functions
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
and(x , y ) | Logical AND. |
not(x ) | Logical NOT. |
or(x , y ) | Logical OR. |
xor(x , y ) | Logical XOR. |
Matrix functions
See matrices.
Function | Description |
---|---|
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
Function | Description |
---|---|
solveODE(func , tspan , y0 ) | Numerical integration of Ordinary Differential Equations. See more |
Probability functions
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
Function | Description |
---|---|
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
:
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:
Or maybe:
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
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.
Radian R&D proudly sponsors MathJS.